|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
org.lyra.Widgets.RegexConstrainedDocument
public class RegexConstrainedDocument
A method for preventing unwanted information from making its way into past the initial user interface. This will permit ports to remain numeric, domains to match a specific structure and so forth.
An example for the use of this document constraint is as follows:
RegexConstrainedDocument doc = new RegexConstrainedDocument("^[\\w-. ]{0,45}$");
JTextField fieldName = new JTextField(doc, "", 45);
As shown above a new constraint document will be created enforcing with length
of the string allowed as well as the characters supported. In this case
[A-Z],[a-z],[0-9],[space],[.],[-] are the characters that will be allowed for
this filter.
Nested Class Summary |
---|
Nested classes/interfaces 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 | |
---|---|
private java.util.regex.Matcher |
myMatch
|
private java.util.regex.Pattern |
myPattern
|
private static long |
serialVersionUID
|
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 | |
---|---|
RegexConstrainedDocument()
Most basic constructor for the class. |
|
RegexConstrainedDocument(javax.swing.text.AbstractDocument.Content c)
Constructor which can provide a document to create the initial data set. |
|
RegexConstrainedDocument(javax.swing.text.AbstractDocument.Content c,
java.lang.String p)
Constructor which can provide a document to create the initial data set for the document. |
|
RegexConstrainedDocument(java.lang.String p)
Constructor to create an empty document with an associated pattern. |
Method Summary | |
---|---|
java.util.regex.Pattern |
getPattern()
Returns the current pattern. |
void |
insertString(int offs,
java.lang.String s,
javax.swing.text.AttributeSet a)
|
void |
setPatternByString(java.lang.String p)
Method used to inject a regular expression into the Constrained Document which will also confirm that the document currently matches that data set. |
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 |
---|
private static final long serialVersionUID
private java.util.regex.Pattern myPattern
private java.util.regex.Matcher myMatch
Constructor Detail |
---|
public RegexConstrainedDocument()
public RegexConstrainedDocument(javax.swing.text.AbstractDocument.Content c)
c
- Content of an existing document to make use of here.public RegexConstrainedDocument(javax.swing.text.AbstractDocument.Content c, java.lang.String p)
c
- Content of an existing document to make use of here.p
- String containing regular expression pattern.public RegexConstrainedDocument(java.lang.String p)
p
- String containing regular expression pattern.Method Detail |
---|
public void setPatternByString(java.lang.String p)
p
- String containing regular expression pattern.public java.util.regex.Pattern getPattern()
public void insertString(int offs, java.lang.String s, javax.swing.text.AttributeSet a) throws javax.swing.text.BadLocationException
insertString
in interface javax.swing.text.Document
insertString
in class javax.swing.text.PlainDocument
javax.swing.text.BadLocationException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |