Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / AbstractAction.java
blobc0ddf44ffa5ca9e6631bce5fea73ef3086686c22
1 /* AbstractAction.java --
2 Copyright (C) 2002, 2004, 2005 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)
9 any later version.
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
19 02111-1307 USA.
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.
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. */
39 package javax.swing;
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;
48 import javax.swing.event.SwingPropertyChangeSupport;
50 /**
51 * AbstractAction
52 * @author Andrew Selkirk
53 * @version 1.0
55 public abstract class AbstractAction
56 implements Action, Cloneable, Serializable
58 private static final long serialVersionUID = -6803159439231523484L;
60 /**
61 * enabled
63 protected boolean enabled = true;
65 /**
66 * changeSupport
68 protected SwingPropertyChangeSupport changeSupport =
69 new SwingPropertyChangeSupport(this);
71 /**
72 * store
74 private transient HashMap store = new HashMap();
76 /**
77 * Constructor AbstractAction
79 public AbstractAction()
81 this(""); // TODO: default name
84 /**
85 * Constructor AbstractAction
87 * @param name TODO
89 public AbstractAction(String name)
91 this(name, null); // TODO: default icon??
94 /**
95 * Constructor AbstractAction
97 * @param name TODO
98 * @param icon TODO
100 public AbstractAction(String name, Icon icon)
102 putValue(NAME, name);
103 putValue(SMALL_ICON, icon);
107 * readObject
109 * @param stream the stream to read from
111 * @exception ClassNotFoundException TODO
112 * @exception IOException if an error occurs
114 private void readObject(ObjectInputStream stream)
115 throws ClassNotFoundException, IOException
117 // TODO
121 * writeObject
123 * @param stream the stream to write to
125 * @exception IOException if an error occurs
127 private void writeObject(ObjectOutputStream stream) throws IOException
129 // TODO
133 * clone
135 * @return Object
137 * @exception CloneNotSupportedException TODO
139 protected Object clone() throws CloneNotSupportedException
141 AbstractAction copy = (AbstractAction) super.clone();
142 copy.store = (HashMap) store.clone();
143 return copy;
147 * Returns a value for a given key from the built-in store.
149 * @param key the key to get the value for
151 * @return Object
153 public Object getValue(String key)
155 return store.get(key);
159 * Puts a key/value pair into the built-in store.
161 * @param key the key
162 * @param value the value
164 public void putValue(String key, Object value)
166 Object old = getValue(key);
167 if (old != value)
169 store.put(key, value);
170 firePropertyChange(key, old, value);
175 * isEnabled
177 * @return boolean
179 public boolean isEnabled()
181 return enabled;
185 * setEnabled
187 * @param enabled TODO
189 public void setEnabled(boolean enabled)
191 if (enabled != this.enabled)
193 this.enabled = enabled;
194 firePropertyChange("enabled", !this.enabled, this.enabled);
199 * getKeys
200 * @returns Object[]
202 public Object[] getKeys()
204 return store.keySet().toArray();
208 * This method fires a PropertyChangeEvent given the propertyName
209 * and the old and new values.
211 * @param propertyName The property that changed.
212 * @param oldValue The old value of the property.
213 * @param newValue The new value of the property.
215 protected void firePropertyChange(String propertyName, Object oldValue,
216 Object newValue)
218 changeSupport.firePropertyChange(propertyName, oldValue, newValue);
222 * This convenience method fires a PropertyChangeEvent given
223 * the propertyName and the old and new values.
225 * @param propertyName The property that changed.
226 * @param oldValue The old value of the property.
227 * @param newValue The new value of the property.
229 private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
231 changeSupport.firePropertyChange(propertyName, oldValue, newValue);
235 * addPropertyChangeListener
237 * @param listener the listener to add
239 public void addPropertyChangeListener(PropertyChangeListener listener)
241 changeSupport.addPropertyChangeListener(listener);
245 * removePropertyChangeListener
247 * @param listener the listener to remove
249 public void removePropertyChangeListener(PropertyChangeListener listener)
251 changeSupport.removePropertyChangeListener(listener);
255 * Returns all registered listeners.
257 * @return array of listeners.
259 * @since 1.4
261 public PropertyChangeListener[] getPropertyChangeListeners()
263 return changeSupport.getPropertyChangeListeners();