author | Claus Gittinger <cg@exept.de> |
Sun, 23 Jan 2011 15:33:06 +0100 | |
changeset 3995 | 4917660dba28 |
parent 3981 | d6cb72181559 |
child 3996 | 4ef9b35afcdc |
permissions | -rw-r--r-- |
422 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2935
e3fa9d1a7a64
Moved ColorMenu and FontMenu from libtool2
Stefan Vogel <sv@exept.de>
parents:
2704
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
1803 | 13 |
|
412 | 14 |
MenuPanel subclass:#ColorMenu |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
15 |
instanceVariableNames:'enabledChannel labelsAreColored color colorName |
3981 | 16 |
allowSymbolicColors showDefaultToggle acceptAction |
17 |
useDefaultColorToggleVisibleHolder' |
|
3322 | 18 |
classVariableNames:'ColorMenuSpec RecentlyUsedColors' |
412 | 19 |
poolDictionaries:'' |
20 |
category:'Interface-UIPainter' |
|
21 |
! |
|
22 |
||
23 |
!ColorMenu class methodsFor:'documentation'! |
|
24 |
||
422 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
||
39 |
! |
|
40 |
||
412 | 41 |
documentation |
42 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
43 |
A simple ColorMenu used by the UIPainter |
412 | 44 |
|
45 |
[see also:] |
|
46 |
UIPainter |
|
47 |
ColorMenuSpec |
|
422 | 48 |
|
49 |
[author:] |
|
50 |
Claus Atzkern |
|
412 | 51 |
" |
52 |
! |
|
53 |
||
54 |
examples |
|
55 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
56 |
very simple example |
412 | 57 |
[exBegin] |
58 |
|tool top channel| |
|
59 |
||
60 |
top := StandardSystemView new. |
|
61 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
62 |
|
412 | 63 |
channel := (Color red) asValue. |
64 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
65 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
66 |
|
412 | 67 |
top open. |
68 |
[exEnd] |
|
69 |
" |
|
70 |
! ! |
|
71 |
||
3322 | 72 |
!ColorMenu class methodsFor:'instance creation'! |
73 |
||
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
74 |
colorMenu:labelsAreColored value:aValue |
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
75 |
"returns a color menu" |
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
76 |
|
3322 | 77 |
|menu| |
78 |
||
79 |
menu := Menu new. |
|
80 |
||
81 |
self colorMenu itemsDo:[:el| |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
82 |
menu addItem:(self resolveMenuItem:el value:aValue labelsAreColored:labelsAreColored). |
3322 | 83 |
]. |
84 |
^ menu |
|
85 |
||
86 |
" |
|
87 |
(ColorMenu colorMenu:true value:nil) startUp |
|
88 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
89 |
" |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
90 |
|
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
91 |
"Modified: / 23-01-2011 / 14:58:32 / cg" |
3322 | 92 |
! ! |
93 |
||
94 |
!ColorMenu class methodsFor:'adding & removing user defined items'! |
|
3280 | 95 |
|
3292 | 96 |
addUserDefinedColors:aColors labels:labelsOrNil title:aTitle |
3322 | 97 |
"add user colors to ALL colormenus" |
98 |
||
99 |
"cg: I think this is a bad hack, as it is too global." |
|
100 |
||
3292 | 101 |
|size submenu item label fgColor bgColor labels defLabel| |
102 |
||
103 |
submenu := self userDefinedSubmenu. |
|
104 |
size := aColors size. |
|
105 |
||
106 |
size == 0 ifTrue:[ "/ separator |
|
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
107 |
submenu addSeparator. |
3292 | 108 |
^ self |
109 |
]. |
|
110 |
||
111 |
labels := labelsOrNil ? #(). |
|
112 |
bgColor := aColors first. |
|
113 |
defLabel := ' '. |
|
114 |
||
115 |
bgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
116 |
ifFalse:[ fgColor := Color black ]. |
|
117 |
||
118 |
aTitle isEmptyOrNil ifTrue:[ label := labels at:1 ifAbsent:defLabel ] |
|
119 |
ifFalse:[ label := aTitle ]. |
|
3280 | 120 |
|
3294 | 121 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:bgColor. |
3292 | 122 |
item := MenuItem labeled:label. |
123 |
submenu addItem:item. |
|
124 |
||
125 |
size == 1 ifTrue:[ |
|
126 |
item argument:bgColor. |
|
127 |
] ifFalse:[ |
|
128 |
item submenu:(submenu := Menu new). |
|
3280 | 129 |
|
3292 | 130 |
aColors keysAndValuesDo:[:idx :aBgColor| |
131 |
aBgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
132 |
ifFalse:[ fgColor := Color black ]. |
|
133 |
||
134 |
label := labels at:idx ifAbsent:defLabel. |
|
3294 | 135 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:aBgColor. |
3292 | 136 |
item := MenuItem labeled:label. |
3293 | 137 |
item argument:aBgColor. |
3292 | 138 |
|
139 |
submenu addItem:item. |
|
140 |
]. |
|
141 |
]. |
|
3280 | 142 |
|
143 |
" |
|
3292 | 144 |
ColorMenu removeAllUserDefinedColors. |
3280 | 145 |
|
3292 | 146 |
#( |
147 |
#( Black 16r000000 ) |
|
148 |
#( Red 16rff0000 ) |
|
149 |
nil |
|
150 |
#( Rust 16rff6600 16rff8533 16rffa366 16rffc299 16rffe0cc ) |
|
151 |
#( Tangerine 16rff9933 16rffad5c 16rffc285 16rffd6ad 16rffebd6 ) |
|
152 |
#( Sunflower 16rffcc00 16rfed633 16rfee066 16rffeb99 16rfff5cc ) |
|
153 |
#( Mango 16rffcc99 16rffd6ad 16rffe0c2 16rffebd6 16rfff5eb ) |
|
154 |
#( Buttercup 16rffff66 16rffff85 16rffffa3 16rffffc2 16rffffe0 ) |
|
155 |
#( Lemon 16rffffcc 16rffffd6 16rffffe0 16rffffeb 16rfffff5 ) |
|
3280 | 156 |
|
3292 | 157 |
) do:[:aDef| |colors title labels percentage| |
158 |
aDef isEmptyOrNil ifTrue:[ |
|
159 |
colors := labels := title := nil. |
|
160 |
] ifFalse:[ |
|
161 |
title := aDef first. |
|
162 |
colors := OrderedCollection new. |
|
163 |
labels := OrderedCollection new. |
|
164 |
percentage := 100. |
|
165 |
||
166 |
aDef from:2 do:[:rgb| |
|
167 |
colors add:(Color rgbValue:rgb). |
|
168 |
labels add:('%1 %2 %%' bindWith:title with:percentage). |
|
169 |
percentage := percentage - 20. |
|
170 |
]. |
|
171 |
]. |
|
172 |
ColorMenu addUserDefinedColors:colors labels:labels title:title. |
|
3280 | 173 |
]. |
3292 | 174 |
" |
3280 | 175 |
! |
176 |
||
3283 | 177 |
removeAllUserDefinedColors |
3322 | 178 |
"flush user defined colors" |
179 |
||
3292 | 180 |
ColorMenuSpec := nil. |
3322 | 181 |
! |
182 |
||
183 |
userDefinedSubmenu |
|
184 |
"answer the menu entry under which the userdefined color entries are placed" |
|
185 |
||
186 |
|menu submenu item icon| |
|
187 |
||
188 |
menu := self colorMenu. |
|
189 |
item := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
190 |
ifNone:nil. |
|
191 |
||
192 |
item isNil ifTrue:[ |
|
3323 | 193 |
icon := ToolbarIconLibrary colorHistory16x16Icon. |
3322 | 194 |
item := MenuItem labeled:icon. |
195 |
item nameKey:#userDefined. |
|
196 |
item activeHelpKey:#userDefinedColors. |
|
197 |
menu addItem:item beforeIndex:1. |
|
198 |
]. |
|
199 |
||
200 |
(submenu := item submenu) isNil ifTrue:[ |
|
201 |
submenu := Menu new. |
|
202 |
item submenu:submenu. |
|
203 |
]. |
|
204 |
^ submenu |
|
3280 | 205 |
! ! |
206 |
||
3709 | 207 |
!ColorMenu class methodsFor:'history'! |
208 |
||
209 |
rememberRecentlyUsedColor:aColor |
|
210 |
aColor notNil ifTrue:[ |
|
211 |
RecentlyUsedColors isNil ifTrue:[ |
|
212 |
RecentlyUsedColors := OrderedCollection new. |
|
213 |
]. |
|
214 |
RecentlyUsedColors remove:aColor ifAbsent:[]. |
|
215 |
RecentlyUsedColors addFirst:aColor. |
|
216 |
RecentlyUsedColors size > 20 ifTrue:[ |
|
217 |
RecentlyUsedColors removeLast |
|
218 |
]. |
|
219 |
]. |
|
220 |
! ! |
|
221 |
||
3341 | 222 |
!ColorMenu class methodsFor:'menu specs'! |
412 | 223 |
|
3322 | 224 |
colorMenuSpec |
225 |
"color definitions used to build a color menu |
|
3292 | 226 |
" |
3322 | 227 |
" |
228 |
ColorMenuSpec := nil. |
|
229 |
" |
|
230 |
^ #( |
|
231 |
#( gray |
|
232 |
gray: |
|
233 |
#( white |
|
234 |
veryLightGray |
|
235 |
lightGray |
|
236 |
gray |
|
237 |
darkGray |
|
238 |
veryDarkGray |
|
239 |
black |
|
240 |
) |
|
241 |
) |
|
242 |
"/ nil "/ separator |
|
243 |
#( red |
|
244 |
red: |
|
3707 | 245 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 246 |
) |
247 |
#( green |
|
248 |
green: |
|
3707 | 249 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 250 |
) |
251 |
#( blue |
|
252 |
blue: |
|
3707 | 253 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 254 |
) |
255 |
"/ nil "/ separator |
|
256 |
#( cyan |
|
257 |
cyan: |
|
3707 | 258 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 259 |
) |
260 |
#( magenta |
|
261 |
magenta: |
|
3707 | 262 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 263 |
) |
264 |
#( yellow |
|
265 |
yellow: |
|
3707 | 266 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 267 |
) |
3292 | 268 |
|
3322 | 269 |
) |
3292 | 270 |
! ! |
271 |
||
272 |
!ColorMenu class methodsFor:'private'! |
|
273 |
||
3280 | 274 |
colorMenu |
3404 | 275 |
|menu menuItem subItem baseColor color label getColSel submenu colorId| |
276 |
||
3707 | 277 |
" |
278 |
ColorMenuSpec := nil |
|
279 |
" |
|
3292 | 280 |
|
3280 | 281 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
282 |
||
3404 | 283 |
menu := Menu new. |
3280 | 284 |
self colorMenuSpec do:[:aSlice| |
3404 | 285 |
menu addItem:(menuItem := MenuItem new). |
3280 | 286 |
|
287 |
aSlice notNil ifTrue:[ |
|
288 |
colorId := aSlice at:1. |
|
289 |
getColSel := aSlice at:2. |
|
290 |
baseColor := Color perform:colorId. |
|
291 |
||
3323 | 292 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
3280 | 293 |
menuItem submenu:(submenu := Menu new). |
3292 | 294 |
menuItem isButton:true. |
3404 | 295 |
menuItem activeHelpKey:('shadesOf',colorId asUppercaseFirst) asSymbol. |
3280 | 296 |
|
297 |
aSlice last do:[:el| |
|
298 |
color := label := nil. |
|
299 |
||
300 |
el isSymbol ifTrue:[ |
|
3322 | 301 |
el == #veryLight ifTrue:[ |
302 |
color := baseColor lightened lightened |
|
303 |
] ifFalse:[ el == #lightened ifTrue:[ |
|
304 |
color := baseColor perform:el |
|
305 |
] ifFalse:[ |
|
306 |
color := Color perform:el |
|
307 |
]]. |
|
3280 | 308 |
colorId == #gray ifTrue:[ label := el ]. |
309 |
] ifFalse:[ |
|
310 |
el isNumber ifTrue:[ |
|
311 |
color := Color perform:getColSel with:el. |
|
312 |
]. |
|
313 |
]. |
|
314 |
color notNil ifTrue:[ |
|
315 |
label isNil ifTrue:[ |
|
316 |
label := getColSel, ' ', el printString. |
|
317 |
]. |
|
3322 | 318 |
subItem := MenuItem label:' ',label,' '. |
3280 | 319 |
subItem argument:color. |
320 |
submenu addItem:subItem. |
|
321 |
]. |
|
322 |
] |
|
323 |
]. |
|
324 |
]. |
|
3404 | 325 |
ColorMenuSpec := menu. |
326 |
^ menu |
|
3280 | 327 |
! |
328 |
||
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
329 |
resolveMenuItem:aMenuItem value:aValue labelsAreColored:labelsAreColored |
3292 | 330 |
|menuItem label color fgColor submenu| |
331 |
||
332 |
label := aMenuItem rawLabel ? ''. |
|
333 |
menuItem := MenuItem label:label. |
|
334 |
menuItem isButton:(aMenuItem isButton). |
|
3404 | 335 |
menuItem activeHelpKey:(aMenuItem activeHelpKey). |
3292 | 336 |
|
337 |
aMenuItem hasSubmenu ifFalse:[ |
|
338 |
color := aMenuItem argument. |
|
339 |
menuItem argument:color. |
|
340 |
||
341 |
(color isColor and:[label isText not]) ifTrue:[ |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
342 |
labelsAreColored ifTrue:[ |
3292 | 343 |
label := Text string:label color:color. |
344 |
] ifFalse:[ |
|
345 |
color brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
346 |
ifFalse:[ fgColor := Color black ]. |
|
347 |
||
348 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
|
349 |
]. |
|
350 |
menuItem label:label. |
|
351 |
menuItem value:aValue. |
|
352 |
]. |
|
353 |
^ menuItem |
|
354 |
]. |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
355 |
|
3292 | 356 |
submenu := Menu new. |
357 |
aMenuItem submenu itemsDo:[:el| |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
358 |
submenu addItem:(self resolveMenuItem:el value:aValue labelsAreColored:labelsAreColored). |
3292 | 359 |
]. |
360 |
menuItem submenu:submenu. |
|
361 |
^ menuItem |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
362 |
|
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
363 |
"Created: / 23-01-2011 / 14:59:19 / cg" |
592 | 364 |
! ! |
365 |
||
1808 | 366 |
!ColorMenu methodsFor:'accepting'! |
412 | 367 |
|
368 |
accept:anItem |
|
3322 | 369 |
"accept the current selected item" |
664 | 370 |
|
412 | 371 |
|item holder color| |
372 |
||
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
373 |
item := super accept:anItem. |
3738 | 374 |
|
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
375 |
(item notNil and:[((item nameKey ? '') startsWith:'pseudo') not]) ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
376 |
holder := self colorHolder. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
377 |
holder == item ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
378 |
enabledChannel value ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
379 |
color := self color. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
380 |
] ifFalse:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
381 |
holder label:(Text string:' '). |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
382 |
]. |
3322 | 383 |
] ifFalse:[ |
666 | 384 |
color := item argument. |
692 | 385 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 386 |
]. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
387 |
self chooseColor:color. |
3709 | 388 |
self class rememberRecentlyUsedColor:color. |
3738 | 389 |
acceptAction notNil ifTrue:[ |
390 |
acceptAction value:color |
|
391 |
]. |
|
3322 | 392 |
] |
393 |
! |
|
394 |
||
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
395 |
chooseColor:aColor |
3322 | 396 |
"accept the current selected item" |
397 |
||
3350 | 398 |
(model notNil |
399 |
and:[ model isSymbol not]) ifTrue:[ |
|
3322 | 400 |
model value:aColor. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
401 |
]. |
3709 | 402 |
color := aColor. |
412 | 403 |
! ! |
404 |
||
405 |
!ColorMenu methodsFor:'accessing'! |
|
406 |
||
3738 | 407 |
acceptAction:something |
408 |
acceptAction := something. |
|
409 |
! |
|
410 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
411 |
allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
412 |
^ allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
413 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
414 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
415 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
416 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
417 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
418 |
|
412 | 419 |
color |
664 | 420 |
"get current color" |
421 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
422 |
^ color |
412 | 423 |
! |
424 |
||
425 |
color:aColor |
|
664 | 426 |
"set current color" |
427 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
428 |
|label newColor| |
412 | 429 |
|
3344 | 430 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
3445 | 431 |
enabledChannel value:false. |
432 |
self colorHolder label:' '. |
|
2184 | 433 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
434 |
newColor := aColor. |
3344 | 435 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
436 |
allowSymbolicColors ifTrue:[ |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
437 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
438 |
] ifFalse:[ |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
439 |
"our caller does not handle symbolic colors (UIPainter does) - convert now. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
440 |
Be careful - for security reasons - do not perform arbitrary symbols here |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
441 |
(could be #halt, #error)!!" |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
442 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
443 |
newColor := Color name:aColor ifIllegal:[color "keep old"]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
444 |
]. |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
445 |
]. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
446 |
newColor isSymbol ifFalse:[ |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
447 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
448 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 449 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
450 |
color := newColor. |
3344 | 451 |
self disabledRedrawDo:[ |
452 |
enabledChannel value:true. |
|
453 |
self colorHolder label:label. |
|
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
454 |
self chooseColor:aColor |
3344 | 455 |
] |
412 | 456 |
] |
664 | 457 |
! |
458 |
||
3406 | 459 |
colorHolder |
460 |
"returns the item which keeps the selected color in its label" |
|
461 |
||
3738 | 462 |
^ self itemAt:#selection |
3406 | 463 |
! |
464 |
||
3698 | 465 |
contents |
466 |
^ self color |
|
467 |
! |
|
468 |
||
3981 | 469 |
enabledChannel |
470 |
^ enabledChannel |
|
471 |
! |
|
472 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
473 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
474 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
475 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
476 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
477 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
478 |
|
664 | 479 |
labelsAreColored: aBoolean |
480 |
"sets whether labels or their backgrounds will be colored" |
|
481 |
||
3280 | 482 |
|bool| |
483 |
||
484 |
bool := aBoolean ? false. |
|
664 | 485 |
|
3280 | 486 |
labelsAreColored ~~ bool ifTrue:[ |
487 |
labelsAreColored := bool. |
|
488 |
self setupMenu |
|
489 |
]. |
|
3981 | 490 |
! |
491 |
||
492 |
useDefaultColorToggleVisibleHolder |
|
493 |
useDefaultColorToggleVisibleHolder isNil ifTrue:[ |
|
494 |
useDefaultColorToggleVisibleHolder := true asValue |
|
495 |
]. |
|
496 |
^ useDefaultColorToggleVisibleHolder |
|
497 |
||
498 |
"Created: / 18-12-2010 / 13:03:48 / cg" |
|
412 | 499 |
! ! |
500 |
||
1818 | 501 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 502 |
|
503 |
model:aValueHolder |
|
664 | 504 |
"set my color channel" |
505 |
||
2184 | 506 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
507 |
model notNil ifTrue:[ |
2186 | 508 |
self updateFromModel |
664 | 509 |
] |
412 | 510 |
! ! |
511 |
||
512 |
!ColorMenu methodsFor:'change & update'! |
|
513 |
||
2186 | 514 |
updateFromModel |
2184 | 515 |
self color:(model value) |
412 | 516 |
! ! |
517 |
||
3439 | 518 |
!ColorMenu methodsFor:'help'! |
519 |
||
520 |
flyByHelpSpec |
|
521 |
"This resource specification was automatically generated |
|
522 |
by the UIHelpTool of ST/X." |
|
523 |
||
524 |
"Do not manually edit this!! If it is corrupted, |
|
525 |
the UIHelpTool may not be able to read the specification." |
|
526 |
||
527 |
" |
|
528 |
UIHelpTool openOnClass:ColorEditDialog |
|
529 |
" |
|
530 |
||
531 |
<resource: #help> |
|
532 |
||
533 |
^ super flyByHelpSpec addPairsFrom:#( |
|
534 |
||
535 |
#useDefaultColorToggle |
|
536 |
'Turn on, to specify the color here. Turn off to use the default' |
|
537 |
||
538 |
#toggleSymbolicColor |
|
539 |
'Turn on, to specify a symbolic color. Turn off to specify a concrete color' |
|
540 |
||
541 |
#recentlyUsedColors |
|
542 |
'Recently used colors' |
|
543 |
||
544 |
#openColorEditor |
|
545 |
'Open a color editor' |
|
546 |
||
547 |
#pickColorFromScreen |
|
548 |
'Pick a color from the screen' |
|
549 |
||
550 |
) |
|
551 |
! ! |
|
552 |
||
412 | 553 |
!ColorMenu methodsFor:'initialization'! |
554 |
||
3322 | 555 |
colorHistorySubmenu |
556 |
|menu| |
|
557 |
||
558 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
559 |
||
560 |
menu := Menu new. |
|
561 |
||
3344 | 562 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 563 |
|label fgColor item| |
564 |
||
3344 | 565 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
566 |
label := eachRecentlyUsedColor . |
|
567 |
] ifFalse:[ |
|
568 |
eachRecentlyUsedColor brightness < 0.5 |
|
569 |
ifTrue:[ fgColor := Color white ] |
|
570 |
ifFalse:[ fgColor := Color black ]. |
|
3322 | 571 |
|
3344 | 572 |
label := eachRecentlyUsedColor htmlPrintString. |
573 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
574 |
]. |
|
575 |
||
3322 | 576 |
item := MenuItem labeled:label. |
3344 | 577 |
item argument:eachRecentlyUsedColor. |
3322 | 578 |
|
579 |
menu addItem:item. |
|
580 |
]. |
|
581 |
||
582 |
^ menu. |
|
583 |
! |
|
584 |
||
412 | 585 |
destroy |
664 | 586 |
"release color channel dependency" |
587 |
||
412 | 588 |
self model:nil. |
664 | 589 |
super destroy |
412 | 590 |
|
591 |
! |
|
592 |
||
593 |
initialize |
|
594 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
595 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
596 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
597 |
allowSymbolicColors := false. |
2254 | 598 |
|
412 | 599 |
self fitFirstPanel:false. |
895 | 600 |
enabledChannel := ValueHolder with:false. |
412 | 601 |
self setupMenu. |
895 | 602 |
|
603 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 604 |
! |
605 |
||
606 |
setupMenu |
|
3707 | 607 |
|menu toggleItem| |
412 | 608 |
|
666 | 609 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 610 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
611 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
612 |
addItem:( |
3322 | 613 |
(MenuItem labeled:nil) |
614 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
|
615 |
value:[ self openColorEditDialog ]; |
|
616 |
nameKey:#pseudoDef; |
|
3404 | 617 |
activeHelpKey:#openColorEditor; |
618 |
isButton: true) |
|
619 |
beforeIndex:1. |
|
806 | 620 |
|
3322 | 621 |
menu |
622 |
addItem:( |
|
623 |
(MenuItem labeled:nil) |
|
624 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
|
625 |
value:[ self pickColorFromScreen ]; |
|
626 |
nameKey:#pseudoPick; |
|
3404 | 627 |
activeHelpKey:#pickColorFromScreen; |
628 |
isButton: true) |
|
629 |
beforeIndex:1. |
|
3322 | 630 |
|
631 |
menu |
|
632 |
addItem:( |
|
633 |
(MenuItem labeled:nil) |
|
3707 | 634 |
labelImage:(ToolbarIconLibrary colorHistory16x16Icon); |
3322 | 635 |
submenuChannel:[ self colorHistorySubmenu ]; |
3401 | 636 |
nameKey:#pseudoHistory; |
3404 | 637 |
activeHelpKey:#recentlyUsedColors; |
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
638 |
isButton: true) |
3322 | 639 |
beforeIndex:1. |
640 |
||
641 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
3738 | 642 |
"/ (showDefaultToggle ? true) ifTrue:[ |
643 |
toggleItem := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
|
644 |
toggleItem value:#selection. |
|
645 |
toggleItem isButton: false. |
|
646 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3981 | 647 |
toggleItem isVisible:(self useDefaultColorToggleVisibleHolder). |
3738 | 648 |
menu addItem:toggleItem beforeIndex:1. |
649 |
"/ ]. |
|
806 | 650 |
|
412 | 651 |
self menu:menu. |
652 |
||
666 | 653 |
self do:[:anItem| |
3404 | 654 |
anItem value == #selection ifTrue:[ |
3322 | 655 |
anItem indication:enabledChannel |
666 | 656 |
] ifFalse:[ |
3322 | 657 |
anItem enabled:enabledChannel. |
412 | 658 |
] |
664 | 659 |
] |
3981 | 660 |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
661 |
"Modified: / 23-01-2011 / 14:49:32 / cg" |
412 | 662 |
! ! |
663 |
||
3406 | 664 |
!ColorMenu methodsFor:'user actions'! |
3322 | 665 |
|
3530 | 666 |
keepColorHolderIndicationAlwaysEnabled |
667 |
self colorHolder indication:true. |
|
668 |
self colorHolder isButton:true. |
|
669 |
! |
|
670 |
||
3322 | 671 |
openColorEditDialog |
672 |
|defineColorDialog| |
|
673 |
||
674 |
defineColorDialog := ColorEditDialog new color: self color. |
|
675 |
defineColorDialog open. |
|
676 |
defineColorDialog accept value ifTrue: [ |
|
3736
1aa04cb6d849
ColorEditDialog was grazy - adapted to changed protocol
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
677 |
self color:defineColorDialog colorNameOrColor |
3322 | 678 |
] |
679 |
! |
|
680 |
||
681 |
pickColorFromScreen |
|
682 |
|color| |
|
683 |
||
684 |
color := Color fromUser. |
|
685 |
color notNil ifTrue:[ |
|
686 |
self color:color. |
|
687 |
] |
|
412 | 688 |
! ! |
689 |
||
690 |
!ColorMenu class methodsFor:'documentation'! |
|
691 |
||
692 |
version |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
693 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.66 2011-01-23 14:33:06 cg Exp $' |
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
694 |
! |
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
695 |
|
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
696 |
version_CVS |
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
697 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.66 2011-01-23 14:33:06 cg Exp $' |
412 | 698 |
! ! |