author | Claus Gittinger <cg@exept.de> |
Tue, 11 May 2004 14:50:21 +0200 | |
changeset 2704 | 0a09fd78eb54 |
parent 2497 | 0beadb2a951c |
child 2935 | e3fa9d1a7a64 |
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 |
" |
|
12 |
||
13 |
||
14 |
||
1803 | 15 |
"{ Package: 'stx:libtool2' }" |
16 |
||
412 | 17 |
MenuPanel subclass:#ColorMenu |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
18 |
instanceVariableNames:'enabledChannel labelsAreColored' |
666 | 19 |
classVariableNames:'' |
412 | 20 |
poolDictionaries:'' |
21 |
category:'Interface-UIPainter' |
|
22 |
! |
|
23 |
||
24 |
!ColorMenu class methodsFor:'documentation'! |
|
25 |
||
422 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
412 | 42 |
documentation |
43 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
44 |
A simple ColorMenu used by the UIPainter |
412 | 45 |
|
46 |
[see also:] |
|
47 |
UIPainter |
|
48 |
ColorMenuSpec |
|
422 | 49 |
|
50 |
[author:] |
|
51 |
Claus Atzkern |
|
412 | 52 |
" |
53 |
! |
|
54 |
||
55 |
examples |
|
56 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
57 |
very simple example |
412 | 58 |
[exBegin] |
59 |
|tool top channel| |
|
60 |
||
61 |
top := StandardSystemView new. |
|
62 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
63 |
|
412 | 64 |
channel := (Color red) asValue. |
65 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
66 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
67 |
|
412 | 68 |
top open. |
69 |
[exEnd] |
|
70 |
" |
|
71 |
! ! |
|
72 |
||
73 |
!ColorMenu class methodsFor:'menu spec'! |
|
74 |
||
666 | 75 |
colorDefinition |
76 |
"color definitions used to build a color menu |
|
412 | 77 |
" |
583 | 78 |
|
666 | 79 |
^ #( |
668 | 80 |
#( gray |
666 | 81 |
gray: |
82 |
#( white |
|
83 |
veryLightGray |
|
84 |
lightGray |
|
85 |
gray |
|
86 |
darkGray |
|
87 |
veryDarkGray |
|
88 |
black |
|
89 |
) |
|
412 | 90 |
) |
666 | 91 |
|
668 | 92 |
#( red |
666 | 93 |
red: |
854 | 94 |
#( lightened 100 87 67 50 33) |
666 | 95 |
) |
96 |
||
668 | 97 |
#( green |
666 | 98 |
green: |
854 | 99 |
#( lightened 100 87 67 50 33) |
666 | 100 |
) |
101 |
||
668 | 102 |
#( blue |
666 | 103 |
blue: |
854 | 104 |
#( lightened 100 87 67 50 33) |
666 | 105 |
) |
106 |
||
668 | 107 |
#( cyan |
854 | 108 |
cyan: |
109 |
#( lightened 100 87 67 50 33) |
|
664 | 110 |
) |
666 | 111 |
|
668 | 112 |
#( magenta |
854 | 113 |
magenta: |
114 |
#( lightened 100 87 67 50 33) |
|
412 | 115 |
) |
666 | 116 |
|
668 | 117 |
#( yellow |
854 | 118 |
yellow: |
119 |
#( lightened 100 87 67 50 33) |
|
412 | 120 |
) |
806 | 121 |
|
412 | 122 |
) |
666 | 123 |
! |
124 |
||
125 |
colorMenu:labelAreColored value:aValue |
|
126 |
"returns a color menu |
|
127 |
" |
|
1410 | 128 |
|menu mainCol style e| |
666 | 129 |
|
130 |
menu := Menu new. |
|
1372
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
131 |
style := (labelAreColored == false) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
132 |
ifTrue:[#backgroundColor] |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
133 |
ifFalse:[#color]. |
666 | 134 |
|
135 |
self colorDefinition do:[:aSlice| |
|
136 |
|size colOp color item smenu| |
|
137 |
||
668 | 138 |
mainCol := Color perform:(aSlice at:1). |
139 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->mainCol)). |
|
666 | 140 |
smenu := Menu new. |
668 | 141 |
colOp := aSlice at:2. |
412 | 142 |
|
668 | 143 |
(aSlice at:3) do:[:el||sitem label| |
666 | 144 |
el isSymbol ifTrue:[ |
145 |
color := el == #lightened ifTrue:[mainCol perform:el] ifFalse:[Color perform:el]. |
|
854 | 146 |
self colorDefinition first ~~ aSlice |
147 |
ifTrue: [label := (colOp upTo: $:), ' ', el] |
|
148 |
ifFalse:[label := el]. |
|
666 | 149 |
] ifFalse:[ |
150 |
el isNumber ifTrue:[ |
|
151 |
color := Color perform:colOp with:el. |
|
152 |
label := colOp, ' ', el printString. |
|
153 |
] ifFalse:[ |
|
154 |
color := Color perform:colOp with:(el at:1) with:(el at:2) with:(el at:3). |
|
155 |
label := ''. |
|
156 |
colOp keywords keysAndValuesDo:[:i :c| label := label, ' ', c, ' ' , (el at:i) printString ]. |
|
157 |
] |
|
158 |
]. |
|
1372
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
159 |
e := style->color. |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
160 |
style == #backgroundColor ifTrue:[ |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
161 |
color brightness < 0.5 ifTrue:[ |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
162 |
e := Array with:e |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
163 |
with:(#color->Color white) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
164 |
] |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
165 |
]. |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
166 |
sitem := MenuItem |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
167 |
labeled:(Text |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
168 |
string:('Color ', label) |
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
169 |
emphasis:e). |
666 | 170 |
sitem argument:color. |
171 |
sitem value:aValue. |
|
172 |
smenu addItem:sitem. |
|
173 |
]. |
|
174 |
item submenu:smenu. |
|
175 |
item value:nil. |
|
176 |
menu addItem:item |
|
177 |
]. |
|
178 |
^ menu |
|
179 |
" |
|
180 |
(ColorMenu colorMenu:true value:nil) startUp |
|
181 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
182 |
" |
|
592 | 183 |
! ! |
184 |
||
1808 | 185 |
!ColorMenu methodsFor:'accepting'! |
412 | 186 |
|
187 |
accept:anItem |
|
664 | 188 |
"accept current selected item" |
189 |
||
412 | 190 |
|item holder color| |
191 |
||
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
192 |
((item := super accept:anItem) notNil and: [item nameKey ~~ #def]) |
664 | 193 |
ifTrue: |
194 |
[ |
|
195 |
(holder := self colorHolder) == item ifTrue: |
|
196 |
[ |
|
412 | 197 |
enabledChannel value ifTrue:[color := self color] |
664 | 198 |
] |
199 |
ifFalse: |
|
1057 | 200 |
[ |
666 | 201 |
color := item argument. |
692 | 202 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 203 |
]. |
204 |
model notNil ifTrue:[model value:color] |
|
205 |
] |
|
206 |
! ! |
|
207 |
||
208 |
!ColorMenu methodsFor:'accessing'! |
|
209 |
||
210 |
color |
|
664 | 211 |
"get current color" |
212 |
||
213 |
|firstEmphasis| |
|
214 |
(firstEmphasis := (self colorHolder label emphasis at:1)) isAssociation ifTrue: [^firstEmphasis value]. |
|
215 |
^(firstEmphasis at: 1) value |
|
412 | 216 |
! |
217 |
||
218 |
color:aColor |
|
664 | 219 |
"set current color" |
220 |
||
412 | 221 |
|holder label| |
222 |
||
2184 | 223 |
aColor isColor ifFalse:[ |
412 | 224 |
enabledChannel value:false |
2184 | 225 |
] ifTrue:[ |
226 |
self |
|
227 |
disabledRedrawDo: |
|
228 |
[ |
|
229 |
holder := self colorHolder. |
|
230 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
231 |
enabledChannel value:true. |
|
232 |
holder label:label. |
|
233 |
model value: aColor |
|
234 |
] |
|
412 | 235 |
] |
664 | 236 |
! |
237 |
||
238 |
labelsAreColored: aBoolean |
|
239 |
"sets whether labels or their backgrounds will be colored" |
|
240 |
||
241 |
labelsAreColored := aBoolean ? false. |
|
242 |
self setupMenu |
|
243 |
||
412 | 244 |
! ! |
245 |
||
1818 | 246 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 247 |
|
248 |
model:aValueHolder |
|
664 | 249 |
"set my color channel" |
250 |
||
2184 | 251 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
252 |
model notNil ifTrue:[ |
2186 | 253 |
self updateFromModel |
664 | 254 |
] |
412 | 255 |
! ! |
256 |
||
257 |
!ColorMenu methodsFor:'change & update'! |
|
258 |
||
2186 | 259 |
updateFromModel |
2184 | 260 |
self color:(model value) |
412 | 261 |
! ! |
262 |
||
263 |
!ColorMenu methodsFor:'initialization'! |
|
264 |
||
265 |
destroy |
|
664 | 266 |
"release color channel dependency" |
267 |
||
412 | 268 |
self model:nil. |
664 | 269 |
super destroy |
412 | 270 |
|
271 |
! |
|
272 |
||
273 |
initialize |
|
664 | 274 |
"setup menu" |
275 |
||
412 | 276 |
super initialize. |
2254 | 277 |
labelsAreColored := false. |
278 |
verticalLayout := false. |
|
279 |
||
412 | 280 |
self fitFirstPanel:false. |
895 | 281 |
enabledChannel := ValueHolder with:false. |
412 | 282 |
self setupMenu. |
895 | 283 |
|
284 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 285 |
! |
286 |
||
287 |
setupMenu |
|
664 | 288 |
"setup menu" |
666 | 289 |
|menu item| |
412 | 290 |
|
666 | 291 |
menu := self class colorMenu:labelsAreColored value:nil. |
292 |
menu itemsDo:[:el| el isButton:true]. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
293 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
294 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
295 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
296 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
297 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
298 |
|defineColor| |
2704 | 299 |
defineColor := ColorEditDialog new color: self color. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
300 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
301 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 302 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
303 |
]; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
304 |
nameKey:#def; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
305 |
isButton: true) |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
306 |
beforeIndex:8. |
1057 | 307 |
menu addItem:(MenuItem labeled:'') beforeIndex:8. |
806 | 308 |
menu addItem:(MenuItem labeled:' ') beforeIndex:5. |
309 |
menu addItem:(MenuItem labeled:' ') beforeIndex:2. |
|
310 |
menu addItem:(MenuItem labeled:' ') beforeIndex:1. |
|
311 |
||
666 | 312 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
313 |
item value:#selection. |
|
314 |
menu addItem:item beforeIndex:1. |
|
806 | 315 |
|
412 | 316 |
self menu:menu. |
317 |
||
666 | 318 |
self do:[:anItem| |
319 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 320 |
anItem enabled:enabledChannel. |
666 | 321 |
] ifFalse:[ |
322 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 323 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
324 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 325 |
] |
664 | 326 |
] |
412 | 327 |
! ! |
328 |
||
329 |
!ColorMenu methodsFor:'private'! |
|
330 |
||
331 |
colorHolder |
|
332 |
"returns the item which keeps the selected color in its label |
|
333 |
" |
|
334 |
^ self itemAt:#selection |
|
335 |
! ! |
|
336 |
||
337 |
!ColorMenu class methodsFor:'documentation'! |
|
338 |
||
339 |
version |
|
2704 | 340 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.33 2004-05-11 12:50:21 cg Exp $' |
412 | 341 |
! ! |