vmm.actions
Class ActionRadioGroup

java.lang.Object
  extended by vmm.actions.ActionRadioGroup
All Implemented Interfaces:
ActionItem

public class ActionRadioGroup
extends java.lang.Object
implements ActionItem

An ActionRadioGroup represents a group of mutually exclusive options. Only one of the options can be selected at a given time; this rule is enforced by the group. Methods are provided for getting sets of JRadioButtons or JRadioButtonMenuItems to represent the group of options; the user can manipulate one of the buttons or menu items to change the currently selected option. When the selected option changes because of a user action, the optionSelected(int) method is called; override this method in a subclass to perform some action when the user changes the selection.


Constructor Summary
ActionRadioGroup()
          Create an initially empty option group.
ActionRadioGroup(java.lang.String[] actionNames)
          Create a group of options in which initially no option is selected.
ActionRadioGroup(java.lang.String[] actionNames, int selectedIndex)
          Create a group of options in which a specifed option is initially selected.
 
Method Summary
 int addItem(java.lang.String itemName)
          Adds an option to the group.
 javax.swing.JRadioButtonMenuItem[] createRadioButtonMenuItems()
          Return a list of radio button menu items that are synchronized with the selection state of the options in this group.
 javax.swing.JRadioButton[] createRadioButtons()
          Return a list of radio buttons that are synchronized with the selection state of the options in this group.
 int getItemCount()
          Returns the number of items in the group.
 javax.swing.JMenuItem[] getMenuItems()
          Returns the same array that would be returned by createRadioButtonMenuItems().
 int getSelectedIndex()
          Return the index of the currently selected option, or -1 if no option is currently selected.
 boolean isEnabled()
          Get the current enabled status of the this action group.
 void optionSelected(int selectedIndex)
          This method is called when one of the options is selected because of a user action on one of the radio buttons or menu items returned by createRadioButtonMenuItems() or createRadioButtons().
 void setEnabled(boolean enabled)
          Set the enabled status of the Actions (and hence the buttons and menu items) associated with this group.
 void setSelectedIndex(int index)
          Set the currently selected option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionRadioGroup

public ActionRadioGroup()
Create an initially empty option group.


ActionRadioGroup

public ActionRadioGroup(java.lang.String[] actionNames)
Create a group of options in which initially no option is selected.

Parameters:
actionNames - Names for the options, which become names of menu items or names or radio buttons. Null values are OK and are meant to represent separators in a menu. If actionNames is null, the list of actions is initially empty.

ActionRadioGroup

public ActionRadioGroup(java.lang.String[] actionNames,
                        int selectedIndex)
Create a group of options in which a specifed option is initially selected.

Parameters:
actionNames - Names for the options, which become names of menu items or names or radio buttons. Null values are OK and are meant to represent separators in a menu. If actionNames is null, the list of actions is initially empty.
selectedIndex - The index in actionNames of the initially selected index, or -1 to indicate that no item is initially selected. If this value is outside the range of indicies for actionNames, or if actionNames[selectedIndex] is null, then the value is silently changed to -1.
Method Detail

optionSelected

public void optionSelected(int selectedIndex)
This method is called when one of the options is selected because of a user action on one of the radio buttons or menu items returned by createRadioButtonMenuItems() or createRadioButtons(). It is not called when the selected index is changed programmatically by setSelectedIndex(int). In this class, this method does nothing. Subclasses can override this method to perform some action when the user changes the selection. Note that this method will be called even when the user selects the option that is already selected.

Parameters:
selectedIndex - The index of the item that was selected, or -1 to indicate that no option is selected.

createRadioButtonMenuItems

public javax.swing.JRadioButtonMenuItem[] createRadioButtonMenuItems()
Return a list of radio button menu items that are synchronized with the selection state of the options in this group. The user can select a new option by selecting the corresponding menu item. The list can contain null items, which are meant to represent separators in the menu.


createRadioButtons

public javax.swing.JRadioButton[] createRadioButtons()
Return a list of radio buttons that are synchronized with the selection state of the options in this group. The user can select a new option by selecting the corresponding button. The list can contain null items, which are meant to represent separators.


addItem

public int addItem(java.lang.String itemName)
Adds an option to the group. Note that using this method after menu items or radio buttons have been created for the group would be a little strange, since they would not be added to the exiting menu item and button groups. There is no way to remove options once they have been added.

Parameters:
itemName - The name of the option, or null if this item is meant to represent a separator in a menu.
Returns:
the index (option number) of the newly added option. This will probably be ignored in most cases.

getSelectedIndex

public int getSelectedIndex()
Return the index of the currently selected option, or -1 if no option is currently selected.


setSelectedIndex

public void setSelectedIndex(int index)
Set the currently selected option.

Parameters:
index - the option to be selected, or -1 to indicate that no option is selected. Any value outside the range of legal option numbers is treated as -1. Also, an index for which the option is a null value is treated as -1.

setEnabled

public void setEnabled(boolean enabled)
Set the enabled status of the Actions (and hence the buttons and menu items) associated with this group.


isEnabled

public boolean isEnabled()
Get the current enabled status of the this action group.

See Also:
setEnabled(boolean)

getMenuItems

public javax.swing.JMenuItem[] getMenuItems()
Returns the same array that would be returned by createRadioButtonMenuItems().

Specified by:
getMenuItems in interface ActionItem

getItemCount

public int getItemCount()
Returns the number of items in the group.