1 | /* AbstractAction.java --
|
---|
2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
6 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA.
|
---|
20 |
|
---|
21 | Linking this library statically or dynamically with other modules is
|
---|
22 | making a combined work based on this library. Thus, the terms and
|
---|
23 | conditions of the GNU General Public License cover the whole
|
---|
24 | combination.
|
---|
25 |
|
---|
26 | As a special exception, the copyright holders of this library give you
|
---|
27 | permission to link this library with independent modules to produce an
|
---|
28 | executable, regardless of the license terms of these independent
|
---|
29 | modules, and to copy and distribute the resulting executable under
|
---|
30 | terms of your choice, provided that you also meet, for each linked
|
---|
31 | independent module, the terms and conditions of the license of that
|
---|
32 | module. An independent module is a module which is not derived from
|
---|
33 | or based on this library. If you modify this library, you may extend
|
---|
34 | this exception to your version of the library, but you are not
|
---|
35 | obligated to do so. If you do not wish to do so, delete this
|
---|
36 | exception statement from your version. */
|
---|
37 |
|
---|
38 | package javax.swing;
|
---|
39 |
|
---|
40 | // Imports
|
---|
41 | import java.awt.event.*;
|
---|
42 | import java.beans.*;
|
---|
43 | import java.io.*;
|
---|
44 | import javax.swing.event.*;
|
---|
45 | import java.util.*;
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * AbstractAction
|
---|
49 | * @author Andrew Selkirk
|
---|
50 | * @version 1.0
|
---|
51 | */
|
---|
52 | public abstract class AbstractAction implements Action, Cloneable, Serializable {
|
---|
53 |
|
---|
54 | //-------------------------------------------------------------
|
---|
55 | // Variables --------------------------------------------------
|
---|
56 | //-------------------------------------------------------------
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * enabled
|
---|
60 | */
|
---|
61 | protected boolean enabled = true;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * changeSupport
|
---|
65 | */
|
---|
66 | protected SwingPropertyChangeSupport changeSupport =
|
---|
67 | new SwingPropertyChangeSupport(this);
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * store
|
---|
71 | */
|
---|
72 | private transient HashMap store = new HashMap();
|
---|
73 |
|
---|
74 |
|
---|
75 | //-------------------------------------------------------------
|
---|
76 | // Initialization ---------------------------------------------
|
---|
77 | //-------------------------------------------------------------
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Constructor AbstractAction
|
---|
81 | */
|
---|
82 | public AbstractAction() {
|
---|
83 | this(""); // TODO: default name
|
---|
84 | } // AbstractAction()
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Constructor AbstractAction
|
---|
88 | * @param name TODO
|
---|
89 | */
|
---|
90 | public AbstractAction(String name) {
|
---|
91 | this(name, null); // TODO: default icon??
|
---|
92 | } // AbstractAction()
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Constructor AbstractAction
|
---|
96 | * @param name TODO
|
---|
97 | * @param icon TODO
|
---|
98 | */
|
---|
99 | public AbstractAction(String name, Icon icon) {
|
---|
100 | putValue(NAME, name);
|
---|
101 | putValue(SMALL_ICON, icon);
|
---|
102 | } // AbstractAction()
|
---|
103 |
|
---|
104 |
|
---|
105 | //-------------------------------------------------------------
|
---|
106 | // Methods ----------------------------------------------------
|
---|
107 | //-------------------------------------------------------------
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * readObject
|
---|
111 | * @param stream TODO
|
---|
112 | * @exception ClassNotFoundException TODO
|
---|
113 | * @exception IOException TODO
|
---|
114 | */
|
---|
115 | private void readObject(ObjectInputStream stream)
|
---|
116 | throws ClassNotFoundException, IOException {
|
---|
117 | // TODO
|
---|
118 | } // readObject()
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * writeObject
|
---|
122 | * @param stream TODO
|
---|
123 | * @exception IOException TODO
|
---|
124 | */
|
---|
125 | private void writeObject(ObjectOutputStream stream) throws IOException {
|
---|
126 | // TODO
|
---|
127 | } // writeObject()
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * clone
|
---|
131 | * @exception CloneNotSupportedException TODO
|
---|
132 | * @returns Object
|
---|
133 | */
|
---|
134 | protected Object clone() throws CloneNotSupportedException {
|
---|
135 | // What to do??
|
---|
136 | return null;
|
---|
137 | } // clone()
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * getValue
|
---|
141 | * @param key TODO
|
---|
142 | * @returns Object
|
---|
143 | */
|
---|
144 | public Object getValue(String key) {
|
---|
145 | return store.get(key);
|
---|
146 | } // getValue()
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * putValue
|
---|
150 | * @param key TODO
|
---|
151 | * @param value TODO
|
---|
152 | */
|
---|
153 | public void putValue(String key, Object value) {
|
---|
154 | store.put(key, value);
|
---|
155 | } // putValue()
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * isEnabled
|
---|
159 | * @returns boolean
|
---|
160 | */
|
---|
161 | public boolean isEnabled() {
|
---|
162 | return enabled;
|
---|
163 | } // isEnabled()
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * setEnabled
|
---|
167 | * @param enabled TODO
|
---|
168 | */
|
---|
169 | public void setEnabled(boolean enabled) {
|
---|
170 | this.enabled = enabled;
|
---|
171 | } // setEnabled()
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * getKeys
|
---|
175 | * @returns Object[]
|
---|
176 | */
|
---|
177 | public Object[] getKeys() {
|
---|
178 | return store.keySet().toArray();
|
---|
179 | } // getKeys()
|
---|
180 |
|
---|
181 | /**
|
---|
182 | * firePropertyChange
|
---|
183 | * @param propertyName TODO
|
---|
184 | * @param oldValue TODO
|
---|
185 | * @param newValue TODO
|
---|
186 | */
|
---|
187 | protected void firePropertyChange(String propertyName,
|
---|
188 | Object oldValue, Object newValue) {
|
---|
189 | changeSupport.firePropertyChange(propertyName, oldValue, newValue);
|
---|
190 | } // firePropertyChange()
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * addPropertyChangeListener
|
---|
194 | * @param listener TODO
|
---|
195 | */
|
---|
196 | public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
|
---|
197 | changeSupport.addPropertyChangeListener(listener);
|
---|
198 | } // addPropertyChangeListener()
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * removePropertyChangeListener
|
---|
202 | * @param listener TODO
|
---|
203 | */
|
---|
204 | public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
|
---|
205 | changeSupport.removePropertyChangeListener(listener);
|
---|
206 | } // removePropertyChangeListener()
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * actionPerformed
|
---|
210 | * @param event TODO
|
---|
211 | */
|
---|
212 | public abstract void actionPerformed(ActionEvent event);
|
---|
213 |
|
---|
214 |
|
---|
215 | } // AbstractAction
|
---|