author | ca |
Wed, 28 Nov 2007 13:38:23 +0100 | |
changeset 3283 | a0388721f027 |
parent 3280 | c42ab6572f32 |
child 3292 | 07786876f1fa |
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 |
||
72 |
addUserDefinedColor:aColor named:aName |
|
73 |
|menu item label submenu| |
|
74 |
||
75 |
" |
|
76 |
ColorMenuSpec := nil. |
|
77 |
||
78 |
self addUserDefinedColor:Color red lightened named:'UBS red'. |
|
79 |
self addUserDefinedColor:Color lightBlue lightened named:'UBS blue'. |
|
80 |
||
81 |
" |
|
82 |
menu := self colorMenu. |
|
83 |
item := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
84 |
ifNone:nil. |
|
85 |
||
86 |
item isNil ifTrue:[ |
|
3283 | 87 |
item := MenuItem labeled:(self userDefinedLabel). |
3280 | 88 |
item nameKey:#userDefined. |
89 |
item submenu:(submenu := Menu new). |
|
90 |
menu addItem:item beforeIndex:1. |
|
91 |
||
92 |
item := MenuItem new. |
|
93 |
item nameKey:#userDefined. |
|
94 |
menu addItem:item beforeIndex:1. |
|
95 |
] ifFalse:[ |
|
96 |
submenu := item submenu. |
|
97 |
item := submenu detectItem:[:el| el argument = aColor ] ifNone:nil. |
|
98 |
item notNil ifTrue:[ ^ self ]. "/ already exists |
|
99 |
]. |
|
100 |
label := ' %1 ' bindWith:(aName ? ' '). |
|
101 |
label := Text string:label emphasis:#backgroundColor->aColor. |
|
102 |
||
103 |
item := MenuItem labeled:label. |
|
104 |
item argument:aColor. |
|
105 |
||
106 |
submenu addItem:item. |
|
107 |
! |
|
108 |
||
3283 | 109 |
removeAllUserDefinedColors |
110 |
|menu item| |
|
111 |
||
112 |
" |
|
113 |
self addUserDefinedColor:Color lightBlue lightened named:'UBS lightBlue'. |
|
114 |
self addUserDefinedColor:Color red lightened named:'UBS red'. |
|
115 |
self removeAllUserDefinedColors. |
|
116 |
" |
|
117 |
menu := self colorMenu. |
|
118 |
||
119 |
[ item := menu detectItem:[:el| el nameKey == #userDefined ] ifNone:nil. |
|
120 |
item notNil |
|
121 |
] whileTrue:[ |
|
122 |
menu removeItem:item. |
|
123 |
]. |
|
124 |
! |
|
125 |
||
3280 | 126 |
removeUserDefinedColor:aColor |
127 |
|menu menuitem submenu subitem| |
|
128 |
||
129 |
" |
|
130 |
ColorMenuSpec := nil. |
|
131 |
||
132 |
self removeUserDefinedColor:Color lightBlue lightened |
|
133 |
self removeUserDefinedColor:Color red lightened |
|
134 |
self addUserDefinedColor:Color lightBlue lightened named:'UBS lightBlue' |
|
135 |
self addUserDefinedColor:Color red lightened named:'UBS red' |
|
136 |
||
137 |
" |
|
138 |
menu := self colorMenu. |
|
139 |
menuitem := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
140 |
ifNone:nil. |
|
141 |
||
142 |
menuitem isNil ifTrue:[ ^ self ]. |
|
143 |
||
144 |
submenu := menuitem submenu. |
|
145 |
subitem := submenu detectItem:[:el| el argument = aColor] ifNone:nil. |
|
146 |
subitem notNil ifTrue:[ |
|
147 |
submenu removeItem:subitem. |
|
148 |
]. |
|
149 |
submenu items size > 0 ifTrue:[^ self]. |
|
150 |
||
151 |
[menuitem notNil] whileTrue:[ |
|
152 |
"/ remove submenu and separators |
|
153 |
menu removeItem:menuitem. |
|
154 |
menuitem := menu detectItem:[:el| el nameKey == #userDefined ] ifNone:nil. |
|
155 |
]. |
|
3283 | 156 |
! |
157 |
||
158 |
userDefinedLabel |
|
159 |
"returns the user defined label used by the ColorMenu" |
|
160 |
||
161 |
^ XPToolbarIconLibrary changesBrowser24x24Icon |
|
3280 | 162 |
! ! |
163 |
||
412 | 164 |
!ColorMenu class methodsFor:'menu spec'! |
165 |
||
3280 | 166 |
colorMenu |
167 |
|menuItem subItem baseColor color label getColSel submenu colorId| |
|
168 |
" |
|
169 |
ColorMenuSpec := nil. |
|
170 |
self colorMenu |
|
171 |
" |
|
172 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
|
173 |
||
174 |
ColorMenuSpec := Menu new. |
|
175 |
||
176 |
self colorMenuSpec do:[:aSlice| |
|
177 |
ColorMenuSpec addItem:(menuItem := MenuItem new). |
|
178 |
||
179 |
aSlice notNil ifTrue:[ |
|
180 |
colorId := aSlice at:1. |
|
181 |
getColSel := aSlice at:2. |
|
182 |
baseColor := Color perform:colorId. |
|
183 |
||
184 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
|
185 |
menuItem submenu:(submenu := Menu new). |
|
186 |
||
187 |
aSlice last do:[:el| |
|
188 |
color := label := nil. |
|
189 |
||
190 |
el isSymbol ifTrue:[ |
|
191 |
el == #lightened ifTrue:[ color := baseColor perform:el ] |
|
192 |
ifFalse:[ color := Color perform:el ]. |
|
193 |
||
194 |
colorId == #gray ifTrue:[ label := el ]. |
|
195 |
] ifFalse:[ |
|
196 |
el isNumber ifTrue:[ |
|
197 |
color := Color perform:getColSel with:el. |
|
198 |
]. |
|
199 |
]. |
|
200 |
color notNil ifTrue:[ |
|
201 |
label isNil ifTrue:[ |
|
202 |
label := getColSel, ' ', el printString. |
|
203 |
]. |
|
204 |
subItem := MenuItem label:label. |
|
205 |
subItem argument:color. |
|
206 |
submenu addItem:subItem. |
|
207 |
]. |
|
208 |
] |
|
209 |
]. |
|
210 |
]. |
|
211 |
^ ColorMenuSpec |
|
212 |
! |
|
213 |
||
214 |
colorMenu:labelAreColored value:aValue |
|
215 |
"returns a color menu |
|
216 |
" |
|
217 |
|style menu menuItem subItem| |
|
218 |
||
219 |
menu := Menu new. |
|
220 |
||
221 |
labelAreColored == false ifTrue:[ style := #backgroundColor ] |
|
222 |
ifFalse:[ style := #color ]. |
|
223 |
||
224 |
self colorMenu itemsDo:[:anItem| |submenu| |
|
225 |
menuItem := MenuItem label:(anItem rawLabel ? ''). |
|
226 |
menu addItem:menuItem. |
|
227 |
||
228 |
anItem hasSubmenu ifTrue:[ |
|
229 |
menuItem isButton:true. |
|
230 |
menuItem submenu:(submenu := Menu new). |
|
231 |
anItem submenu itemsDo:[:el| | label color emphasis| |
|
232 |
label := el rawLabel ? ' '. |
|
233 |
color := el argument. |
|
234 |
||
235 |
label isText ifFalse:[ |
|
236 |
emphasis := style->color. |
|
237 |
||
238 |
style == #backgroundColor ifTrue:[ |
|
239 |
color brightness < 0.5 ifTrue:[ |
|
240 |
emphasis := Array with:emphasis with:(#color->Color white) |
|
241 |
] |
|
242 |
]. |
|
243 |
label := Text string:('Color ', label) emphasis:emphasis. |
|
244 |
]. |
|
245 |
subItem := MenuItem label:label value:aValue. |
|
246 |
subItem argument:color. |
|
247 |
submenu addItem:subItem. |
|
248 |
]]. |
|
249 |
]. |
|
250 |
^ menu |
|
251 |
" |
|
252 |
(ColorMenu colorMenu:true value:nil) startUp |
|
253 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
254 |
" |
|
255 |
! |
|
256 |
||
257 |
colorMenuSpec |
|
666 | 258 |
"color definitions used to build a color menu |
412 | 259 |
" |
3280 | 260 |
" |
261 |
ColorMenuSpec := nil. |
|
262 |
" |
|
666 | 263 |
^ #( |
3280 | 264 |
nil "/ separator |
668 | 265 |
#( gray |
666 | 266 |
gray: |
267 |
#( white |
|
268 |
veryLightGray |
|
269 |
lightGray |
|
270 |
gray |
|
271 |
darkGray |
|
272 |
veryDarkGray |
|
273 |
black |
|
274 |
) |
|
412 | 275 |
) |
3280 | 276 |
nil "/ separator |
668 | 277 |
#( red |
666 | 278 |
red: |
854 | 279 |
#( lightened 100 87 67 50 33) |
666 | 280 |
) |
668 | 281 |
#( green |
666 | 282 |
green: |
854 | 283 |
#( lightened 100 87 67 50 33) |
666 | 284 |
) |
668 | 285 |
#( blue |
666 | 286 |
blue: |
854 | 287 |
#( lightened 100 87 67 50 33) |
666 | 288 |
) |
3280 | 289 |
nil "/ separator |
668 | 290 |
#( cyan |
854 | 291 |
cyan: |
292 |
#( lightened 100 87 67 50 33) |
|
664 | 293 |
) |
668 | 294 |
#( magenta |
854 | 295 |
magenta: |
296 |
#( lightened 100 87 67 50 33) |
|
412 | 297 |
) |
668 | 298 |
#( yellow |
854 | 299 |
yellow: |
300 |
#( lightened 100 87 67 50 33) |
|
412 | 301 |
) |
806 | 302 |
|
412 | 303 |
) |
592 | 304 |
! ! |
305 |
||
1808 | 306 |
!ColorMenu methodsFor:'accepting'! |
412 | 307 |
|
308 |
accept:anItem |
|
664 | 309 |
"accept current selected item" |
310 |
||
412 | 311 |
|item holder color| |
312 |
||
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
313 |
((item := super accept:anItem) notNil and: [item nameKey ~~ #def]) |
664 | 314 |
ifTrue: |
315 |
[ |
|
316 |
(holder := self colorHolder) == item ifTrue: |
|
317 |
[ |
|
412 | 318 |
enabledChannel value ifTrue:[color := self color] |
664 | 319 |
] |
320 |
ifFalse: |
|
1057 | 321 |
[ |
666 | 322 |
color := item argument. |
692 | 323 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 324 |
]. |
325 |
model notNil ifTrue:[model value:color] |
|
326 |
] |
|
327 |
! ! |
|
328 |
||
329 |
!ColorMenu methodsFor:'accessing'! |
|
330 |
||
331 |
color |
|
664 | 332 |
"get current color" |
333 |
||
334 |
|firstEmphasis| |
|
335 |
(firstEmphasis := (self colorHolder label emphasis at:1)) isAssociation ifTrue: [^firstEmphasis value]. |
|
336 |
^(firstEmphasis at: 1) value |
|
412 | 337 |
! |
338 |
||
339 |
color:aColor |
|
664 | 340 |
"set current color" |
341 |
||
412 | 342 |
|holder label| |
343 |
||
2184 | 344 |
aColor isColor ifFalse:[ |
412 | 345 |
enabledChannel value:false |
2184 | 346 |
] ifTrue:[ |
347 |
self |
|
348 |
disabledRedrawDo: |
|
349 |
[ |
|
350 |
holder := self colorHolder. |
|
351 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
352 |
enabledChannel value:true. |
|
353 |
holder label:label. |
|
354 |
model value: aColor |
|
355 |
] |
|
412 | 356 |
] |
664 | 357 |
! |
358 |
||
359 |
labelsAreColored: aBoolean |
|
360 |
"sets whether labels or their backgrounds will be colored" |
|
361 |
||
3280 | 362 |
|bool| |
363 |
||
364 |
bool := aBoolean ? false. |
|
664 | 365 |
|
3280 | 366 |
labelsAreColored ~~ bool ifTrue:[ |
367 |
labelsAreColored := bool. |
|
368 |
self setupMenu |
|
369 |
]. |
|
412 | 370 |
! ! |
371 |
||
1818 | 372 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 373 |
|
374 |
model:aValueHolder |
|
664 | 375 |
"set my color channel" |
376 |
||
2184 | 377 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
378 |
model notNil ifTrue:[ |
2186 | 379 |
self updateFromModel |
664 | 380 |
] |
412 | 381 |
! ! |
382 |
||
383 |
!ColorMenu methodsFor:'change & update'! |
|
384 |
||
2186 | 385 |
updateFromModel |
2184 | 386 |
self color:(model value) |
412 | 387 |
! ! |
388 |
||
389 |
!ColorMenu methodsFor:'initialization'! |
|
390 |
||
391 |
destroy |
|
664 | 392 |
"release color channel dependency" |
393 |
||
412 | 394 |
self model:nil. |
664 | 395 |
super destroy |
412 | 396 |
|
397 |
! |
|
398 |
||
399 |
initialize |
|
664 | 400 |
"setup menu" |
401 |
||
412 | 402 |
super initialize. |
2254 | 403 |
labelsAreColored := false. |
404 |
verticalLayout := false. |
|
405 |
||
412 | 406 |
self fitFirstPanel:false. |
895 | 407 |
enabledChannel := ValueHolder with:false. |
412 | 408 |
self setupMenu. |
895 | 409 |
|
410 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 411 |
! |
412 |
||
413 |
setupMenu |
|
664 | 414 |
"setup menu" |
666 | 415 |
|menu item| |
412 | 416 |
|
666 | 417 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 418 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
419 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
420 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
421 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
422 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
423 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
424 |
|defineColor| |
2704 | 425 |
defineColor := ColorEditDialog new color: self color. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
426 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
427 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 428 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
429 |
]; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
430 |
nameKey:#def; |
3280 | 431 |
isButton: true). |
806 | 432 |
|
666 | 433 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
434 |
item value:#selection. |
|
435 |
menu addItem:item beforeIndex:1. |
|
806 | 436 |
|
412 | 437 |
self menu:menu. |
438 |
||
666 | 439 |
self do:[:anItem| |
440 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 441 |
anItem enabled:enabledChannel. |
666 | 442 |
] ifFalse:[ |
443 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 444 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
445 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 446 |
] |
664 | 447 |
] |
412 | 448 |
! ! |
449 |
||
450 |
!ColorMenu methodsFor:'private'! |
|
451 |
||
452 |
colorHolder |
|
453 |
"returns the item which keeps the selected color in its label |
|
454 |
" |
|
455 |
^ self itemAt:#selection |
|
456 |
! ! |
|
457 |
||
458 |
!ColorMenu class methodsFor:'documentation'! |
|
459 |
||
460 |
version |
|
3283 | 461 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.37 2007-11-28 12:38:23 ca Exp $' |
412 | 462 |
! ! |