author | ca |
Tue, 04 Dec 2007 09:23:13 +0100 | |
changeset 3293 | 1ae2428ad1e5 |
parent 3292 | 07786876f1fa |
child 3294 | da0fdfe54c4e |
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 |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
15 |
instanceVariableNames:'enabledChannel labelsAreColored' |
3280 | 16 |
classVariableNames:'ColorMenuSpec' |
412 | 17 |
poolDictionaries:'' |
18 |
category:'Interface-UIPainter' |
|
19 |
! |
|
20 |
||
21 |
!ColorMenu class methodsFor:'documentation'! |
|
22 |
||
422 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
||
37 |
! |
|
38 |
||
412 | 39 |
documentation |
40 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
41 |
A simple ColorMenu used by the UIPainter |
412 | 42 |
|
43 |
[see also:] |
|
44 |
UIPainter |
|
45 |
ColorMenuSpec |
|
422 | 46 |
|
47 |
[author:] |
|
48 |
Claus Atzkern |
|
412 | 49 |
" |
50 |
! |
|
51 |
||
52 |
examples |
|
53 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
54 |
very simple example |
412 | 55 |
[exBegin] |
56 |
|tool top channel| |
|
57 |
||
58 |
top := StandardSystemView new. |
|
59 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
60 |
|
412 | 61 |
channel := (Color red) asValue. |
62 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
63 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
64 |
|
412 | 65 |
top open. |
66 |
[exEnd] |
|
67 |
" |
|
68 |
! ! |
|
69 |
||
3280 | 70 |
!ColorMenu class methodsFor:'adding & removing'! |
71 |
||
3292 | 72 |
addUserDefinedColors:aColors labels:labelsOrNil title:aTitle |
73 |
|size submenu item label fgColor bgColor labels defLabel| |
|
74 |
||
75 |
submenu := self userDefinedSubmenu. |
|
76 |
size := aColors size. |
|
77 |
||
78 |
size == 0 ifTrue:[ "/ separator |
|
79 |
submenu addItem:(MenuItem label:'-'). |
|
80 |
^ self |
|
81 |
]. |
|
82 |
||
83 |
labels := labelsOrNil ? #(). |
|
84 |
bgColor := aColors first. |
|
85 |
defLabel := ' '. |
|
86 |
||
87 |
bgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
88 |
ifFalse:[ fgColor := Color black ]. |
|
89 |
||
90 |
aTitle isEmptyOrNil ifTrue:[ label := labels at:1 ifAbsent:defLabel ] |
|
91 |
ifFalse:[ label := aTitle ]. |
|
3280 | 92 |
|
3292 | 93 |
label := Text string:label foregroundColor:fgColor backgroundColor:bgColor. |
94 |
item := MenuItem labeled:label. |
|
95 |
submenu addItem:item. |
|
96 |
||
97 |
size == 1 ifTrue:[ |
|
98 |
item argument:bgColor. |
|
99 |
] ifFalse:[ |
|
100 |
item submenu:(submenu := Menu new). |
|
3280 | 101 |
|
3292 | 102 |
aColors keysAndValuesDo:[:idx :aBgColor| |
103 |
aBgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
104 |
ifFalse:[ fgColor := Color black ]. |
|
105 |
||
106 |
label := labels at:idx ifAbsent:defLabel. |
|
107 |
label := Text string:label foregroundColor:fgColor backgroundColor:aBgColor. |
|
108 |
item := MenuItem labeled:label. |
|
3293 | 109 |
item argument:aBgColor. |
3292 | 110 |
|
111 |
submenu addItem:item. |
|
112 |
]. |
|
113 |
]. |
|
3280 | 114 |
|
115 |
" |
|
3292 | 116 |
ColorMenu removeAllUserDefinedColors. |
3280 | 117 |
|
3292 | 118 |
#( |
119 |
#( Black 16r000000 ) |
|
120 |
#( Red 16rff0000 ) |
|
121 |
nil |
|
122 |
#( Rust 16rff6600 16rff8533 16rffa366 16rffc299 16rffe0cc ) |
|
123 |
#( Tangerine 16rff9933 16rffad5c 16rffc285 16rffd6ad 16rffebd6 ) |
|
124 |
#( Sunflower 16rffcc00 16rfed633 16rfee066 16rffeb99 16rfff5cc ) |
|
125 |
#( Mango 16rffcc99 16rffd6ad 16rffe0c2 16rffebd6 16rfff5eb ) |
|
126 |
#( Buttercup 16rffff66 16rffff85 16rffffa3 16rffffc2 16rffffe0 ) |
|
127 |
#( Lemon 16rffffcc 16rffffd6 16rffffe0 16rffffeb 16rfffff5 ) |
|
3280 | 128 |
|
3292 | 129 |
) do:[:aDef| |colors title labels percentage| |
130 |
aDef isEmptyOrNil ifTrue:[ |
|
131 |
colors := labels := title := nil. |
|
132 |
] ifFalse:[ |
|
133 |
title := aDef first. |
|
134 |
colors := OrderedCollection new. |
|
135 |
labels := OrderedCollection new. |
|
136 |
percentage := 100. |
|
137 |
||
138 |
aDef from:2 do:[:rgb| |
|
139 |
colors add:(Color rgbValue:rgb). |
|
140 |
labels add:('%1 %2 %%' bindWith:title with:percentage). |
|
141 |
percentage := percentage - 20. |
|
142 |
]. |
|
143 |
]. |
|
144 |
ColorMenu addUserDefinedColors:colors labels:labels title:title. |
|
3280 | 145 |
]. |
3292 | 146 |
" |
3280 | 147 |
! |
148 |
||
3283 | 149 |
removeAllUserDefinedColors |
3292 | 150 |
ColorMenuSpec := nil. |
3280 | 151 |
! ! |
152 |
||
412 | 153 |
!ColorMenu class methodsFor:'menu spec'! |
154 |
||
3292 | 155 |
colorMenu:labelAreColored value:aValue |
156 |
"returns a color menu |
|
157 |
" |
|
158 |
|menu| |
|
159 |
||
160 |
menu := Menu new. |
|
161 |
||
162 |
self colorMenu itemsDo:[:el| |
|
163 |
menu addItem:(self resolveMenuItem:el value:aValue labelAreColored:labelAreColored). |
|
164 |
]. |
|
165 |
^ menu |
|
166 |
" |
|
167 |
(ColorMenu colorMenu:true value:nil) startUp |
|
168 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
169 |
" |
|
170 |
! ! |
|
171 |
||
172 |
!ColorMenu class methodsFor:'private'! |
|
173 |
||
3280 | 174 |
colorMenu |
175 |
|menuItem subItem baseColor color label getColSel submenu colorId| |
|
3292 | 176 |
|
3280 | 177 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
178 |
||
179 |
ColorMenuSpec := Menu new. |
|
180 |
||
181 |
self colorMenuSpec do:[:aSlice| |
|
182 |
ColorMenuSpec addItem:(menuItem := MenuItem new). |
|
183 |
||
184 |
aSlice notNil ifTrue:[ |
|
185 |
colorId := aSlice at:1. |
|
186 |
getColSel := aSlice at:2. |
|
187 |
baseColor := Color perform:colorId. |
|
188 |
||
189 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
|
190 |
menuItem submenu:(submenu := Menu new). |
|
3292 | 191 |
menuItem isButton:true. |
3280 | 192 |
|
193 |
aSlice last do:[:el| |
|
194 |
color := label := nil. |
|
195 |
||
196 |
el isSymbol ifTrue:[ |
|
197 |
el == #lightened ifTrue:[ color := baseColor perform:el ] |
|
198 |
ifFalse:[ color := Color perform:el ]. |
|
199 |
||
200 |
colorId == #gray ifTrue:[ label := el ]. |
|
201 |
] ifFalse:[ |
|
202 |
el isNumber ifTrue:[ |
|
203 |
color := Color perform:getColSel with:el. |
|
204 |
]. |
|
205 |
]. |
|
206 |
color notNil ifTrue:[ |
|
207 |
label isNil ifTrue:[ |
|
208 |
label := getColSel, ' ', el printString. |
|
209 |
]. |
|
3292 | 210 |
subItem := MenuItem label:'Color ', label. |
3280 | 211 |
subItem argument:color. |
212 |
submenu addItem:subItem. |
|
213 |
]. |
|
214 |
] |
|
215 |
]. |
|
216 |
]. |
|
217 |
^ ColorMenuSpec |
|
218 |
! |
|
219 |
||
220 |
colorMenuSpec |
|
666 | 221 |
"color definitions used to build a color menu |
412 | 222 |
" |
3280 | 223 |
" |
224 |
ColorMenuSpec := nil. |
|
225 |
" |
|
666 | 226 |
^ #( |
668 | 227 |
#( gray |
666 | 228 |
gray: |
229 |
#( white |
|
230 |
veryLightGray |
|
231 |
lightGray |
|
232 |
gray |
|
233 |
darkGray |
|
234 |
veryDarkGray |
|
235 |
black |
|
236 |
) |
|
412 | 237 |
) |
3280 | 238 |
nil "/ separator |
668 | 239 |
#( red |
666 | 240 |
red: |
854 | 241 |
#( lightened 100 87 67 50 33) |
666 | 242 |
) |
668 | 243 |
#( green |
666 | 244 |
green: |
854 | 245 |
#( lightened 100 87 67 50 33) |
666 | 246 |
) |
668 | 247 |
#( blue |
666 | 248 |
blue: |
854 | 249 |
#( lightened 100 87 67 50 33) |
666 | 250 |
) |
3280 | 251 |
nil "/ separator |
668 | 252 |
#( cyan |
854 | 253 |
cyan: |
254 |
#( lightened 100 87 67 50 33) |
|
664 | 255 |
) |
668 | 256 |
#( magenta |
854 | 257 |
magenta: |
258 |
#( lightened 100 87 67 50 33) |
|
412 | 259 |
) |
668 | 260 |
#( yellow |
854 | 261 |
yellow: |
262 |
#( lightened 100 87 67 50 33) |
|
412 | 263 |
) |
806 | 264 |
|
412 | 265 |
) |
3292 | 266 |
! |
267 |
||
268 |
resolveMenuItem:aMenuItem value:aValue labelAreColored:labelAreColored |
|
269 |
|menuItem label color fgColor submenu| |
|
270 |
||
271 |
label := aMenuItem rawLabel ? ''. |
|
272 |
menuItem := MenuItem label:label. |
|
273 |
menuItem isButton:(aMenuItem isButton). |
|
274 |
||
275 |
aMenuItem hasSubmenu ifFalse:[ |
|
276 |
color := aMenuItem argument. |
|
277 |
menuItem argument:color. |
|
278 |
||
279 |
(color isColor and:[label isText not]) ifTrue:[ |
|
280 |
labelAreColored ifTrue:[ |
|
281 |
label := Text string:label color:color. |
|
282 |
] ifFalse:[ |
|
283 |
color brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
284 |
ifFalse:[ fgColor := Color black ]. |
|
285 |
||
286 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
|
287 |
]. |
|
288 |
menuItem label:label. |
|
289 |
menuItem value:aValue. |
|
290 |
]. |
|
291 |
^ menuItem |
|
292 |
]. |
|
293 |
submenu := Menu new. |
|
294 |
aMenuItem submenu itemsDo:[:el| |
|
295 |
submenu addItem:(self resolveMenuItem:el value:aValue labelAreColored:labelAreColored). |
|
296 |
]. |
|
297 |
menuItem submenu:submenu. |
|
298 |
^ menuItem |
|
299 |
! |
|
300 |
||
301 |
userDefinedSubmenu |
|
302 |
"answer the menu entry under which the userdefined color entries are placed" |
|
303 |
||
304 |
|menu submenu item icon| |
|
305 |
||
306 |
menu := self colorMenu. |
|
307 |
item := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
308 |
ifNone:nil. |
|
309 |
||
310 |
item isNil ifTrue:[ |
|
311 |
icon := XPToolbarIconLibrary changesBrowser24x24Icon. |
|
312 |
item := MenuItem labeled:icon. |
|
313 |
item nameKey:#userDefined. |
|
314 |
menu addItem:item beforeIndex:1. |
|
315 |
]. |
|
316 |
||
317 |
(submenu := item submenu) isNil ifTrue:[ |
|
318 |
submenu := Menu new. |
|
319 |
item submenu:submenu. |
|
320 |
]. |
|
321 |
^ submenu |
|
592 | 322 |
! ! |
323 |
||
1808 | 324 |
!ColorMenu methodsFor:'accepting'! |
412 | 325 |
|
326 |
accept:anItem |
|
664 | 327 |
"accept current selected item" |
328 |
||
412 | 329 |
|item holder color| |
330 |
||
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
331 |
((item := super accept:anItem) notNil and: [item nameKey ~~ #def]) |
664 | 332 |
ifTrue: |
333 |
[ |
|
334 |
(holder := self colorHolder) == item ifTrue: |
|
335 |
[ |
|
412 | 336 |
enabledChannel value ifTrue:[color := self color] |
664 | 337 |
] |
338 |
ifFalse: |
|
1057 | 339 |
[ |
666 | 340 |
color := item argument. |
692 | 341 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 342 |
]. |
343 |
model notNil ifTrue:[model value:color] |
|
344 |
] |
|
345 |
! ! |
|
346 |
||
347 |
!ColorMenu methodsFor:'accessing'! |
|
348 |
||
349 |
color |
|
664 | 350 |
"get current color" |
351 |
||
352 |
|firstEmphasis| |
|
353 |
(firstEmphasis := (self colorHolder label emphasis at:1)) isAssociation ifTrue: [^firstEmphasis value]. |
|
354 |
^(firstEmphasis at: 1) value |
|
412 | 355 |
! |
356 |
||
357 |
color:aColor |
|
664 | 358 |
"set current color" |
359 |
||
412 | 360 |
|holder label| |
361 |
||
2184 | 362 |
aColor isColor ifFalse:[ |
412 | 363 |
enabledChannel value:false |
2184 | 364 |
] ifTrue:[ |
365 |
self |
|
366 |
disabledRedrawDo: |
|
367 |
[ |
|
368 |
holder := self colorHolder. |
|
369 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
370 |
enabledChannel value:true. |
|
371 |
holder label:label. |
|
372 |
model value: aColor |
|
373 |
] |
|
412 | 374 |
] |
664 | 375 |
! |
376 |
||
377 |
labelsAreColored: aBoolean |
|
378 |
"sets whether labels or their backgrounds will be colored" |
|
379 |
||
3280 | 380 |
|bool| |
381 |
||
382 |
bool := aBoolean ? false. |
|
664 | 383 |
|
3280 | 384 |
labelsAreColored ~~ bool ifTrue:[ |
385 |
labelsAreColored := bool. |
|
386 |
self setupMenu |
|
387 |
]. |
|
412 | 388 |
! ! |
389 |
||
1818 | 390 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 391 |
|
392 |
model:aValueHolder |
|
664 | 393 |
"set my color channel" |
394 |
||
2184 | 395 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
396 |
model notNil ifTrue:[ |
2186 | 397 |
self updateFromModel |
664 | 398 |
] |
412 | 399 |
! ! |
400 |
||
401 |
!ColorMenu methodsFor:'change & update'! |
|
402 |
||
2186 | 403 |
updateFromModel |
2184 | 404 |
self color:(model value) |
412 | 405 |
! ! |
406 |
||
407 |
!ColorMenu methodsFor:'initialization'! |
|
408 |
||
409 |
destroy |
|
664 | 410 |
"release color channel dependency" |
411 |
||
412 | 412 |
self model:nil. |
664 | 413 |
super destroy |
412 | 414 |
|
415 |
! |
|
416 |
||
417 |
initialize |
|
664 | 418 |
"setup menu" |
419 |
||
412 | 420 |
super initialize. |
2254 | 421 |
labelsAreColored := false. |
422 |
verticalLayout := false. |
|
423 |
||
412 | 424 |
self fitFirstPanel:false. |
895 | 425 |
enabledChannel := ValueHolder with:false. |
412 | 426 |
self setupMenu. |
895 | 427 |
|
428 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 429 |
! |
430 |
||
431 |
setupMenu |
|
664 | 432 |
"setup menu" |
666 | 433 |
|menu item| |
412 | 434 |
|
666 | 435 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 436 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
437 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
438 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
439 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
440 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
441 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
442 |
|defineColor| |
2704 | 443 |
defineColor := ColorEditDialog new color: self color. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
444 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
445 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 446 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
447 |
]; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
448 |
nameKey:#def; |
3280 | 449 |
isButton: true). |
806 | 450 |
|
3292 | 451 |
menu addItem:(MenuItem label:'') beforeIndex:1. |
666 | 452 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
453 |
item value:#selection. |
|
454 |
menu addItem:item beforeIndex:1. |
|
806 | 455 |
|
412 | 456 |
self menu:menu. |
457 |
||
666 | 458 |
self do:[:anItem| |
459 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 460 |
anItem enabled:enabledChannel. |
666 | 461 |
] ifFalse:[ |
462 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 463 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
464 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 465 |
] |
664 | 466 |
] |
412 | 467 |
! ! |
468 |
||
469 |
!ColorMenu methodsFor:'private'! |
|
470 |
||
471 |
colorHolder |
|
472 |
"returns the item which keeps the selected color in its label |
|
473 |
" |
|
474 |
^ self itemAt:#selection |
|
475 |
! ! |
|
476 |
||
477 |
!ColorMenu class methodsFor:'documentation'! |
|
478 |
||
479 |
version |
|
3293 | 480 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.39 2007-12-04 08:23:13 ca Exp $' |
412 | 481 |
! ! |