com.taursys.model
Class DefaultCheckboxModel

java.lang.Object
  extended bycom.taursys.model.DefaultTextModel
      extended bycom.taursys.model.DefaultCheckboxModel
All Implemented Interfaces:
javax.swing.event.ChangeListener, CheckboxModel, java.util.EventListener, TextModel

public class DefaultCheckboxModel
extends DefaultTextModel
implements CheckboxModel

CheckboxModel is a model which maintains 2 states: selected or unselected. The CheckboxModel provides access to the internal "state" or value via the setText, getText, setSelected and isSelected methods.

The setSelected method simply invokes the setText method with either the selectedValue or unselectedValue. The isSelected method simply invokes the getText method and returns true if the value equals the selectedValue.

The set/getText methods provide any required parsing or formatting as they transform the value between its String representation and actual internal representation (int, Date, boolean, etc). There are 2 properties which govern the parse/format process: format and formatPattern. These use the standard java.text.Format objects and patterns.

If the setText method is invoked directly, the value passed to it must be equal to either the selectedValue or unselectedValue, otherwise an UnknownStateValueException will occur.

This model supports null as the "unselected" state. This is accomplished by setting the unselectedValue to blank (""). A initial null value in the value holder is treated as unselected by the isSelected and getText methods.

Version:
1.0
Author:
Marty Phelan

Constructor Summary
DefaultCheckboxModel()
          Constructs a new DefaultCheckboxModel The default valueHolder for this model is a String VariantValueHolder.
DefaultCheckboxModel(int javaDataType)
          Constructs new DefaultCheckboxModel and sets valueHolder to a VariantValueHolder for given data type.
 
Method Summary
 java.lang.String getSelectedValue()
          Get the value used to indicate a selected state.
 java.lang.String getText()
          Returns text/display value of current state.
 java.lang.String getUnselectedValue()
          Get the value used to indicate an unselected state.
 boolean isSelected()
          Gets the current state as selected(true) or unselected(false).
 void setSelected(boolean newSelected)
          Sets the current state as selected(true) or unselected(false).
 void setSelectedValue(java.lang.String newSelectedValue)
          Set the value used to indicate a selected state.
 void setText(java.lang.String value)
          Sets the current state by matching the given value to the selected or unselected values.
 void setUnselectedValue(java.lang.String newUnselectedValue)
          Set the value used to indicate an unselected state.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class com.taursys.model.DefaultTextModel
addChangeListener, createDefaultValueHolder, fireStateChanged, getFormat, getFormatPattern, getPropertyName, getValueHolder, removeChangeListener, setFormat, setFormatPattern, setPropertyName, setupFormat, setValueHolder, stateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.taursys.model.TextModel
addChangeListener, getFormat, getFormatPattern, getPropertyName, getValueHolder, removeChangeListener, setFormat, setFormatPattern, setPropertyName, setValueHolder
 

Constructor Detail

DefaultCheckboxModel

public DefaultCheckboxModel()
Constructs a new DefaultCheckboxModel The default valueHolder for this model is a String VariantValueHolder.


DefaultCheckboxModel

public DefaultCheckboxModel(int javaDataType)
                     throws UnsupportedDataTypeException
Constructs new DefaultCheckboxModel and sets valueHolder to a VariantValueHolder for given data type.

Throws:
UnsupportedDataTypeException - if invalid javaDataType is given
See Also:
DataTypes
Method Detail

getText

public java.lang.String getText()
                         throws UnknownStateValueException,
                                ModelException
Returns text/display value of current state. If the underlying valueHolder value is null, the unselectedValue will be returned.

Specified by:
getText in interface CheckboxModel
Overrides:
getText in class DefaultTextModel
Returns:
the valueHolder's propertyValue as a formatted String
Throws:
UnknownStateValueException - if the given value does not match the selected or unselected values.
ModelException - if problem while matching properties of valueHolder object to list object.

setText

public void setText(java.lang.String value)
             throws UnknownStateValueException,
                    ModelException
Sets the current state by matching the given value to the selected or unselected values.

Specified by:
setText in interface CheckboxModel
Overrides:
setText in class DefaultTextModel
Throws:
UnknownStateValueException - if the given value does not match the selected or unselected values.
ModelException - if problem while setting properties of object in valueHolder.

setSelected

public void setSelected(boolean newSelected)
                 throws ModelException
Sets the current state as selected(true) or unselected(false). This method stores either the selectedValue or unselectedValue as the text value depending on the given value.

Specified by:
setSelected in interface CheckboxModel
Throws:
ModelException - if problem while setting properties of object in valueHolder.

isSelected

public boolean isSelected()
                   throws UnknownStateValueException,
                          ModelException
Gets the current state as selected(true) or unselected(false). This method compares the selectedValue to the text value to determine the state.

Specified by:
isSelected in interface CheckboxModel
Throws:
UnknownStateValueException - if the given value does not match the selected or unselected values.
ModelException - if problem while setting properties of object in valueHolder.

setSelectedValue

public void setSelectedValue(java.lang.String newSelectedValue)
Set the value used to indicate a selected state. Default value is "true".

Specified by:
setSelectedValue in interface CheckboxModel
Parameters:
newSelectedValue - the value used to indicate a selected state.

getSelectedValue

public java.lang.String getSelectedValue()
Get the value used to indicate a selected state. Default value is "true".

Specified by:
getSelectedValue in interface CheckboxModel
Returns:
the value used to indicate a selected state.

setUnselectedValue

public void setUnselectedValue(java.lang.String newUnselectedValue)
Set the value used to indicate an unselected state. Default value is "" (blank).

Specified by:
setUnselectedValue in interface CheckboxModel
Parameters:
newUnselectedValue - the value used to indicate a unselected state.

getUnselectedValue

public java.lang.String getUnselectedValue()
Get the value used to indicate an unselected state. Default value is "" (blank).

Specified by:
getUnselectedValue in interface CheckboxModel
Returns:
the value used to indicate a unselected state.

toString

public java.lang.String toString()
Returns a string representation of this object. This contains the object identity and state information.

Overrides:
toString in class DefaultTextModel
Returns:
a string representation of this object


Copyright © 2007 Martin T Phelan. All Rights Reserved.