1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.util;
21
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Container;
25
26 import javax.swing.UIManager;
27 import javax.swing.plaf.metal.MetalLookAndFeel;
28
29
30
31
32
33
34
35
36
37
38
39 public final class ColorHelper {
40 public final static String[] COLOR_NAMES = new String[] {
41 "Alarm", "AlarmOutline", "Control", "ControlDarkShadow",
42 "ControlHighlight", "ControlShadow", "ControlText", "CosyControl",
43 "CosyControlDarkShadow", "CosyControlHighlight", "CosyControlShadow",
44 "CosyControlText", "CosyErrorText", "CosyInputBackground",
45 "CosyOverlay", "Error", "EmergencyOutline", "Emergency", "Focus",
46 "Hyperlink", "Text", "TextHighlight", "TimeOut", "Warning",
47 "WarningOutline", "WindowBackground"
48 };
49 public final static String[] JAVA_COLOR_NAMES = new String[] {
50 "BLACK", "BLUE", "CYAN", "DARK_GRAY", "GRAY", "GREEN", "LIGHT_GRAY",
51 "MAGENTA", "ORANGE", "PINK", "RED", "WHITE", "YELLOW"
52 };
53 private final static Color COSY_CONTROL = new Color(206, 206, 227);
54 private final static Color COSY_CONTROL_SHADOW = new Color(126, 126, 177);
55 private final static Color COSY_CONTROL_HIGHLIGHT = new Color(246, 246, 255);
56 private final static Color COSY_CONTROL_DARK_SHADOW = new Color(86, 86, 157);
57 private final static Color HYPERLINK = new Color(0, 0, 255);
58 private final static Color ALARM = new Color(255, 128, 128);
59 private final static Color ALARM_OUTLINE = new Color(255, 0, 0);
60 private final static Color EMERGENCY = new Color(255, 64, 64);
61 private final static Color EMERGENCY_OUTLINE = new Color(255, 0, 0);
62 private final static Color WARNING = new Color(255, 255, 0);
63 private final static Color WARNING_OUTLINE = new Color(232, 216, 0);
64 private final static Color TIMEOUT = new Color(242, 0, 218);
65 private final static Color TIMEOUT_OUTLINE = new Color(242, 121, 230);
66 private final static Color ALARM_INVALID = new Color(242, 0, 200);
67 private final static Color ALARM_MAJOR = new Color(255, 0, 0);
68 private final static Color ALARM_MINOR = new Color(255, 235, 0);
69 private final static Color ALARM_INVALID_BACKGROUND = new Color(242, 124, 222);
70 private final static Color ALARM_MAJOR_BACKGROUND = new Color(255, 96, 96);
71 private final static Color ALARM_MINOR_BACKGROUND = new Color(255, 248, 40);
72
73
74
75
76
77
78
79
80
81 public static Color getControl() {
82 Color ret = UIManager.getColor("control");
83
84 if (ret != null) {
85 return ret;
86 }
87
88 return MetalLookAndFeel.getControl();
89 }
90
91
92
93
94
95
96 public static Color getControlShadow() {
97 Color ret = UIManager.getColor("controlShadow");
98
99 if (ret != null) {
100 return ret;
101 }
102
103 return MetalLookAndFeel.getControlDarkShadow();
104 }
105
106
107
108
109
110
111 public static Color getControlDarkShadow() {
112 Color ret = UIManager.getColor("controlDkShadow");
113
114 if (ret != null) {
115 return ret;
116 }
117
118 return MetalLookAndFeel.getControlDarkShadow();
119 }
120
121
122
123
124
125
126 public static Color getControlHighlight() {
127 Color ret = UIManager.getColor("controlHighlight");
128
129 if (ret != null) {
130 return ret;
131 }
132
133 return MetalLookAndFeel.getControlHighlight();
134 }
135
136
137
138
139
140
141 public static Color getControlLightHighlight() {
142 Color ret = UIManager.getColor("controlLtHighlight");
143
144 if (ret != null) {
145 return ret;
146 }
147
148 return MetalLookAndFeel.getControlHighlight();
149 }
150
151
152
153
154
155
156 public static final Color getControlText() {
157 Color ret = UIManager.getColor("controlText");
158
159 if (ret != null) {
160 return ret;
161 }
162
163 return MetalLookAndFeel.getControlTextColor();
164 }
165
166
167
168
169
170
171 public static Color getWindowBackground() {
172 Color ret = UIManager.getColor("window");
173
174 if (ret != null) {
175 return ret;
176 }
177
178 return MetalLookAndFeel.getWindowBackground();
179 }
180
181
182
183
184
185
186 public static Color getText() {
187 Color ret = UIManager.getColor("windowText");
188
189 if (ret != null) {
190 return ret;
191 }
192
193 return MetalLookAndFeel.getUserTextColor();
194 }
195
196
197
198
199
200
201 public static Color getTextHighlight() {
202 Color ret = UIManager.getColor("textHighlight");
203
204 if (ret != null) {
205 return ret;
206 }
207
208 return MetalLookAndFeel.getTextHighlightColor();
209 }
210
211
212
213
214 public static Color getTextHighlightText() {
215 Color ret = UIManager.getColor("textHighlightText");
216
217 if (ret != null) {
218 return ret;
219 }
220
221 return MetalLookAndFeel.getUserTextColor();
222 }
223
224
225
226
227
228
229
230 public static Color getFocus() {
231
232 return MetalLookAndFeel.getFocusColor();
233 }
234
235
236
237
238
239
240 public static Color getCosyControl() {
241 return COSY_CONTROL;
242 }
243
244
245
246
247
248
249 public static Color getCosyControlHighlight() {
250 return COSY_CONTROL_HIGHLIGHT;
251 }
252
253
254
255
256
257
258 public static Color getCosyControlShadow() {
259 return COSY_CONTROL_SHADOW;
260 }
261
262
263
264
265
266
267 public static Color getCosyControlDarkShadow() {
268 return COSY_CONTROL_DARK_SHADOW;
269 }
270
271
272
273
274
275
276 public static Color getCosyControlText() {
277 return Color.BLACK;
278 }
279
280
281
282
283
284
285 public static Color getCosyInputBackground() {
286 return MetalLookAndFeel.getWindowBackground();
287 }
288
289
290
291
292
293
294 public static Color getCosyErrorText() {
295 return Color.RED;
296 }
297
298
299
300
301
302
303 public static Color getCosyOverlay() {
304 return Color.GRAY;
305 }
306
307
308
309
310
311
312 public static Color getTimeOut() {
313 return TIMEOUT;
314 }
315
316 public static Color getTimeOutOutline() {
317 return TIMEOUT_OUTLINE;
318 }
319
320
321
322
323
324
325 public static Color getWarning() {
326 return WARNING;
327 }
328
329
330
331
332
333
334 public static Color getWarningOutline() {
335 return WARNING_OUTLINE;
336 }
337
338
339
340
341
342
343 public static Color getError() {
344 return Color.RED;
345 }
346
347
348
349
350
351
352 public static Color getAlarm() {
353 return ALARM;
354 }
355
356
357
358
359
360
361 public static Color getAlarmInvalid() {
362 return ALARM_INVALID;
363 }
364
365
366
367
368
369
370 public static Color getAlarmMajor() {
371 return ALARM_MAJOR;
372 }
373
374
375
376
377
378 public static Color getAlarmMinor() {
379 return ALARM_MINOR;
380 }
381
382
383
384
385
386
387 public static Color getAlarmMinorBackground() {
388 return ALARM_MINOR_BACKGROUND;
389 }
390
391
392
393
394
395 public static Color getAlarmInvalidBackground() {
396 return ALARM_INVALID_BACKGROUND;
397 }
398
399
400
401
402
403
404 public static Color getAlarmMajorBackground() {
405 return ALARM_MAJOR_BACKGROUND;
406 }
407
408
409
410
411
412
413 public static Color getAlarmOutline() {
414 return ALARM_OUTLINE;
415 }
416
417
418
419
420
421
422 public static Color getEmergency() {
423 return EMERGENCY;
424 }
425
426
427
428
429
430
431 public static Color getEmergencyOutline() {
432 return EMERGENCY_OUTLINE;
433 }
434
435 public static Color getHyperlink() {
436 return HYPERLINK;
437 }
438
439
440
441
442
443
444
445
446 public static void setBackgroundForComponents(Component[] components, Color background) {
447 for (Component c : components) {
448 c.setBackground(background);
449 if (c instanceof Container) {
450 setBackgroundForComponents(((Container)c).getComponents(), background);
451 }
452 }
453 }
454
455
456
457
458
459
460
461
462 public static void setForegroundForComponents(Component[] components, Color foreground) {
463 for (Component c : components) {
464 c.setForeground(foreground);
465 if (c instanceof Container) {
466 setForegroundForComponents(((Container)c).getComponents(), foreground);
467 }
468 }
469 }
470
471 }