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.boolean
Gets lowercase flag.int
Gets max characters allowed.Gets the replacable characters.Gets the replaced characters.boolean
Gets uppercase flag.Gets valid characters.void
insertString
(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attrs) Invoked prior to insertion of text into the specified Document.void
remove
(DocumentFilter.FilterBypass fb, int offset, int length) Invoked prior to removal of the specified region in the specified Document.void
replace
(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) Invoked prior to replacing a region of text in the specified Document.void
setInvalidChars
(String all) Sets invalid characters.void
setLowerCase
(boolean f) Sets lowercase flag.void
setMaxChars
(int num) Sets max characters allowed.void
setReplacableChars
(String all) Sets replacable characters.void
setReplacedChars
(String all) Sets replaced characters.void
setUpperCase
(boolean f) Sets uppercase flag.void
setValidChars
(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:
insertString
in 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:
remove
in 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:
replace
in 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.
-