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