com.metamatrix.toolbox.ui.widget.text
Class DefaultTextFieldModel

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.metamatrix.toolbox.ui.widget.text.DefaultTextFieldModel
All Implemented Interfaces:
TextConstants, java.io.Serializable, javax.swing.text.Document

public class DefaultTextFieldModel
extends javax.swing.text.PlainDocument
implements TextConstants

The default model for TextFields.

Since:
2.0
Version:
2.0
Author:
John P. A. Verhaeg
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement
 
Field Summary
 
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
 
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
 
Fields inherited from interface com.metamatrix.toolbox.ui.widget.text.TextConstants
IS_MODIFIED_PROPERTY, IS_VALID_PROPERTY, MAXIMUM_LENGTH_PROPERTY, TEXT_PROPERTY
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
DefaultTextFieldModel()
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Registers a PropertyChangeListener to be notified of text and validity changes to the model.
 void addValidator(Validator validator)
          Adds the specified text validator to the end of the list of registered validators.
 void addValidator(Validator validator, int index)
          Adds the specified text validator to the list of registered validators at the specified index.
 void commit()
          Commits any new text set on the model.
protected  void firePropertyChangeEvent(java.beans.PropertyChangeEvent event)
          Notifies all registered PropertyChangeListeners of a property change.
protected  void firePropertyChangeEvent(java.lang.String prop, boolean oldVal, boolean newVal)
          Notifies all registered PropertyChangeListeners of a boolean value (flag) change.
protected  void firePropertyChangeEvent(java.lang.String prop, int oldVal, int newVal)
          Notifies all registered PropertyChangeListeners of a integer value change.
protected  void firePropertyChangeEvent(java.lang.String prop, java.lang.String oldText, java.lang.String newText)
          Notifies all registered PropertyChangeListeners of a text change.
 int getMaximumLength()
           
 java.lang.Object getValidationResult()
          Retrieves the result of the last validation check.
protected  void initializeDefaultTextFieldModel()
           
 void insertString(int index, java.lang.String text, javax.swing.text.AttributeSet ignored)
          Overridden to prevent insertion of invalid characters and mark model as modified.
protected  void invalidInsertionAttempted(char character, int subIndex)
          Called whenever an attempt is made to insert an invalid character.
 boolean isValid()
          Determines whether the model's contents are valid by invoking each of its registered Validators.
 void remove(int index, int length)
          Overridden to mark model as modified.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Unregisters a PropertyChangeListener.
 void removeValiditor(int index)
          Removes the text validator at the specified index from the list of registered validators.
 void removeValiditor(Validator validator)
          Removes the specified text validator from the list of registered validators.
 void rollback()
          Rollsback to the previous value in the model.
 void setInvalidCharacters(java.lang.String invalidCharacters)
          Sets the list of invalid characters that cannot be inserted into this model.
 void setMaximumLength(int length)
           
 void setModified(boolean isModified)
          Sets whether the model is marked as modified.
 void setValid(boolean isValid)
          Sets whether the model's contents are marked as valid.
 void setValidCharacters(java.lang.String validCharacters)
          Sets the list of valid characters that can be inserted into this model.
 
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
 
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTextFieldModel

public DefaultTextFieldModel()
Since:
2.0
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Registers a PropertyChangeListener to be notified of text and validity changes to the model.

Parameters:
listener - A PropertyChangeListener
Since:
2.0

addValidator

public void addValidator(Validator validator)
Adds the specified text validator to the end of the list of registered validators. Validation occurs by iterating through this list, starting with the validator that was registered first and finishing with the most recently registered validator. All validators must return Boolean.TRUE if validation succeeds.

Parameters:
validator - An instance of Validator
Since:
2.0

addValidator

public void addValidator(Validator validator,
                         int index)
Adds the specified text validator to the list of registered validators at the specified index. Validation occurs by iterating through this list, starting with the validator that was registered first and finishing with the most recently registered validator. All validators must return Boolean.TRUE if validation succeeds.

Parameters:
validator - An instance of Validator
index - The index within the validation list that the validator should be added
Since:
2.0

commit

public void commit()
Commits any new text set on the model.

Since:
2.0

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.beans.PropertyChangeEvent event)
Notifies all registered PropertyChangeListeners of a property change.

Since:
2.0

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String prop,
                                       java.lang.String oldText,
                                       java.lang.String newText)
Notifies all registered PropertyChangeListeners of a text change.

Since:
2.0

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String prop,
                                       boolean oldVal,
                                       boolean newVal)
Notifies all registered PropertyChangeListeners of a boolean value (flag) change.

Since:
2.0

firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String prop,
                                       int oldVal,
                                       int newVal)
Notifies all registered PropertyChangeListeners of a integer value change.

Since:
2.0

getMaximumLength

public int getMaximumLength()
Returns:
The maximum length of the text, zero if not set
Since:
2.0

getValidationResult

public java.lang.Object getValidationResult()
Retrieves the result of the last validation check.

Returns:
The result of the last validation check if it failed, null otherwise
Since:
2.0

initializeDefaultTextFieldModel

protected void initializeDefaultTextFieldModel()
Since:
2.0

insertString

public void insertString(int index,
                         java.lang.String text,
                         javax.swing.text.AttributeSet ignored)
                  throws javax.swing.text.BadLocationException
Overridden to prevent insertion of invalid characters and mark model as modified.

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.PlainDocument
Throws:
javax.swing.text.BadLocationException
Since:
2.0

invalidInsertionAttempted

protected void invalidInsertionAttempted(char character,
                                         int subIndex)
Called whenever an attempt is made to insert an invalid character. Just beeps by default.

Parameters:
character - The invalid character for which insertion was attempted
subIndex - The index within the model's text where the insertion was attempted
Since:
2.0

isValid

public boolean isValid()
Determines whether the model's contents are valid by invoking each of its registered Validators.

Returns:
The results of the last validity check if the model hasn't been modified since then, else the results of any registered Validators, else true (meaning no Validators have been registered)
Since:
2.0

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Unregisters a PropertyChangeListener.

Parameters:
listener - A PropertyChangeListener
Since:
2.0

remove

public void remove(int index,
                   int length)
            throws javax.swing.text.BadLocationException
Overridden to mark model as modified.

Specified by:
remove in interface javax.swing.text.Document
Overrides:
remove in class javax.swing.text.AbstractDocument
Throws:
javax.swing.text.BadLocationException
Since:
2.0

removeValiditor

public void removeValiditor(int index)
Removes the text validator at the specified index from the list of registered validators.

Since:
2.0

removeValiditor

public void removeValiditor(Validator validator)
Removes the specified text validator from the list of registered validators.

Since:
2.0

rollback

public void rollback()
              throws javax.swing.text.BadLocationException
Rollsback to the previous value in the model.

Throws:
javax.swing.text.BadLocationException
Since:
2.0

setInvalidCharacters

public void setInvalidCharacters(java.lang.String invalidCharacters)
                          throws java.text.ParseException
Sets the list of invalid characters that cannot be inserted into this model. All characters in the specified string will be added to the list, with the exception of dash ('-') characters, which are used to specify characters ranges (e.g., "A-Z"). To explicitly specify a dash as an invalid character, it must be entered as either the first character in the string (not part of a range) or the final character in any range within the string. Note that "A-Z" specifies a different range than "a-z".

Parameters:
invalidCharacters - A list of invalid characters and/or character ranges
Throws:
java.text.ParseException - If a dash appears at the end of the string
Since:
2.0

setMaximumLength

public void setMaximumLength(int length)
Since:
2.0

setModified

public void setModified(boolean isModified)
Sets whether the model is marked as modified.

Parameters:
isModified - True if the model should be marked as modified
Since:
2.0

setValid

public void setValid(boolean isValid)
Sets whether the model's contents are marked as valid.

Parameters:
isValid - True if the model's contents should be marked as valid
Since:
2.0

setValidCharacters

public void setValidCharacters(java.lang.String validCharacters)
                        throws java.text.ParseException
Sets the list of valid characters that can be inserted into this model. All characters in the specified string will be added to the list, with the exception of dash ('-') characters, which are used to specify characters ranges (e.g., "A-Z"). To explicitly specify a dash as a valid character, it must be entered as either the first character in the string (not part of a range) or the final character in any range within the string. Note that "A-Z" specifies a different range than "a-z".

Parameters:
validCharacters - A list of valid characters and/or character ranges
Throws:
java.text.ParseException - If a dash appears at the end of the string
Since:
2.0


Copyright © 2009. All Rights Reserved.