org.tbee.swing
Class JButtonGroup<T>

java.lang.Object
  extended by javax.swing.ButtonGroup
      extended by org.tbee.swing.JButtonGroup<T>
All Implemented Interfaces:
java.io.Serializable

public class JButtonGroup<T>
extends javax.swing.ButtonGroup

Extends javax.swing.ButtonGroup to provide methods that allow working with button references instead of button models. By using bindValue(button, value) or the associated add(button, value) it is possible to relate a value to a button. By using setValue(), getValue() and the value property change event, the buttongroup can be bound to a bean property.

Version:
$Revision: 1.13 $
See Also:
ButtonGroup, Serialized Form

Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static java.lang.String VALUE_PROPERTY_ID
           
 
Fields inherited from class javax.swing.ButtonGroup
buttons
 
Constructor Summary
JButtonGroup()
          Creates an empty JButtonGroup
JButtonGroup(javax.swing.AbstractButton... buttons)
          Creates a JButtonGroup object from an array of buttons and adds the buttons to the group No button will be selected initially.
 
Method Summary
 void add(javax.swing.AbstractButton... buttons)
          Adds an array of buttons to the group
 void add(javax.swing.AbstractButton button)
          Adds a button to the group
 void add(javax.swing.AbstractButton button, T value)
          Adds a button to the group
 void addPropertyChangeListener(java.beans.PropertyChangeListener o)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener o)
           
 void bindValue(javax.swing.AbstractButton button, T value)
          store the relation between button and value
 boolean contains(javax.swing.AbstractButton button)
          Checks whether the group contains the given button
 void firePropertyChange(java.lang.String name, T before, T after)
           
 void fireValueChangedIfRequired()
           
 javax.swing.AbstractButton getButton(javax.swing.ButtonModel model)
          Returns the AbstractButton whose ButtonModel is given.
 java.util.List<javax.swing.AbstractButton> getButtons()
          Returns the buttons in the group as a List
 java.beans.PropertyChangeListener[] getPropertyChangeListeners()
          PropertyChange
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
           
 javax.swing.AbstractButton getSelected()
          Returns the selected button in the group.
 T getValue()
           
 boolean isSelected(javax.swing.AbstractButton button)
          Returns whether the button is selected
 void remove(javax.swing.AbstractButton... buttons)
          Removes all the buttons in the array from the group
 void remove(javax.swing.AbstractButton button)
          Removes a button from the group
 void removePropertyChangeListener(java.beans.PropertyChangeListener o)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener o)
           
 void setSelected(javax.swing.AbstractButton button, boolean selected)
          Sets the selected button in the group Only one button in the group can be selected
 void setSelected(javax.swing.ButtonModel model, boolean selected)
          Sets the selected button model in the group
 void setValue(T value)
          get the value of the selected button
 void unbindValue(javax.swing.AbstractButton button)
           
 
Methods inherited from class javax.swing.ButtonGroup
clearSelection, getButtonCount, getElements, getSelection, isSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

VALUE_PROPERTY_ID

public static final java.lang.String VALUE_PROPERTY_ID
See Also:
Constant Field Values
Constructor Detail

JButtonGroup

public JButtonGroup()
Creates an empty JButtonGroup


JButtonGroup

public JButtonGroup(javax.swing.AbstractButton... buttons)
Creates a JButtonGroup object from an array of buttons and adds the buttons to the group No button will be selected initially.

Parameters:
buttons - an array of AbstractButtons
Method Detail

add

public void add(javax.swing.AbstractButton button)
Adds a button to the group

Overrides:
add in class javax.swing.ButtonGroup
Parameters:
button - an AbstractButton reference

add

public void add(javax.swing.AbstractButton... buttons)
Adds an array of buttons to the group

Parameters:
buttons - an array of AbstractButtons

remove

public void remove(javax.swing.AbstractButton button)
Removes a button from the group

Overrides:
remove in class javax.swing.ButtonGroup
Parameters:
button - the button to be removed

remove

public void remove(javax.swing.AbstractButton... buttons)
Removes all the buttons in the array from the group

Parameters:
buttons - an array of AbstractButtons

setSelected

public void setSelected(javax.swing.AbstractButton button,
                        boolean selected)
Sets the selected button in the group Only one button in the group can be selected

Parameters:
button - an AbstractButton reference
selected - an boolean representing the selection state of the button

setSelected

public void setSelected(javax.swing.ButtonModel model,
                        boolean selected)
Sets the selected button model in the group

Overrides:
setSelected in class javax.swing.ButtonGroup
Parameters:
model - a ButtonModel reference
selected - an boolean representing the selection state of the button

getButton

public javax.swing.AbstractButton getButton(javax.swing.ButtonModel model)
Returns the AbstractButton whose ButtonModel is given. If the model does not belong to a button in the group, returns null.

Parameters:
model - a ButtonModel that should belong to a button in the group
Returns:
an AbstractButton reference whose model is model if the button belongs to the group, nullotherwise

getSelected

public javax.swing.AbstractButton getSelected()
Returns the selected button in the group.

Returns:
a reference to the currently selected button in the group or null if no button is selected

isSelected

public boolean isSelected(javax.swing.AbstractButton button)
Returns whether the button is selected

Parameters:
button - an AbstractButton reference
Returns:
true if the button is selected, false otherwise

getButtons

public java.util.List<javax.swing.AbstractButton> getButtons()
Returns the buttons in the group as a List

Returns:
a List containing the buttons in the group, in the order they were added to the group

contains

public boolean contains(javax.swing.AbstractButton button)
Checks whether the group contains the given button

Returns:
true if the button is contained in the group, false otherwise

setValue

public void setValue(T value)
get the value of the selected button


getValue

public T getValue()

fireValueChangedIfRequired

public void fireValueChangedIfRequired()

bindValue

public void bindValue(javax.swing.AbstractButton button,
                      T value)
store the relation between button and value


unbindValue

public void unbindValue(javax.swing.AbstractButton button)

add

public void add(javax.swing.AbstractButton button,
                T value)
Adds a button to the group

Parameters:
button - an AbstractButton reference

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
PropertyChange


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener o)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener o)

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener o)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener o)

firePropertyChange

public void firePropertyChange(java.lang.String name,
                               T before,
                               T after)


Copyright © 2010 KnowledgePlaza. All Rights Reserved.