KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > resource > JFaceColors


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.jface.resource;
12
13 import org.eclipse.jface.preference.JFacePreferences;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Color;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Display;
18
19 /**
20  * JFaceColors is the class that stores references
21  * to all of the colors used by JFace.
22  */

23 public class JFaceColors {
24
25     /**
26      * @param display the display the color is from
27      * @return the Color used for banner backgrounds
28      * @see SWT#COLOR_LIST_BACKGROUND
29      * @see Display#getSystemColor(int)
30      */

31     public static Color getBannerBackground(Display display) {
32         return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
33     }
34
35     /**
36      * @param display the display the color is from
37      * @return the Color used for banner foregrounds
38      * @see SWT#COLOR_LIST_FOREGROUND
39      * @see Display#getSystemColor(int)
40      */

41     public static Color getBannerForeground(Display display) {
42         return display.getSystemColor(SWT.COLOR_LIST_FOREGROUND);
43     }
44
45     /**
46      * @param display the display the color is from
47      * @return the background Color for widgets that display errors.
48      * @see SWT#COLOR_WIDGET_BACKGROUND
49      * @see Display#getSystemColor(int)
50      */

51     public static Color getErrorBackground(Display display) {
52         return display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
53     }
54
55     /**
56      * @param display the display the color is from
57      * @return the border Color for widgets that display errors.
58      * @see SWT#COLOR_WIDGET_DARK_SHADOW
59      * @see Display#getSystemColor(int)
60      */

61     public static Color getErrorBorder(Display display) {
62         return display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
63     }
64
65     /**
66      * @param display the display the color is from
67      * @return the default color to use for displaying errors.
68      * @see ColorRegistry#get(String)
69      * @see JFacePreferences#ERROR_COLOR
70      */

71     public static Color getErrorText(Display display) {
72         return JFaceResources.getColorRegistry().get(
73                 JFacePreferences.ERROR_COLOR);
74     }
75
76     /**
77      * @param display the display the color is from
78      * @return the default color to use for displaying hyperlinks.
79      * @see ColorRegistry#get(String)
80      * @see JFacePreferences#HYPERLINK_COLOR
81      */

82     public static Color getHyperlinkText(Display display) {
83         return JFaceResources.getColorRegistry().get(
84                 JFacePreferences.HYPERLINK_COLOR);
85     }
86
87     /**
88      * @param display the display the color is from
89      * @return the default color to use for displaying active hyperlinks.
90      * @see ColorRegistry#get(String)
91      * @see JFacePreferences#ACTIVE_HYPERLINK_COLOR
92      */

93     public static Color getActiveHyperlinkText(Display display) {
94         return JFaceResources.getColorRegistry().get(
95                 JFacePreferences.ACTIVE_HYPERLINK_COLOR);
96     }
97
98     /**
99      * Clear out the cached color for name. This is generally
100      * done when the color preferences changed and any cached colors
101      * may be disposed. Users of the colors in this class should add a IPropertyChangeListener
102      * to detect when any of these colors change.
103      * @param colorName name of the color
104      *
105      * @deprecated JFaceColors no longer maintains a cache of colors. This job
106      * is now handled by the ColorRegistry.
107      */

108     public static void clearColor(String JavaDoc colorName) {
109         //no-op
110
}
111
112     /**
113      * Dispose of all allocated colors. Called on workbench
114      * shutdown.
115      *
116      * @deprecated JFaceColors no longer maintains a cache of colors. This job
117      * is now handled by the ColorRegistry.
118      */

119     public static void disposeColors() {
120         //no-op
121
}
122
123     /**
124      * Set the foreground and background colors of the
125      * control to the specified values. If the values are
126      * null than ignore them.
127      * @param control the control the foreground and/or background color should be set
128      *
129      * @param foreground Color the foreground color (maybe <code>null</code>)
130      * @param background Color the background color (maybe <code>null</code>)
131      */

132     public static void setColors(Control control, Color foreground,
133             Color background) {
134         if (foreground != null) {
135             control.setForeground(foreground);
136         }
137         if (background != null) {
138             control.setBackground(background);
139         }
140     }
141
142 }
143
Popular Tags