|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.DefaultButtonModel
javax.swing.JToggleButton.ToggleButtonModel
com.jgoodies.binding.adapter.ToggleButtonAdapter
public final class ToggleButtonAdapter
Converts ValueModels to the ToggleButtonModel interface. Useful to bind JToggleButton, JCheckBox and JCheckBoxMenuItem to a ValueModel.
This adapter holds two values that represent the selected and the deselected state. These are used to determine the selection state if the underlying subject ValueModel changes its value. If the selection is set, the corresponding representant is written to the underlying ValueModel.
Constraints: The subject ValueModel must allow read-access to its value. Also, it is strongly recommended (though not required) that the underlying ValueModel provides only two values, for example Boolean.TRUE and Boolean.FALSE. This is so because the toggle button component may behave "strangely" when it is used with ValueModels that provide more than two elements.
Examples:
// Recommended binding style using a factory ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = BasicComponentFactory.createCheckBox(model, "Visible"); // Binding using the Bindings class ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = new JCheckBox("Visible"); Bindings.bind(visibleBox, model); // Hand-made binding ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = new JCheckBox("Visible"); visibleBox.setModel(new ToggleButtonAdapter(model));
ButtonModel
,
JCheckBox
,
JCheckBoxMenuItem
,
Serialized FormField Summary |
---|
Fields inherited from class javax.swing.DefaultButtonModel |
---|
actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask |
Constructor Summary | |
---|---|
ToggleButtonAdapter(ValueModel subject)
Constructs a ToggleButtonAdapter on the given subject ValueModel. |
|
ToggleButtonAdapter(ValueModel subject,
Object selectedValue,
Object deselectedValue)
Constructs a ToggleButtonAdapter on the given subject ValueModel using the specified values for the selected and deselected state. |
Method Summary | |
---|---|
void |
setSelected(boolean b)
First, the subject value is set to this adapter's selected value if the argument is true , to the deselected value otherwise. |
Methods inherited from class javax.swing.JToggleButton.ToggleButtonModel |
---|
isSelected, setPressed |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ToggleButtonAdapter(ValueModel subject)
Boolean.TRUE
.
subject
- the subject that holds the value
NullPointerException
- if the subject is null
.public ToggleButtonAdapter(ValueModel subject, Object selectedValue, Object deselectedValue)
selectedValue
.
subject
- the subject that holds the valueselectedValue
- the value that will be set if this is selecteddeselectedValue
- the value that will be set if this is deselected
NullPointerException
- if the subject is null
.
IllegalArgumentException
- if the selected and deselected values
are equalMethod Detail |
---|
public void setSelected(boolean b)
true
, to the deselected value otherwise.
Second, this adapter's state is set to the then current subject value.
This ensures that the selected state is synchronized with the subject
- even if the subject rejects the change.
setSelected
in interface ButtonModel
setSelected
in class JToggleButton.ToggleButtonModel
b
- true
sets the selected value as subject value,
false
sets the deselected value as subject value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |