01: /*
02: * @(#)UIAction.java 8/20/2006
03: *
04: * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
05: */
06:
07: package com.jidesoft.plaf.basic;
08:
09: import javax.swing.*;
10: import java.beans.PropertyChangeListener;
11:
12: /**
13: * UIAction is the basis of all of basic's action classes that are used in
14: * an ActionMap. Subclasses need to override <code>actionPerformed</code>.
15: * <p/>
16: * A typical subclass will look like:
17: * <pre>
18: * private static class Actions extends UIAction {
19: * Actions(String name) {
20: * super(name);
21: * }
22: * <p/>
23: * public void actionPerformed(ActionEvent ae) {
24: * if (getName() == "selectAll") {
25: * selectAll();
26: * }
27: * else if (getName() == "cancelEditing") {
28: * cancelEditing();
29: * }
30: * }
31: * }
32: * </pre>
33: * <p/>
34: * Subclasses that wish to conditionalize the enabled state should override
35: * <code>isEnabled(Component)</code>, and be aware that the passed in
36: * <code>Component</code> may be null.
37: *
38: * @author Scott Violet
39: * @version 1.4 11/17/05
40: * @see javax.swing.Action
41: */
42: public abstract class UIAction implements Action {
43: private String name;
44:
45: public UIAction(String name) {
46: this .name = name;
47: }
48:
49: public final String getName() {
50: return name;
51: }
52:
53: public Object getValue(String key) {
54: if (key == NAME) {
55: return name;
56: }
57: return null;
58: }
59:
60: // UIAction is not mutable, this does nothing.
61: public void putValue(String key, Object value) {
62: }
63:
64: // UIAction is not mutable, this does nothing.
65: public void setEnabled(boolean b) {
66: }
67:
68: /**
69: * Cover method for <code>isEnabled(null)</code>.
70: */
71: public final boolean isEnabled() {
72: return isEnabled(null);
73: }
74:
75: /**
76: * Subclasses that need to conditionalize the enabled state should
77: * override this. Be aware that <code>sender</code> may be null.
78: *
79: * @param sender Widget enabled state is being asked for, may be null.
80: */
81: public boolean isEnabled(Object sender) {
82: return true;
83: }
84:
85: // UIAction is not mutable, this does nothing.
86: public void addPropertyChangeListener(
87: PropertyChangeListener listener) {
88: }
89:
90: // UIAction is not mutable, this does nothing.
91: public void removePropertyChangeListener(
92: PropertyChangeListener listener) {
93: }
94: }
|