blob: 52b2282030141dae3260d6f1b35101d5fcc83110 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25package sun.swing;
26
27import java.beans.PropertyChangeListener;
28
29import javax.swing.Action;
30
31/**
32 * UIAction is the basis of all of basic's action classes that are used in
33 * an ActionMap. Subclasses need to override <code>actionPerformed</code>.
34 * <p>
35 * A typical subclass will look like:
36 * <pre>
37 * private static class Actions extends UIAction {
38 * Actions(String name) {
39 * super(name);
40 * }
41 *
42 * public void actionPerformed(ActionEvent ae) {
43 * if (getName() == "selectAll") {
44 * selectAll();
45 * }
46 * else if (getName() == "cancelEditing") {
47 * cancelEditing();
48 * }
49 * }
50 * }
51 * </pre>
52 * <p>
53 * Subclasses that wish to conditionalize the enabled state should override
54 * <code>isEnabled(Component)</code>, and be aware that the passed in
55 * <code>Component</code> may be null.
56 *
57 * @see com.sun.java.swing.ExtendedAction
58 * @see javax.swing.Action
59 * @author Scott Violet
60 */
61public abstract class UIAction implements Action {
62 private String name;
63
64 public UIAction(String name) {
65 this.name = name;
66 }
67
68 public final String getName() {
69 return name;
70 }
71
72 public Object getValue(String key) {
73 if (key == NAME) {
74 return name;
75 }
76 return null;
77 }
78
79 // UIAction is not mutable, this does nothing.
80 public void putValue(String key, Object value) {
81 }
82
83 // UIAction is not mutable, this does nothing.
84 public void setEnabled(boolean b) {
85 }
86
87 /**
88 * Cover method for <code>isEnabled(null)</code>.
89 */
90 public final boolean isEnabled() {
91 return isEnabled(null);
92 }
93
94 /**
95 * Subclasses that need to conditionalize the enabled state should
96 * override this. Be aware that <code>sender</code> may be null.
97 *
98 * @param sender Widget enabled state is being asked for, may be null.
99 */
100 public boolean isEnabled(Object sender) {
101 return true;
102 }
103
104 // UIAction is not mutable, this does nothing.
105 public void addPropertyChangeListener(PropertyChangeListener listener) {
106 }
107
108 // UIAction is not mutable, this does nothing.
109 public void removePropertyChangeListener(PropertyChangeListener listener) {
110 }
111}