com.taursys.model
Class DefaultTextModel

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

public class DefaultTextModel
extends java.lang.Object
implements TextModel, javax.swing.event.ChangeListener

This class implements the TextModel interface and is designed to work with Parameter and Fields. This model stores its value in a ValueHolder object under a propertyName. This model converts the value to/from text using a given format and formatPattern. By default, this model uses a VariantValueHolder.


Constructor Summary
DefaultTextModel()
          Constructs new DefaultTextModel and initializes valueHolder via createDefaultValueHolder
DefaultTextModel(int javaDataType)
          Constructs new DefaultTextModel and sets valueHolder to a VariantValueHolder for given data type.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          Adds the specified change listener to receive change events from this model.
protected  ValueHolder createDefaultValueHolder()
          Creates default valueHolder to be used by this model.
protected  void fireStateChanged(javax.swing.event.ChangeEvent e)
          Reports a state change to all change listeners.
 java.text.Format getFormat()
          Returns the format for this model which is used by set/getText to parse/display values.
 java.lang.String getFormatPattern()
          Returns the format formatPattern for this model which is used by set/getText to parse/display values.
 java.lang.String getPropertyName()
          Returns the propertyName in the valueHolder where this model stores the value.
 java.lang.String getText()
          Returns the valueHolder's propertyValue as a String value using Format if defined.
 ValueHolder getValueHolder()
          Returns the valueHolder for this model.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Removes the specified change listener so that it no longer receives change events from this model.
 void setFormat(java.text.Format newFormat)
          Sets the format for this model which is used by set/getText to parse/display values.
 void setFormatPattern(java.lang.String newPattern)
          Sets the format formatPattern for this model which is used by set/getText to parse/display values.
 void setPropertyName(java.lang.String newPropertyName)
          Sets the propertyName in the valueHolder where this model stores the value.
 void setText(java.lang.String value)
          Sets the valueHolder's propertyValue from the given String value to DataType using Format(if defined) to parse.
protected  void setupFormat()
          Tries to applies the formatPattern to the format.
 void setValueHolder(ValueHolder newValueHolder)
          Sets the valueHolder for this model.
 void stateChanged(javax.swing.event.ChangeEvent e)
          Invoked when the target ValueHolder of the listener has changed its state.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultTextModel

public DefaultTextModel()
Constructs new DefaultTextModel and initializes valueHolder via createDefaultValueHolder


DefaultTextModel

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

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

createDefaultValueHolder

protected ValueHolder createDefaultValueHolder()
Creates default valueHolder to be used by this model. Override this method or use the setValueHolder method to change the valueHolder.

Returns:
a new ValueHolder for this component to use.

getText

public java.lang.String getText()
                         throws ModelException
Returns the valueHolder's propertyValue as a String value using Format if defined. If the valueHolder's propertyValue is null, it will return an empty String ("").

Specified by:
getText in interface TextModel
Returns:
the valueHolder's propertyValue as a formatted String
Throws:
ModelException - if problem occurs when retrieving value from ValueHolder

setText

public void setText(java.lang.String value)
             throws ModelException
Sets the valueHolder's propertyValue from the given String value to DataType using Format(if defined) to parse. If the given String value is null or empty (""), the accessed valueHolder's propertyValue is set to null.

Specified by:
setText in interface TextModel
Throws:
ModelException - if problem parsing or storing value

setupFormat

protected void setupFormat()
Tries to applies the formatPattern to the format. This only occurs if the format and formatPattern are not null, and the format is an instance of MessageFormat, SimpleDateFormat, ChoiceFormat, or DecimalFormat.


setValueHolder

public void setValueHolder(ValueHolder newValueHolder)
Sets the valueHolder for this model. The valueHolder is the object which holds the Object where this model stores the value. The default valueHolder is a VariantValueHolder with a javaDataType of String. Removes this DefaultTextModel as a change listener from the current ValueHolder (if any) and adds this as a change listener to the given ValueHolder.

Specified by:
setValueHolder in interface TextModel

getValueHolder

public ValueHolder getValueHolder()
Returns the valueHolder for this model. The valueHolder is the object which holds the Object where this model stores the value. The default valueHolder is a VariantValueHolder with a javaDataType of String.

Specified by:
getValueHolder in interface TextModel
Returns:
the ValueHolder used by this model to hold the actual value

setPropertyName

public void setPropertyName(java.lang.String newPropertyName)
Sets the propertyName in the valueHolder where this model stores the value. This name is ignored if you are using the VariantValueHolder.

Specified by:
setPropertyName in interface TextModel

getPropertyName

public java.lang.String getPropertyName()
Returns the propertyName in the valueHolder where this model stores the value. This name is ignored if you are using the VariantValueHolder.

Specified by:
getPropertyName in interface TextModel
Returns:
the name of the property in the ValueHolder which holds the actual value.

setFormat

public void setFormat(java.text.Format newFormat)
Sets the format for this model which is used by set/getText to parse/display values.

Specified by:
setFormat in interface TextModel

getFormat

public java.text.Format getFormat()
Returns the format for this model which is used by set/getText to parse/display values.

Specified by:
getFormat in interface TextModel
Returns:
the Format object used to format and parse the text value

setFormatPattern

public void setFormatPattern(java.lang.String newPattern)
Sets the format formatPattern for this model which is used by set/getText to parse/display values.

Specified by:
setFormatPattern in interface TextModel

getFormatPattern

public java.lang.String getFormatPattern()
Returns the format formatPattern for this model which is used by set/getText to parse/display values.

Specified by:
getFormatPattern in interface TextModel
Returns:
the pattern to be used by the Format object to format and parse the text value.

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Invoked when the target ValueHolder of the listener has changed its state. This message will simply be propagated to listeners of this component.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Removes the specified change listener so that it no longer receives change events from this model. Change events are generated whenever the contents of the value holder change.

Specified by:
removeChangeListener in interface TextModel

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Adds the specified change listener to receive change events from this model. Change events are generated whenever the contents of the value holder change.

Specified by:
addChangeListener in interface TextModel

fireStateChanged

protected void fireStateChanged(javax.swing.event.ChangeEvent e)
Reports a state change to all change listeners.


toString

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

Returns:
a string representation of this object


Copyright © 2007 Martin T Phelan. All Rights Reserved.