001 /*
002 * Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.swing.plaf.metal;
027
028 import javax.swing.plaf.*;
029 import javax.swing.*;
030
031 /**
032 * {@code MetalTheme} provides the color palette and fonts used by
033 * the Java Look and Feel.
034 * <p>
035 * {@code MetalTheme} is abstract, see {@code DefaultMetalTheme} and
036 * {@code OceanTheme} for concrete implementations.
037 * <p>
038 * {@code MetalLookAndFeel} maintains the current theme that the
039 * the {@code ComponentUI} implementations for metal use. Refer to
040 * {@link MetalLookAndFeel#setCurrentTheme
041 * MetalLookAndFeel.setCurrentTheme(MetalTheme)} for details on changing
042 * the current theme.
043 * <p>
044 * {@code MetalTheme} provides a number of public methods for getting
045 * colors. These methods are implemented in terms of a
046 * handful of protected abstract methods. A subclass need only override
047 * the protected abstract methods ({@code getPrimary1},
048 * {@code getPrimary2}, {@code getPrimary3}, {@code getSecondary1},
049 * {@code getSecondary2}, and {@code getSecondary3}); although a subclass
050 * may override the other public methods for more control over the set of
051 * colors that are used.
052 * <p>
053 * Concrete implementations of {@code MetalTheme} must return {@code non-null}
054 * values from all methods. While the behavior of returning {@code null} is
055 * not specified, returning {@code null} will result in incorrect behavior.
056 * <p>
057 * It is strongly recommended that subclasses return completely opaque colors.
058 * To do otherwise may result in rendering problems, such as visual garbage.
059 *
060 * @see DefaultMetalTheme
061 * @see OceanTheme
062 * @see MetalLookAndFeel#setCurrentTheme
063 *
064 * @version 1.35 05/05/07
065 * @author Steve Wilson
066 */
067 public abstract class MetalTheme {
068
069 // Contants identifying the various Fonts that are Theme can support
070 static final int CONTROL_TEXT_FONT = 0;
071 static final int SYSTEM_TEXT_FONT = 1;
072 static final int USER_TEXT_FONT = 2;
073 static final int MENU_TEXT_FONT = 3;
074 static final int WINDOW_TITLE_FONT = 4;
075 static final int SUB_TEXT_FONT = 5;
076
077 static ColorUIResource white = new ColorUIResource(255, 255, 255);
078 private static ColorUIResource black = new ColorUIResource(0, 0, 0);
079
080 /**
081 * Returns the name of this theme.
082 *
083 * @return the name of this theme
084 */
085 public abstract String getName();
086
087 /**
088 * Returns the primary 1 color.
089 *
090 * @return the primary 1 color
091 */
092 protected abstract ColorUIResource getPrimary1(); // these are blue in Metal Default Theme
093
094 /**
095 * Returns the primary 2 color.
096 *
097 * @return the primary 2 color
098 */
099 protected abstract ColorUIResource getPrimary2();
100
101 /**
102 * Returns the primary 3 color.
103 *
104 * @return the primary 3 color
105 */
106 protected abstract ColorUIResource getPrimary3();
107
108 /**
109 * Returns the secondary 1 color.
110 *
111 * @return the secondary 1 color
112 */
113 protected abstract ColorUIResource getSecondary1(); // these are gray in Metal Default Theme
114
115 /**
116 * Returns the secondary 2 color.
117 *
118 * @return the secondary 2 color
119 */
120 protected abstract ColorUIResource getSecondary2();
121
122 /**
123 * Returns the secondary 3 color.
124 *
125 * @return the secondary 3 color
126 */
127 protected abstract ColorUIResource getSecondary3();
128
129 /**
130 * Returns the control text font.
131 *
132 * @return the control text font
133 */
134 public abstract FontUIResource getControlTextFont();
135
136 /**
137 * Returns the system text font.
138 *
139 * @return the system text font
140 */
141 public abstract FontUIResource getSystemTextFont();
142
143 /**
144 * Returns the user text font.
145 *
146 * @return the user text font
147 */
148 public abstract FontUIResource getUserTextFont();
149
150 /**
151 * Returns the menu text font.
152 *
153 * @return the menu text font
154 */
155 public abstract FontUIResource getMenuTextFont();
156
157 /**
158 * Returns the window title font.
159 *
160 * @return the window title font
161 */
162 public abstract FontUIResource getWindowTitleFont();
163
164 /**
165 * Returns the sub-text font.
166 *
167 * @return the sub-text font
168 */
169 public abstract FontUIResource getSubTextFont();
170
171 /**
172 * Returns the white color. This returns opaque white
173 * ({@code 0xFFFFFFFF}).
174 *
175 * @return the white color
176 */
177 protected ColorUIResource getWhite() {
178 return white;
179 }
180
181 /**
182 * Returns the black color. This returns opaque black
183 * ({@code 0xFF000000}).
184 *
185 * @return the black color
186 */
187 protected ColorUIResource getBlack() {
188 return black;
189 }
190
191 /**
192 * Returns the focus color. This returns the value of
193 * {@code getPrimary2()}.
194 *
195 * @return the focus color
196 */
197 public ColorUIResource getFocusColor() {
198 return getPrimary2();
199 }
200
201 /**
202 * Returns the desktop color. This returns the value of
203 * {@code getPrimary2()}.
204 *
205 * @return the desktop color
206 */
207 public ColorUIResource getDesktopColor() {
208 return getPrimary2();
209 }
210
211 /**
212 * Returns the control color. This returns the value of
213 * {@code getSecondary3()}.
214 *
215 * @return the control color
216 */
217 public ColorUIResource getControl() {
218 return getSecondary3();
219 }
220
221 /**
222 * Returns the control shadow color. This returns
223 * the value of {@code getSecondary2()}.
224 *
225 * @return the control shadow color
226 */
227 public ColorUIResource getControlShadow() {
228 return getSecondary2();
229 }
230
231 /**
232 * Returns the control dark shadow color. This returns
233 * the value of {@code getSecondary1()}.
234 *
235 * @return the control dark shadow color
236 */
237 public ColorUIResource getControlDarkShadow() {
238 return getSecondary1();
239 }
240
241 /**
242 * Returns the control info color. This returns
243 * the value of {@code getBlack()}.
244 *
245 * @return the control info color
246 */
247 public ColorUIResource getControlInfo() {
248 return getBlack();
249 }
250
251 /**
252 * Returns the control highlight color. This returns
253 * the value of {@code getWhite()}.
254 *
255 * @return the control highlight color
256 */
257 public ColorUIResource getControlHighlight() {
258 return getWhite();
259 }
260
261 /**
262 * Returns the control disabled color. This returns
263 * the value of {@code getSecondary2()}.
264 *
265 * @return the control disabled color
266 */
267 public ColorUIResource getControlDisabled() {
268 return getSecondary2();
269 }
270
271 /**
272 * Returns the primary control color. This returns
273 * the value of {@code getPrimary3()}.
274 *
275 * @return the primary control color
276 */
277 public ColorUIResource getPrimaryControl() {
278 return getPrimary3();
279 }
280
281 /**
282 * Returns the primary control shadow color. This returns
283 * the value of {@code getPrimary2()}.
284 *
285 * @return the primary control shadow color
286 */
287 public ColorUIResource getPrimaryControlShadow() {
288 return getPrimary2();
289 }
290
291 /**
292 * Returns the primary control dark shadow color. This
293 * returns the value of {@code getPrimary1()}.
294 *
295 * @return the primary control dark shadow color
296 */
297 public ColorUIResource getPrimaryControlDarkShadow() {
298 return getPrimary1();
299 }
300
301 /**
302 * Returns the primary control info color. This
303 * returns the value of {@code getBlack()}.
304 *
305 * @return the primary control info color
306 */
307 public ColorUIResource getPrimaryControlInfo() {
308 return getBlack();
309 }
310
311 /**
312 * Returns the primary control highlight color. This
313 * returns the value of {@code getWhite()}.
314 *
315 * @return the primary control highlight color
316 */
317 public ColorUIResource getPrimaryControlHighlight() {
318 return getWhite();
319 }
320
321 /**
322 * Returns the system text color. This returns the value of
323 * {@code getBlack()}.
324 *
325 * @return the system text color
326 */
327 public ColorUIResource getSystemTextColor() {
328 return getBlack();
329 }
330
331 /**
332 * Returns the control text color. This returns the value of
333 * {@code getControlInfo()}.
334 *
335 * @return the control text color
336 */
337 public ColorUIResource getControlTextColor() {
338 return getControlInfo();
339 }
340
341 /**
342 * Returns the inactive control text color. This returns the value of
343 * {@code getControlDisabled()}.
344 *
345 * @return the inactive control text color
346 */
347 public ColorUIResource getInactiveControlTextColor() {
348 return getControlDisabled();
349 }
350
351 /**
352 * Returns the inactive system text color. This returns the value of
353 * {@code getSecondary2()}.
354 *
355 * @return the inactive system text color
356 */
357 public ColorUIResource getInactiveSystemTextColor() {
358 return getSecondary2();
359 }
360
361 /**
362 * Returns the user text color. This returns the value of
363 * {@code getBlack()}.
364 *
365 * @return the user text color
366 */
367 public ColorUIResource getUserTextColor() {
368 return getBlack();
369 }
370
371 /**
372 * Returns the text highlight color. This returns the value of
373 * {@code getPrimary3()}.
374 *
375 * @return the text highlight color
376 */
377 public ColorUIResource getTextHighlightColor() {
378 return getPrimary3();
379 }
380
381 /**
382 * Returns the highlighted text color. This returns the value of
383 * {@code getControlTextColor()}.
384 *
385 * @return the highlighted text color
386 */
387 public ColorUIResource getHighlightedTextColor() {
388 return getControlTextColor();
389 }
390
391 /**
392 * Returns the window background color. This returns the value of
393 * {@code getWhite()}.
394 *
395 * @return the window background color
396 */
397 public ColorUIResource getWindowBackground() {
398 return getWhite();
399 }
400
401 /**
402 * Returns the window title background color. This returns the value of
403 * {@code getPrimary3()}.
404 *
405 * @return the window title background color
406 */
407 public ColorUIResource getWindowTitleBackground() {
408 return getPrimary3();
409 }
410
411 /**
412 * Returns the window title foreground color. This returns the value of
413 * {@code getBlack()}.
414 *
415 * @return the window title foreground color
416 */
417 public ColorUIResource getWindowTitleForeground() {
418 return getBlack();
419 }
420
421 /**
422 * Returns the window title inactive background color. This
423 * returns the value of {@code getSecondary3()}.
424 *
425 * @return the window title inactive background color
426 */
427 public ColorUIResource getWindowTitleInactiveBackground() {
428 return getSecondary3();
429 }
430
431 /**
432 * Returns the window title inactive foreground color. This
433 * returns the value of {@code getBlack()}.
434 *
435 * @return the window title inactive foreground color
436 */
437 public ColorUIResource getWindowTitleInactiveForeground() {
438 return getBlack();
439 }
440
441 /**
442 * Returns the menu background color. This
443 * returns the value of {@code getSecondary3()}.
444 *
445 * @return the menu background color
446 */
447 public ColorUIResource getMenuBackground() {
448 return getSecondary3();
449 }
450
451 /**
452 * Returns the menu foreground color. This
453 * returns the value of {@code getBlack()}.
454 *
455 * @return the menu foreground color
456 */
457 public ColorUIResource getMenuForeground() {
458 return getBlack();
459 }
460
461 /**
462 * Returns the menu selected background color. This
463 * returns the value of {@code getPrimary2()}.
464 *
465 * @return the menu selected background color
466 */
467 public ColorUIResource getMenuSelectedBackground() {
468 return getPrimary2();
469 }
470
471 /**
472 * Returns the menu selected foreground color. This
473 * returns the value of {@code getBlack()}.
474 *
475 * @return the menu selected foreground color
476 */
477 public ColorUIResource getMenuSelectedForeground() {
478 return getBlack();
479 }
480
481 /**
482 * Returns the menu disabled foreground color. This
483 * returns the value of {@code getSecondary2()}.
484 *
485 * @return the menu disabled foreground color
486 */
487 public ColorUIResource getMenuDisabledForeground() {
488 return getSecondary2();
489 }
490
491 /**
492 * Returns the separator background color. This
493 * returns the value of {@code getWhite()}.
494 *
495 * @return the separator background color
496 */
497 public ColorUIResource getSeparatorBackground() {
498 return getWhite();
499 }
500
501 /**
502 * Returns the separator foreground color. This
503 * returns the value of {@code getPrimary1()}.
504 *
505 * @return the separator foreground color
506 */
507 public ColorUIResource getSeparatorForeground() {
508 return getPrimary1();
509 }
510
511 /**
512 * Returns the accelerator foreground color. This
513 * returns the value of {@code getPrimary1()}.
514 *
515 * @return the accelerator foreground color
516 */
517 public ColorUIResource getAcceleratorForeground() {
518 return getPrimary1();
519 }
520
521 /**
522 * Returns the accelerator selected foreground color. This
523 * returns the value of {@code getBlack()}.
524 *
525 * @return the accelerator selected foreground color
526 */
527 public ColorUIResource getAcceleratorSelectedForeground() {
528 return getBlack();
529 }
530
531 /**
532 * Adds values specific to this theme to the defaults table. This method
533 * is invoked when the look and feel defaults are obtained from
534 * {@code MetalLookAndFeel}.
535 * <p>
536 * This implementation does nothing; it is provided for subclasses
537 * that wish to customize the defaults table.
538 *
539 * @param table the {@code UIDefaults} to add the values to
540 *
541 * @see MetalLookAndFeel#getDefaults
542 */
543 public void addCustomEntriesToTable(UIDefaults table) {
544 }
545
546 /**
547 * This is invoked when a MetalLookAndFeel is installed and about to
548 * start using this theme. When we can add API this should be nuked
549 * in favor of DefaultMetalTheme overriding addCustomEntriesToTable.
550 */
551 void install() {
552 }
553
554 /**
555 * Returns true if this is a theme provided by the core platform.
556 */
557 boolean isSystemTheme() {
558 return false;
559 }
560 }
|