org.wings
Class SButtonGroup

java.lang.Object
  extended by org.wings.SButtonGroup
All Implemented Interfaces:
Serializable, SDelayedEventModel

public class SButtonGroup
extends Object
implements SDelayedEventModel, Serializable

Used to create a multiple-exclusion scope for a set of buttons.

Creating a set of buttons with the same ButtonGroup object means that turning "on" one of those buttons turns off all other buttons in the group.

A SButtonGroup can be used with any set of objects that inherit from SAbstractButton, because they support the selected state.

Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to "off", in order to clear the button group.

Details:The implementation of the button group is a bit tricky for the HTML generation. In HTML, groups of components are usually formed by giving them all the same name. The problem is, that any SComponent, especially the SAbstractButton, have globally unique names. So this implementation gives all buttons in the group the name of this SButtonGroup, and sets their value to their actual name. So a bit of dispatching is already done here.

Author:
Armin Haaf
See Also:
ButtonGroup, Serialized Form

Field Summary
protected  ArrayList buttons
           
protected  ArrayList delayedEvents
          all delayed events are stored here.
protected  EventListenerList listenerList
           
static String SELECTION_CHANGED
           
 
Constructor Summary
SButtonGroup()
           
 
Method Summary
 void add(SAbstractButton button)
          adds a button to the group.
 void addActionListener(ActionListener listener)
          Adds an action listener to this group of buttons.
protected  void fireActionEvent(ActionEvent e)
          Fire an ActionEvent at each registered listener.
protected  void fireActionPerformed(String command)
          Fire an ActionEvent at each registered listener.
 void fireDelayedFinalEvents()
          fire remaining delayed events.
 void fireDelayedIntermediateEvents()
          fire delayed events which describes a "in progress" state change, like TreeWillExpand, or ListSelectionEvent with getIsAdjusting() true, ...
 ActionListener[] getActionListeners()
          Returns an array of all the ActionListeners added to this group of buttons with addActionListener().
 String getComponentId()
          Return a jvm wide unique id.
 boolean getDelayEvents()
           
 Enumeration getElements()
          Gets all the buttons the group consists of.
 String getLowLevelEventId()
          Gets the id of the component.
 SAbstractButton getSelection()
          Gets the button of the group that is selected.
 boolean isSelected(SAbstractButton button)
          Returns the state of the button.
 Iterator iterator()
           
 void remove(SAbstractButton button)
          removes a button from the group.
 void removeActionListener(ActionListener listener)
          Removes the supplied Listener from the listener list
 void removeAll()
          removes all buttons from the group.
 void setDelayEvents(boolean b)
          if this is set to true, events are not fired immediately.
 void setSelected(SAbstractButton b, boolean selected)
          Sets a button in the selected state.
protected  void setSelection(SAbstractButton button)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTION_CHANGED

public static final String SELECTION_CHANGED
See Also:
Constant Field Values

buttons

protected final ArrayList buttons

listenerList

protected final EventListenerList listenerList

delayedEvents

protected final ArrayList delayedEvents
all delayed events are stored here.

Constructor Detail

SButtonGroup

public SButtonGroup()
Method Detail

getComponentId

public final String getComponentId()
Return a jvm wide unique id.

Returns:
an id

setSelection

protected void setSelection(SAbstractButton button)

add

public void add(SAbstractButton button)
adds a button to the group.

Parameters:
button - the button that is to be added

remove

public void remove(SAbstractButton button)
removes a button from the group.

Parameters:
button - the button that is to be removed

removeAll

public void removeAll()
removes all buttons from the group.


getSelection

public final SAbstractButton getSelection()
Gets the button of the group that is selected.

Returns:
the selected button
See Also:
setSelection(SAbstractButton)

setSelected

public void setSelected(SAbstractButton b,
                        boolean selected)
Sets a button in the selected state. There can be only one button selected at a time.

Parameters:
b - the button.
selected - true if this button is to be selected, otherwise false.

isSelected

public boolean isSelected(SAbstractButton button)
Returns the state of the button. True if the button is selected, false if not.

Parameters:
button - the button.
Returns:
true if the button is selected, otherwise false.

iterator

public Iterator iterator()

getElements

public Enumeration getElements()
Gets all the buttons the group consists of.

Returns:
an enumeration of the buttons of the group

getLowLevelEventId

public String getLowLevelEventId()
Gets the id of the component.

Returns:
the component id

addActionListener

public void addActionListener(ActionListener listener)
Adds an action listener to this group of buttons. If one of the buttons contained in this group gets selected, an action event will occur.

Parameters:
listener -

removeActionListener

public void removeActionListener(ActionListener listener)
Removes the supplied Listener from the listener list


getActionListeners

public ActionListener[] getActionListeners()
Returns an array of all the ActionListeners added to this group of buttons with addActionListener().

Returns:
all of the ActionListeners added or an empty array if no listeners have been added

fireActionPerformed

protected void fireActionPerformed(String command)
Fire an ActionEvent at each registered listener.


fireActionEvent

protected void fireActionEvent(ActionEvent e)
Fire an ActionEvent at each registered listener.


setDelayEvents

public void setDelayEvents(boolean b)
Description copied from interface: SDelayedEventModel
if this is set to true, events are not fired immediately. They are collected and fired after setting this to false...

Specified by:
setDelayEvents in interface SDelayedEventModel

getDelayEvents

public boolean getDelayEvents()
Specified by:
getDelayEvents in interface SDelayedEventModel

fireDelayedIntermediateEvents

public void fireDelayedIntermediateEvents()
Description copied from interface: SDelayedEventModel
fire delayed events which describes a "in progress" state change, like TreeWillExpand, or ListSelectionEvent with getIsAdjusting() true, ...

Specified by:
fireDelayedIntermediateEvents in interface SDelayedEventModel

fireDelayedFinalEvents

public void fireDelayedFinalEvents()
Description copied from interface: SDelayedEventModel
fire remaining delayed events. In this level all events, which are important to an application should be fired. All listeners, which are notified in this level can assume that the components are in a consistent (considering user interaction) state.

Specified by:
fireDelayedFinalEvents in interface SDelayedEventModel


wingS Swings ;-)