001    /* Action.java --
002       Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    package javax.swing;
039    
040    import java.awt.event.ActionListener;
041    import java.beans.PropertyChangeListener;
042    
043    /**
044     * Provides a convenient central point of control for some task
045     * that can be triggered by more than one control in a Swing user interface
046     * (for example, a menu item and a toolbar button).
047     * 
048     * @see AbstractButton#setAction(Action)
049     * 
050     * @author Ronald Veldema (rveldema@cs.vu.nl)
051     * @author Andrew Selkirk
052     */
053    public interface Action extends ActionListener {
054    
055      /**
056       * A key to access the default property for the action (this is not used).
057       */
058      String DEFAULT = "Default";
059    
060      /**
061       * A key to access the long description for the action.
062       */
063      String LONG_DESCRIPTION = "LongDescription";
064    
065      /**
066       * A key to access the name for the action.
067       */
068      String NAME = "Name";
069    
070      /**
071       * A key to access the short description for the action (the short
072       * description is typically used as the tool tip text).
073       */
074      String SHORT_DESCRIPTION = "ShortDescription";
075    
076      /**
077       * A key to access the icon for the action.
078       */
079      String SMALL_ICON = "SmallIcon";
080    
081      /**
082       * A key to access the {@link KeyStroke} used as the accelerator for the
083       * action.
084       */
085      String ACCELERATOR_KEY = "AcceleratorKey";
086    
087      /**
088       * A key to access the action command string for the action.
089       */
090      String ACTION_COMMAND_KEY = "ActionCommandKey";
091    
092      /**
093       * A key to access the mnemonic for the action.
094       */
095      String MNEMONIC_KEY = "MnemonicKey";
096    
097      /**
098       * Returns the value associated with the specified key.
099       * 
100       * @param key  the key (not <code>null</code>).
101       * 
102       * @return The value associated with the specified key, or 
103       *         <code>null</code> if the key is not found.
104       */
105      Object getValue(String key);
106    
107      /**
108       * Sets the value associated with the specified key and sends a 
109       * {@link java.beans.PropertyChangeEvent} to all registered listeners.  
110       * The standard keys are defined in this interface: {@link #NAME}, 
111       * {@link #SHORT_DESCRIPTION}, {@link #LONG_DESCRIPTION}, 
112       * {@link #SMALL_ICON}, {@link #ACTION_COMMAND_KEY}, 
113       * {@link #ACCELERATOR_KEY} and {@link #MNEMONIC_KEY}. Any existing value 
114       * associated with the key will be overwritten.  
115       * 
116       * @param key  the key (not <code>null</code>).
117       * @param value  the value (<code>null</code> permitted).
118       */
119      void putValue(String key, Object value);
120    
121      /**
122       * Returns the flag that indicates whether or not this action is enabled.
123       * 
124       * @return The flag.
125       */
126      boolean isEnabled();
127    
128      /**
129       * Sets the flag that indicates whether or not this action is enabled.  If
130       * the value changes, a {@link java.beans.PropertyChangeEvent} is sent to 
131       * all registered listeners.
132       * 
133       * @param b  the new value of the flag.
134       */
135      void setEnabled(boolean b);
136    
137      /**
138       * Registers a listener to receive notification whenever one of the
139       * action's properties is modified.
140       * 
141       * @param listener  the listener.
142       */
143      void addPropertyChangeListener(PropertyChangeListener listener);
144    
145      /**
146       * Deregisters a listener so that it no longer receives notification of
147       * changes to the action's properties. 
148       * 
149       * @param listener  the listener.
150       */
151      void removePropertyChangeListener(PropertyChangeListener listener);
152    
153    } // Action