KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > util > swing > ThemeWrapperItem


1 package net.suberic.util.swing;
2
3 import net.suberic.util.*;
4 import java.util.*;
5 import javax.swing.*;
6 import javax.swing.plaf.metal.*;
7 import javax.swing.plaf.*;
8
9
10 /**
11  *
12  */

13 public class ThemeWrapperItem implements Item, ValueChangeListener {
14
15   private String JavaDoc itemId;
16   private String JavaDoc resourceString;
17
18   private VariableBundle bundle = null;
19
20   private WeakHashMap themeListenerList = new WeakHashMap();
21   
22   private MetalTheme mWrappedTheme = null;
23
24   /**
25    * Creates a new ItemOcreanTheme from the given property.
26    */

27   public ThemeWrapperItem(VariableBundle sourceBundle, String JavaDoc newResourceString, String JavaDoc newItemId) {
28     itemId = newItemId;
29     resourceString = newResourceString;
30     
31     bundle = sourceBundle;
32
33     sourceBundle.addValueChangeListener(this, getItemProperty() + ".*");
34   }
35
36   /**
37    * Sets the wrapped theme.
38    */

39   public void setWrappedTheme(MetalTheme pWrappedTheme) {
40     mWrappedTheme = pWrappedTheme;
41   }
42
43   /**
44    * Gets the wrapped theme.
45    */

46   public MetalTheme getWrappedTheme() {
47     return mWrappedTheme;
48   }
49
50   /**
51    * The Item ID. For example, if you were to have a list of users, a
52    * given user's itemID may be "defaultUser".
53    */

54   public String JavaDoc getItemID() {
55     return itemId;
56   }
57   
58   /**
59    * The Item property. For example, if you were to have a list of users, a
60    * given user's itemProperty may be "Users.defaultUser".
61    */

62   public String JavaDoc getItemProperty() {
63     return resourceString + "." + itemId;
64   }
65
66   /**
67    * Called when a ui value changes.
68    */

69   public void valueChanged(String JavaDoc changedValue) {
70     fireThemeChangedEvent();
71   }
72
73   /**
74    * Adds a ThemeListener to the ListenerList.
75    */

76   public void addThemeListener(ThemeListener tl) {
77     if (! themeListenerList.containsKey(tl))
78       themeListenerList.put(tl, null);
79   }
80   
81   /**
82    * Removes a ThemeListener from the ListenerList.
83    */

84   public void removeThemeListener(ThemeListener tl) {
85     themeListenerList.remove(tl);
86   }
87
88   /**
89    * Notifies all registered ThemeListeners that this Theme has changed.
90    */

91   public void fireThemeChangedEvent() {
92     // no-op. this theme doesn't change.
93
}
94
95   public String JavaDoc getName() { return getItemID(); }
96   
97 }
98
Popular Tags