001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: ColorTheme.java,v $
023   Revision 1.4  2004/05/12 19:14:13  markl
024   comment block updates
025
026   Revision 1.3  2003/01/19 09:50:53  markl
027   Javadoc & comment header updates.
028
029   Revision 1.2  2001/03/12 09:27:52  markl
030   Source code and Javadoc cleanup.
031
032   Revision 1.1  1999/05/10 09:00:02  markl
033   Initial revision
034   ----------------------------------------------------------------------------
035*/
036
037package kiwi.ui;
038
039import javax.swing.plaf.*;
040import javax.swing.plaf.metal.*;
041import javax.swing.*;
042import javax.swing.border.*;
043import java.awt.*;
044import java.io.*;
045import java.util.*;
046
047import kiwi.util.*;
048
049  /** A color theme object that can be constructed from a <code>Config</code>
050   * object. This allows themes to be read from data files.
051   *
052   * @author Mark Lindner
053   */
054
055public class ColorTheme extends DefaultMetalTheme
056  {
057  private String name;
058  private ColorUIResource primary1, primary2, primary3;
059  private ColorUIResource secondary1, secondary2, secondary3;
060  private ColorUIResource black, white;
061  private ColorUIResource acceleratorForegroundColor,
062    acceleratorSelectedForegroundColor, controlColor,
063    controlDarkShadowColor, controlDisabledColor,
064    controlHighlightColor, controlInfoColor, controlShadowColor,
065    controlTextColor, desktopColor, focusColor, highlightedTextColor,
066    inactiveControlTextColor, inactiveSystemTextColor, menuBackgroundColor,
067    menuDisabledForegroundColor, menuForegroundColor,
068    menuSelectedBackgroundColor, menuSelectedForegroundColor,
069    primaryControlColor, primaryControlDarkShadowColor,
070    primaryControlHighlightColor, primaryControlInfoColor,
071    primaryControlShadowColor, separatorBackgroundColor,
072    separatorForegroundColor, systemTextColor, textHighlightColor,
073    userTextColor, windowBackgroundColor, windowTitleBackgroundColor,
074    windowTitleForegroundColor, windowTitleInactiveBackgroundColor,
075    windowTitleInactiveForegroundColor;  
076  private FontUIResource controlTextFont, menuTextFont, subTextFont,
077    systemTextFont, userTextFont, windowTitleFont;
078
079  /** Construct a new <code>ColorTheme</code>.
080   *
081   * @param config The <code>Config</code> object from which color and font
082   * properties will be read.
083   */
084  
085  public ColorTheme(Config config)
086    {
087    primary1 = super.getPrimary1();
088    primary2 = super.getPrimary2();
089    primary3 = super.getPrimary3();
090    
091    secondary1 = super.getSecondary1();
092    secondary2 = super.getSecondary2();
093    secondary3 = super.getSecondary3();
094
095    black = super.getBlack();
096    white = super.getWhite();
097
098    init(config);
099    }
100
101  /** Get the name of this color theme.
102   *
103   * @return The name of the theme.
104   */
105  
106  public String getName()
107    {
108    return(name);
109    }
110
111  /* primary and secondary colors */
112  
113  protected ColorUIResource getPrimary1()
114    {
115    return(primary1);
116    }
117
118  protected ColorUIResource getPrimary2()
119    {
120    return(primary2);
121    }
122
123  protected ColorUIResource getPrimary3()
124    {
125    return(primary3);
126    }
127
128  protected ColorUIResource getSecondary1()
129    {
130    return(secondary1);
131    }
132
133  protected ColorUIResource getSecondary2()
134    {
135    return(secondary2);
136    }
137
138  protected ColorUIResource getSecondary3()
139    {
140    return(secondary3);
141    }
142
143  protected ColorUIResource getBlack()
144    {
145    return(black);
146    }
147
148  protected ColorUIResource getWhite()
149    {
150    return(white);
151    }
152
153  /* specific colors */
154
155  public ColorUIResource getAcceleratorForeground()
156    {
157    return(acceleratorForegroundColor);
158    }
159
160  public ColorUIResource getAcceleratorSelectedForeground()
161    {
162    return(acceleratorSelectedForegroundColor);
163    }
164  
165  public ColorUIResource getControl()
166    {
167    return(controlColor);
168    }
169
170  public ColorUIResource getControlDarkShadow()
171    {
172    return(controlDarkShadowColor);
173    }
174
175  public ColorUIResource getControlDisabled()
176    {
177    return(controlDisabledColor);
178    }
179
180  public ColorUIResource getControlHighlight()
181    {
182    return(controlHighlightColor);
183    }
184
185  public ColorUIResource getControlInfo()
186    {
187    return(controlInfoColor);
188    }
189
190  public ColorUIResource getControlShadow()
191    {
192    return(controlShadowColor);
193    }
194
195  public ColorUIResource getControlTextColor()
196    {
197    return(controlTextColor);
198    }
199
200  public ColorUIResource getDesktopColor()
201    {
202    return(desktopColor);
203    }
204
205  public ColorUIResource getFocusColor()
206    {
207    return(focusColor);
208    }
209
210  public ColorUIResource getHighlightedTextColor()
211    {
212    return(highlightedTextColor);
213    }
214
215  public ColorUIResource getInactiveControlTextColor()
216    {
217    return(inactiveControlTextColor);
218    }
219
220  public ColorUIResource getInactiveSystemTextColor()
221    {
222    return(inactiveSystemTextColor);
223    }
224
225  public ColorUIResource getMenuBackground()
226    {
227    return(menuBackgroundColor);
228    }
229
230  public ColorUIResource getMenuDisabledForeground()
231    {
232    return(menuDisabledForegroundColor);
233    }
234
235  public ColorUIResource getMenuForeground()
236    {
237    return(menuForegroundColor);
238    }
239
240  public ColorUIResource getMenuSelectedBackground()
241    {
242    return(menuSelectedBackgroundColor);
243    }
244  
245  public ColorUIResource getMenuSelectedForeground()
246    {
247    return(menuSelectedForegroundColor);
248    }
249
250  public ColorUIResource getPrimaryControl()
251    {
252    return(primaryControlColor);
253    }
254
255  public ColorUIResource getPrimaryControlDarkShadow()
256    {
257    return(primaryControlDarkShadowColor);
258    }
259
260  public ColorUIResource getPrimaryControlHighlight()
261    {
262    return(primaryControlHighlightColor);
263    }
264  
265  public ColorUIResource getPrimaryControlInfo()
266    {
267    return(primaryControlInfoColor);
268    }
269
270  public ColorUIResource getPrimaryControlShadow()
271    {
272    return(primaryControlShadowColor);
273    }
274
275  public ColorUIResource getSeparatorBackground()
276    {
277    return(separatorBackgroundColor);
278    }
279
280  public ColorUIResource getSeparatorForeground()
281    {
282    return(separatorForegroundColor);
283    }
284
285  public ColorUIResource getSystemTextColor()
286    {
287    return(systemTextColor);
288    }
289
290  public ColorUIResource getTextHighlightColor()
291    {
292    return(textHighlightColor);
293    }
294
295  public ColorUIResource getUserTextColor()
296    {
297    return(userTextColor);
298    }
299  
300  public ColorUIResource getWindowBackground()
301    {
302    return(windowBackgroundColor);
303    }
304
305  public ColorUIResource getWindowTitleBackground()
306    {
307    return(windowTitleBackgroundColor);
308    }
309
310  public ColorUIResource getWindowTitleForeground()
311    {
312    return(windowTitleForegroundColor);
313    }
314
315  public ColorUIResource getWindowTitleInactiveBackground()
316    {
317    return(windowTitleInactiveBackgroundColor);
318    }
319
320  public ColorUIResource getWindowTitleInactiveForeground()
321    {
322    return(windowTitleInactiveForegroundColor);
323    }
324  
325  /* fonts */
326  
327  public FontUIResource getControlTextFont()
328    {
329    return(controlTextFont);
330    }
331
332  public FontUIResource getMenuTextFont()
333    {
334    return(menuTextFont);
335    }
336
337  public FontUIResource getSubTextFont()
338    {
339    return(subTextFont);
340    }
341
342  public FontUIResource getSystemTextFont()
343    {
344    return(systemTextFont);
345    }
346
347  public FontUIResource getUserTextFont()
348    {
349    return(userTextFont);
350    }
351
352  public FontUIResource getWindowTitleFont()
353    {
354    return(windowTitleFont);
355    }
356
357  /* Read the properties from the Config object. */
358  
359  private void init(Config config)
360    {
361    name = config.getString("name", "Unnamed Color Theme");
362
363    // primary color resources
364    
365    primary1 = new ColorUIResource(config.getColor("color.primary1",
366                                                   super.getPrimary1()));
367    primary2 = new ColorUIResource(config.getColor("color.primary2",
368                                                   super.getPrimary2()));
369    primary3 = new ColorUIResource(config.getColor("color.primary3",
370                                                   super.getPrimary3()));
371
372    // secondary color resources
373    
374    secondary1 = new ColorUIResource(config.getColor("color.secondary1",
375                                                     super.getSecondary1()));
376    secondary2 = new ColorUIResource(config.getColor("color.secondary2",
377                                                     super.getSecondary2()));
378    secondary3 = new ColorUIResource(config.getColor("color.secondary3",
379                                                     super.getSecondary3()));
380
381    // black & white color resources
382    
383    black = new ColorUIResource(config.getColor("color.black",
384                                                super.getBlack()));
385    white = new ColorUIResource(config.getColor("color.white",
386                                                super.getWhite()));
387
388    // specific color resources
389
390    acceleratorForegroundColor
391      = new ColorUIResource(config.getColor("color.acceleratorForeground",
392                                            super.getAcceleratorForeground()));
393
394    acceleratorSelectedForegroundColor
395      = new ColorUIResource(config.getColor("color.acceleratorSelectedForeground",
396                                            super.getAcceleratorSelectedForeground()));
397
398    controlColor
399      = new ColorUIResource(config.getColor("color.control",
400                                            super.getControl()));
401      
402    
403    controlDarkShadowColor
404      = new ColorUIResource(config.getColor("color.controlDarkShadow",
405                                            super.getControlDarkShadow()));
406
407    controlDisabledColor
408      = new ColorUIResource(config.getColor("color.controlDisabled",
409                                            super.getControlDisabled()));
410    controlHighlightColor
411      = new ColorUIResource(config.getColor("color.controlHighlight",
412                                            super.getControlHighlight()));
413
414    controlInfoColor
415      = new ColorUIResource(config.getColor("color.controlInfo",
416                                            super.getControlInfo()));
417
418    controlShadowColor
419      = new ColorUIResource(config.getColor("color.controlShadow",
420                                            super.getControlShadow()));
421
422    controlTextColor
423      = new ColorUIResource(config.getColor("color.controlText",
424                                            super.getControlTextColor()));
425
426    desktopColor
427      = new ColorUIResource(config.getColor("color.desktop",
428                                            super.getDesktopColor()));
429
430    focusColor
431      = new ColorUIResource(config.getColor("color.focus",
432                                            super.getFocusColor()));
433
434    highlightedTextColor
435      = new ColorUIResource(config.getColor("color.highlightedText",
436                                            super.getHighlightedTextColor()));
437
438    inactiveControlTextColor
439      = new ColorUIResource(config.getColor("color.inactiveControlText",
440                                            super.getInactiveControlTextColor()));
441
442    inactiveSystemTextColor
443      = new ColorUIResource(config.getColor("color.inactiveSystemText",
444                                            super.getInactiveSystemTextColor()));
445
446    menuBackgroundColor
447      = new ColorUIResource(config.getColor("color.menuBackground",
448                                            super.getMenuBackground()));
449    
450    menuDisabledForegroundColor
451      = new ColorUIResource(config.getColor("color.menuDisabledForeground",
452                                            super.getMenuDisabledForeground()));
453
454    menuForegroundColor
455      = new ColorUIResource(config.getColor("color.menuForeground",
456                                            super.getMenuForeground()));
457
458    menuSelectedBackgroundColor
459      = new ColorUIResource(config.getColor("color.menuSelectedBackground",
460                                            super.getMenuSelectedBackground()));
461
462    menuSelectedForegroundColor
463      = new ColorUIResource(config.getColor("color.menuSelectedForeground",
464                                            super.getMenuSelectedForeground()));
465
466    primaryControlColor
467      = new ColorUIResource(config.getColor("color.primaryControl",
468                                            super.getPrimaryControl()));
469    
470    primaryControlDarkShadowColor
471      = new ColorUIResource(config.getColor("color.primaryControlDarkShadow",
472                                            super.getPrimaryControlDarkShadow()));
473
474    primaryControlHighlightColor
475      = new ColorUIResource(config.getColor("color.primaryControlHighlight",
476                                            super.getPrimaryControlHighlight()));
477
478    primaryControlInfoColor
479      = new ColorUIResource(config.getColor("color.primaryControlInfo",
480                                            super.getPrimaryControlInfo()));
481
482    primaryControlShadowColor
483      = new ColorUIResource(config.getColor("color.primaryControlShadow",
484                                            super.getPrimaryControlShadow()));
485
486    separatorBackgroundColor
487      = new ColorUIResource(config.getColor("color.separatorBackground",
488                                            super.getSeparatorBackground()));
489
490    separatorForegroundColor
491      = new ColorUIResource(config.getColor("color.separatorForeground",
492                                            super.getSeparatorForeground()));
493
494    systemTextColor
495      = new ColorUIResource(config.getColor("color.systemText",
496                                            super.getSystemTextColor()));
497    
498    textHighlightColor
499      = new ColorUIResource(config.getColor("color.textHighlight",
500                                            super.getTextHighlightColor()));
501    
502    userTextColor
503      = new ColorUIResource(config.getColor("color.userText",
504                                            super.getUserTextColor()));
505
506    windowBackgroundColor
507      = new ColorUIResource(config.getColor("color.windowBackground",
508                                            super.getWindowBackground()));
509    
510    windowTitleBackgroundColor
511      = new ColorUIResource(config.getColor("color.windowTitleBackground",
512                                            super.getWindowTitleBackground()));
513
514    windowTitleForegroundColor
515      = new ColorUIResource(config.getColor("color.windowTitleForeground",
516                                            super.getWindowTitleForeground()));
517    
518    windowTitleInactiveBackgroundColor
519      = new ColorUIResource(config.getColor("color.windowTitleInactiveBackground",
520                                            super.getWindowTitleInactiveBackground()));
521
522    windowTitleInactiveForegroundColor
523      = new ColorUIResource(config.getColor("color.windowTitleInactiveForeground",
524                                            super.getWindowTitleInactiveForeground()));
525    
526    // font resources
527    
528    controlTextFont
529      = new FontUIResource(config.getFont("font.controlText",
530                                          super.getControlTextFont()));
531    menuTextFont
532      = new FontUIResource(config.getFont("font.menuText",
533                                          super.getMenuTextFont()));
534    subTextFont
535      = new FontUIResource(config.getFont("font.subText",
536                                          super.getSubTextFont()));
537    systemTextFont
538      = new FontUIResource(config.getFont("font.systemText",
539                                          super.getSystemTextFont()));
540    userTextFont
541      = new FontUIResource(config.getFont("font.userText",
542                                          super.getUserTextFont()));
543    windowTitleFont
544      = new FontUIResource(config.getFont("font.windowTitle",
545                                          super.getWindowTitleFont()));
546    }
547
548  }
549
550/* end of source file */