001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Pavel Dolgov
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.geom.AffineTransform;
023: import java.awt.geom.Rectangle2D;
024: import java.awt.image.ColorModel;
025: import java.io.IOException;
026: import java.io.ObjectInputStream;
027: import java.io.Serializable;
028:
029: import org.apache.harmony.awt.FieldsAccessor;
030:
031: public final class SystemColor extends Color implements Serializable {
032:
033: private static final long serialVersionUID = 4503142729533789064L;
034:
035: public static final int DESKTOP = 0;
036:
037: public static final int ACTIVE_CAPTION = 1;
038:
039: public static final int ACTIVE_CAPTION_TEXT = 2;
040:
041: public static final int ACTIVE_CAPTION_BORDER = 3;
042:
043: public static final int INACTIVE_CAPTION = 4;
044:
045: public static final int INACTIVE_CAPTION_TEXT = 5;
046:
047: public static final int INACTIVE_CAPTION_BORDER = 6;
048:
049: public static final int WINDOW = 7;
050:
051: public static final int WINDOW_BORDER = 8;
052:
053: public static final int WINDOW_TEXT = 9;
054:
055: public static final int MENU = 10;
056:
057: public static final int MENU_TEXT = 11;
058:
059: public static final int TEXT = 12;
060:
061: public static final int TEXT_TEXT = 13;
062:
063: public static final int TEXT_HIGHLIGHT = 14;
064:
065: public static final int TEXT_HIGHLIGHT_TEXT = 15;
066:
067: public static final int TEXT_INACTIVE_TEXT = 16;
068:
069: public static final int CONTROL = 17;
070:
071: public static final int CONTROL_TEXT = 18;
072:
073: public static final int CONTROL_HIGHLIGHT = 19;
074:
075: public static final int CONTROL_LT_HIGHLIGHT = 20;
076:
077: public static final int CONTROL_SHADOW = 21;
078:
079: public static final int CONTROL_DK_SHADOW = 22;
080:
081: public static final int SCROLLBAR = 23;
082:
083: public static final int INFO = 24;
084:
085: public static final int INFO_TEXT = 25;
086:
087: public static final int NUM_COLORS = 26;
088:
089: public static final SystemColor desktop = new SystemColor(DESKTOP);
090:
091: public static final SystemColor activeCaption = new SystemColor(
092: ACTIVE_CAPTION);
093:
094: public static final SystemColor activeCaptionText = new SystemColor(
095: ACTIVE_CAPTION_TEXT);
096:
097: public static final SystemColor activeCaptionBorder = new SystemColor(
098: ACTIVE_CAPTION_BORDER);
099:
100: public static final SystemColor inactiveCaption = new SystemColor(
101: INACTIVE_CAPTION);
102:
103: public static final SystemColor inactiveCaptionText = new SystemColor(
104: INACTIVE_CAPTION_TEXT);
105:
106: public static final SystemColor inactiveCaptionBorder = new SystemColor(
107: INACTIVE_CAPTION_BORDER);
108:
109: public static final SystemColor window = new SystemColor(WINDOW);
110:
111: public static final SystemColor windowBorder = new SystemColor(
112: WINDOW_BORDER);
113:
114: public static final SystemColor windowText = new SystemColor(
115: WINDOW_TEXT);
116:
117: public static final SystemColor menu = new SystemColor(MENU);
118:
119: public static final SystemColor menuText = new SystemColor(
120: MENU_TEXT);
121:
122: public static final SystemColor text = new SystemColor(TEXT);
123:
124: public static final SystemColor textText = new SystemColor(
125: TEXT_TEXT);
126:
127: public static final SystemColor textHighlight = new SystemColor(
128: TEXT_HIGHLIGHT);
129:
130: public static final SystemColor textHighlightText = new SystemColor(
131: TEXT_HIGHLIGHT_TEXT);
132:
133: public static final SystemColor textInactiveText = new SystemColor(
134: TEXT_INACTIVE_TEXT);
135:
136: public static final SystemColor control = new SystemColor(CONTROL);
137:
138: public static final SystemColor controlText = new SystemColor(
139: CONTROL_TEXT);
140:
141: public static final SystemColor controlHighlight = new SystemColor(
142: CONTROL_HIGHLIGHT);
143:
144: public static final SystemColor controlLtHighlight = new SystemColor(
145: CONTROL_LT_HIGHLIGHT);
146:
147: public static final SystemColor controlShadow = new SystemColor(
148: CONTROL_SHADOW);
149:
150: public static final SystemColor controlDkShadow = new SystemColor(
151: CONTROL_DK_SHADOW);
152:
153: public static final SystemColor scrollbar = new SystemColor(
154: SCROLLBAR);
155:
156: public static final SystemColor info = new SystemColor(INFO);
157:
158: public static final SystemColor infoText = new SystemColor(
159: INFO_TEXT);
160:
161: private final transient Toolkit toolkit = Toolkit
162: .getDefaultToolkit();
163:
164: private int getHeadlessSystemColorARGB(int index) {
165: switch (index) {
166: // Grey-blue
167: case SystemColor.ACTIVE_CAPTION:
168: return 0xff336699;
169: case SystemColor.ACTIVE_CAPTION_BORDER:
170: return 0xffcccccc;
171: case SystemColor.ACTIVE_CAPTION_TEXT:
172: return 0xffffffff;
173: // Light grey
174: case SystemColor.CONTROL:
175: return 0xffdddddd;
176: // Dark grey
177: case SystemColor.CONTROL_DK_SHADOW:
178: return 0xff777777;
179: // Almost white
180: case SystemColor.CONTROL_HIGHLIGHT:
181: return 0xffeeeeee;
182: // White
183: case SystemColor.CONTROL_LT_HIGHLIGHT:
184: return 0xffffffff;
185: // Grey
186: case SystemColor.CONTROL_SHADOW:
187: return 0xff999999;
188: // Black
189: case SystemColor.CONTROL_TEXT:
190: return 0xff000000;
191: // Dark blue
192: case SystemColor.DESKTOP:
193: return 0xff224466;
194: // Another grey
195: case SystemColor.INACTIVE_CAPTION:
196: return 0xff888888;
197: // Grey
198: case SystemColor.INACTIVE_CAPTION_BORDER:
199: return 0xffcccccc;
200: // Light grey
201: case SystemColor.INACTIVE_CAPTION_TEXT:
202: return 0xffdddddd;
203: // Almost white
204: case SystemColor.INFO:
205: return 0xffeeeeee;
206: case SystemColor.INFO_TEXT:
207: return 0xff222222;
208: // Light grey
209: case SystemColor.MENU:
210: return 0xffdddddd;
211: // Black
212: case SystemColor.MENU_TEXT:
213: return 0xff000000;
214: // Grey
215: case SystemColor.SCROLLBAR:
216: return 0xffcccccc;
217: // White
218: case SystemColor.TEXT:
219: return 0xffffffff;
220: // Grey blue
221: case SystemColor.TEXT_HIGHLIGHT:
222: return 0xff336699;
223: // White
224: case SystemColor.TEXT_HIGHLIGHT_TEXT:
225: return 0xffffffff;
226: // Almost white
227: case SystemColor.TEXT_INACTIVE_TEXT:
228: return 0xffdddddd;
229: // Black
230: case SystemColor.TEXT_TEXT:
231: return 0xff000000;
232: // White
233: case SystemColor.WINDOW:
234: return 0xffffffff;
235: // Black
236: case SystemColor.WINDOW_BORDER:
237: return 0xff000000;
238: // Black
239: case SystemColor.WINDOW_TEXT:
240: return 0xff000000;
241: }
242: // Black
243: return 0xFF000000;
244: }
245:
246: private final int index;
247:
248: @Override
249: public String toString() {
250: return getClass().getName() + "[index=" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
251: }
252:
253: @Override
254: public int getRGB() {
255: return value = getARGB();
256: }
257:
258: private SystemColor(int index) {
259: super (0, 0, 0);
260: this .index = index;
261: value = getRGB();
262: }
263:
264: private int getARGB() {
265: return GraphicsEnvironment.getLocalGraphicsEnvironment()
266: .isHeadlessInstance() ? getHeadlessSystemColorARGB(index)
267: : toolkit.getWTK().getSystemProperties()
268: .getSystemColorARGB(index);
269: }
270:
271: @Override
272: public PaintContext createContext(ColorModel cm, Rectangle r,
273: Rectangle2D r2d, AffineTransform at, RenderingHints rh) {
274: return new Color.ColorPaintContext(getRGB());
275: }
276:
277: private void readObject(ObjectInputStream stream)
278: throws IOException, ClassNotFoundException {
279:
280: stream.defaultReadObject();
281:
282: FieldsAccessor accessor = new FieldsAccessor(Component.class,
283: this );
284: accessor.set("toolkit", Toolkit.getDefaultToolkit()); //$NON-NLS-1$
285: }
286:
287: }
|