com.isti.util.gui.textvalidator
Class AbstractValidatedDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.isti.util.gui.textvalidator.AbstractValidatedDocument
All Implemented Interfaces:
AllowedCharactersConstants, StringConstants, java.io.Serializable, javax.swing.text.Document
Direct Known Subclasses:
TextValidatorDocument, ValidatedDocument

public abstract class AbstractValidatedDocument
extends javax.swing.text.PlainDocument
implements AllowedCharactersConstants

Class AbstractValidatedDocument is an extension of 'PlainDocument' that implements the validating of input characters.

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.isti.util.StringConstants
ALPHA_CAP_CHARS, ALPHA_CHARS, ALPHA_LOW_CHARS, ALPHANUM_CHARS_STRING, ALPHANUMERIC_CHARS, BOOLEAN_FALSE_TEXT, BOOLEAN_TRUE_TEXT, DATE_FORMAT_AMPM_STR, DATE_FORMAT_RFC_822_STR, DATE_FORMAT24_STR, DEFAULT_JAVA_VERSION_STRING, DEFAULT_NULL_STR, DEFAULT_SEP_STR, EFLOAT_CHARS, EMPTY_STRING, FLOAT_CHARS, HEX_ALPHA_CAP_CHARS, HEX_ALPHA_LOW_CHARS, HEX_CHARS, INTEGER_CHARS, INVALID_FILENAME_CHARS, QUOTE_STRING, SIGNED_EFLOAT_CHARS, SIGNED_FLOAT_CHARS, SIGNED_INT_CHARS, SPACE_STRING, TOD_CHARS, WHITE_SPACE_CHARS, WILDCARD_ALL_CHAR, WILDCARD_CHARS, WILDCARD_SINGLE_CHAR
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
AbstractValidatedDocument()
           
 
Method Summary
abstract  boolean getAllowedFlag()
          Gets the allowed flag.
abstract  int getColumns()
          Gets the number of columns.
abstract  int getMaxNumChars()
          Gets the maximum number of characters.
abstract  java.lang.String getSpecialChars()
          Gets the allowed (or not allowed) special characters.
abstract  TextValidator getTextValidator()
          Returns the text validator.
 void insertString(int insOffs, java.lang.String insStr, javax.swing.text.AttributeSet aSet)
          Inserts data into the document, validating it along the way.
protected  boolean isAllowed(char ch)
          Determines if the character is allowed.
abstract  boolean isNumeric()
          Determines if the characters represent a numeric value.
protected  boolean isReplace()
          Determines if trying to replace characters.
protected static boolean isReplace(java.lang.String specialChars, boolean numericFlag)
          Determines if trying to replace characters.
protected  boolean isSpecialChar(char ch)
          Determines if the character is a special character.
abstract  void setTextValidator(TextValidator tv)
          Sets the text validator.
 
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, remove, 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

AbstractValidatedDocument

public AbstractValidatedDocument()
Method Detail

getAllowedFlag

public abstract boolean getAllowedFlag()
Gets the allowed flag.

Returns:
true to allow only the special characters, false to not allow the special characters.
See Also:
getSpecialChars()

getColumns

public abstract int getColumns()
Gets the number of columns.

Returns:
the number of columns or -1 for the default.

getMaxNumChars

public abstract int getMaxNumChars()
Gets the maximum number of characters.

Returns:
the maximum number of characters or 0 if none.

getSpecialChars

public abstract java.lang.String getSpecialChars()
Gets the allowed (or not allowed) special characters. If there are no special characters then all characters are allowed.

Returns:
the allowed characters or null for none.
See Also:
getAllowedFlag()

getTextValidator

public abstract TextValidator getTextValidator()
Returns the text validator.

Returns:
the text validator or null if none.

insertString

public void insertString(int insOffs,
                         java.lang.String insStr,
                         javax.swing.text.AttributeSet aSet)
                  throws javax.swing.text.BadLocationException
Inserts data into the document, validating it along the way.

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.PlainDocument
Parameters:
insOffs - the starting offset (greater than or equal to zero).
insStr - the string to insert (empty and null strings are ignored).
aSet - the attributes for the inserted content.
Throws:
javax.swing.text.BadLocationException - if the given position is not a valid position within the document.

isAllowed

protected boolean isAllowed(char ch)
Determines if the character is allowed.

Parameters:
ch - the character.
Returns:
true if the character is allowed, false otherwise.

isNumeric

public abstract boolean isNumeric()
Determines if the characters represent a numeric value.

Returns:
true if numeric value, false otherwise

isReplace

protected boolean isReplace()
Determines if trying to replace characters.

Returns:
true if trying to replace characters, false otherwise.

isSpecialChar

protected boolean isSpecialChar(char ch)
Determines if the character is a special character.

Parameters:
ch - the character.
Returns:
true if the character is a special character, false otherwise.

setTextValidator

public abstract void setTextValidator(TextValidator tv)
Sets the text validator.

Parameters:
tv - the text validator or null if none.

isReplace

protected static boolean isReplace(java.lang.String specialChars,
                                   boolean numericFlag)
Determines if trying to replace characters.

Parameters:
specialChars - a String of characters allowed (or not) into the document.
numericFlag - true for valid numeric only, false otherwise.
Returns:
true if trying to replace characters, false otherwise.