edu.neu.ccs.gui
Class RadioPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.RadioPanel
All Implemented Interfaces:
Accessible, Displayable, ImageObserver, JPTConstants, MenuContainer, Serializable, SwingConstants
Direct Known Subclasses:
OptionsView, StringObjectRadioPanel

public class RadioPanel
extends JPanel
implements Displayable, JPTConstants

RadioPanel implements the base panel for matching strings and radio buttons and maintaining the mutual exclusiveness of button selection.

Since:
2.3
Version:
2.3.3
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String BACKGROUND
          Bound property name for the set background property.
protected  ButtonGroup buttonGroup
          Button buttonGroup to enforce mutual exclusion for selections.
protected  ActionSequence commonactions
          The common actions for all buttons.
protected static int DEFAULT_SELECTION
          Default initial selection for an options view.
protected  TableLayout defaultLayout
          The default layout.
protected  String defaultViewState
          The default view state.
protected  StringObjectMap labelButtonMap
          The string-object map that contains pairs with a label and its associated radio button.
protected  QuickHashMap labelIndexMap
          The hash map that contains pairs with a label and an index installed as Integer with the position of the label in the view.
protected  QuickHashMap modelButtonMap
          The hash map that contains pairs with a model and its button.
static String OPTION_COUNT
          Bound property name for the option count property.
static String SELECTED_BUTTON
          Bound property name for the selected index property.
static String SELECTED_INDEX
          Bound property name for the selected index property.
static String SELECTED_LABEL
          Bound property name for the selected index property.
static String SET_LABEL_TEXT
          Bound property name for the set label text property.
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RadioPanel()
          The default constructor.
RadioPanel(LayoutManager layout)
          Constructs a panel with the given layout manager.
RadioPanel(String[] strings)
          Constructs a panel containing radio buttons labeled with the given array of strings.
RadioPanel(String[] strings, ActionListener action)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons.
RadioPanel(String[] strings, ActionListener[] actions)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.
RadioPanel(String[] strings, ActionListener[] actions, int selection)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.
RadioPanel(String[] strings, ActionListener[] actions, int selection, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.
RadioPanel(String[] strings, ActionListener[] actions, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.
RadioPanel(String[] strings, ActionListener action, int selection)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given selection is the index of the button that is initially selected.
RadioPanel(String[] strings, ActionListener action, int selection, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given selection is the index of the button that is initially selected; the given layout manager is used to layout the buttons.
RadioPanel(String[] strings, ActionListener action, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given layout manager is used to layout the buttons.
RadioPanel(String[] strings, int selection)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given selection is the index of the button that is initially selected.
RadioPanel(String[] strings, int selection, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given selection is the index of the button that is initially selected; the given layout manager is used to layout the buttons.
RadioPanel(String[] strings, LayoutManager layout)
          Constructs a panel containing radio buttons labeled with the given array of strings; the given layout manager is used to layout the buttons.
 
Method Summary
 void addActionListener(ActionListener listener)
          Adds the given action listener to all buttons.
 void addActionListener(int index, ActionListener listener)
          Adds the given action listener to the button at the given index.
 void addActionListeners(ActionListener[] listeners)
          Adds the given action listeners to the corresponding buttons.
 void addOption(String label)
          Adds a button to the end of the view with the given label.
 void addOption(String label, Action action)
          Adds a button to the end of the view with the given label and the given action.
 void addOption(String label, Action action, boolean selected)
          Adds a button to the end of the view with the given label, the given action, and the given selection state.
 void addOption(String label, boolean selected)
          Adds a button to the end of the view with the given label and the given selection state.
 void addOptions(String[] labels)
          Add the options in succession to the end of the view.
 void addOptions(String[] labels, Action action)
          Add the options in succession to the end of the view with the same action for each option.
 void addOptions(String[] labels, Action[] actions)
          Add the options in succession to the end of the view with the each option paired with a corresponding action.
protected  ButtonModel getButtonModel(JRadioButton button)
          Returns the ButtonModel of the radio button or returns null if the button is null or is not in the view.
static Color getDefaultBackground()
          Returns the default background for a JRadioButton.
static Font getDefaultFont()
          Returns the default font for a JRadioButton.
 String getDefaultViewState()
          Returns the current default view state string.
 int getIndex(JRadioButton button)
          Returns the index of the option with the given button or -1 if the button is not in the view.
 int getIndex(String label)
          Returns the index of the option with the given label or -1 if the label is not in the view.
 String getLabel(int index)
          Returns the label of the option at the given index or null if the index is out of bounds.
 String getLabel(JRadioButton button)
          Returns the label of the given button or null if the button is null or is not in the view.
 String getLabelText(int index)
          Returns the label text for the button at the given index, or null if the given index is invalid.
protected  JRadioButton getOptionButton(ButtonModel model)
          Returns the JRadioButton of the button model or returns null if the model is null or if the model does not correspond to a button in the view.
 JRadioButton getOptionButton(int index)
          Returns the JRadioButton at the given index or returns null if the index is out of bounds.
 JRadioButton getOptionButton(String label)
          Returns the JRadioButton corresponding to the given label or returns null if the label is null or if the label does not correspond to a button in the view.
 JRadioButton[] getOptionButtons()
          Returns an array containing the radio buttons for this view.
 int getOptionCount()
          Returns the number of options for this view.
 JRadioButton getSelectedButton()
          Returns the currently selected button or null if there are no buttons.
 int getSelectedIndex()
          Returns the index of the selected button, or -1 if there are no buttons.
 String getSelectedLabel()
          Returns the label of the currently selected button or null if there are no buttons.
 String getViewState()
          Returns the label associated with the currently selected button or null if the panel is empty.
protected  void initializeRadioPanel(String[] strings, int selection, LayoutManager layout)
          Performs the common initialization code for this class.
 void refreshComponent()
          Refreshes the component by repacking the parent window.
 void removeActionListener(ActionListener listener)
          Removes the given action listener from all buttons.
 void removeActionListener(int index, ActionListener listener)
          Removes the given action listener from the button at the given index.
 void removeActionListeners(ActionListener[] listeners)
          Removes the given action listeners from the corresponding buttons.
 void reset()
          Sets the currently selected button to the one corresponding to the current default view state string.
 void setBackground(Color color)
          Sets the background for this component and its buttons.
 void setDefaultViewState(String state)
          Sets the string corresponding to the default button selection.
 void setEnabled(boolean isEnabled)
          Enable or disable the panel and its individual radio buttons.
 void setFont(Font font)
          Sets the font for this component.
 boolean setLabelText(int index, String label)
          Sets the label for the button at the given index to the given label.
 boolean setSelectedButton(JRadioButton button)
          Selects the given button.
 boolean setSelectedIndex(int index)
          Selects the button at the given index.
 boolean setSelectedLabel(String label)
          Selects the button corresponding to the label.
 void setViewState(String state)
          Sets the currently selected button to the button whose string is the given state.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OPTION_COUNT

public static final String OPTION_COUNT
Bound property name for the option count property.

See Also:
Constant Field Values

SELECTED_INDEX

public static final String SELECTED_INDEX
Bound property name for the selected index property.

See Also:
Constant Field Values

SELECTED_LABEL

public static final String SELECTED_LABEL
Bound property name for the selected index property.

See Also:
Constant Field Values

SELECTED_BUTTON

public static final String SELECTED_BUTTON
Bound property name for the selected index property.

See Also:
Constant Field Values

SET_LABEL_TEXT

public static final String SET_LABEL_TEXT
Bound property name for the set label text property.

See Also:
Constant Field Values

BACKGROUND

public static final String BACKGROUND
Bound property name for the set background property.

See Also:
Constant Field Values

DEFAULT_SELECTION

protected static final int DEFAULT_SELECTION
Default initial selection for an options view.

See Also:
Constant Field Values

defaultViewState

protected String defaultViewState
The default view state.


labelButtonMap

protected StringObjectMap labelButtonMap
The string-object map that contains pairs with a label and its associated radio button.


labelIndexMap

protected QuickHashMap labelIndexMap
The hash map that contains pairs with a label and an index installed as Integer with the position of the label in the view.


modelButtonMap

protected QuickHashMap modelButtonMap
The hash map that contains pairs with a model and its button.


buttonGroup

protected ButtonGroup buttonGroup
Button buttonGroup to enforce mutual exclusion for selections.


defaultLayout

protected TableLayout defaultLayout
The default layout.


commonactions

protected ActionSequence commonactions
The common actions for all buttons.

Constructor Detail

RadioPanel

public RadioPanel()

The default constructor.

Other constructors:


RadioPanel

public RadioPanel(LayoutManager layout)

Constructs a panel with the given layout manager.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
layout - the layout manager for the panel
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings)

Constructs a panel containing radio buttons labeled with the given array of strings.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
layout - the layout manager for the panel
Since:
2.3.3
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  int selection)

Constructs a panel containing radio buttons labeled with the given array of strings; the given selection is the index of the button that is initially selected.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
selection - the index of the button selected by default
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  int selection,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given selection is the index of the button that is initially selected; the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
selection - the index of the button selected by default
layout - the layout manager for the panel
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener action)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
action - the action listener that will listen for selection
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener action,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
action - the action listener that will listen for selection
layout - the layout manager for the panel
Since:
2.3.3
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener action,
                  int selection)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given selection is the index of the button that is initially selected.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
action - the action listener that will listen for selection
selection - the index of the button selected by default
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener action,
                  int selection,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listener becomes a listener for all buttons; the given selection is the index of the button that is initially selected; the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
action - the action listener that will listen for selection
selection - the index of the button selected by default
layout - the layout manager for the panel
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener[] actions)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
actions - the action listeners that will listen for selection
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener[] actions,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.

the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
actions - the action listeners that will listen for selection
layout - the layout manager for the panel
Since:
2.3.3
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener[] actions,
                  int selection)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.

the given selection is the index of the button that is initially selected.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

Parameters:
strings - the array of labels for the radio buttons
actions - the action listeners that will listen for selection
selection - the index of the button selected by default
See Also:
RadioPanel()

RadioPanel

public RadioPanel(String[] strings,
                  ActionListener[] actions,
                  int selection,
                  LayoutManager layout)

Constructs a panel containing radio buttons labeled with the given array of strings; the given action listeners become listeners for the corresponding buttons.

the given selection is the index of the button that is initially selected; the given layout manager is used to layout the buttons.

The strings in the array of strings should be distinct as duplicate strings will be ignored.

If the initial selection index is invalid and if there are buttons in the panel then the selection index will be set to 0.

If the strings array is null or of length zero, the panel will be initialized with no buttons.

If the given layout manager is null, then a TableLayout with WEST alignment and VERTICAL orientation will be used.

Parameters:
strings - the array of labels for the radio buttons
actions - the action listeners that will listen for selection
selection - the index of the button selected by default
layout - the layout manager for the panel
See Also:
RadioPanel()
Method Detail

initializeRadioPanel

protected final void initializeRadioPanel(String[] strings,
                                          int selection,
                                          LayoutManager layout)
Performs the common initialization code for this class.

Parameters:
strings - the array of labels for the radio buttons
selection - the index of the button selected by default
layout - the layout manager for the panel

getIndex

public final int getIndex(String label)
Returns the index of the option with the given label or -1 if the label is not in the view.

Returns:
the index corresponding to the label
See Also:
getIndex(JRadioButton), getLabel(int), getLabel(JRadioButton), getOptionButton(int), getOptionButton(String), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getIndex

public final int getIndex(JRadioButton button)
Returns the index of the option with the given button or -1 if the button is not in the view.

Returns:
the index corresponding to the label
See Also:
getIndex(String), getLabel(int), getLabel(JRadioButton), getOptionButton(int), getOptionButton(String), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getLabel

public final String getLabel(int index)
Returns the label of the option at the given index or null if the index is out of bounds.

Returns:
the label corresponding to the index
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(JRadioButton), getOptionButton(int), getOptionButton(String), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getLabel

public final String getLabel(JRadioButton button)
Returns the label of the given button or null if the button is null or is not in the view.

Returns:
the label corresponding to the index
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(int), getOptionButton(int), getOptionButton(String), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getOptionButton

public final JRadioButton getOptionButton(int index)
Returns the JRadioButton at the given index or returns null if the index is out of bounds.

Parameters:
index - the index of the desired button
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(int), getLabel(JRadioButton), getOptionButton(String), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getOptionButton

public final JRadioButton getOptionButton(String label)
Returns the JRadioButton corresponding to the given label or returns null if the label is null or if the label does not correspond to a button in the view.

Parameters:
label - the label of the desired button
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(int), getLabel(JRadioButton), getOptionButton(int), getOptionButton(ButtonModel), getButtonModel(JRadioButton)

getOptionButton

protected final JRadioButton getOptionButton(ButtonModel model)
Returns the JRadioButton of the button model or returns null if the model is null or if the model does not correspond to a button in the view.

Parameters:
model - the button model of the desired button
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(int), getLabel(JRadioButton), getOptionButton(int), getOptionButton(String), getButtonModel(JRadioButton)

getButtonModel

protected final ButtonModel getButtonModel(JRadioButton button)
Returns the ButtonModel of the radio button or returns null if the button is null or is not in the view.

Parameters:
button - the radio button
See Also:
getIndex(String), getIndex(JRadioButton), getLabel(int), getLabel(JRadioButton), getOptionButton(int), getOptionButton(String), getOptionButton(ButtonModel)

setSelectedIndex

public final boolean setSelectedIndex(int index)

Selects the button at the given index.

Does nothing if the index is out of bounds or is equal to the current selected index.

Parameters:
index - the index of the button to be selected
Returns:
whether or not the selection was changed
See Also:
getSelectedIndex(), setSelectedLabel(String), getSelectedLabel(), setSelectedButton(JRadioButton), getSelectedButton()

getSelectedIndex

public final int getSelectedIndex()
Returns the index of the selected button, or -1 if there are no buttons.

See Also:
setSelectedIndex(int), setSelectedLabel(String), getSelectedLabel(), setSelectedButton(JRadioButton), getSelectedButton()

setSelectedLabel

public final boolean setSelectedLabel(String label)

Selects the button corresponding to the label.

This method does not change the current selection if the label corresponds to the current selection or is not associated with a button.

Parameters:
label - the label of the option to be selected
Returns:
whether or not the selection was changed
See Also:
setSelectedIndex(int), getSelectedIndex(), getSelectedLabel(), setSelectedButton(JRadioButton), getSelectedButton()

getSelectedLabel

public final String getSelectedLabel()
Returns the label of the currently selected button or null if there are no buttons.

See Also:
setSelectedIndex(int), getSelectedIndex(), setSelectedLabel(String), setSelectedButton(JRadioButton), getSelectedButton()

setSelectedButton

public final boolean setSelectedButton(JRadioButton button)

Selects the given button.

This method does not change the current selection if the button is already the selected button or is not in the view.

Parameters:
button - the button to be selected
Returns:
whether or not the selection was changed
See Also:
setSelectedIndex(int), getSelectedIndex(), setSelectedLabel(String), getSelectedLabel(), getSelectedButton()

getSelectedButton

public final JRadioButton getSelectedButton()
Returns the currently selected button or null if there are no buttons.

Returns:
the currently selected button
See Also:
setSelectedIndex(int), getSelectedIndex(), setSelectedLabel(String), getSelectedLabel(), setSelectedButton(JRadioButton)

setLabelText

public final boolean setLabelText(int index,
                                  String label)

Sets the label for the button at the given index to the given label.

Does nothing if:

Parameters:
index - the index of the button
label - the new label for the button
Returns:
whether or not the operation was successful
See Also:
getLabelText(int)

getLabelText

public final String getLabelText(int index)

Returns the label text for the button at the given index, or null if the given index is invalid.

Equivalent to getLabel(index) but retained for compatibility with older code.

Parameters:
index - the index of the option whose label is to be returned
See Also:
setLabelText(int, String)

addOption

public final void addOption(String label)

Adds a button to the end of the view with the given label.

Refreshes the component.

Parameters:
label - the label for the button
See Also:
addOption(String, Action), addOption(String, boolean), addOption(String, Action, boolean), addOptions(String[]), addOptions(String[], Action), addOptions(String[], Action[])

addOption

public final void addOption(String label,
                            Action action)

Adds a button to the end of the view with the given label and the given action.

Refreshes the component.

Parameters:
label - the label for the button
action - the action to perform if the option is pressed
See Also:
addOption(String), addOption(String, boolean), addOption(String, Action, boolean), addOptions(String[]), addOptions(String[], Action), addOptions(String[], Action[])

addOption

public final void addOption(String label,
                            boolean selected)

Adds a button to the end of the view with the given label and the given selection state.

Refreshes the component.

Parameters:
label - the label for the button
selected - whether or not the option should be selected
See Also:
addOption(String), addOption(String, Action), addOption(String, Action, boolean), addOptions(String[]), addOptions(String[], Action), addOptions(String[], Action[])

addOption

public final void addOption(String label,
                            Action action,
                            boolean selected)

Adds a button to the end of the view with the given label, the given action, and the given selection state.

Refreshes the component.

Parameters:
label - the label for the button
action - the action to perform if the option is pressed
selected - whether or not the option should be selected
See Also:
addOption(String), addOption(String, Action), addOption(String, boolean), addOptions(String[]), addOptions(String[], Action), addOptions(String[], Action[])

addOptions

public final void addOptions(String[] labels)

Add the options in succession to the end of the view.

Refreshes the component.

Parameters:
labels - the label text for the various options
See Also:
addOption(String), addOption(String, Action), addOption(String, boolean), addOption(String, Action, boolean), addOptions(String[], Action), addOptions(String[], Action[])

addOptions

public final void addOptions(String[] labels,
                             Action action)

Add the options in succession to the end of the view with the same action for each option.

Refreshes the component.

Parameters:
labels - the label text for the various options
action - the action to pair with each option
See Also:
addOption(String), addOption(String, Action), addOption(String, boolean), addOption(String, Action, boolean), addOptions(String[]), addOptions(String[], Action[])

addOptions

public final void addOptions(String[] labels,
                             Action[] actions)

Add the options in succession to the end of the view with the each option paired with a corresponding action.

Refreshes the component.

Parameters:
labels - the label text for the various options
actions - the actions to pair with the options
See Also:
addOption(String), addOption(String, Action), addOption(String, boolean), addOption(String, Action, boolean), addOptions(String[]), addOptions(String[], Action)

getOptionCount

public final int getOptionCount()
Returns the number of options for this view.


getOptionButtons

public final JRadioButton[] getOptionButtons()
Returns an array containing the radio buttons for this view.

See Also:
getOptionButton(int)

addActionListener

public final void addActionListener(ActionListener listener)

Adds the given action listener to all buttons.

Does nothing if the action listener is null.

Parameters:
listener - the action listener to add to all buttons

addActionListener

public final void addActionListener(int index,
                                    ActionListener listener)

Adds the given action listener to the button at the given index.

Does nothing if the index is out of bounds or the action listener is null.

Parameters:
index - the index of the button
listener - the action listener to add to the button

addActionListeners

public final void addActionListeners(ActionListener[] listeners)

Adds the given action listeners to the corresponding buttons.

Does nothing if the action listeners array is null.

Parameters:
listeners - the action listeners to add to the corresponding buttons

removeActionListener

public final void removeActionListener(ActionListener listener)

Removes the given action listener from all buttons.

Does nothing if the action listener is null.

Parameters:
listener - the action to remove from all buttons

removeActionListener

public final void removeActionListener(int index,
                                       ActionListener listener)

Removes the given action listener from the button at the given index.

Does nothing if the index is out of bounds or the action listener is null.

Parameters:
index - the index of the button
listener - the listener to remove from the button

removeActionListeners

public final void removeActionListeners(ActionListener[] listeners)

Removes the given action listeners from the corresponding buttons.

Does nothing if the action listeners array is null.

Parameters:
listeners - the action listeners to remove from the corresponding buttons

setFont

public void setFont(Font font)

Sets the font for this component.

If the given font is null then it is set to getDefaultFont().

Calls the super setFont method and then sets the font for each radio button.

Refreshes the component.

Fires property change FONT.

Parameters:
font - the font to set for this view
Since:
2.3.3

getDefaultFont

public static Font getDefaultFont()
Returns the default font for a JRadioButton.

Since:
2.3.3

setBackground

public void setBackground(Color color)

Sets the background for this component and its buttons.

If the given color is null then sets the given color to getDefaultBackground().

Calls the super setBackground method and then sets the background for each radio button.

Fires property change BACKGROUND.

Parameters:
color - the background to set for this component
Since:
2.3.3

getDefaultBackground

public static Color getDefaultBackground()
Returns the default background for a JRadioButton.

Since:
2.3.3

setViewState

public void setViewState(String state)

Sets the currently selected button to the button whose string is the given state.

If the given state does not correspond to a button, then does nothing.

This method may be overridden in a derived class if the class does not consider the view state of the view to be equivalent to the button label of the selected button.

Specified by:
setViewState in interface Displayable
Parameters:
state - the string to select the button
See Also:
getViewState(), Displayable

getViewState

public String getViewState()

Returns the label associated with the currently selected button or null if the panel is empty.

This method may be overridden in a derived class if the class does not consider the view state of the view to be equivalent to the button label of the selected button.

Specified by:
getViewState in interface Displayable
Returns:
the view state as a String
See Also:
setViewState(String), Displayable

setDefaultViewState

public void setDefaultViewState(String state)

Sets the string corresponding to the default button selection.

If the given string does not correspond to a button at the time the method reset() is called, then reset() will do nothing. In other words, the given state is not checked for validity at the time this method is called but only when the default view state is used to reset the view state.

This method may be overridden in a derived class if the class does not consider the view state of the view to be equivalent to the button label of the selected button.

Specified by:
setDefaultViewState in interface Displayable
Parameters:
state - the proposed default view state
See Also:
reset(), Displayable

getDefaultViewState

public String getDefaultViewState()
Returns the current default view state string.

This method may be overridden in a derived class if the class does not consider the view state of the view to be equivalent to the button label of the selected button.

Specified by:
getDefaultViewState in interface Displayable
Returns:
the current default view state string
See Also:
setDefaultViewState(String), reset()

reset

public final void reset()

Sets the currently selected button to the one corresponding to the current default view state string.

If the current default view state string does not currently correspond to a button, then does nothing.

Equivalent to setViewState(getDefaultViewState()).

Specified by:
reset in interface Displayable
See Also:
setDefaultViewState(String), Displayable

setEnabled

public final void setEnabled(boolean isEnabled)
Enable or disable the panel and its individual radio buttons.

Specified by:
setEnabled in interface Displayable
Parameters:
isEnabled - whether to enable or disable

refreshComponent

public void refreshComponent()
Refreshes the component by repacking the parent window.