author | ca |
Fri, 20 Oct 2006 11:17:54 +0200 | |
changeset 3129 | 8bdcf8e416a3 |
parent 2935 | e3fa9d1a7a64 |
child 3280 | c42ab6572f32 |
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' |
666 | 16 |
classVariableNames:'' |
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 |
||
70 |
!ColorMenu class methodsFor:'menu spec'! |
|
71 |
||
666 | 72 |
colorDefinition |
73 |
"color definitions used to build a color menu |
|
412 | 74 |
" |
583 | 75 |
|
666 | 76 |
^ #( |
668 | 77 |
#( gray |
666 | 78 |
gray: |
79 |
#( white |
|
80 |
veryLightGray |
|
81 |
lightGray |
|
82 |
gray |
|
83 |
darkGray |
|
84 |
veryDarkGray |
|
85 |
black |
|
86 |
) |
|
412 | 87 |
) |
666 | 88 |
|
668 | 89 |
#( red |
666 | 90 |
red: |
854 | 91 |
#( lightened 100 87 67 50 33) |
666 | 92 |
) |
93 |
||
668 | 94 |
#( green |
666 | 95 |
green: |
854 | 96 |
#( lightened 100 87 67 50 33) |
666 | 97 |
) |
98 |
||
668 | 99 |
#( blue |
666 | 100 |
blue: |
854 | 101 |
#( lightened 100 87 67 50 33) |
666 | 102 |
) |
103 |
||
668 | 104 |
#( cyan |
854 | 105 |
cyan: |
106 |
#( lightened 100 87 67 50 33) |
|
664 | 107 |
) |
666 | 108 |
|
668 | 109 |
#( magenta |
854 | 110 |
magenta: |
111 |
#( lightened 100 87 67 50 33) |
|
412 | 112 |
) |
666 | 113 |
|
668 | 114 |
#( yellow |
854 | 115 |
yellow: |
116 |
#( lightened 100 87 67 50 33) |
|
412 | 117 |
) |
806 | 118 |
|
412 | 119 |
) |
666 | 120 |
! |
121 |
||
122 |
colorMenu:labelAreColored value:aValue |
|
123 |
"returns a color menu |
|
124 |
" |
|
3129 | 125 |
|menu style| |
126 |
||
127 |
menu := Menu new. |
|
666 | 128 |
|
3129 | 129 |
labelAreColored == false ifTrue:[ style := #backgroundColor ] |
130 |
ifFalse:[ style := #color ]. |
|
666 | 131 |
|
3129 | 132 |
self colorDefinition do:[:aSlice| |item baseColor getColSel subMenu colorId| |
666 | 133 |
|
3129 | 134 |
subMenu := Menu new. |
135 |
colorId := aSlice at:1. |
|
136 |
getColSel := aSlice at:2. |
|
137 |
baseColor := Color perform:colorId. |
|
412 | 138 |
|
3129 | 139 |
aSlice last do:[:el||label color| |
140 |
color := label := nil. |
|
141 |
||
666 | 142 |
el isSymbol ifTrue:[ |
3129 | 143 |
el == #lightened ifTrue:[ color := baseColor perform:el ] |
144 |
ifFalse:[ color := Color perform:el ]. |
|
145 |
||
146 |
colorId == #gray ifTrue:[ label := el ]. |
|
666 | 147 |
] ifFalse:[ |
148 |
el isNumber ifTrue:[ |
|
3129 | 149 |
color := Color perform:getColSel with:el. |
666 | 150 |
] |
151 |
]. |
|
3129 | 152 |
color notNil ifTrue:[ |emphasis| |
153 |
label isNil ifTrue:[ label := getColSel, ' ', el printString ]. |
|
154 |
||
155 |
emphasis := style->color. |
|
156 |
style == #backgroundColor ifTrue:[ |
|
157 |
color brightness < 0.5 ifTrue:[ |
|
158 |
emphasis := Array with:emphasis with:(#color->Color white) |
|
159 |
] |
|
160 |
]. |
|
161 |
item := MenuItem labeled:(Text string:('Color ', label) emphasis:emphasis). |
|
162 |
item argument:color. |
|
163 |
item value:aValue. |
|
164 |
subMenu addItem:item. |
|
1372
54d8812de860
care for good contrast in color-menus
Claus Gittinger <cg@exept.de>
parents:
1119
diff
changeset
|
165 |
]. |
666 | 166 |
]. |
3129 | 167 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
168 |
item submenu:subMenu. |
|
666 | 169 |
item value:nil. |
3129 | 170 |
menu addItem:item. |
666 | 171 |
]. |
172 |
^ menu |
|
173 |
" |
|
174 |
(ColorMenu colorMenu:true value:nil) startUp |
|
175 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
176 |
" |
|
592 | 177 |
! ! |
178 |
||
1808 | 179 |
!ColorMenu methodsFor:'accepting'! |
412 | 180 |
|
181 |
accept:anItem |
|
664 | 182 |
"accept current selected item" |
183 |
||
412 | 184 |
|item holder color| |
185 |
||
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
186 |
((item := super accept:anItem) notNil and: [item nameKey ~~ #def]) |
664 | 187 |
ifTrue: |
188 |
[ |
|
189 |
(holder := self colorHolder) == item ifTrue: |
|
190 |
[ |
|
412 | 191 |
enabledChannel value ifTrue:[color := self color] |
664 | 192 |
] |
193 |
ifFalse: |
|
1057 | 194 |
[ |
666 | 195 |
color := item argument. |
692 | 196 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 197 |
]. |
198 |
model notNil ifTrue:[model value:color] |
|
199 |
] |
|
200 |
! ! |
|
201 |
||
202 |
!ColorMenu methodsFor:'accessing'! |
|
203 |
||
204 |
color |
|
664 | 205 |
"get current color" |
206 |
||
207 |
|firstEmphasis| |
|
208 |
(firstEmphasis := (self colorHolder label emphasis at:1)) isAssociation ifTrue: [^firstEmphasis value]. |
|
209 |
^(firstEmphasis at: 1) value |
|
412 | 210 |
! |
211 |
||
212 |
color:aColor |
|
664 | 213 |
"set current color" |
214 |
||
412 | 215 |
|holder label| |
216 |
||
2184 | 217 |
aColor isColor ifFalse:[ |
412 | 218 |
enabledChannel value:false |
2184 | 219 |
] ifTrue:[ |
220 |
self |
|
221 |
disabledRedrawDo: |
|
222 |
[ |
|
223 |
holder := self colorHolder. |
|
224 |
label := Text string: ' ' emphasis:(#backgroundColor->aColor). |
|
225 |
enabledChannel value:true. |
|
226 |
holder label:label. |
|
227 |
model value: aColor |
|
228 |
] |
|
412 | 229 |
] |
664 | 230 |
! |
231 |
||
232 |
labelsAreColored: aBoolean |
|
233 |
"sets whether labels or their backgrounds will be colored" |
|
234 |
||
235 |
labelsAreColored := aBoolean ? false. |
|
236 |
self setupMenu |
|
237 |
||
412 | 238 |
! ! |
239 |
||
1818 | 240 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 241 |
|
242 |
model:aValueHolder |
|
664 | 243 |
"set my color channel" |
244 |
||
2184 | 245 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
246 |
model notNil ifTrue:[ |
2186 | 247 |
self updateFromModel |
664 | 248 |
] |
412 | 249 |
! ! |
250 |
||
251 |
!ColorMenu methodsFor:'change & update'! |
|
252 |
||
2186 | 253 |
updateFromModel |
2184 | 254 |
self color:(model value) |
412 | 255 |
! ! |
256 |
||
257 |
!ColorMenu methodsFor:'initialization'! |
|
258 |
||
259 |
destroy |
|
664 | 260 |
"release color channel dependency" |
261 |
||
412 | 262 |
self model:nil. |
664 | 263 |
super destroy |
412 | 264 |
|
265 |
! |
|
266 |
||
267 |
initialize |
|
664 | 268 |
"setup menu" |
269 |
||
412 | 270 |
super initialize. |
2254 | 271 |
labelsAreColored := false. |
272 |
verticalLayout := false. |
|
273 |
||
412 | 274 |
self fitFirstPanel:false. |
895 | 275 |
enabledChannel := ValueHolder with:false. |
412 | 276 |
self setupMenu. |
895 | 277 |
|
278 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 279 |
! |
280 |
||
281 |
setupMenu |
|
664 | 282 |
"setup menu" |
666 | 283 |
|menu item| |
412 | 284 |
|
666 | 285 |
menu := self class colorMenu:labelsAreColored value:nil. |
286 |
menu itemsDo:[:el| el isButton:true]. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
287 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
288 |
addItem:( |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
289 |
(MenuItem labeled:'...') |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
290 |
value: |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
291 |
[ |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
292 |
|defineColor| |
2704 | 293 |
defineColor := ColorEditDialog new color: self color. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
294 |
defineColor open. |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
295 |
defineColor accept value ifTrue: [self color: defineColor color] |
1057 | 296 |
|
2183
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 |
nameKey:#def; |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
299 |
isButton: true) |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
300 |
beforeIndex:8. |
1057 | 301 |
menu addItem:(MenuItem labeled:'') beforeIndex:8. |
806 | 302 |
menu addItem:(MenuItem labeled:' ') beforeIndex:5. |
303 |
menu addItem:(MenuItem labeled:' ') beforeIndex:2. |
|
304 |
menu addItem:(MenuItem labeled:' ') beforeIndex:1. |
|
305 |
||
666 | 306 |
item := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
307 |
item value:#selection. |
|
308 |
menu addItem:item beforeIndex:1. |
|
806 | 309 |
|
412 | 310 |
self menu:menu. |
311 |
||
666 | 312 |
self do:[:anItem| |
313 |
(anItem submenu) notNil ifTrue:[ |
|
412 | 314 |
anItem enabled:enabledChannel. |
666 | 315 |
] ifFalse:[ |
316 |
anItem value == #selection ifTrue:[anItem indication:enabledChannel] |
|
1057 | 317 |
ifFalse:[anItem enabled:false]. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
318 |
anItem nameKey == #def ifTrue:[anItem enabled:enabledChannel] |
412 | 319 |
] |
664 | 320 |
] |
412 | 321 |
! ! |
322 |
||
323 |
!ColorMenu methodsFor:'private'! |
|
324 |
||
325 |
colorHolder |
|
326 |
"returns the item which keeps the selected color in its label |
|
327 |
" |
|
328 |
^ self itemAt:#selection |
|
329 |
! ! |
|
330 |
||
331 |
!ColorMenu class methodsFor:'documentation'! |
|
332 |
||
333 |
version |
|
3129 | 334 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.35 2006-10-20 09:17:54 ca Exp $' |
412 | 335 |
! ! |