gov.sns.tools.swing.patternfilter
Class PatternEventPoster

java.lang.Object
  |
  +--gov.sns.tools.swing.patternfilter.PatternEventPoster

public class PatternEventPoster
extends java.lang.Object

PatternEventPoster is a tool for monitoring text changes in a javax.swing.Document, constructing a pattern from the text and then posting the pattern for use in filtering items by name. Most often this will be used to monitor a text field and generate a pattern filter based on the user's input. The pattern filter may be used to filter a JList or JTable or other list of named items in real time.


Nested Class Summary
protected  class PatternEventPoster.DocumentHandler
          Internal class for monitoring a document's text and handling the events by updating the text which forces an update of the pattern filter.
 
Field Summary
protected  javax.swing.text.Document _document
           
protected  PatternEventPoster.DocumentHandler _documentHandler
           
protected  MessageCenter _messageCenter
           
protected  java.util.regex.Pattern _pattern
           
protected  int _patternFlags
           
protected  PatternGenerator _patternGenerator
           
protected  PatternChangeListener _proxy
           
protected  boolean _queueExists
           
protected  java.lang.String _queueText
           
protected  Lock PROCESS_LOCK
           
protected  java.lang.Object QUEUE_LOCK
           
 
Constructor Summary
PatternEventPoster(javax.swing.text.Document document)
          Constructor which uses the pattern generator for checking if the matching text is contained in the items.
PatternEventPoster(javax.swing.text.Document document, boolean caseSensitive)
          Constructor which uses the pattern generator for checking if the matching text is contained in the items.
PatternEventPoster(javax.swing.text.Document document, int patternFlags)
          Constructor which uses the pattern generator for checking if the matching text is contained in the items.
PatternEventPoster(javax.swing.text.Document document, PatternGenerator patternGenerator, boolean caseSensitive)
          Constructor which uses the pattern generator for checking if the matching text is contained in the items.
PatternEventPoster(javax.swing.text.Document document, PatternGenerator patternGenerator, int patternFlags)
          Primary constructor
 
Method Summary
 void addPatternChangeListener(PatternChangeListener listener)
          Add a listener of pattern change events
protected  java.lang.String getDocumentText()
          Get the text from the monitored document.
 java.util.regex.Pattern getPattern()
          Get the pattern
 void removePatternChangeListener(PatternChangeListener listener)
          Remove a listener of pattern change events
protected  void setDocument(javax.swing.text.Document document)
          Set the document to monitor for the text that generates the pattern filters.
protected  void updatePattern()
          Update the pattern based on the latest document text and post the pattern change event to the listeners.
protected  void updateText()
          Update the text from the monitored document and then update the pattern accordingly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_messageCenter

protected MessageCenter _messageCenter

_proxy

protected PatternChangeListener _proxy

QUEUE_LOCK

protected final java.lang.Object QUEUE_LOCK

PROCESS_LOCK

protected final Lock PROCESS_LOCK

_queueText

protected volatile java.lang.String _queueText

_queueExists

protected volatile boolean _queueExists

_documentHandler

protected PatternEventPoster.DocumentHandler _documentHandler

_document

protected javax.swing.text.Document _document

_pattern

protected volatile java.util.regex.Pattern _pattern

_patternGenerator

protected PatternGenerator _patternGenerator

_patternFlags

protected int _patternFlags
Constructor Detail

PatternEventPoster

public PatternEventPoster(javax.swing.text.Document document,
                          PatternGenerator patternGenerator,
                          int patternFlags)
Primary constructor

Parameters:
document - The document to monitor for text changes
patternGenerator - the generator used to convert the document text to a pattern
patternFlags - the pattern flags used to compile a pattern using Pattern.compile()
See Also:
Pattern

PatternEventPoster

public PatternEventPoster(javax.swing.text.Document document,
                          int patternFlags)
Constructor which uses the pattern generator for checking if the matching text is contained in the items.

Parameters:
document - The document to monitor for text changes
patternFlags - the pattern flags used to compile a pattern using Pattern.compile()

PatternEventPoster

public PatternEventPoster(javax.swing.text.Document document,
                          boolean caseSensitive)
Constructor which uses the pattern generator for checking if the matching text is contained in the items. The pattern flags are set to zero, but the case sensitivity flag is specified using the boolean flag.

Parameters:
document - The document to monitor for text changes
caseSensitive - true to enforce case sensitive matching and false to ignore it

PatternEventPoster

public PatternEventPoster(javax.swing.text.Document document,
                          PatternGenerator patternGenerator,
                          boolean caseSensitive)
Constructor which uses the pattern generator for checking if the matching text is contained in the items. The pattern flags are set to zero, but the case sensitivity flag is specified using the boolean flag.

Parameters:
document - The document to monitor for text changes
patternGenerator - the generator used to convert the document text to a pattern
caseSensitive - true to enforce case sensitive matching and false to ignore it

PatternEventPoster

public PatternEventPoster(javax.swing.text.Document document)
Constructor which uses the pattern generator for checking if the matching text is contained in the items. The pattern flags are set to zero.

Parameters:
document - The document to monitor for text changes
Method Detail

addPatternChangeListener

public void addPatternChangeListener(PatternChangeListener listener)
Add a listener of pattern change events

Parameters:
listener - the listener to add for receiving pattern change events

removePatternChangeListener

public void removePatternChangeListener(PatternChangeListener listener)
Remove a listener of pattern change events

Parameters:
listener - the listener to remove from receiving pattern change events

getPattern

public java.util.regex.Pattern getPattern()
Get the pattern

Returns:
the pattern based on the present text in the monitored document

updatePattern

protected void updatePattern()
Update the pattern based on the latest document text and post the pattern change event to the listeners.


updateText

protected void updateText()
Update the text from the monitored document and then update the pattern accordingly


getDocumentText

protected java.lang.String getDocumentText()
Get the text from the monitored document.

Returns:
the text from the monitored document.

setDocument

protected void setDocument(javax.swing.text.Document document)
Set the document to monitor for the text that generates the pattern filters.

Parameters:
document - the new document to monitor for text patterns