com.threerings.opengl.gui
Class ButtonGroup

java.lang.Object
  extended by com.threerings.opengl.gui.ButtonGroup
All Implemented Interfaces:
ActionListener, ComponentListener, Selectable<ToggleButton>

public class ButtonGroup
extends Object
implements ActionListener, Selectable<ToggleButton>

Manages a group of ToggleButtons, ensuring that only one is selected at any given time.


Field Summary
protected  List<ToggleButton> _buttons
          The buttons in the group.
protected  List<ActionListener> _listeners
          Listeners for action events.
 
Fields inherited from interface com.threerings.opengl.gui.Selectable
SELECT
 
Constructor Summary
ButtonGroup(ToggleButton... buttons)
          Creates a new button group.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Dispatched when a component has generated an "action".
 void add(ToggleButton button)
          Adds a button to the group.
 void addListener(ActionListener listener)
          Adds a listener for selection changes.
 ToggleButton getButton(int idx)
          Returns the button at the specified index.
 int getButtonCount()
          Returns the number of buttons in the group.
 ToggleButton getSelected()
          Get the selected item, if any.
 ToggleButton getSelectedButton()
          Deprecated. 
 int getSelectedIndex()
          Get the index of the selected item, or -1.
 void remove(ToggleButton button)
          Removes a button from the group.
 void removeAll()
          Removes all of the buttons in the group.
 void removeListener(ActionListener listener)
          Removes a selection change listener.
protected  void selectionChanged(ToggleButton selected, long when, int modifiers)
          Updates the states of the unselected buttons and fires a selection event.
 void setSelected(ToggleButton button)
          Set the selected item.
 void setSelectedButton(ToggleButton button)
          Deprecated. 
 void setSelectedIndex(int idx)
          Set the index of the selected item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_buttons

protected List<ToggleButton> _buttons
The buttons in the group.


_listeners

protected List<ActionListener> _listeners
Listeners for action events.

Constructor Detail

ButtonGroup

public ButtonGroup(ToggleButton... buttons)
Creates a new button group.

Parameters:
buttons - the buttons in the group.
Method Detail

addListener

public void addListener(ActionListener listener)
Adds a listener for selection changes.


removeListener

public void removeListener(ActionListener listener)
Removes a selection change listener.


add

public void add(ToggleButton button)
Adds a button to the group.


remove

public void remove(ToggleButton button)
Removes a button from the group.


removeAll

public void removeAll()
Removes all of the buttons in the group.


getButtonCount

public int getButtonCount()
Returns the number of buttons in the group.


getSelected

public ToggleButton getSelected()
Description copied from interface: Selectable
Get the selected item, if any.

Specified by:
getSelected in interface Selectable<ToggleButton>

setSelected

public void setSelected(ToggleButton button)
Description copied from interface: Selectable
Set the selected item.

Specified by:
setSelected in interface Selectable<ToggleButton>

getButton

public ToggleButton getButton(int idx)
Returns the button at the specified index.


setSelectedButton

@Deprecated
public void setSelectedButton(ToggleButton button)
Deprecated. 


getSelectedButton

@Deprecated
public ToggleButton getSelectedButton()
Deprecated. 


setSelectedIndex

public void setSelectedIndex(int idx)
Description copied from interface: Selectable
Set the index of the selected item.

Specified by:
setSelectedIndex in interface Selectable<ToggleButton>

getSelectedIndex

public int getSelectedIndex()
Description copied from interface: Selectable
Get the index of the selected item, or -1.

Specified by:
getSelectedIndex in interface Selectable<ToggleButton>

actionPerformed

public void actionPerformed(ActionEvent event)
Description copied from interface: ActionListener
Dispatched when a component has generated an "action".

Specified by:
actionPerformed in interface ActionListener

selectionChanged

protected void selectionChanged(ToggleButton selected,
                                long when,
                                int modifiers)
Updates the states of the unselected buttons and fires a selection event.