KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > util > thread > ActionWrapper


1 package net.suberic.util.thread;
2 import net.suberic.util.DynamicAbstractAction;
3 import javax.swing.Action JavaDoc;
4 import javax.swing.Icon JavaDoc;
5 import javax.swing.AbstractAction JavaDoc;
6 import java.beans.PropertyChangeListener JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8
9 /**
10  * This class associates an Action with a particular ActionThread. It
11  * then can be used in place of the wrapped Action. When the Action is
12  * performed, the work is done by the ActionThread, rather than the
13  * original thread.
14  */

15 public class ActionWrapper extends net.suberic.util.DynamicAbstractAction {
16   Action wrappedAction;
17   ActionThread thread;
18
19   /**
20    * This creates a new ActionWrapper from an Action and a Thread.
21    */

22   public ActionWrapper(Action newWrappedAction, ActionThread newThread) {
23     super();
24     wrappedAction=newWrappedAction;
25     thread=newThread;
26   }
27   
28   /**
29    * This performs the wrapped Action on the configured Thread.
30    */

31   public void actionPerformed(ActionEvent JavaDoc e) {
32     thread.addToQueue(wrappedAction, e);
33   }
34     
35   /**
36    * This passes the call on to the wrapped Action.
37    */

38   public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
39     wrappedAction.addPropertyChangeListener(listener);
40   }
41   
42   /**
43    * This passes the call on to the wrapped Action.
44    */

45   public Object JavaDoc getValue(String JavaDoc key) {
46     return wrappedAction.getValue(key);
47   }
48   
49   /**
50    * This passes the call on to the wrapped Action.
51    */

52   public boolean isEnabled() {
53     return wrappedAction.isEnabled();
54   }
55   
56   /**
57    * This passes the call on to the wrapped Action.
58    */

59   public void putValue(String JavaDoc key, Object JavaDoc newValue) {
60     wrappedAction.putValue(key, newValue);
61     // have to call super.putValue() in order to work around a bug in
62
// javax.swing.AbstractAction.clone() later
63
super.putValue(key, newValue);
64   }
65   
66   /**
67    * This passes the call on to the wrapped Action.
68    */

69   public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
70     wrappedAction.removePropertyChangeListener(listener);
71   }
72   
73   /**
74    * This passes the call on to the wrapped Action.
75    */

76   public void setEnabled(boolean newValue) {
77     wrappedAction.setEnabled(newValue);
78   }
79     
80   public Action getWrappedAction() {
81     return wrappedAction;
82   }
83   
84   public void setWrappedAction(Action newValue) {
85     wrappedAction = newValue;
86   }
87   
88   public ActionThread getThread() {
89     return thread;
90   }
91   
92   public void setThread(ActionThread newValue) {
93     thread=newValue;
94   }
95   
96   public Action cloneDynamicAction() throws CloneNotSupportedException JavaDoc {
97     if (wrappedAction instanceof DynamicAbstractAction) {
98       this.putValue("bugWorkaround", "true");
99       ActionWrapper newAction = (ActionWrapper)this.clone();
100       newAction.setWrappedAction(((DynamicAbstractAction) wrappedAction).cloneDynamicAction());
101       return newAction;
102     } else {
103       throw new CloneNotSupportedException JavaDoc();
104     }
105   }
106   
107 }
108
Popular Tags