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

Quick Search    Search Deep

Source code: com/trapezium/chisel/AbstractAction.java


1   
2   package com.trapezium.chisel;
3   
4   import java.awt.*;
5   import java.awt.event.*;
6   import java.beans.*;
7   import java.util.ResourceBundle;
8   import java.util.Locale;
9   import java.util.MissingResourceException;
10  
11  
12  public abstract class AbstractAction implements ActionListener
13  {
14    /**
15     * Text to be displayed on text button or in menu
16     */
17    public static final String NAME = "Name";
18  
19    /**
20     * Verbose description for help, or advanced info
21     */
22    public static final String LONG_DESCRIPTION = "LongDescription";
23  
24    /**
25     * Short description to be displayed in tooltips etc
26     */
27    public static final String SHORT_DESCRIPTION = "ShortDescription";
28  
29    /**
30     * Key string for returning small (16x16) icon to be displayd on button
31     */
32    public static final String SMALL_ICON = "SmallIcon";
33  
34    /**
35     * mpEDIT additon: Small Icon in disabled state
36     */
37  
38    public static final String SMALL_ICON_DISABLED = "SmallIconDisabled";
39  
40    /**
41     * mpEDIT addition: provide emacs-like action identifier
42     */
43    public static final String ID_STRING = "IdString";
44  
45    /**
46     * Identifier passed to PropertyChangeListeners when enabled flag has changed
47     */
48    public static final String ENABLED = "enabled";
49  
50    static private ResourceBundle strings = ChiselResources.getDefaultResourceBundle();
51  
52    private boolean enabled = true;
53    private PropertyChangeSupport propertyChangeSupport;
54  
55    protected String idString;
56    protected String name;
57    protected String shortDescription;
58  
59    public AbstractAction(String aIdString)
60    {
61      idString = aIdString;
62      propertyChangeSupport = new PropertyChangeSupport(this);
63      try
64      {
65        name = strings.getString("action." + idString + ".name");
66        shortDescription = strings.getString("action." + idString + ".short");
67      } catch ( MissingResourceException e )
68        {
69          System.out.println("No description for action " + idString);
70        }
71    }
72    
73    public abstract void actionPerformed( ActionEvent e );
74  
75    public String getText( String key )
76    {
77      if ( key.equals(NAME) )
78        return name;
79      else if ( key.equals(ID_STRING) )
80        return idString;
81      else if ( key.equals(SHORT_DESCRIPTION) )
82        return shortDescription;
83      return idString;
84    }
85  
86    public void setText( String key, String text )
87    {
88      if ( key.equals(NAME) )
89        setName(text);
90      else if ( key.equals(SHORT_DESCRIPTION) )
91        setShortDescription(text);
92      else
93        throw new RuntimeException("Value " + key + " cannot be set");
94    }
95  
96    public String getIdString()
97    {
98      return idString;
99    }
100 
101   public String getShortDescription()
102   {
103     return shortDescription;
104   }
105 
106   public void setShortDescription( String text )
107   {
108     propertyChangeSupport.firePropertyChange( SHORT_DESCRIPTION,
109       shortDescription, text );
110     shortDescription = text;
111   }
112 
113   public String getName()
114   {
115     return name;
116   }
117 
118   public void setName(String text)
119   {
120     propertyChangeSupport.firePropertyChange( NAME,
121       name, text );
122     name = text;
123   }
124 
125   public boolean isEnabled()
126   {
127     return enabled;
128   }
129 
130   public void setEnabled( boolean b )
131   {
132     propertyChangeSupport.firePropertyChange( ENABLED, 
133       new Boolean(enabled), new Boolean(b) );
134     enabled = b;
135   }
136 
137   public void addPropertyChangeListener(PropertyChangeListener listener)
138   {
139     propertyChangeSupport.addPropertyChangeListener(listener);
140   }
141 
142   public void removePropertyChangeListener(PropertyChangeListener listener)
143   {
144     propertyChangeSupport.removePropertyChangeListener(listener);
145   }
146 }