1 7 package javax.swing; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.beans.*; 12 import java.util.Hashtable ; 13 import java.util.Enumeration ; 14 import java.io.Serializable ; 15 import java.io.IOException ; 16 import java.io.ObjectInputStream ; 17 import java.io.ObjectOutputStream ; 18 import javax.swing.event.SwingPropertyChangeSupport ; 19 20 40 public abstract class AbstractAction implements Action , Cloneable , Serializable 41 { 42 45 protected boolean enabled = true; 46 47 48 51 private transient ArrayTable arrayTable; 52 53 57 public AbstractAction() { 58 } 59 60 64 public AbstractAction(String name) { 65 putValue(Action.NAME, name); 66 } 67 68 72 public AbstractAction(String name, Icon icon) { 73 this(name); 74 putValue(Action.SMALL_ICON, icon); 75 } 76 77 85 public Object getValue(String key) { 86 if (arrayTable == null) { 87 return null; 88 } 89 return arrayTable.get(key); 90 } 91 92 99 public void putValue(String key, Object newValue) { 100 Object oldValue = null; 101 if (arrayTable == null) { 102 arrayTable = new ArrayTable (); 103 } 104 if (arrayTable.containsKey(key)) 105 oldValue = arrayTable.get(key); 106 if (newValue == null) { 109 arrayTable.remove(key); 110 } else { 111 arrayTable.put(key,newValue); 112 } 113 firePropertyChange(key, oldValue, newValue); 114 } 115 116 122 public boolean isEnabled() { 123 return enabled; 124 } 125 126 133 public void setEnabled(boolean newValue) { 134 boolean oldValue = this.enabled; 135 136 if (oldValue != newValue) { 137 this.enabled = newValue; 138 firePropertyChange("enabled", 139 Boolean.valueOf(oldValue), Boolean.valueOf(newValue)); 140 } 141 } 142 143 144 152 public Object [] getKeys() { 153 if (arrayTable == null) { 154 return null; 155 } 156 Object [] keys = new Object [arrayTable.size()]; 157 arrayTable.getKeys(keys); 158 return keys; 159 } 160 161 165 protected SwingPropertyChangeSupport changeSupport; 166 167 173 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { 174 if (changeSupport == null || 175 (oldValue != null && newValue != null && oldValue.equals(newValue))) { 176 return; 177 } 178 changeSupport.firePropertyChange(propertyName, oldValue, newValue); 179 } 180 181 182 197 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { 198 if (changeSupport == null) { 199 changeSupport = new SwingPropertyChangeSupport (this); 200 } 201 changeSupport.addPropertyChangeListener(listener); 202 } 203 204 205 214 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { 215 if (changeSupport == null) { 216 return; 217 } 218 changeSupport.removePropertyChangeListener(listener); 219 } 220 221 222 230 public synchronized PropertyChangeListener[] getPropertyChangeListeners() { 231 if (changeSupport == null) { 232 return new PropertyChangeListener[0]; 233 } 234 return changeSupport.getPropertyChangeListeners(); 235 } 236 237 238 243 244 protected Object clone() throws CloneNotSupportedException { 245 AbstractAction newAction = (AbstractAction )super.clone(); 246 synchronized(this) { 247 if (arrayTable != null) { 248 newAction.arrayTable = (ArrayTable )arrayTable.clone(); 249 } 250 } 251 return newAction; 252 } 253 254 private void writeObject(ObjectOutputStream s) throws IOException { 255 s.defaultWriteObject(); 257 258 ArrayTable.writeArrayTable(s, arrayTable); 260 } 261 262 private void readObject(ObjectInputStream s) throws ClassNotFoundException , 263 IOException { 264 s.defaultReadObject(); 265 for (int counter = s.readInt() - 1; counter >= 0; counter--) { 266 putValue((String )s.readObject(), s.readObject()); 267 } 268 } 269 } 270
| Popular Tags
|