com.isti.util.gui
Class TimeFilteredDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.PlainDocument
          extended by com.isti.util.gui.TimeFilteredDocument
All Implemented Interfaces:
java.io.Serializable, javax.swing.text.Document

 class TimeFilteredDocument
extends javax.swing.text.PlainDocument

Class TimeFilteredDocument is an extension of 'PlainDocument' that implements the filtering of input characters.


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
static java.lang.String[] ALLOWED_CHARS
           
static java.lang.String HOURS_FIRST_DIGITS
           
static java.lang.String MINS_SECS_FIRST_DIGITS
           
static java.lang.String TIME_DIGITS
           
 
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 javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
TimeFilteredDocument(TimeJTextField textField, int maxNumChars)
          Constructs a plain text document.
 
Method Summary
 TimeJTextField getTextField()
          Gets the text field for this document.
protected  int insertChar(int offs, char ch)
          Inserts a character into the document.
 void insertString(int offs, java.lang.String str, javax.swing.text.AttributeSet aSet)
          Inserts data into the document, filtering it along the way.
protected static boolean isValidChar(int offs, char ch)
          Determines if the character is valid for the specified position.
protected  boolean isValidStr(int offs, java.lang.String str)
          Determines if the string is valid for the specified position.
 void remove(int offs, int len)
          Removes some content from the document.
protected  int removeChar(int offs)
          Remove the character from the document.
 
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
 

Field Detail

TIME_DIGITS

public static final java.lang.String TIME_DIGITS
See Also:
Constant Field Values

HOURS_FIRST_DIGITS

public static final java.lang.String HOURS_FIRST_DIGITS

MINS_SECS_FIRST_DIGITS

public static final java.lang.String MINS_SECS_FIRST_DIGITS

ALLOWED_CHARS

public static final java.lang.String[] ALLOWED_CHARS
Constructor Detail

TimeFilteredDocument

public TimeFilteredDocument(TimeJTextField textField,
                            int maxNumChars)
Constructs a plain text document.

Parameters:
textField - the text field for the document.
maxNumChars - the maximum number of characters.
Method Detail

insertChar

protected int insertChar(int offs,
                         char ch)
                  throws javax.swing.text.BadLocationException
Inserts a character into the document.

Parameters:
offs - the offset.
ch - the character to insert.
Returns:
the next offset or -1 if the character was not added.
Throws:
javax.swing.text.BadLocationException - if the given position is not a valid position within the document.

isValidChar

protected static boolean isValidChar(int offs,
                                     char ch)
Determines if the character is valid for the specified position.

Parameters:
offs - the offset.
ch - the character to insert.
Returns:
true if the character is valid.

isValidStr

protected boolean isValidStr(int offs,
                             java.lang.String str)
Determines if the string is valid for the specified position.

Parameters:
offs - the offset.
str - the string to insert.
Returns:
true if the string is valid.

removeChar

protected int removeChar(int offs)
                  throws javax.swing.text.BadLocationException
Remove the character from the document.

Parameters:
offs - the offset.
Returns:
the next offset or -1 if the character was not removed.
Throws:
javax.swing.text.BadLocationException - if the given position is not a valid position within the document.

getTextField

public TimeJTextField getTextField()
Gets the text field for this document.

Returns:
the text field for this document.

insertString

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

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.PlainDocument
Parameters:
offs - the starting offset (greater than or equal to zero).
str - 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.

remove

public void remove(int offs,
                   int len)
            throws javax.swing.text.BadLocationException
Removes some content from the document. Removing content causes a write lock to be held while the actual changes are taking place. Observers are notified of the change on the thread that called this method.

Specified by:
remove in interface javax.swing.text.Document
Overrides:
remove in class javax.swing.text.AbstractDocument
Parameters:
offs - the starting offset >= 0
len - the number of characters to remove >= 0
Throws:
javax.swing.text.BadLocationException - the given remove position is not a valid position within the document