swingx
Version 2009-07-31

org.jdesktop.swingx.autocomplete
Class AutoCompleteDocument

java.lang.Object
  extended by org.jdesktop.swingx.autocomplete.AutoCompleteDocument
All Implemented Interfaces:
Document
Direct Known Subclasses:
AutoCompleteStyledDocument

public class AutoCompleteDocument
extends Object
implements Document

A document that can be plugged into any JTextComponent to enable automatic completion. It finds and selects matching items using any implementation of the AbstractAutoCompleteAdaptor.


Field Summary
protected  Document delegate
           
protected  boolean strictMatching
          true, if only items from the adaptors's list can be entered false, otherwise (selected item might not be in the adaptors's list)
 
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
 
Constructor Summary
AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching)
          Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.
AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching, ObjectToStringConverter stringConverter)
          Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.
AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor, boolean strictMatching, ObjectToStringConverter stringConverter, Document delegate)
          Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.
 
Method Summary
 void addDocumentListener(DocumentListener listener)
          
 void addUndoableEditListener(UndoableEditListener listener)
          
protected  Document createDefaultDocument()
          Creates the default backing document when no delegate is passed to this document.
 Position createPosition(int offs)
          
 Element getDefaultRootElement()
          
 Position getEndPosition()
          
 int getLength()
          
 Object getProperty(Object key)
          
 Element[] getRootElements()
          
 Position getStartPosition()
          
 String getText(int offset, int length)
          
 void getText(int offset, int length, Segment txt)
          
 void insertString(int offs, String str, AttributeSet a)
           
 boolean isStrictMatching()
          Returns if only items from the adaptor's list should be allowed to be entered.
 void putProperty(Object key, Object value)
          
 void remove(int offs, int len)
           
 void removeDocumentListener(DocumentListener listener)
          
 void removeUndoableEditListener(UndoableEditListener listener)
          
 void render(Runnable r)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strictMatching

protected boolean strictMatching
true, if only items from the adaptors's list can be entered false, otherwise (selected item might not be in the adaptors's list)


delegate

protected final Document delegate
Constructor Detail

AutoCompleteDocument

public AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor,
                            boolean strictMatching,
                            ObjectToStringConverter stringConverter,
                            Document delegate)
Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.

Parameters:
adaptor - The adaptor that will be used to find and select matching items.
strictMatching - true, if only items from the adaptor's list should be allowed to be entered
stringConverter - the converter used to transform items to strings
delegate - the Document delegate backing this document

AutoCompleteDocument

public AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor,
                            boolean strictMatching,
                            ObjectToStringConverter stringConverter)
Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.

Parameters:
adaptor - The adaptor that will be used to find and select matching items.
strictMatching - true, if only items from the adaptor's list should be allowed to be entered
stringConverter - the converter used to transform items to strings

AutoCompleteDocument

public AutoCompleteDocument(AbstractAutoCompleteAdaptor adaptor,
                            boolean strictMatching)
Creates a new AutoCompleteDocument for the given AbstractAutoCompleteAdaptor.

Parameters:
strictMatching - true, if only items from the adaptor's list should be allowed to be entered
adaptor - The adaptor that will be used to find and select matching items.
Method Detail

createDefaultDocument

protected Document createDefaultDocument()
Creates the default backing document when no delegate is passed to this document.

Returns:
the default backing document

remove

public void remove(int offs,
                   int len)
            throws BadLocationException
Specified by:
remove in interface Document
Throws:
BadLocationException

insertString

public void insertString(int offs,
                         String str,
                         AttributeSet a)
                  throws BadLocationException
Specified by:
insertString in interface Document
Throws:
BadLocationException

addDocumentListener

public void addDocumentListener(DocumentListener listener)

Specified by:
addDocumentListener in interface Document

addUndoableEditListener

public void addUndoableEditListener(UndoableEditListener listener)

Specified by:
addUndoableEditListener in interface Document

createPosition

public Position createPosition(int offs)
                        throws BadLocationException

Specified by:
createPosition in interface Document
Throws:
BadLocationException

getDefaultRootElement

public Element getDefaultRootElement()

Specified by:
getDefaultRootElement in interface Document

getEndPosition

public Position getEndPosition()

Specified by:
getEndPosition in interface Document

getLength

public int getLength()

Specified by:
getLength in interface Document

getProperty

public Object getProperty(Object key)

Specified by:
getProperty in interface Document

getRootElements

public Element[] getRootElements()

Specified by:
getRootElements in interface Document

getStartPosition

public Position getStartPosition()

Specified by:
getStartPosition in interface Document

getText

public String getText(int offset,
                      int length)
               throws BadLocationException

Specified by:
getText in interface Document
Throws:
BadLocationException

getText

public void getText(int offset,
                    int length,
                    Segment txt)
             throws BadLocationException

Specified by:
getText in interface Document
Throws:
BadLocationException

putProperty

public void putProperty(Object key,
                        Object value)

Specified by:
putProperty in interface Document

removeDocumentListener

public void removeDocumentListener(DocumentListener listener)

Specified by:
removeDocumentListener in interface Document

removeUndoableEditListener

public void removeUndoableEditListener(UndoableEditListener listener)

Specified by:
removeUndoableEditListener in interface Document

render

public void render(Runnable r)

Specified by:
render in interface Document

isStrictMatching

public boolean isStrictMatching()
Returns if only items from the adaptor's list should be allowed to be entered.

Returns:
if only items from the adaptor's list should be allowed to be entered

swingx
Version 2009-07-31