Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/menu/IDEAction.java


1   package javax.ide.menu;
2   
3   import java.beans.PropertyChangeListener;
4   
5   import java.util.List;
6   
7   import javax.ide.Identifiable;
8   import javax.ide.extension.ExtensionRegistry;
9   import javax.ide.menu.spi.MenuHook;
10  import javax.ide.util.IconDescription;
11  import javax.ide.view.DefaultViewable;
12  import javax.ide.view.Viewable;
13  
14  import javax.swing.event.SwingPropertyChangeSupport;
15  
16  /**
17   * <code>IDEAction</code> encapsulates the meta-data describing an
18   * executable action.
19   */
20  public class IDEAction extends DefaultViewable 
21    implements Identifiable, Viewable
22  {
23    /**
24     * Identifies the bound property 'mnemonic'.
25     */
26    public static final String PROP_MNEMONIC = "mnemonic";
27  
28    /**
29     * Identifies the bound property 'checked'.
30     */
31    public static final String PROP_CHECKED = "checked";
32  
33    /**
34     * Identifies the bound property 'enabled'.
35     */
36    public static final String PROP_ENABLED = "enabled";
37  
38    private String _id;
39    private boolean _isToggle;
40    private boolean _checked;
41    private boolean _enabled = true;
42    private String _label;
43    private int _mnemonic;
44    private String _toolTip;
45    private IconDescription _icon;
46    private SwingPropertyChangeSupport _propertyChangeSupport;
47    
48    //---------------------------------------------------------------------------
49    // Public methods.
50    //---------------------------------------------------------------------------
51    /**
52     * Find out whether the state of this <code>IDEAction</code> is checked
53     * or unchecked.
54     *
55     * @return The state of the <code>IDEAction</code>. 
56     */
57    public boolean isChecked()
58    {
59      return _checked;
60    }
61  
62    /**
63     * Set the state of the <code>IDEAction</code>.  
64     * Bound property.
65     *
66     * @param checked The state of the <code>IDEAction</code>.
67     */
68    public void setChecked( boolean checked )
69    {
70      final Boolean oldVal = Boolean.valueOf( _checked );
71      _checked = checked;
72      firePropertyChange( PROP_CHECKED, oldVal, Boolean.valueOf( _checked ) );
73    }
74  
75    /**
76     * @return <code>true</code> if the <code>IDEAction</code> is enabled.
77     * <code>false</code> otherwise.
78     */
79    public boolean isEnabled()
80    {
81      return _enabled;
82    }
83  
84    /**
85     * Set the enabled state of the <code>IDEAction</code>.
86     * Bound property.
87     *
88     * @param enabled The state of the <code>IDEAction</code>.
89     */
90    public void setEnabled( boolean enabled )
91    {
92      final Boolean oldVal = Boolean.valueOf( _enabled );
93      _enabled = enabled;
94      firePropertyChange( PROP_ENABLED, oldVal, Boolean.valueOf( _enabled ) );
95    }
96  
97    /**
98     * Get whether this action is a toggle action.
99     * 
100    * @return <tt>true</tt> if this action is a toggle.
101    */
102   public boolean isToggleItem()
103   {
104     return _isToggle;
105   }
106 
107   /*-
108    * IDEAction interface method.
109    */
110   public String getLabel()
111   {
112     return _label;
113   }
114   
115   /**
116    * Set the action label.
117    */
118   public void setLabel( String label )
119   {
120     final String oldVal = _label;
121     _label = label;
122     firePropertyChange( PROP_LABEL, oldVal, _label );
123   }
124 
125   /*-
126    * IDEAction interface method.
127    */
128   public int getMnemonic()
129   {
130     return _mnemonic;
131   }
132   
133   /**
134    * Set the action label mnemonic character.
135    *
136    * @param mnemonic The character to be used as mnemonic.
137    */
138   public void setMnemonic( int mnemonic )
139   {
140     final Integer oldVal = new Integer( _mnemonic );
141     _mnemonic = mnemonic;  
142     firePropertyChange( PROP_MNEMONIC, oldVal, new Integer( _mnemonic ) );
143   }
144 
145   /*-
146    * IDEAction interface method.
147    */
148   public String getToolTip()
149   {
150     return _toolTip;
151   }
152 
153   /**
154    * Set the action tooltip.
155    */
156   public void setToolTip( String toolTip )
157   {
158     final String oldVal = _toolTip;
159     _toolTip = toolTip;
160     firePropertyChange( PROP_MNEMONIC, oldVal, _toolTip );
161   }
162 
163   /*-
164    * IDEAction interface method.
165    */
166   public IconDescription getIcon()
167   {
168     return _icon;
169   }
170 
171   /**
172    * Set the action icon path.
173    */
174   public void setIcon( IconDescription icon )
175   {
176     final IconDescription oldVal = _icon;
177     _icon = icon;
178     firePropertyChange( PROP_ICON_PATH, oldVal, _icon );
179   }
180 
181   /**
182    * Get the controllers for this action.
183    * 
184    * @return a list of controllers for this action.
185    */
186   public List /*<Controller>*/ getControllers()
187   {
188     MenuHook menuHook = (MenuHook)
189       ExtensionRegistry.getExtensionRegistry().getHook( MenuHook.ELEMENT );
190     return menuHook.getModel().getControllers( getID() );
191   }
192 
193   /*-
194    * IDEAction interface method.
195    */
196   public void addPropertyChangeListener( PropertyChangeListener listener )
197   {
198     if ( _propertyChangeSupport == null )
199     {
200       _propertyChangeSupport = new SwingPropertyChangeSupport( this );
201     }
202     _propertyChangeSupport.addPropertyChangeListener( listener );
203   }
204 
205   /*-
206    * IDEAction interface method.
207    */
208   public void removePropertyChangeListener( PropertyChangeListener listener )
209   {
210     if ( _propertyChangeSupport != null )
211     {
212       _propertyChangeSupport.removePropertyChangeListener( listener );
213     }
214   }
215 
216   //--------------------------------------------------------------------------
217   // Object overrides.
218   //--------------------------------------------------------------------------
219   public String toString()
220   {
221     return getID().toString();
222   }
223   
224   public int hashCode() 
225   {
226     return toString().hashCode();
227   }
228 
229   //---------------------------------------------------------------------------
230   // Methods used by IDE providers to set action property values as defined 
231   // in the extension deployment descriptor.
232   //---------------------------------------------------------------------------
233 
234   //--------------------------------------------------------------------------
235   // Protected methods...
236   //--------------------------------------------------------------------------
237   /**
238    * Constructor. The <code>id</code> must be a unique string 
239    * identifier. This ID can be used to find the action using the
240    * {@link javax.ide.menu.ActionRegistry}. 
241    *
242    * @param id A unique string identifying the command. The <code>id</code>
243    * of an action has an undefined type, an the id name set to the string 
244    * identifying the action.
245    */
246   public IDEAction( String id  )
247   {
248     _id = id;
249   }
250   
251   public String getID()
252   {
253     return _id;
254   }
255   
256   public void setToggleItem( boolean isToggleItem )
257   {
258     _isToggle = isToggleItem;
259   }
260 
261 }