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