diff options
Diffstat (limited to 'libjava/javax/swing/DefaultButtonModel.java')
-rw-r--r-- | libjava/javax/swing/DefaultButtonModel.java | 110 |
1 files changed, 80 insertions, 30 deletions
diff --git a/libjava/javax/swing/DefaultButtonModel.java b/libjava/javax/swing/DefaultButtonModel.java index a608de4..e9a1356 100644 --- a/libjava/javax/swing/DefaultButtonModel.java +++ b/libjava/javax/swing/DefaultButtonModel.java @@ -41,6 +41,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; import java.io.Serializable; import java.util.EventListener; @@ -80,56 +81,52 @@ public class DefaultButtonModel implements ButtonModel, Serializable /** Indicates that the button is <em>partially</em> committed to being pressed, but not entirely. This usually happens when a user has pressed but not yet released the mouse button. */ - static int ARMED = 1; + public static final int ARMED = 1; /** State constant indicating that the button is enabled. Buttons cannot be pressed or selected unless they are enabled. */ - static int ENABLED = 2; + public static final int ENABLED = 8; /** State constant indicating that the user is holding down the button. When this transitions from true to false, an ActionEvent may be fired, depending on the value of the "armed" property.*/ - static int PRESSED = 4; + public static final int PRESSED = 4; /** State constant indicating that the mouse is currently positioned over the button. */ - static int ROLLOVER = 8; + public static final int ROLLOVER = 16; /** State constant indicating that the button is selected. This constant is only meaningful for toggle-type buttons (radio buttons, checkboxes). */ - static int SELECTED = 16; + public static final int SELECTED = 2; /** Represents the "state properties" (armed, enabled, pressed, rollover and selected) by a bitwise combination of integer constants. */ - int stateMask; + protected int stateMask = ENABLED; /** List of ItemListeners, ChangeListeners, and ActionListeners registered on this model. */ - EventListenerList listenerList; + protected EventListenerList listenerList = new EventListenerList();; /** The single ChangeEvent this model (re)uses to call its ChangeListeners. */ - ChangeEvent changeEvent; + protected ChangeEvent changeEvent = new ChangeEvent(this); /** The group this model belongs to. Only one button in a group may be selected at any given time. */ - ButtonGroup group; + protected ButtonGroup group; /** The key code (one of {@link java.awt.event.KeyEvent} VK_*) used to press this button via a keyboard interface. */ - int mnemonic; + protected int mnemonic = KeyEvent.VK_UNDEFINED; /** The string used as the "command" property of any ActionEvent this model sends. */ - String actionCommand; + protected String actionCommand; public DefaultButtonModel() { - stateMask = ENABLED; - mnemonic = java.awt.event.KeyEvent.VK_UNDEFINED; - listenerList = new EventListenerList(); - changeEvent = new ChangeEvent(this); } /** @@ -144,6 +141,18 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns a specified class of listeners. + * + * @param listenerType the type of listener to return + * + * @return array of listeners + */ + public EventListener[] getListeners(Class listenerType) + { + return listenerList.getListeners(listenerType); + } + + /** * Add an ActionListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -166,6 +175,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ActionListener</code> objects. + * + * @return array of <code>ActionListener</code> objects + */ + public ActionListener[] getActionListeners() + { + return (ActionListener[]) listenerList.getListeners(ActionListener.class); + } + + /** * Add an ItemListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -188,6 +207,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ItemListener</code> objects. + * + * @return array of <code>ItemListener</code> objects + */ + public ItemListener[] getItemListeners() + { + return (ItemListener[]) listenerList.getListeners(ItemListener.class); + } + + /** * Add a ChangeListener to the model. Usually only called to subscribe * an AbstractButton's listener to the model. * @@ -210,6 +239,16 @@ public class DefaultButtonModel implements ButtonModel, Serializable } /** + * Returns all registered <code>ChangeListener</code> objects. + * + * @return array of <code>ChangeListener</code> objects + */ + public ChangeListener[] getChangeListeners() + { + return (ChangeListener[]) listenerList.getListeners(ChangeListener.class); + } + + /** * Inform each ItemListener in the {@link listenerList} that an ItemEvent * has occurred. This happens in response to any change to the {@link * stateMask} field. @@ -218,9 +257,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable */ public void fireItemStateChanged(ItemEvent e) { - EventListener[] ll = listenerList.getListeners(ItemListener.class); + ItemListener[] ll = getItemListeners(); + for (int i = 0; i < ll.length; i++) - ((ItemListener)ll[i]).itemStateChanged(e); + ll[i].itemStateChanged(e); } /** @@ -233,9 +273,10 @@ public class DefaultButtonModel implements ButtonModel, Serializable */ public void fireActionPerformed(ActionEvent e) { - EventListener[] ll = listenerList.getListeners(ActionListener.class); + ActionListener[] ll = getActionListeners(); + for (int i = 0; i < ll.length; i++) - ((ActionListener)ll[i]).actionPerformed(e); + ll[i].actionPerformed(e); } /** @@ -245,11 +286,12 @@ public class DefaultButtonModel implements ButtonModel, Serializable * * @param event The ChangeEvent to fire */ - public void fireStateChanged(ChangeEvent e) + public void fireStateChanged() { - EventListener[] ll = listenerList.getListeners(ChangeListener.class); + ChangeListener[] ll = getChangeListeners(); + for (int i = 0; i < ll.length; i++) - ((ChangeListener)ll[i]).stateChanged(e); + ll[i].stateChanged(changeEvent); } /** @@ -276,7 +318,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable stateMask = newstate; - fireStateChanged(changeEvent); + fireStateChanged(); if ((oldstate & SELECTED) == 0 && (newstate & SELECTED) == SELECTED) @@ -418,7 +460,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (mnemonic != key) { mnemonic = key; - fireStateChanged(changeEvent); + fireStateChanged(); } } @@ -434,14 +476,12 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (actionCommand != s) { actionCommand = s; - fireStateChanged(changeEvent); + fireStateChanged(); } } /** - * Set the value of the model's "actionCommand" property. This property - * is used as the "command" property of the {@link ActionEvent} fired - * from the model. + * Returns the current value of the model's "actionCommand" property. * * @return The current "actionCommand" property */ @@ -453,7 +493,7 @@ public class DefaultButtonModel implements ButtonModel, Serializable /** * Set the value of the model's "group" property. The model is said to be * a member of the {@link ButtonGroup} held in its "group" property, and - * only one models in a given group can have their "selected" property be + * only one model in a given group can have their "selected" property be * <code>true</code> at a time. * * @param g The new "group" property @@ -463,7 +503,17 @@ public class DefaultButtonModel implements ButtonModel, Serializable if (group != g) { group = g; - fireStateChanged(changeEvent); + fireStateChanged(); } } + + /** + * Returns the current value of the model's "group" property. + * + * @return The value of the "group" property + */ + public ButtonGroup getGroup() + { + return group; + } } |