001    /* MetalTheme.java --
002       Copyright (C) 2004, 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    
040    package javax.swing.plaf.metal;
041    
042    import java.awt.Color;
043    
044    import javax.swing.UIDefaults;
045    import javax.swing.plaf.ColorUIResource;
046    import javax.swing.plaf.FontUIResource;
047    
048    /**
049     * The base class for themes used by the {@link MetalLookAndFeel}.  A default
050     * theme ({@link DefaultMetalTheme}) is provided, or you can create and use
051     * your own.
052     * 
053     * @see MetalLookAndFeel#setCurrentTheme(MetalTheme)
054     */
055    public abstract class MetalTheme
056    {
057      private ColorUIResource BLACK = new ColorUIResource(Color.BLACK);
058      private ColorUIResource WHITE = new ColorUIResource(Color.WHITE);
059    
060      /**
061       * Default constructor.
062       */
063      public MetalTheme()
064      {
065        // Do nothing here.
066      }
067    
068      /**
069       * Returns the name of the theme.
070       * 
071       * @return The name of the theme.
072       */
073      public abstract String getName();
074    
075      /**
076       * Adds custom entries to the UI defaults table.  This method is empty.
077       * 
078       * @param table  the table.
079       */
080      public void addCustomEntriesToTable(UIDefaults table)
081      {
082        // Do nothing here.
083        // This method needs to be overridden to actually do something.
084        // It is called from MetalLookAndFeel.getDefaults().
085      }
086    
087      /**
088       * Returns the accelerator foreground color.  The default implementation
089       * returns the color from {@link #getPrimary1()}.
090       * 
091       * @return The accelerator foreground color.
092       */
093      public ColorUIResource getAcceleratorForeground()
094      {
095        return getPrimary1();
096      }
097    
098      /**
099       * Returns the accelerator selected foreground color.  The default 
100       * implementation returns the color from {@link #getBlack()}.
101       * 
102       * @return The accelerator selected foreground color.
103       */
104      public ColorUIResource getAcceleratorSelectedForeground()
105      {
106        return getBlack();
107      }
108      
109      /**
110       * Returns the control color.  The default implementation returns the color 
111       * from {@link #getSecondary3()}.
112       * 
113       * @return The control color.
114       */
115      public ColorUIResource getControl()
116      {
117        return getSecondary3();
118      }
119    
120      /**
121       * Returns the color used for dark shadows on controls.  The default 
122       * implementation returns the color from  {@link #getSecondary1()}.
123       * 
124       * @return The color used for dark shadows on controls.
125       */
126      public ColorUIResource getControlDarkShadow()
127      {
128        return getSecondary1();
129      }
130    
131      /**
132       * Returns the color used for disabled controls.  The default implementation
133       * returns the color from {@link #getSecondary1()}.
134       * 
135       * @return The color used for disabled controls.
136       */
137      public ColorUIResource getControlDisabled()
138      {
139        return getSecondary2();
140      }
141    
142      /**
143       * Returns the color used to draw highlights for controls.  The default 
144       * implementation returns the color from {@link #getWhite()}.
145       * 
146       * @return The color used to draw highlights for controls.
147       */
148      public ColorUIResource getControlHighlight()
149      {
150        return getWhite();
151      }
152    
153      /**
154       * Returns the color used to display control info.  The default 
155       * implementation returns the color from {@link #getBlack()}.
156       * 
157       * @return The color used to display control info.
158       */
159      public ColorUIResource getControlInfo()
160      {
161        return getBlack();
162      }
163    
164      /**
165       * Returns the color used to draw shadows for controls.  The default 
166       * implementation returns the color from {@link #getSecondary2()}.
167       * 
168       * @return The color used to draw shadows for controls.
169       */
170      public ColorUIResource getControlShadow()
171      {
172        return getSecondary2();
173      }
174    
175      /**
176       * Returns the color used for text on controls.  The default implementation
177       * returns the color from {@link #getControlInfo()}.
178       * 
179       * @return The color used for text on controls.
180       */
181      public ColorUIResource getControlTextColor()
182      {
183        return getControlInfo();
184      }
185    
186      /**
187       * Returns the color used for the desktop background.  The default 
188       * implementation returns the color from {@link #getPrimary2()}.
189       * 
190       * @return The color used for the desktop background.
191       */
192      public ColorUIResource getDesktopColor()
193      {
194        return getPrimary2();
195      }
196    
197      /**
198       * Returns the color used to draw focus highlights.  The default 
199       * implementation returns the color from {@link #getPrimary2()}.
200       * 
201       * @return The color used to draw focus highlights.
202       */
203      public ColorUIResource getFocusColor()
204      {
205        return getPrimary2();
206      }
207    
208      /**
209       * Returns the color used to draw highlighted text.  The default
210       * implementation returns the color from {@link #getHighlightedTextColor()}.
211       * 
212       * @return The color used to draw highlighted text.
213       */
214      public ColorUIResource getHighlightedTextColor()
215      {
216        return getControlTextColor();
217      }
218    
219      /**
220       * Returns the color used to draw text on inactive controls.  The default
221       * implementation returns the color from {@link #getControlDisabled()}.
222       * 
223       * @return The color used to draw text on inactive controls.
224       */
225      public ColorUIResource getInactiveControlTextColor()
226      {
227        return getControlDisabled();
228      }
229    
230      /**
231       * Returns the color used to draw inactive system text.  The default
232       * implementation returns the color from {@link #getSecondary2()}.
233       * 
234       * @return The color used to draw inactive system text.
235       */
236      public ColorUIResource getInactiveSystemTextColor()
237      {
238        return getSecondary2();
239      }
240    
241      /**
242       * Returns the background color for menu items.  The default implementation
243       * returns the color from {@link #getSecondary3()}.
244       * 
245       * @return The background color for menu items.
246       * 
247       * @see #getMenuSelectedBackground()
248       */
249      public ColorUIResource getMenuBackground()
250      {
251        return getSecondary3();
252      }
253    
254      /**
255       * Returns the foreground color for disabled menu items.  The default 
256       * implementation returns the color from {@link #getSecondary2()}.
257       * 
258       * @return The foreground color for disabled menu items.
259       * 
260       * @see #getMenuForeground()
261       */
262      public ColorUIResource getMenuDisabledForeground()
263      {
264        return getSecondary2();
265      }
266    
267      /**
268       * Returns the foreground color for menu items.  The default implementation
269       * returns the color from {@link #getBlack()}.
270       * 
271       * @return The foreground color for menu items.
272       * 
273       * @see #getMenuDisabledForeground()
274       * @see #getMenuSelectedForeground()
275       */
276      public ColorUIResource getMenuForeground()
277      {
278        return getBlack();
279      }
280    
281      /**
282       * Returns the background color for selected menu items.  The default 
283       * implementation returns the color from {@link #getPrimary2()}.
284       * 
285       * @return The background color for selected menu items.
286       * 
287       * @see #getMenuBackground()
288       */
289      public ColorUIResource getMenuSelectedBackground()
290      {
291        return getPrimary2();
292      }
293    
294      /**
295       * Returns the foreground color for selected menu items.  The default 
296       * implementation returns the value from {@link #getBlack()}.
297       * 
298       * @return The foreground color for selected menu items.
299       * 
300       * @see #getMenuForeground()
301       */
302      public ColorUIResource getMenuSelectedForeground()
303      {
304        return getBlack();
305      }
306    
307      /**
308       * Returns the primary color for controls.  The default implementation
309       * returns the color from {@link #getPrimary3()}.
310       * 
311       * @return The primary color for controls.
312       */
313      public ColorUIResource getPrimaryControl()
314      {
315        return getPrimary3();
316      }
317    
318      /**
319       * Returns the primary color for the dark shadow on controls.  The default 
320       * implementation returns the color from {@link #getPrimary1()}.
321       * 
322       * @return The primary color for the dark shadow on controls.
323       */
324      public ColorUIResource getPrimaryControlDarkShadow()
325      {
326        return getPrimary1();
327      }
328    
329      /**
330       * Returns the primary color for the highlight on controls.  The default 
331       * implementation returns the color from {@link #getWhite()}.
332       * 
333       * @return The primary color for the highlight on controls.
334       */
335      public ColorUIResource getPrimaryControlHighlight()
336      {
337        return getWhite();
338      }
339    
340      /**
341       * Returns the primary color for the information on controls.  The default 
342       * implementation returns the color from {@link #getBlack()}.
343       * 
344       * @return The primary color for the information on controls.
345       */
346      public ColorUIResource getPrimaryControlInfo()
347      {
348        return getBlack();
349      }
350    
351      /**
352       * Returns the primary color for the shadow on controls.  The default 
353       * implementation returns the color from {@link #getPrimary2()}.
354       * 
355       * @return The primary color for the shadow on controls.
356       */
357      public ColorUIResource getPrimaryControlShadow()
358      {
359        return getPrimary2();
360      }
361    
362      /**
363       * Returns the background color for separators.  The default implementation
364       * returns the color from {@link #getWhite()}.
365       * 
366       * @return The background color for separators.
367       */
368      public ColorUIResource getSeparatorBackground()
369      {
370        return getWhite();
371      }
372    
373      /**
374       * Returns the foreground color for separators.  The default implementation
375       * returns the value from {@link #getPrimary1()}.
376       * 
377       * @return The foreground color for separators.
378       */
379      public ColorUIResource getSeparatorForeground()
380      {
381        return getPrimary1();
382      }
383    
384      /**
385       * Returns the color used for system text.  The default implementation 
386       * returns the color from {@link #getBlack()}.
387       * 
388       * @return The color used for system text.
389       */
390      public ColorUIResource getSystemTextColor()
391      {
392        return getBlack();
393      }
394    
395      /**
396       * Returns the color used to highlight text.  The default implementation
397       * returns the color from {@link #getPrimary3()}.
398       * 
399       * @return The color used to highlight text.
400       */
401      public ColorUIResource getTextHighlightColor()
402      {
403        return getPrimary3();
404      }
405    
406      /**
407       * Returns the color used to display user text.  The default implementation
408       * returns the color from {@link #getBlack()}.
409       * 
410       * @return The color used to display user text.
411       */
412      public ColorUIResource getUserTextColor()
413      {
414        return getBlack();
415      }
416      
417      /**
418       * Returns the window background color.  The default implementation returns
419       * the color from {@link #getWhite()}.
420       * 
421       * @return The window background color.
422       */
423      public ColorUIResource getWindowBackground()
424      {
425        return getWhite();
426      }
427    
428      /**
429       * Returns the window title background color.  The default implementation
430       * returns the color from {@link #getPrimary3()}.
431       * 
432       * @return The window title background color.
433       */
434      public ColorUIResource getWindowTitleBackground()
435      {
436        return getPrimary3();
437      }
438    
439      /**
440       * Returns the window title foreground color.  The default implementation
441       * returns the color from {@link #getBlack()}.
442       * 
443       * @return The window title foreground color.
444       */
445      public ColorUIResource getWindowTitleForeground()
446      {
447        return getBlack();
448      }
449    
450      /**
451       * Returns the background color for an inactive window title.  The default
452       * implementation returns the color from {@link #getSecondary3()}.
453       * 
454       * @return The background color for an inactive window title.
455       */
456      public ColorUIResource getWindowTitleInactiveBackground()
457      {
458        return getSecondary3();
459      }
460    
461      /**
462       * Returns the foreground color for an inactive window title.  The default
463       * implementation returns the color from {@link #getBlack()}.
464       * 
465       * @return The foreground color for an inactive window title.
466       */
467      public ColorUIResource getWindowTitleInactiveForeground()
468      {
469        return getBlack();
470      }
471    
472      /**
473       * Returns the color used for black.
474       * 
475       * @return The color used for black.
476       */
477      protected ColorUIResource getBlack()
478      {
479        return BLACK;
480      }
481    
482      /**
483       * Returns the color used for white.
484       * 
485       * @return The color used for white.
486       */
487      protected ColorUIResource getWhite()
488      {
489        return WHITE;
490      }
491    
492      /**
493       * Returns the first primary color for this theme.
494       * 
495       * @return The first primary color.
496       */
497      protected abstract ColorUIResource getPrimary1();
498      
499      /**
500       * Returns the second primary color for this theme.
501       * 
502       * @return The second primary color.
503       */
504      protected abstract ColorUIResource getPrimary2();
505    
506      /**
507       * Returns the third primary color for this theme.
508       * 
509       * @return The third primary color.
510       */
511      protected abstract ColorUIResource getPrimary3();
512      
513      /**
514       * Returns the first secondary color for this theme.
515       * 
516       * @return The first secondary color.
517       */
518      protected abstract ColorUIResource getSecondary1();
519    
520      /**
521       * Returns the second secondary color for this theme.
522       * 
523       * @return The second secondary color.
524       */
525      protected abstract ColorUIResource getSecondary2();
526    
527      /**
528       * Returns the third secondary color for this theme.
529       * 
530       * @return The third secondary color.
531       */
532      protected abstract ColorUIResource getSecondary3();
533    
534      /**
535       * Returns the font used for text on controls.
536       * 
537       * @return The font used for text on controls.
538       */
539      public abstract FontUIResource getControlTextFont();
540    
541      /**
542       * Returns the font used for text in menus.
543       * 
544       * @return The font used for text in menus.
545       */
546      public abstract FontUIResource getMenuTextFont();
547    
548      /**
549       * Returns the font used for sub text.
550       * 
551       * @return The font used for sub text.
552       */
553      public abstract FontUIResource getSubTextFont();
554      
555      /**
556       * Returns the font used for system text.
557       * 
558       * @return The font used for system text.
559       */
560      public abstract FontUIResource getSystemTextFont();
561      
562      /**
563       * Returns the font used for user text.
564       * 
565       * @return The font used for user text.
566       */
567      public abstract FontUIResource getUserTextFont();
568    
569      /**
570       * Returns the font used for window titles.
571       * 
572       * @return The font used for window titles.
573       */
574      public abstract FontUIResource getWindowTitleFont();
575      
576    }