Class TypeSafeTextDocumentFilter

java.lang.Object
javax.swing.text.DocumentFilter
gr.zeus.ui.typesafe.TypeSafeTextDocumentFilter

public final class TypeSafeTextDocumentFilter extends DocumentFilter
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
    • Field Details

    • 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 class DocumentFilter
        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 class DocumentFilter
        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 class DocumentFilter
        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

        public String getValidChars()
        Gets valid characters.

        Returns:
        validChars.
      • setValidChars

        public void setValidChars(String all)
        Sets valid characters.

        Parameters:
        all - validChars.
      • getInvalidChars

        public String getInvalidChars()
        Gets invalid characters.

        Returns:
        invalidChars.
      • setInvalidChars

        public void setInvalidChars(String all)
        Sets invalid characters.

        Parameters:
        all - invalidChars.
      • getReplacableChars

        public String getReplacableChars()
        Gets the replacable characters. Must be used in conjuction with replaced characters.

        Returns:
        replacableChars.
      • setReplacableChars

        public void setReplacableChars(String all)
        Sets replacable characters. Must be used in conjuction with replaced characters.

        Parameters:
        all - replacableChars.
      • getReplacedChars

        public String getReplacedChars()
        Gets the replaced characters. Must be used in conjuction with replacable characters.

        Returns:
        replacedChars.
      • setReplacedChars

        public void setReplacedChars(String all)
        Sets replaced characters. Must be used in conjuction with replacable characters.

        Parameters:
        all - replacedChars.