borland Packages Class Hierarchy dbswing Package
java.lang.Object +----com.borland.dbswing.DBButtonDataBinder
Constructors Properties Methods
Implements DBDataBinder, AccessListener, ColumnAware, DataChangeListener, DataSetAware, Designable, NavigationListener, ActionListener, ItemListener, PropertyChangeListener, Serializable, EventListener
DBButtonDataBinder
maps the state of a button's ButtonModel
to a value in a DataSet Column
. Properties on DBButtonDataBinder
specify values to be set when a ButtonModel
is in a selected or unselected state. DBButtonDataBinder
is used to make the JdbToggleButton
, JdbRadioButton
, and JdbCheckBox
components data aware.
There are two ways to hook up a button to a DBButtonDataBinder
. The simpler way is to set the abstractButton
property of DBButtonDataBinder
to any button that extends the AbstractButton
class, such as JButton
, JToggleButton
, JRadioButton
, or JCheckbox
. Or you can make any component using a ButtonModel
data aware by setting DBButtonDataBinder's
buttonModel
property to the component's ButtonModel
. Note that when using this second approach, however, you are responsible for opening the DataSet
before using it.
If you set the abstractButton
property, DBButtonDataBinder
also binds the text
, alignment
, background
, foreground
, and font
properties from those defined on Column
columnName
, if one is specified, unless these same properties are already explicitly set on the AbstractButton
itself. The text
property is considered to be in its default (not explicitly set) state if it is null
or an empty string (""). The button's horizontalAlignment
property is considered to be in its default state if its value is SwingConstants.CENTER
for a JButton
or JToggleButton
, or SwingConstants.LEFT
for a JRadioButton
or JCheckBox
. The button's verticalAlignment
property is considered to be in its default state if its value is SwingConstants.CENTER
.
Set the dataSet
and columnName
properties to indicate the DataSet
and Column
which data values are read from and written to.
selectedDataValue
and unselectedDataValue
propertiesYou must specify the values DBButtonDataBinder
should save to the DataSet
when the button is in its selected and unselected states. Do this by setting DBButtonDataBinder's
selectedDataValue
and unselectedDataValue
properties, respectively; specify the values as String
s. DBButtonDataBinder
automatically converts these strings to the proper data type for the DataSet
Column
you specified. To prevent writing a selected or unselected data value to a DataSet
, don't set the property value or set it to null
. Note that a null
value has a different meaning than an empty string (""), which actually clears whatever value is in the DataSet
's column.
For some button types, such as JToggleButton
, it makes sense to set a value for both the selectedDataValue
and unselectedDataValue
properties. Buttons that work in groups, such as JRadioButton
, usually would use just a selectedDataValue
, however. For example, if several JRadioButtons
are attached to the same DataSet
Column
, you would probably want to set the selectedDataValue
only for each JRadioButton
because selecting a JRadioButton
deselects all others in the same button group. In this case, if you have also set the unselectedDataValue
property for each JRadioButton
's DBButtonDataBinder
, the value that is finally written to the DataSet
is unpredictable; the actual value would depend on the order in which the buttons are selected and unselected.
Besides writing a value to a DataSet
when a button is selected, DBButtonDataBinder
also ensures that the state of the button is consistent with the current value of the DataSet
Column
to which it is attached. What happens when the value in the DataSet
does not match either of the selectedDataValue
or unselectedDataValue
properties? In this case, DBButtonDataBinder
leaves the button, or more accurately, the button's model, in its current state. You can, however, set the unknownDataValueMode
property to one of the following values to specify different behavior:
DataSet
value does not match either selectedDataValue
or unselectedDataValue
.
DataSet
value does not match either selectedDataValue
or unselectedDataValue
.
DataSet
value if it doesn't match either selectedDataValue
or unselectedDataValue
.
JToggleButton jToggleButton = new JToggleButton("Modulation"); DBButtonDataBinder dbButtonDataBinder = new DBButtonDataBinder(); // attach the button to DBButtonDataBinder dbButtonDataBinder.setAbstractbutton(JToggleButton); // set the values to be written to DataSet dbButtonDataBinder.setSelectedDataValue("Frequency"); dbButtonDataBinder.setUnselectedDataValue("Amplitude"); // set the target DataSet and Column dbButtonDataBinder.setDataSet(dataSet); dbButtonDataBinder.setColumnName("Band");
public DBButtonDataBinder()Constructs a
DBButtonDataBinder
. Calls the null
constructor of its superclass.
public DBButtonDataBinder(AbstractButton button)Constructs a
DBButtonDataBinder
that makes the specified button data aware. Calls the null
constructor of its superclass.
button
DBButtonDataBinder
makes data aware.
public AbstractButton getAbstractButton() public void setAbstractButton(AbstractButton button)Returns and sets the button that this
DBButtonDataBinder
makes data aware.
public ButtonModel getButtonModel() public void setButtonModel(ButtonModel buttonModel)Returns and sets the
buttonModel
of the button DBButtonDataBinder
makes data aware. By specifying a buttonModel
of a button as the value of the DBButtonDataBinder
buttonModel
, the button becomes data aware. You must, however, open the DataSet
before using the button component.
public String getColumnName() public void setColumnName(String columnName)Returns and sets the column name of the
DataSet
from which data values are read and to which data values are written.
DataSet
public DataSet getDataSet() public void setDataSet(DataSet dataSet)Returns and sets the
DataSet
from which data values are read and to which data values are written.
columnName
public String getSelectedDataValue() public void setSelectedDataValue(String selectedValue)Returns and sets the value written to the
DataSet
when the button is selected. Setting this value to null
writes nothing to the DataSet
. Setting this value to an empty string ("") clears the value in the DataSet
.
unselectedDataValue
public int getUnknownDataValueMode() public void setUnknownDataValueMode(int mode)Returns and sets the policy for setting button state when synchronizing a button with its
DataSet
value when the value doesn't match either of the selectedDataValue
or unselectedDataValue
property values. Valid values for the mode parameter are DEFAULT, DISABLE_COMPONENT, and CLEAR_VALUE.
public String getUnselectedDataValue() public void setUnselectedDataValue(String unselectedValue)Returns and sets the value written to the
DataSet
when the button is unselected. Setting this value to null
writes nothing to the DataSet
. Setting this value to an empty string ("") clears the value in the DataSet
.
selectedDataValue
protected void updateButtonState()Synchronizes the state of the button model with the current
DataSet
value.