Package gr.zeus.ui.typesafe
Class TypeSafeTextDocumentFilter
java.lang.Object
javax.swing.text.DocumentFilter
gr.zeus.ui.typesafe.TypeSafeTextDocumentFilter
This class creates a custom filter for JTextComponents by extending the
DocumentFilter. With this filter we achieve the following data validation
within a field:
max characters
uppercase/lowercase or not
valid characters
invalid characters
replaceable/replaced character pairs
- Since:
- 1.20
- Author:
- Gregory Kotsaftis
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.text.DocumentFilter
DocumentFilter.FilterBypass -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets invalid characters.booleanGets lowercase flag.intGets max characters allowed.Gets the replacable characters.Gets the replaced characters.booleanGets uppercase flag.Gets valid characters.voidinsertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attrs) Invoked prior to insertion of text into the specified Document.voidremove(DocumentFilter.FilterBypass fb, int offset, int length) Invoked prior to removal of the specified region in the specified Document.voidreplace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) Invoked prior to replacing a region of text in the specified Document.voidsetInvalidChars(String all) Sets invalid characters.voidsetLowerCase(boolean f) Sets lowercase flag.voidsetMaxChars(int num) Sets max characters allowed.voidsetReplacableChars(String all) Sets replacable characters.voidsetReplacedChars(String all) Sets replaced characters.voidsetUpperCase(boolean f) Sets uppercase flag.voidsetValidChars(String all) Sets valid characters.
-
Field Details
-
DEFAULT_MAXCHARS
public static final int DEFAULT_MAXCHARS- See Also:
-
-
Constructor Details
-
TypeSafeTextDocumentFilter
public TypeSafeTextDocumentFilter()Constructor.
-
-
Method Details
-
insertString
public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attrs) throws BadLocationException Invoked prior to insertion of text into the specified Document.- Overrides:
insertStringin classDocumentFilter- Parameters:
fb- The FilterBypass.offset- The offset.text- The text to insert.attrs- The AttributeSet.- Throws:
BadLocationException
-
remove
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException Invoked prior to removal of the specified region in the specified Document.- Overrides:
removein classDocumentFilter- Parameters:
fb- The FilterBypass.offset- The offset.length- The length to remove.- Throws:
BadLocationException
-
replace
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException Invoked prior to replacing a region of text in the specified Document.- Overrides:
replacein classDocumentFilter- Parameters:
fb- The FilterBypass.offset- The offset.length- The length of the text.text- The text to replace.attrs- The AttributeSet.- Throws:
BadLocationException
-
getUpperCase
public boolean getUpperCase()Gets uppercase flag.- Returns:
- true/false.
-
setUpperCase
public void setUpperCase(boolean f) Sets uppercase flag.- Parameters:
f- true/false.
-
getLowerCase
public boolean getLowerCase()Gets lowercase flag.- Returns:
- true/false.
-
setLowerCase
public void setLowerCase(boolean f) Sets lowercase flag.- Parameters:
f- true/false.
-
getMaxChars
public int getMaxChars()Gets max characters allowed.- Returns:
- maxChars.
-
setMaxChars
public void setMaxChars(int num) Sets max characters allowed.- Parameters:
num- maxChars.
-
getValidChars
Gets valid characters.- Returns:
- validChars.
-
setValidChars
Sets valid characters.- Parameters:
all- validChars.
-
getInvalidChars
Gets invalid characters.- Returns:
- invalidChars.
-
setInvalidChars
Sets invalid characters.- Parameters:
all- invalidChars.
-
getReplacableChars
Gets the replacable characters. Must be used in conjuction with replaced characters.- Returns:
- replacableChars.
-
setReplacableChars
Sets replacable characters. Must be used in conjuction with replaced characters.- Parameters:
all- replacableChars.
-
getReplacedChars
Gets the replaced characters. Must be used in conjuction with replacable characters.- Returns:
- replacedChars.
-
setReplacedChars
Sets replaced characters. Must be used in conjuction with replacable characters.- Parameters:
all- replacedChars.
-