bill.util.gui
Class JTextFieldFilterDocument
java.lang.Object
|
+--javax.swing.text.AbstractDocument
|
+--javax.swing.text.PlainDocument
|
+--bill.util.gui.JTextFieldMaxCharsDocument
|
+--bill.util.gui.JTextFieldFilterDocument
- All Implemented Interfaces:
- Document, Serializable
- public class JTextFieldFilterDocument
- extends JTextFieldMaxCharsDocument
This class is a special subclass of the JTextFieldMaxCharsDocument
class. It checks to make sure characters being inserted into the
document (and therefor the text field) are contained in the filter string.
If we are using the class in include mode and they are not, they are
discarded. If we are using the class in exclude mode and they are, they
are discarded.
- See Also:
- Serialized Form
Method Summary |
String |
getFilter()
Retrieves the current filter string value. |
void |
insertString(int offs,
String str,
AttributeSet a)
Called when a character (or characters) are added to the
document. |
boolean |
isInclude()
Retrieves the include mode for this instance. |
void |
setFilter(String filter)
Sets the filter string to the specified value. |
void |
setInclude(boolean include)
Sets the include mode of the filter. |
Methods inherited from class javax.swing.text.AbstractDocument |
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentProperties, writeLock, writeUnlock |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JTextFieldFilterDocument
public JTextFieldFilterDocument(JTextFieldFilterInterface textField)
- Creates a new class instance with the specified filter that uses
include mode and limits the number of characters entered.
- Parameters:
textField
- The text field that we are putting the filter on.
setFilter
public void setFilter(String filter)
- Sets the filter string to the specified value. We do not allow the
filter to be set to
null
so if the user passes this
in we set the filter to an empty string.
- Parameters:
filter
- String to set the filter to.
getFilter
public String getFilter()
- Retrieves the current filter string value.
- Returns:
- The filter string value.
setInclude
public void setInclude(boolean include)
- Sets the include mode of the filter. If the include mode is
true
then characters entered that are in the filter string
are kept and others are dropped, if false
then vice
versa.
- Parameters:
include
- Value to set include mode to.
isInclude
public boolean isInclude()
- Retrieves the include mode for this instance.
- Returns:
true
if we are using include mode, false
if we are using exclude mode.
insertString
public void insertString(int offs,
String str,
AttributeSet a)
throws BadLocationException
- Called when a character (or characters) are added to the
document. Applies the filter criteria and updates the document
as appropriate.
- Overrides:
insertString
in class JTextFieldMaxCharsDocument
- Parameters:
offs
- The starting offset to insert at (>=0).str
- The string to insert, does nothing with null/empty strings.a
- The attributes for the inserted content.