1 /* AbstractAction.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
41 import java.beans.PropertyChangeListener;
42 import java.io.IOException;
43 import java.io.ObjectInputStream;
44 import java.io.ObjectOutputStream;
45 import java.io.Serializable;
46 import java.util.HashMap;
47 import javax.swing.event.SwingPropertyChangeSupport;
51 * @author Andrew Selkirk
54 public abstract class AbstractAction
55 implements Action, Cloneable, Serializable
57 static final long serialVersionUID = -6803159439231523484L;
62 protected boolean enabled = true;
67 protected SwingPropertyChangeSupport changeSupport =
68 new SwingPropertyChangeSupport(this);
73 private transient HashMap store = new HashMap();
76 * Constructor AbstractAction
78 public AbstractAction()
80 this(""); // TODO: default name
84 * Constructor AbstractAction
88 public AbstractAction(String name)
90 this(name, null); // TODO: default icon??
94 * Constructor AbstractAction
99 public AbstractAction(String name, Icon icon)
101 putValue(NAME, name);
102 putValue(SMALL_ICON, icon);
108 * @param stream the stream to read from
110 * @exception ClassNotFoundException TODO
111 * @exception IOException if an error occurs
113 private void readObject(ObjectInputStream stream)
114 throws ClassNotFoundException, IOException
122 * @param stream the stream to write to
124 * @exception IOException if an error occurs
126 private void writeObject(ObjectOutputStream stream) throws IOException
136 * @exception CloneNotSupportedException TODO
138 protected Object clone() throws CloneNotSupportedException
140 AbstractAction copy = (AbstractAction) super.clone();
141 copy.store = (HashMap) store.clone();
146 * Returns a value for a given key from the built-in store.
148 * @param key the key to get the value for
152 public Object getValue(String key)
154 return store.get(key);
158 * Puts a key/value pair into the built-in store.
161 * @param value the value
163 public void putValue(String key, Object value)
165 store.put(key, value);
173 public boolean isEnabled()
181 * @param enabled TODO
183 public void setEnabled(boolean enabled)
185 this.enabled = enabled;
192 public Object[] getKeys()
194 return store.keySet().toArray();
200 * @param propertyName TODO
201 * @param oldValue TODO
202 * @param newValue TODO
204 protected void firePropertyChange(String propertyName, Object oldValue,
207 changeSupport.firePropertyChange(propertyName, oldValue, newValue);
211 * addPropertyChangeListener
213 * @param listener the listener to add
215 public void addPropertyChangeListener(PropertyChangeListener listener)
217 changeSupport.addPropertyChangeListener(listener);
221 * removePropertyChangeListener
223 * @param listener the listener to remove
225 public void removePropertyChangeListener(PropertyChangeListener listener)
227 changeSupport.removePropertyChangeListener(listener);
231 * Returns all registered listeners.
233 * @return array of listeners.
237 public PropertyChangeListener[] getPropertyChangeListeners()
239 return changeSupport.getPropertyChangeListeners();