com.sdm.quasar.client.swing.ui.text
Class RestrictionDocument

java.lang.Object
  extended byjavax.swing.text.AbstractDocument
      extended byjavax.swing.text.PlainDocument
          extended bycom.sdm.quasar.client.swing.ui.text.RestrictionDocument
All Implemented Interfaces:
javax.swing.text.Document, java.io.Serializable

public class RestrictionDocument
extends javax.swing.text.PlainDocument

A Document for multi-line text. The number of lines and the length of each line as well as the total text length can be restricted. Additionally there can be specified, which characters can be entered into this document and which characters are used when counting the length.

Author:
Thomas Wolf
See Also:
Serialized Form

Nested Class Summary
static interface RestrictionDocument.FixedLengthListener
          A listener interface for FixedLengthDocuments.
 
Nested classes 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 ASCII_LETTER_NOSPACE_PATTERN
          Pattern with all ascii-characters (without space) without special characters.
static java.lang.String ASCII_LETTER_PATTERN
          Pattern with all ascii-characters (and the space) without special characters.
static java.lang.String ASCII_LOWER_LETTER
          Pattern with all lower ascii-characters without special characters.
static java.lang.String ASCII_UPPER_LETTER
          Pattern with all upper ascii-characters without special characters.
static int CASEMODE_LOWER
          Convert to lowercase.
static int CASEMODE_ORIGINAL
          Leave the original case as it is.
static int CASEMODE_UPPER
          Convert to uppercase.
static java.lang.String DIGIT_LETTER_PATTERN
          Pattern with all decimal digits and all unicode letters.
static java.lang.String DIGIT_PATTERN
          Pattern with all decimal digits.
static java.lang.String FOREIGN_KEY_PATTERN
          Pattern with all valid characters for foreign keys.
static java.lang.String LETTER_PATTERN
          Pattern with all unicode letters.
static java.lang.String NUMBER_PATTERN
          Pattern with all decimal digits plus characters for number representation ('+','-','.',',').
static int UNRESTRICTED_LINE_LENGTH
          Special value for the line length, indicating to not enforce any restrictions.
static int UNRESTRICTED_LINE_NUMBER
          Special value for the line number, indicating to not enforce any restrictions.
static int UNRESTRICTED_TOTAL_LENGTH
          Special value for the total length, indicating to not enforce any restrictions.
 
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
RestrictionDocument()
          Creates a new RestrictionDocument without restrictions.
RestrictionDocument(int max_length)
          Creates a new RestrictionDocument
RestrictionDocument(int max_length, int max_line_number, int max_line_length)
          Creates a new RestrictionDocument
RestrictionDocument(int max_length, int max_line_number, int max_line_length, java.lang.String validCharacters)
          Creates a new RestrictionDocument
RestrictionDocument(int max_length, java.lang.String validCharacters)
          Creates a new RestrictionDocument
RestrictionDocument(int max_length, java.lang.String validCharacters, int caseMode)
          Creates a new RestrictionDocument
 
Method Summary
 void addFixedLenghtListener(RestrictionDocument.FixedLengthListener listener)
          Adds a new RestrictionDocument.FixedLengthListener to this RestrictionDocument.
protected  void fireCutOff(java.lang.String cut_off)
          Notifies registered listeners, that the given string was cut-off.
 int getCaseMode()
          Returns the int.
 java.lang.String getCountCharacters()
           
protected  int getCountLength(java.lang.String s)
          Returns the length of the string as returned by the count filter.
 int getFilteredLength()
          Returns the number of the count-filtered characters (see #setCountFilter(CharacterFilter)).
 int getMaxLength()
          Returns the maximum length (number of characters) of this document.
 int getMaxLineLength()
          Returns the maxmimum length of each line
 int getMaxLineNumber()
          Returns the maximum number of lines
 java.lang.String getValidCharacters()
           
 void insertString(int offset, java.lang.String s, javax.swing.text.AttributeSet attributeSet)
          Inserts a string of content.
 boolean isBeepOnError()
          Shall errors be reported by a beep sound?
protected static int occurrencesOf(java.lang.String wholeString, java.lang.String searchString)
          How often does the search string occur in the whole string?
 void removeFixedLenghtListener(RestrictionDocument.FixedLengthListener listener)
          Removes a previously added RestrictionDocument.FixedLengthListener from this RestrictionDocument.
 void setBeepOnError(boolean beepOnError)
          Beep on invalid input.
 void setCaseMode(int caseMode)
          Sets the case mode to the given value.
 void setCountCharacters(java.lang.String countCharacters)
          Sets the valid characters for counting the maximum length.
 void setMaxLength(int new_max_length)
          Sets the maximum length (number of characters) of this document.
 void setMaxLineLength(int lineLength)
          Sets the maxmimum length of each line
 void setMaxLineNumber(int lineNumber)
          Sets the maximum number of lines
 void setValidCharacters(java.lang.String validCharacters)
          Sets the CharacterFilter, which accepts characters.
 
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, remove, 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

DIGIT_PATTERN

public static final java.lang.String DIGIT_PATTERN
Pattern with all decimal digits.

See Also:
Constant Field Values

ASCII_UPPER_LETTER

public static final java.lang.String ASCII_UPPER_LETTER
Pattern with all upper ascii-characters without special characters.

See Also:
Constant Field Values

ASCII_LOWER_LETTER

public static final java.lang.String ASCII_LOWER_LETTER
Pattern with all lower ascii-characters without special characters.

See Also:
Constant Field Values

ASCII_LETTER_NOSPACE_PATTERN

public static final java.lang.String ASCII_LETTER_NOSPACE_PATTERN
Pattern with all ascii-characters (without space) without special characters.

See Also:
Constant Field Values

ASCII_LETTER_PATTERN

public static final java.lang.String ASCII_LETTER_PATTERN
Pattern with all ascii-characters (and the space) without special characters.

See Also:
Constant Field Values

LETTER_PATTERN

public static final java.lang.String LETTER_PATTERN
Pattern with all unicode letters.

See Also:
Constant Field Values

DIGIT_LETTER_PATTERN

public static final java.lang.String DIGIT_LETTER_PATTERN
Pattern with all decimal digits and all unicode letters.

See Also:
Constant Field Values

NUMBER_PATTERN

public static final java.lang.String NUMBER_PATTERN
Pattern with all decimal digits plus characters for number representation ('+','-','.',',').

See Also:
Constant Field Values

FOREIGN_KEY_PATTERN

public static final java.lang.String FOREIGN_KEY_PATTERN
Pattern with all valid characters for foreign keys.

See Also:
Constant Field Values

CASEMODE_ORIGINAL

public static final int CASEMODE_ORIGINAL
Leave the original case as it is.

See Also:
Constant Field Values

CASEMODE_UPPER

public static final int CASEMODE_UPPER
Convert to uppercase.

See Also:
Constant Field Values

CASEMODE_LOWER

public static final int CASEMODE_LOWER
Convert to lowercase.

See Also:
Constant Field Values

UNRESTRICTED_TOTAL_LENGTH

public static final int UNRESTRICTED_TOTAL_LENGTH
Special value for the total length, indicating to not enforce any restrictions.

See Also:
Constant Field Values

UNRESTRICTED_LINE_LENGTH

public static final int UNRESTRICTED_LINE_LENGTH
Special value for the line length, indicating to not enforce any restrictions.

See Also:
Constant Field Values

UNRESTRICTED_LINE_NUMBER

public static final int UNRESTRICTED_LINE_NUMBER
Special value for the line number, indicating to not enforce any restrictions.

See Also:
Constant Field Values
Constructor Detail

RestrictionDocument

public RestrictionDocument()
Creates a new RestrictionDocument without restrictions.


RestrictionDocument

public RestrictionDocument(int max_length)
Creates a new RestrictionDocument

Parameters:
max_length - the maximum total length of the contents

RestrictionDocument

public RestrictionDocument(int max_length,
                           java.lang.String validCharacters)
Creates a new RestrictionDocument

Parameters:
max_length - the maximum total length of the contents
validCharacters - the valid characters accepted

RestrictionDocument

public RestrictionDocument(int max_length,
                           java.lang.String validCharacters,
                           int caseMode)
Creates a new RestrictionDocument

Parameters:
max_length - the maximum total length of the contents
validCharacters - the valid characters accepted
caseMode - the case mode to set (one of CASEMODE_ORIGINAL, CASEMODE_LOWER or CASEMODE_UPPER).

RestrictionDocument

public RestrictionDocument(int max_length,
                           int max_line_number,
                           int max_line_length)
Creates a new RestrictionDocument

Parameters:
max_length - the maximum total length of the contents
max_line_number - the maximum number of lines
max_line_length - the maximum length of each line

RestrictionDocument

public RestrictionDocument(int max_length,
                           int max_line_number,
                           int max_line_length,
                           java.lang.String validCharacters)
Creates a new RestrictionDocument

Parameters:
max_length - the maximum total length of the contents
max_line_number - the maximum number of lines
max_line_length - the maximum length of each line
validCharacters - the valid characters accepted
Method Detail

setBeepOnError

public void setBeepOnError(boolean beepOnError)
Beep on invalid input. This is the default behaviour.


isBeepOnError

public boolean isBeepOnError()
Shall errors be reported by a beep sound?

Returns:
true if errors are reported acustically

getCountCharacters

public java.lang.String getCountCharacters()
Returns:
the valid characters used to count the length.

getValidCharacters

public java.lang.String getValidCharacters()
Returns:
the characters accepted by this document.

setCountCharacters

public void setCountCharacters(java.lang.String countCharacters)
Sets the valid characters for counting the maximum length.

Parameters:
countCharacters - the characters used to count the length.

setValidCharacters

public void setValidCharacters(java.lang.String validCharacters)
Sets the CharacterFilter, which accepts characters.


getCaseMode

public int getCaseMode()
Returns the int.


setCaseMode

public void setCaseMode(int caseMode)
Sets the case mode to the given value.

Parameters:
caseMode - the case mode to set (one of CASEMODE_ORIGINAL, CASEMODE_LOWER or CASEMODE_UPPER).

getMaxLength

public int getMaxLength()
Returns the maximum length (number of characters) of this document. If a count filter is set, this length specifies the maximum number of valid characters, otherwise the total number of characters is used.

Returns:
the maximum length (number of characters) of this document

getMaxLineLength

public int getMaxLineLength()
Returns the maxmimum length of each line

Returns:
The maxmimum length of each line

getMaxLineNumber

public int getMaxLineNumber()
Returns the maximum number of lines

Returns:
The maximum number of lines

setMaxLength

public void setMaxLength(int new_max_length)
Sets the maximum length (number of characters) of this document. If a count filter is set, this length specifies the maximum number of valid characters, otherwise the total number of characters is used.

Parameters:
new_max_length - the maximum length (number of characters) of this document.

setMaxLineLength

public void setMaxLineLength(int lineLength)
Sets the maxmimum length of each line

Parameters:
lineLength - The maxmimum length of each line

setMaxLineNumber

public void setMaxLineNumber(int lineNumber)
Sets the maximum number of lines

Parameters:
lineNumber - The maximum number of lines

getCountLength

protected int getCountLength(java.lang.String s)
Returns the length of the string as returned by the count filter.

Returns:
the string length

getFilteredLength

public int getFilteredLength()
Returns the number of the count-filtered characters (see #setCountFilter(CharacterFilter)).

Returns:
the number of the count-filtered characters.

insertString

public void insertString(int offset,
                         java.lang.String s,
                         javax.swing.text.AttributeSet attributeSet)
                  throws javax.swing.text.BadLocationException
Inserts a string of content.

Parameters:
offset - the offset into the document to insert the content >= 0. All positions that track change at or after the given location will move.
Throws:
javax.swing.text.BadLocationException

occurrencesOf

protected static int occurrencesOf(java.lang.String wholeString,
                                   java.lang.String searchString)
How often does the search string occur in the whole string?

Parameters:
wholeString - The string that may contain the search string
searchString - The string to be searched for

addFixedLenghtListener

public void addFixedLenghtListener(RestrictionDocument.FixedLengthListener listener)
Adds a new RestrictionDocument.FixedLengthListener to this RestrictionDocument.

Parameters:
listener - the RestrictionDocument.FixedLengthListener to add

removeFixedLenghtListener

public void removeFixedLenghtListener(RestrictionDocument.FixedLengthListener listener)
Removes a previously added RestrictionDocument.FixedLengthListener from this RestrictionDocument.

Parameters:
listener - the RestrictionDocument.FixedLengthListener to remove

fireCutOff

protected void fireCutOff(java.lang.String cut_off)
Notifies registered listeners, that the given string was cut-off.

Parameters:
cut_off - the string that was cut-off