1/*
2 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.swing.plaf.metal;
27
28import javax.swing.plaf.*;
29import javax.swing.*;
30
31/**
32 * {@code MetalTheme} provides the color palette and fonts used by
33 * the Java Look and Feel.
34 * <p>
35 * {@code MetalTheme} is abstract, see {@code DefaultMetalTheme} and
36 * {@code OceanTheme} for concrete implementations.
37 * <p>
38 * {@code MetalLookAndFeel} maintains the current theme that the
39 * the {@code ComponentUI} implementations for metal use. Refer to
40 * {@link MetalLookAndFeel#setCurrentTheme
41 * MetalLookAndFeel.setCurrentTheme(MetalTheme)} for details on changing
42 * the current theme.
43 * <p>
44 * {@code MetalTheme} provides a number of public methods for getting
45 * colors. These methods are implemented in terms of a
46 * handful of protected abstract methods. A subclass need only override
47 * the protected abstract methods ({@code getPrimary1},
48 * {@code getPrimary2}, {@code getPrimary3}, {@code getSecondary1},
49 * {@code getSecondary2}, and {@code getSecondary3}); although a subclass
50 * may override the other public methods for more control over the set of
51 * colors that are used.
52 * <p>
53 * Concrete implementations of {@code MetalTheme} must return {@code non-null}
54 * values from all methods. While the behavior of returning {@code null} is
55 * not specified, returning {@code null} will result in incorrect behavior.
56 * <p>
57 * It is strongly recommended that subclasses return completely opaque colors.
58 * To do otherwise may result in rendering problems, such as visual garbage.
59 *
60 * @see DefaultMetalTheme
61 * @see OceanTheme
62 * @see MetalLookAndFeel#setCurrentTheme
63 *
64 * @author Steve Wilson
65 */
66public abstract class MetalTheme {
67
68    // Contants identifying the various Fonts that are Theme can support
69    static final int CONTROL_TEXT_FONT = 0;
70    static final int SYSTEM_TEXT_FONT = 1;
71    static final int USER_TEXT_FONT = 2;
72    static final int MENU_TEXT_FONT = 3;
73    static final int WINDOW_TITLE_FONT = 4;
74    static final int SUB_TEXT_FONT = 5;
75
76    static ColorUIResource white = new ColorUIResource( 255, 255, 255 );
77    private static ColorUIResource black = new ColorUIResource( 0, 0, 0 );
78
79    /**
80     * Returns the name of this theme.
81     *
82     * @return the name of this theme
83     */
84    public abstract String getName();
85
86    /**
87     * Returns the primary 1 color.
88     *
89     * @return the primary 1 color
90     */
91    protected abstract ColorUIResource getPrimary1();  // these are blue in Metal Default Theme
92
93    /**
94     * Returns the primary 2 color.
95     *
96     * @return the primary 2 color
97     */
98    protected abstract ColorUIResource getPrimary2();
99
100    /**
101     * Returns the primary 3 color.
102     *
103     * @return the primary 3 color
104     */
105    protected abstract ColorUIResource getPrimary3();
106
107    /**
108     * Returns the secondary 1 color.
109     *
110     * @return the secondary 1 color
111     */
112    protected abstract ColorUIResource getSecondary1();  // these are gray in Metal Default Theme
113
114    /**
115     * Returns the secondary 2 color.
116     *
117     * @return the secondary 2 color
118     */
119    protected abstract ColorUIResource getSecondary2();
120
121    /**
122     * Returns the secondary 3 color.
123     *
124     * @return the secondary 3 color
125     */
126    protected abstract ColorUIResource getSecondary3();
127
128    /**
129     * Returns the control text font.
130     *
131     * @return the control text font
132     */
133    public abstract FontUIResource getControlTextFont();
134
135    /**
136     * Returns the system text font.
137     *
138     * @return the system text font
139     */
140    public abstract FontUIResource getSystemTextFont();
141
142    /**
143     * Returns the user text font.
144     *
145     * @return the user text font
146     */
147    public abstract FontUIResource getUserTextFont();
148
149    /**
150     * Returns the menu text font.
151     *
152     * @return the menu text font
153     */
154    public abstract FontUIResource getMenuTextFont();
155
156    /**
157     * Returns the window title font.
158     *
159     * @return the window title font
160     */
161    public abstract FontUIResource getWindowTitleFont();
162
163    /**
164     * Returns the sub-text font.
165     *
166     * @return the sub-text font
167     */
168    public abstract FontUIResource getSubTextFont();
169
170    /**
171     * Returns the white color. This returns opaque white
172     * ({@code 0xFFFFFFFF}).
173     *
174     * @return the white color
175     */
176    protected ColorUIResource getWhite() { return white; }
177
178    /**
179     * Returns the black color. This returns opaque black
180     * ({@code 0xFF000000}).
181     *
182     * @return the black color
183     */
184    protected ColorUIResource getBlack() { return black; }
185
186    /**
187     * Returns the focus color. This returns the value of
188     * {@code getPrimary2()}.
189     *
190     * @return the focus color
191     */
192    public ColorUIResource getFocusColor() { return getPrimary2(); }
193
194    /**
195     * Returns the desktop color. This returns the value of
196     * {@code getPrimary2()}.
197     *
198     * @return the desktop color
199     */
200    public  ColorUIResource getDesktopColor() { return getPrimary2(); }
201
202    /**
203     * Returns the control color. This returns the value of
204     * {@code getSecondary3()}.
205     *
206     * @return the control color
207     */
208    public ColorUIResource getControl() { return getSecondary3(); }
209
210    /**
211     * Returns the control shadow color. This returns
212     * the value of {@code getSecondary2()}.
213     *
214     * @return the control shadow color
215     */
216    public ColorUIResource getControlShadow() { return getSecondary2(); }
217
218    /**
219     * Returns the control dark shadow color. This returns
220     * the value of {@code getSecondary1()}.
221     *
222     * @return the control dark shadow color
223     */
224    public ColorUIResource getControlDarkShadow() { return getSecondary1(); }
225
226    /**
227     * Returns the control info color. This returns
228     * the value of {@code getBlack()}.
229     *
230     * @return the control info color
231     */
232    public ColorUIResource getControlInfo() { return getBlack(); }
233
234    /**
235     * Returns the control highlight color. This returns
236     * the value of {@code getWhite()}.
237     *
238     * @return the control highlight color
239     */
240    public ColorUIResource getControlHighlight() { return getWhite(); }
241
242    /**
243     * Returns the control disabled color. This returns
244     * the value of {@code getSecondary2()}.
245     *
246     * @return the control disabled color
247     */
248    public ColorUIResource getControlDisabled() { return getSecondary2(); }
249
250    /**
251     * Returns the primary control color. This returns
252     * the value of {@code getPrimary3()}.
253     *
254     * @return the primary control color
255     */
256    public ColorUIResource getPrimaryControl() { return getPrimary3(); }
257
258    /**
259     * Returns the primary control shadow color. This returns
260     * the value of {@code getPrimary2()}.
261     *
262     * @return the primary control shadow color
263     */
264    public ColorUIResource getPrimaryControlShadow() { return getPrimary2(); }
265    /**
266     * Returns the primary control dark shadow color. This
267     * returns the value of {@code getPrimary1()}.
268     *
269     * @return the primary control dark shadow color
270     */
271    public ColorUIResource getPrimaryControlDarkShadow() { return getPrimary1(); }
272
273    /**
274     * Returns the primary control info color. This
275     * returns the value of {@code getBlack()}.
276     *
277     * @return the primary control info color
278     */
279    public ColorUIResource getPrimaryControlInfo() { return getBlack(); }
280
281    /**
282     * Returns the primary control highlight color. This
283     * returns the value of {@code getWhite()}.
284     *
285     * @return the primary control highlight color
286     */
287    public ColorUIResource getPrimaryControlHighlight() { return getWhite(); }
288
289    /**
290     * Returns the system text color. This returns the value of
291     * {@code getBlack()}.
292     *
293     * @return the system text color
294     */
295    public ColorUIResource getSystemTextColor() { return getBlack(); }
296
297    /**
298     * Returns the control text color. This returns the value of
299     * {@code getControlInfo()}.
300     *
301     * @return the control text color
302     */
303    public ColorUIResource getControlTextColor() { return getControlInfo(); }
304
305    /**
306     * Returns the inactive control text color. This returns the value of
307     * {@code getControlDisabled()}.
308     *
309     * @return the inactive control text color
310     */
311    public ColorUIResource getInactiveControlTextColor() { return getControlDisabled(); }
312
313    /**
314     * Returns the inactive system text color. This returns the value of
315     * {@code getSecondary2()}.
316     *
317     * @return the inactive system text color
318     */
319    public ColorUIResource getInactiveSystemTextColor() { return getSecondary2(); }
320
321    /**
322     * Returns the user text color. This returns the value of
323     * {@code getBlack()}.
324     *
325     * @return the user text color
326     */
327    public ColorUIResource getUserTextColor() { return getBlack(); }
328
329    /**
330     * Returns the text highlight color. This returns the value of
331     * {@code getPrimary3()}.
332     *
333     * @return the text highlight color
334     */
335    public ColorUIResource getTextHighlightColor() { return getPrimary3(); }
336
337    /**
338     * Returns the highlighted text color. This returns the value of
339     * {@code getControlTextColor()}.
340     *
341     * @return the highlighted text color
342     */
343    public ColorUIResource getHighlightedTextColor() { return getControlTextColor(); }
344
345    /**
346     * Returns the window background color. This returns the value of
347     * {@code getWhite()}.
348     *
349     * @return the window background color
350     */
351    public ColorUIResource getWindowBackground() { return getWhite(); }
352
353    /**
354     * Returns the window title background color. This returns the value of
355     * {@code getPrimary3()}.
356     *
357     * @return the window title background color
358     */
359    public ColorUIResource getWindowTitleBackground() { return getPrimary3(); }
360
361    /**
362     * Returns the window title foreground color. This returns the value of
363     * {@code getBlack()}.
364     *
365     * @return the window title foreground color
366     */
367    public ColorUIResource getWindowTitleForeground() { return getBlack(); }
368
369    /**
370     * Returns the window title inactive background color. This
371     * returns the value of {@code getSecondary3()}.
372     *
373     * @return the window title inactive background color
374     */
375    public ColorUIResource getWindowTitleInactiveBackground() { return getSecondary3(); }
376
377    /**
378     * Returns the window title inactive foreground color. This
379     * returns the value of {@code getBlack()}.
380     *
381     * @return the window title inactive foreground color
382     */
383    public ColorUIResource getWindowTitleInactiveForeground() { return getBlack(); }
384
385    /**
386     * Returns the menu background color. This
387     * returns the value of {@code getSecondary3()}.
388     *
389     * @return the menu background color
390     */
391    public ColorUIResource getMenuBackground() { return getSecondary3(); }
392
393    /**
394     * Returns the menu foreground color. This
395     * returns the value of {@code getBlack()}.
396     *
397     * @return the menu foreground color
398     */
399    public ColorUIResource getMenuForeground() { return  getBlack(); }
400
401    /**
402     * Returns the menu selected background color. This
403     * returns the value of {@code getPrimary2()}.
404     *
405     * @return the menu selected background color
406     */
407    public ColorUIResource getMenuSelectedBackground() { return getPrimary2(); }
408
409    /**
410     * Returns the menu selected foreground color. This
411     * returns the value of {@code getBlack()}.
412     *
413     * @return the menu selected foreground color
414     */
415    public ColorUIResource getMenuSelectedForeground() { return getBlack(); }
416
417    /**
418     * Returns the menu disabled foreground color. This
419     * returns the value of {@code getSecondary2()}.
420     *
421     * @return the menu disabled foreground color
422     */
423    public ColorUIResource getMenuDisabledForeground() { return getSecondary2(); }
424
425    /**
426     * Returns the separator background color. This
427     * returns the value of {@code getWhite()}.
428     *
429     * @return the separator background color
430     */
431    public ColorUIResource getSeparatorBackground() { return getWhite(); }
432
433    /**
434     * Returns the separator foreground color. This
435     * returns the value of {@code getPrimary1()}.
436     *
437     * @return the separator foreground color
438     */
439    public ColorUIResource getSeparatorForeground() { return getPrimary1(); }
440
441    /**
442     * Returns the accelerator foreground color. This
443     * returns the value of {@code getPrimary1()}.
444     *
445     * @return the accelerator foreground color
446     */
447    public ColorUIResource getAcceleratorForeground() { return getPrimary1(); }
448
449    /**
450     * Returns the accelerator selected foreground color. This
451     * returns the value of {@code getBlack()}.
452     *
453     * @return the accelerator selected foreground color
454     */
455    public ColorUIResource getAcceleratorSelectedForeground() { return getBlack(); }
456
457    /**
458     * Adds values specific to this theme to the defaults table. This method
459     * is invoked when the look and feel defaults are obtained from
460     * {@code MetalLookAndFeel}.
461     * <p>
462     * This implementation does nothing; it is provided for subclasses
463     * that wish to customize the defaults table.
464     *
465     * @param table the {@code UIDefaults} to add the values to
466     *
467     * @see MetalLookAndFeel#getDefaults
468     */
469    public void addCustomEntriesToTable(UIDefaults table) {}
470
471    /**
472     * This is invoked when a MetalLookAndFeel is installed and about to
473     * start using this theme. When we can add API this should be nuked
474     * in favor of DefaultMetalTheme overriding addCustomEntriesToTable.
475     */
476    void install() {
477    }
478
479    /**
480     * Returns true if this is a theme provided by the core platform.
481     */
482    boolean isSystemTheme() {
483        return false;
484    }
485}
486