KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > r21 > R21Colors


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.presentations.r21;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.runtime.Assert;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.RGB;
20 import org.eclipse.swt.widgets.Display;
21
22 /**
23  * This class manages the R21 workbench colors (they are fixed).
24  */

25 public class R21Colors {
26
27     static private boolean init = false;
28
29     static private HashMap JavaDoc colorMap;
30
31     static private HashMap JavaDoc systemColorMap;
32
33     static private Color workbenchColors[];
34
35     static private Color[] activeViewGradient;
36
37     static private Color[] deactivatedViewGradient;
38
39     static private Color[] activeEditorGradient;
40
41     static private Color[] activeNoFocusEditorGradient;
42
43     static private Color[] deactivatedEditorGradient;
44
45     static private int[] activeViewPercentages;
46
47     static private int[] deactivatedViewPercentages;
48
49     static private int[] activeEditorPercentages;
50
51     static private int[] activeNoFocusEditorPercentages;
52
53     static private int[] deactivatedEditorPercentages;
54
55     static private final String JavaDoc CLR_VIEW_GRAD_START = "clrViewGradStart";//$NON-NLS-1$
56

57     static private final String JavaDoc CLR_VIEW_GRAD_END = "clrViewGradEnd";//$NON-NLS-1$
58

59     static private final String JavaDoc CLR_EDITOR_GRAD_START = "clrEditorGradStart";//$NON-NLS-1$
60

61     static private final String JavaDoc CLR_EDITOR_GRAD_END = "clrEditorGradEnd";//$NON-NLS-1$
62

63     /**
64      * Dispose all color pre-allocated by the workbench.
65      */

66     private static void disposeWorkbenchColors() {
67         for (int i = 0; i < workbenchColors.length; i++) {
68             workbenchColors[i].dispose();
69         }
70     }
71
72     /**
73      * Returns the active editor gradient.
74      */

75     static public Color[] getActiveEditorGradient() {
76         return activeEditorGradient;
77     }
78
79     /**
80      * Returns the active editor gradient end color.
81      */

82     static public Color getActiveEditorGradientEnd() {
83         Color clr = (Color) systemColorMap.get(CLR_EDITOR_GRAD_END);
84         Assert.isNotNull(clr);
85         return clr;
86     }
87
88     /**
89      * Returns the active editor gradient percents.
90      */

91     static public int[] getActiveEditorGradientPercents() {
92         return activeEditorPercentages;
93     }
94
95     /**
96      * Returns the active editor gradient start color.
97      */

98     static public Color getActiveEditorGradientStart() {
99         Color clr = (Color) systemColorMap.get(CLR_EDITOR_GRAD_START);
100         Assert.isNotNull(clr);
101         return clr;
102     }
103
104     /**
105      * Returns the active no focus editor gradient.
106      */

107     static public Color[] getActiveNoFocusEditorGradient() {
108         return activeNoFocusEditorGradient;
109     }
110
111     /**
112      * Returns the active no focus editor gradient percents.
113      */

114     static public int[] getActiveNoFocusEditorGradientPercents() {
115         return activeNoFocusEditorPercentages;
116     }
117
118     /**
119      * Returns the active gradient for views.
120      */

121     static public Color[] getActiveViewGradient() {
122         return activeViewGradient;
123     }
124
125     /**
126      * Returns the active view gradient end color.
127      */

128     static public Color getActiveViewGradientEnd() {
129         Color clr = (Color) systemColorMap.get(CLR_VIEW_GRAD_END);
130         Assert.isNotNull(clr);
131         return clr;
132     }
133
134     /**
135      * Returns the active view gradient percents.
136      */

137     static public int[] getActiveViewGradientPercents() {
138         return activeViewPercentages;
139     }
140
141     /**
142      * Returns the active view gradient start color.
143      */

144     static public Color getActiveViewGradientStart() {
145         Color clr = (Color) systemColorMap.get(CLR_VIEW_GRAD_START);
146         Assert.isNotNull(clr);
147         return clr;
148     }
149
150     /**
151      * Returns the gradient for editors when the window is deactivated.
152      */

153     static public Color[] getDeactivatedEditorGradient() {
154         return deactivatedEditorGradient;
155     }
156
157     /**
158      * Returns the editor gradient percents when the window is deactivated.
159      */

160     static public int[] getDeactivatedEditorGradientPercents() {
161         return deactivatedEditorPercentages;
162     }
163
164     /**
165      * Returns the gradient for views when the window is deactivated.
166      */

167     static public Color[] getDeactivatedViewGradient() {
168         return deactivatedViewGradient;
169     }
170
171     /**
172      * Returns the view gradient percents when the window is deactivated.
173      */

174     static public int[] getDeactivatedViewGradientPercents() {
175         return deactivatedViewPercentages;
176     }
177
178     /**
179      * Returns a color identified by an RGB value.
180      */

181     static public Color getColor(RGB rgbValue) {
182         Color clr = (Color) colorMap.get(rgbValue);
183         if (clr == null) {
184             Display disp = Display.getDefault();
185             clr = new Color(disp, rgbValue);
186             colorMap.put(rgbValue, clr);
187         }
188         return clr;
189     }
190
191     /**
192      * Returns a system color identified by a SWT constant.
193      */

194     static public Color getSystemColor(int swtId) {
195         Integer JavaDoc bigInt = new Integer JavaDoc(swtId);
196         Color clr = (Color) systemColorMap.get(bigInt);
197         if (clr == null) {
198             Display disp = Display.getDefault();
199             clr = disp.getSystemColor(swtId);
200             systemColorMap.put(bigInt, clr);
201         }
202         return clr;
203     }
204
205     /**
206      * Initialize all colors used in the workbench in case the OS is using a 256
207      * color palette making sure the workbench colors are allocated.
208      *
209      * This list comes from the designers.
210      */

211     private static void initWorkbenchColors(Display d) {
212         if (workbenchColors != null) {
213             return;
214         }
215
216         workbenchColors = new Color[] {
217         //Product pallet
218
new Color(d, 255, 255, 255), new Color(d, 255, 251, 240),
219                 new Color(d, 223, 223, 191), new Color(d, 223, 191, 191),
220                 new Color(d, 192, 220, 192), new Color(d, 192, 192, 192),
221                 new Color(d, 191, 191, 191), new Color(d, 191, 191, 159),
222                 new Color(d, 191, 159, 191), new Color(d, 160, 160, 164),
223                 new Color(d, 159, 159, 191), new Color(d, 159, 159, 159),
224                 new Color(d, 159, 159, 127), new Color(d, 159, 127, 159),
225                 new Color(d, 159, 127, 127), new Color(d, 128, 128, 128),
226                 new Color(d, 127, 159, 159), new Color(d, 127, 159, 127),
227                 new Color(d, 127, 127, 159), new Color(d, 127, 127, 127),
228                 new Color(d, 127, 127, 95), new Color(d, 127, 95, 127),
229                 new Color(d, 127, 95, 95), new Color(d, 95, 127, 127),
230                 new Color(d, 95, 127, 95), new Color(d, 95, 95, 127),
231                 new Color(d, 95, 95, 95), new Color(d, 95, 95, 63),
232                 new Color(d, 95, 63, 95), new Color(d, 95, 63, 63),
233                 new Color(d, 63, 95, 95), new Color(d, 63, 95, 63),
234                 new Color(d, 63, 63, 95), new Color(d, 0, 0, 0),
235                 //wizban pallet
236
new Color(d, 195, 204, 224), new Color(d, 214, 221, 235),
237                 new Color(d, 149, 168, 199), new Color(d, 128, 148, 178),
238                 new Color(d, 106, 128, 158), new Color(d, 255, 255, 255),
239                 new Color(d, 0, 0, 0), new Color(d, 0, 0, 0),
240                 //Perspective
241
new Color(d, 132, 130, 132), new Color(d, 143, 141, 138),
242                 new Color(d, 171, 168, 165),
243                 //PreferenceDialog and TitleAreaDialog
244
new Color(d, 230, 226, 221) };
245     }
246
247     /**
248      * Disposes of the colors. Ignore all system colors as they do not need to
249      * be disposed.
250      */

251     static public void shutdown() {
252         if (!init) {
253             return;
254         }
255
256         disposeWorkbenchColors();
257
258         Iterator JavaDoc iter = colorMap.values().iterator();
259         while (iter.hasNext()) {
260             Color clr = (Color) iter.next();
261             if (clr != null) {
262                 clr.dispose();
263             }
264         }
265
266         colorMap.clear();
267         systemColorMap.clear();
268         init = false;
269     }
270
271     /**
272      * Initializes the colors.
273      */

274     static public void startup() {
275         if (init) {
276             return;
277         }
278
279         // Initialize the caches first.
280
init = true;
281         colorMap = new HashMap JavaDoc(10);
282         systemColorMap = new HashMap JavaDoc(10);
283
284         initWorkbenchColors(Display.getDefault());
285         // Define active view gradient using same OS title gradient colors.
286
Color clr1 = getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
287         Color clr2 = getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
288         Color clr3 = getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
289         systemColorMap.put(CLR_VIEW_GRAD_START, clr1);
290         systemColorMap.put(CLR_VIEW_GRAD_END, clr3);
291         activeViewGradient = new Color[] { clr1, clr2, clr3 };
292         activeViewPercentages = new int[] { 50, 100 };
293
294         // Define active editor gradient using same OS title gradient colors.
295
systemColorMap.put(CLR_EDITOR_GRAD_START, clr1);
296         systemColorMap.put(CLR_EDITOR_GRAD_END, null); // use widget default
297
// background
298
activeEditorGradient = new Color[] { clr1, clr2, null, null };
299         activeEditorPercentages = new int[] { 50, 90, 100 };
300
301         // Define active no focus editor gradient
302
activeNoFocusEditorGradient = new Color[] { getSystemColor(SWT.COLOR_LIST_BACKGROUND) };
303         activeNoFocusEditorPercentages = new int[0];
304
305         // Define view gradient for deactivated window using same OS title
306
// gradient colors.
307
clr1 = getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND);
308         clr2 = getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
309         clr3 = getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
310         deactivatedViewGradient = new Color[] { clr1, clr2, clr3 };
311         deactivatedViewPercentages = new int[] { 70, 100 };
312
313         // Define editor gradient for deactivated window using same OS title
314
// gradient colors.
315
deactivatedEditorGradient = new Color[] { clr1, clr2, null, null };
316         deactivatedEditorPercentages = new int[] { 70, 95, 100 };
317
318         // Preload.
319
getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
320         getSystemColor(SWT.COLOR_BLACK);
321     }
322 }
323
Popular Tags