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