001: package net.suberic.util.thread;
002:
003: import net.suberic.util.DynamicAbstractAction;
004: import javax.swing.Action;
005: import javax.swing.Icon;
006: import javax.swing.AbstractAction;
007: import java.beans.PropertyChangeListener;
008: import java.awt.event.ActionEvent;
009:
010: /**
011: * This class associates an Action with a particular ActionThread. It
012: * then can be used in place of the wrapped Action. When the Action is
013: * performed, the work is done by the ActionThread, rather than the
014: * original thread.
015: */
016: public class ActionWrapper extends
017: net.suberic.util.DynamicAbstractAction {
018: Action wrappedAction;
019: ActionThread thread;
020:
021: /**
022: * This creates a new ActionWrapper from an Action and a Thread.
023: */
024: public ActionWrapper(Action newWrappedAction, ActionThread newThread) {
025: super ();
026: wrappedAction = newWrappedAction;
027: thread = newThread;
028: }
029:
030: /**
031: * This performs the wrapped Action on the configured Thread.
032: */
033: public void actionPerformed(ActionEvent e) {
034: thread.addToQueue(wrappedAction, e);
035: }
036:
037: /**
038: * This passes the call on to the wrapped Action.
039: */
040: public void addPropertyChangeListener(
041: PropertyChangeListener listener) {
042: wrappedAction.addPropertyChangeListener(listener);
043: }
044:
045: /**
046: * This passes the call on to the wrapped Action.
047: */
048: public Object getValue(String key) {
049: return wrappedAction.getValue(key);
050: }
051:
052: /**
053: * This passes the call on to the wrapped Action.
054: */
055: public boolean isEnabled() {
056: return wrappedAction.isEnabled();
057: }
058:
059: /**
060: * This passes the call on to the wrapped Action.
061: */
062: public void putValue(String key, Object newValue) {
063: wrappedAction.putValue(key, newValue);
064: // have to call super.putValue() in order to work around a bug in
065: // javax.swing.AbstractAction.clone() later
066: super .putValue(key, newValue);
067: }
068:
069: /**
070: * This passes the call on to the wrapped Action.
071: */
072: public void removePropertyChangeListener(
073: PropertyChangeListener listener) {
074: wrappedAction.removePropertyChangeListener(listener);
075: }
076:
077: /**
078: * This passes the call on to the wrapped Action.
079: */
080: public void setEnabled(boolean newValue) {
081: wrappedAction.setEnabled(newValue);
082: }
083:
084: public Action getWrappedAction() {
085: return wrappedAction;
086: }
087:
088: public void setWrappedAction(Action newValue) {
089: wrappedAction = newValue;
090: }
091:
092: public ActionThread getThread() {
093: return thread;
094: }
095:
096: public void setThread(ActionThread newValue) {
097: thread = newValue;
098: }
099:
100: public Action cloneDynamicAction()
101: throws CloneNotSupportedException {
102: if (wrappedAction instanceof DynamicAbstractAction) {
103: this .putValue("bugWorkaround", "true");
104: ActionWrapper newAction = (ActionWrapper) this .clone();
105: newAction
106: .setWrappedAction(((DynamicAbstractAction) wrappedAction)
107: .cloneDynamicAction());
108: return newAction;
109: } else {
110: throw new CloneNotSupportedException();
111: }
112: }
113:
114: }
|