KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > UIDefaults


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: UIDefaults.java,v $
11    Revision 1.3 2004/04/15 11:24:33 bobintetley
12    (Dan Naab) ComponentUI, UIDefaults/UIManager and Accessibility support.
13    (Antonio Weber) TableColumnModelListener implementation and support
14
15    Revision 1.2 2004/03/30 10:42:46 bobintetley
16    Many minor bug fixes, event improvements by Dan Naab. Full swing.Icon support
17
18    Revision 1.1 2004/01/26 08:11:00 bobintetley
19    Many bugfixes and addition of SwingSet
20
21
22 */

23
24 package swingwtx.swing;
25
26  import swingwt.awt.*;
27  import swingwtx.swing.border.*;
28  import swingwtx.swing.event.*;
29  import swingwtx.swing.plaf.*;
30  
31  import java.beans.PropertyChangeListener JavaDoc;
32  import java.util.Locale JavaDoc;
33  
34  /**
35   * This UIDefaults implementation is functionally read-only - changing values with put()
36   * has no real effect. It is useful for code that needs to read UIDefaults to create derivative
37   * UIResources and acts as a stub for code that attempts to change default resources.
38   *
39   * If possible with SWT, put() could be modified to recognize set keys and call appropriate methods to
40   * update the SWT defaults. However, since SWT uses native controls this is probably difficult.
41   *
42   * @author Naab
43   * @version %I%, %G%
44   */

45  public class UIDefaults extends java.util.HashMap JavaDoc {
46      
47      private SwingPropertyChangeSupport swingPropertyChangeSupport = new SwingPropertyChangeSupport(this);
48  
49      private Object JavaDoc getKeyAsType(Object JavaDoc key, Class JavaDoc type)
50      {
51          Object JavaDoc value = get(key);
52          if (value.getClass().equals(type)) return value;
53          else return null;
54      }
55  
56      private Object JavaDoc getKeyAsType(Object JavaDoc key, Locale JavaDoc locale, Class JavaDoc type)
57      {
58          // TODO: Handle locales?
59
return getKeyAsType(key, type);
60      }
61  
62      public Font getFont(Object JavaDoc key) { return (Font) getKeyAsType(key, Font.class); }
63      public Font getFont(Object JavaDoc key, Locale JavaDoc locale) { return (Font) getKeyAsType(key, locale, Font.class); }
64      public Color getColor(Object JavaDoc key) { return (Color) getKeyAsType(key, Color.class); }
65      public Color getColor(Object JavaDoc key, Locale JavaDoc locale) { return (Color) getKeyAsType(key, locale, Color.class); }
66      public Icon getIcon(Object JavaDoc key) { return (Icon) getKeyAsType(key, Icon.class); }
67      public Icon getIcon(Object JavaDoc key, Locale JavaDoc locale) { return (Icon) getKeyAsType(key, locale, Icon.class); }
68      public Border getBorder(Object JavaDoc key) { return (Border) getKeyAsType(key, Border.class); }
69      public Border getBorder(Object JavaDoc key, Locale JavaDoc locale) { return (Border) getKeyAsType(key, locale, Border.class); }
70      public String JavaDoc getString(Object JavaDoc key) { return (String JavaDoc) getKeyAsType(key, String JavaDoc.class); }
71      public String JavaDoc getString(Object JavaDoc key, Locale JavaDoc locale) { return (String JavaDoc) getKeyAsType(key, locale, String JavaDoc.class); }
72      public Integer JavaDoc getInt(Object JavaDoc key) { return (Integer JavaDoc) getKeyAsType(key, Integer JavaDoc.class); }
73      public Integer JavaDoc getInt(Object JavaDoc key, Locale JavaDoc locale) { return (Integer JavaDoc) getKeyAsType(key, locale, Integer JavaDoc.class); }
74      public Boolean JavaDoc getBoolean(Object JavaDoc key) { return (Boolean JavaDoc) getKeyAsType(key, Boolean JavaDoc.class); }
75      public Boolean JavaDoc getBoolean(Object JavaDoc key, Locale JavaDoc locale) { return (Boolean JavaDoc) getKeyAsType(key, locale, Boolean JavaDoc.class); }
76      public Insets getInsets(Object JavaDoc key) { return (Insets) getKeyAsType(key, Insets.class); }
77      public Insets getInsets(Object JavaDoc key, Locale JavaDoc locale) { return (Insets) getKeyAsType(key, locale, Insets.class); }
78      public Dimension getDimension(Object JavaDoc key) { return (Dimension) getKeyAsType(key, Dimension.class); }
79      public Dimension getDimension(Object JavaDoc key, Locale JavaDoc locale) { return (Dimension) getKeyAsType(key, locale, Dimension.class); }
80  
81      public synchronized void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) { swingPropertyChangeSupport.addPropertyChangeListener(listener); }
82      public synchronized void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) { swingPropertyChangeSupport.removePropertyChangeListener(listener); }
83      public synchronized PropertyChangeListener JavaDoc[] getPropertyChangeListeners() { return swingPropertyChangeSupport.getPropertyChangeListeners(); }
84  
85      /* TODO: Implement L&F ComponentUI, ResourceBundle (Locale) support */
86      public Class JavaDoc getUIClass(String JavaDoc uiClassID, ClassLoader JavaDoc uiClassLoader) { return null; }
87      public Class JavaDoc getUIClass(String JavaDoc uiClassID) { return null; }
88      public ComponentUI getUI(JComponent target) { return null; }
89      public synchronized void addResourceBundle(String JavaDoc bundleName) {}
90      
91  }
Popular Tags