KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > UIAction


1 /*
2  * $Id: UIAction.java,v 1.2 2004/09/07 18:16:00 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 /*
9  * @(#)UIAction.java 1.2 03/04/24
10  *
11  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
12  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
13  */

14 package org.jdesktop.swing;
15
16 import java.beans.PropertyChangeListener JavaDoc;
17
18 import javax.swing.Action JavaDoc;
19
20 /**
21  * UIAction is the basis of all of basic's action classes that are used in
22  * an ActionMap. Subclasses need to override <code>actionPerformed</code>.
23  * <p>
24  * A typical subclass will look like:
25  * <pre>
26  * private static class Actions extends UIAction {
27  * Actions(String name) {
28  * super(name);
29  * }
30  *
31  * public void actionPerformed(ActionEvent ae) {
32  * if (getName() == "selectAll") {
33  * selectAll();
34  * }
35  * else if (getName() == "cancelEditing") {
36  * cancelEditing();
37  * }
38  * }
39  * }
40  * </pre>
41  * <p>
42  * Subclasses that wish to conditionalize the enabled state should override
43  * <code>isEnabled(Component)</code>, and be aware that the passed in
44  * <code>Component</code> may be null.
45  * <p>
46  * This is based on sun.swing.UIAction in J2SE 1.5
47  *
48  * @see javax.swing.Action
49  * @author Scott Violet
50  */

51 public abstract class UIAction implements Action JavaDoc {
52     private String JavaDoc name;
53
54     public UIAction(String JavaDoc name) {
55         this.name = name;
56     }
57
58     public final String JavaDoc getName() {
59         return name;
60     }
61
62     public Object JavaDoc getValue(String JavaDoc key) {
63         if (key == NAME) {
64             return name;
65         }
66         return null;
67     }
68
69     // UIAction is not mutable, this does nothing.
70
public void putValue(String JavaDoc key, Object JavaDoc value) {
71     }
72
73     // UIAction is not mutable, this does nothing.
74
public void setEnabled(boolean b) {
75     }
76
77     /**
78      * Cover method for <code>isEnabled(null)</code>.
79      */

80     public final boolean isEnabled() {
81         return isEnabled(null);
82     }
83
84     /**
85      * Subclasses that need to conditionalize the enabled state should
86      * override this. Be aware that <code>sender</code> may be null.
87      *
88      * @param sender Widget enabled state is being asked for, may be null.
89      */

90     public boolean isEnabled(Object JavaDoc sender) {
91         return true;
92     }
93
94     // UIAction is not mutable, this does nothing.
95
public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
96     }
97
98     // UIAction is not mutable, this does nothing.
99
public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
100     }
101 }
102
Popular Tags