OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libjava / javax / swing / AbstractAction.java
1 /* AbstractAction.java --
2    Copyright (C) 2002, 2004 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
39 package javax.swing;
40
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;
48
49 /**
50  * AbstractAction
51  * @author      Andrew Selkirk
52  * @version     1.0
53  */
54 public abstract class AbstractAction
55   implements Action, Cloneable, Serializable
56 {
57   static final long serialVersionUID = -6803159439231523484L;
58
59   /**
60    * enabled
61    */
62   protected boolean enabled = true;
63
64   /**
65    * changeSupport
66    */
67   protected SwingPropertyChangeSupport changeSupport =
68     new SwingPropertyChangeSupport(this);
69
70   /**
71    * store
72    */
73   private transient HashMap store = new HashMap();
74
75   /**
76    * Constructor AbstractAction
77    */
78   public AbstractAction()
79   {
80     this(""); // TODO: default name
81   }
82
83   /**
84    * Constructor AbstractAction
85    *
86    * @param name TODO
87    */
88   public AbstractAction(String name)
89   {
90     this(name, null); // TODO: default icon??
91   }
92
93   /**
94    * Constructor AbstractAction
95    *
96    * @param name TODO
97    * @param icon TODO
98    */
99   public AbstractAction(String name, Icon icon)
100   {
101     putValue(NAME, name);
102     putValue(SMALL_ICON, icon);
103   }
104
105   /**
106    * readObject
107    *
108    * @param stream the stream to read from
109    *
110    * @exception ClassNotFoundException TODO
111    * @exception IOException if an error occurs
112    */
113   private void readObject(ObjectInputStream stream)
114     throws ClassNotFoundException, IOException
115   {
116     // TODO
117   }
118
119   /**
120    * writeObject
121    *
122    * @param stream the stream to write to
123    *
124    * @exception IOException if an error occurs
125    */
126   private void writeObject(ObjectOutputStream stream) throws IOException
127   {
128     // TODO
129   }
130
131   /**
132    * clone
133    *
134    * @return Object
135    *
136    * @exception CloneNotSupportedException TODO
137    */
138   protected Object clone() throws CloneNotSupportedException
139   {
140     AbstractAction copy = (AbstractAction) super.clone();
141     copy.store = (HashMap) store.clone();
142     return copy;
143   }
144
145   /**
146    * Returns a value for a given key from the built-in store.
147    *
148    * @param key the key to get the value for
149    *
150    * @return Object
151    */
152   public Object getValue(String key)
153   {
154     return store.get(key);
155   }
156
157   /**
158    * Puts a key/value pair into the built-in store.
159    *
160    * @param key the key
161    * @param value the value
162    */
163   public void putValue(String key, Object value)
164   {
165     store.put(key, value);
166   }
167
168   /**
169    * isEnabled
170    *
171    * @return boolean
172    */
173   public boolean isEnabled()
174   {
175     return enabled;
176   }
177
178   /**
179    * setEnabled
180    *
181    * @param enabled TODO
182    */
183   public void setEnabled(boolean enabled)
184   {
185     this.enabled = enabled;
186   }
187
188   /**
189    * getKeys
190    * @returns Object[]
191    */
192   public Object[] getKeys()
193   {
194     return store.keySet().toArray();
195   }
196
197   /**
198    * firePropertyChange
199    *
200    * @param propertyName TODO
201    * @param oldValue TODO
202    * @param newValue TODO
203    */
204   protected void firePropertyChange(String propertyName, Object oldValue,
205                                     Object newValue)
206   {
207     changeSupport.firePropertyChange(propertyName, oldValue, newValue);
208   }
209
210   /**
211    * addPropertyChangeListener
212    *
213    * @param listener the listener to add
214    */
215   public void addPropertyChangeListener(PropertyChangeListener listener)
216   {
217     changeSupport.addPropertyChangeListener(listener);
218   }
219
220   /**
221    * removePropertyChangeListener
222    *
223    * @param listener the listener to remove
224    */
225   public void removePropertyChangeListener(PropertyChangeListener listener)
226   {
227     changeSupport.removePropertyChangeListener(listener);
228   }
229
230   /**
231    * Returns all registered listeners.
232    *
233    * @return array of listeners.
234    * 
235    * @since 1.4
236    */
237   public PropertyChangeListener[] getPropertyChangeListeners()
238   {
239     return changeSupport.getPropertyChangeListeners();
240   }
241 }