uic.model
Class UICRestrictedDocument

java.lang.Object
  extended byjavax.swing.text.AbstractDocument
      extended byjavax.swing.text.PlainDocument
          extended byuic.model.UICRestrictedDocument
All Implemented Interfaces:
Document, Serializable

public class UICRestrictedDocument
extends PlainDocument

A document which you can set on things like a JTextField or JTextArea which limits input the specified chars. Example which only takes integers as the argument; all others will be rejected:

tfMxSize = new UICTextField();
      tfMxSize.setDocument(new UICRestrictedDocument(UICRestrictedDocument.ALLOW_ABC));
  
Another example where both integers and alphanumeric (abc as well as ABC) are accepted.
myText = new UICTextField();
      myText.setDocument(new UICRestrictedDocument(
              UICRestrictedDocument.ALLOW_INTEGERS + UICRestrictedDocument.ALLOW_ABC));
  

Since:
1.2
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
 
Field Summary
static int ALLOW_ABC
           
static int ALLOW_ALL
           
static int ALLOW_FILESYSTEM_CHARS
           
static int ALLOW_INTEGERS
           
 
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
UICRestrictedDocument(char[] characters)
           
UICRestrictedDocument(int type)
          Constructor with type of chars allowed.
UICRestrictedDocument(String characters)
           
 
Method Summary
 void addAllowedCharacters(char[] characters)
           
 void addAllowedCharacters(String characters)
           
 int getMaximumAllowedColumns()
           
 void insertString(int offs, String str, AttributeSet a)
          overloaded method to limit the characters the user can add
 void keepDocumentSingleLine(boolean on)
          Setting this boolean to true will convert any '\n' to a space which will then be checked.
 void setMaximumAllowedColumns(int num)
          Set the maximum column size of this document.
 
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

ALLOW_INTEGERS

public static final int ALLOW_INTEGERS
See Also:
Constant Field Values

ALLOW_ABC

public static final int ALLOW_ABC
See Also:
Constant Field Values

ALLOW_ALL

public static final int ALLOW_ALL
See Also:
Constant Field Values

ALLOW_FILESYSTEM_CHARS

public static final int ALLOW_FILESYSTEM_CHARS
See Also:
Constant Field Values
Constructor Detail

UICRestrictedDocument

public UICRestrictedDocument(int type)
Constructor with type of chars allowed.

Parameters:
type - any combination of ALLOW_* integers like found on this class.

UICRestrictedDocument

public UICRestrictedDocument(String characters)

UICRestrictedDocument

public UICRestrictedDocument(char[] characters)
Method Detail

keepDocumentSingleLine

public void keepDocumentSingleLine(boolean on)
Setting this boolean to true will convert any '\n' to a space which will then be checked. If you have a single line document the pasting of an newline character will result in a bad document, or a failure depending on whether the newline character is an allowed character. Both situations are not really wanted; so if you want to paste a multiline text setting this boolean to true will convert newline characters to spaces unconditionally. If you allow spaces in your document the paste will then succeed, resulting in a a single line document.


addAllowedCharacters

public void addAllowedCharacters(String characters)

addAllowedCharacters

public void addAllowedCharacters(char[] characters)

setMaximumAllowedColumns

public void setMaximumAllowedColumns(int num)
Set the maximum column size of this document. Notice that the document will not be changed, only that extra characters will not be allowed above the max.


getMaximumAllowedColumns

public int getMaximumAllowedColumns()

insertString

public void insertString(int offs,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
overloaded method to limit the characters the user can add

Throws:
BadLocationException


Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence