View Javadoc

1   package org.glassbox;
2   
3   import java.awt.*;
4   import javax.swing.*;
5   import javax.swing.border.*;
6   
7   import java.util.HashMap;
8   
9   /***
10     A simple implementation of <code>ThemeProperties</code>.
11     Only maps property keys directly to the corresponding properties.
12     @author Tilman Linden
13   */
14  public class SimpleThemeProperties implements ThemeProperties {
15      protected HashMap _fonts;
16      protected HashMap _colors;
17      protected HashMap _cursors;
18      protected HashMap _paints;
19      protected HashMap _insets;
20      protected HashMap _strokes;
21      protected HashMap _icons;
22      protected HashMap _borders;
23      protected HashMap _dimensions;
24      protected HashMap _texts;
25  
26      public SimpleThemeProperties() {
27  	_fonts = new HashMap();
28  	_colors = new HashMap();
29  	_cursors = new HashMap();
30  	_paints = new HashMap();
31  	_insets = new HashMap();
32  	_strokes = new HashMap();
33  	_icons = new HashMap();
34  	_borders = new HashMap();
35  	_dimensions = new HashMap();
36  	_texts = new HashMap();
37      }
38  
39      protected void setProperty(String key, Object value) {
40  	if (value instanceof Font) _fonts.put(key, value);
41  	else if (value instanceof Color &&
42  		 key.endsWith("color")) _colors.put(key, value);
43  	else if (value instanceof Cursor) _cursors.put(key, value);
44  	else if (value instanceof Paint) _paints.put(key, value);
45  	else if (value instanceof Insets) _insets.put(key, value);
46  	else if (value instanceof Stroke) _strokes.put(key, value);
47  	else if (value instanceof Icon) _icons.put(key, value);
48  	else if (value instanceof Border) _borders.put(key, value);
49  	else if (value instanceof Dimension) _dimensions.put(key, value); 
50  	else if (value instanceof String) _texts.put(key, value);
51      }
52  
53      public Font getFont(String key) {
54  	return (Font)_fonts.get(key);
55      }
56  
57      public Color getColor(String key) {
58  	return (Color)_colors.get(key);
59      }
60  
61      public Cursor getCursor(String key) {
62  	return (Cursor)_cursors.get(key);
63      }
64  
65      public Paint getPaint(String key) {
66  	return (Paint)_paints.get(key);
67      }
68  
69      public Insets getInsets(String key) {
70  	return (Insets)_insets.get(key);
71      }
72  
73      public Stroke getStroke(String key) {
74  	return (Stroke)_strokes.get(key);
75      }
76  
77      public Icon getIcon(String key) {
78  	return (Icon)_icons.get(key);
79      }
80  
81      public Border getBorder(String key) {
82  	return (Border)_borders.get(key);
83      }
84  
85      public Dimension getSize(String key) {
86  	return (Dimension)_dimensions.get(key);
87      }
88  
89      public String getText(String key) {
90  	return (String)_texts.get(key);
91      }
92  }