| Converts ValueModels to the ToggleButtonModel interface. Useful to bind
JRadioButtons and JRadioButtonMenuItems to a ValueModel.
This adapter holds a choice object that is used to determine
the selection state if the underlying subject ValueModel changes its value.
This model is selected if the subject's value equals the choice object.
And if the selection is set, the choice object is set to the subject.
Note: You must not use a ButtonGroup with this adapter.
The RadioButtonAdapter ensures that only one choice is selected by sharing
a single subject ValueModel - at least if all choice values differ.
See also the example below.
Example:
// Recommended binding style using a factory
PresentationModel presentationModel = new PresentationModel(printerSettings);
ValueModel orientationModel =
presentationModel.getModel(PrinterSettings.PROPERTYNAME_ORIENTATION);
JRadioButton landscapeButton = BasicComponentFactory.createRadioButton(
orientationModel, PrinterSettings.LANDSCAPE, "Landscape");
JRadioButton portraitButton = BasicComponentFactory.createRadioButton(
orientationModel, PrinterSettings.PORTRAIT, "Portrait");
// Binding using the Bindings class
ValueModel orientationModel =
presentationModel.getModel(PrinterSettings.PROPERTYNAME_ORIENTATION);
JRadioButton landscapeButton = new JRadioButton("Landscape");
Bindings.bind(landscapeButton, orientationModel, "landscape");
JRadioButton portraitButton = new JRadioButton("Portrait");
Bindings.bind(portraitButton, orientationModel, "portrait");
// Hand-made style
ValueModel orientationModel =
presentationModel.getModel(PrinterSettings.PROPERTYNAME_ORIENTATION);
JRadioButton landscapeButton = new JRadioButton("Landscape");
landscapeButton.setModel(new RadioButtonAdapter(model, "landscape");
JRadioButton portraitButton = new JRadioButton("Portrait");
portraitButton.setModel(new RadioButtonAdapter(model, "portrait");
author: Karsten Lentzsch version: $Revision: 1.5 $ See Also: javax.swing.ButtonModel See Also: javax.swing.JRadioButton See Also: javax.swing.JRadioButtonMenuItem |