|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xnap.commons.gui.completion.Completion
public class Completion
The Completion class follows the mediator pattern.
It manages the text component and the completion model and decouples
them from the CompletionMode
which decides when and how to
offer completion to the user.
If you want to provide your own completion modes, install them in the
CompletionModeFactory
.
During its lifetime the completion object is coupled to only one
JTextComponent, it's a one-to-one mapping. To disable it, use
setEnabled(false)
.
A completion object can be used as follows:
JTextField jtf = new JTextField(); Completion comp = new Completion(jtf, new FileCompletionModel()); comp.setMode(new AutomaticDropDownCompletionMode());When typing into the text field above the text is matched against existing files on the filesystem and possible completions are presented according to the
AutomaticDropDownCompletionMode
.
Constructor Summary | |
---|---|
Completion(JTextComponent textComponent)
Convenience wrapper for Completion(JTextComponent, boolean) . |
|
Completion(JTextComponent textComponent,
boolean wholeText)
Convenience wrapper for Completion(JTextComponent,
CompletionModel, boolean) . |
|
Completion(JTextComponent textComponent,
CompletionModel model)
Convenience wrapper for Completion(JTextComponent,
CompletionModel, boolean) . |
|
Completion(JTextComponent textComponent,
CompletionModel model,
boolean wholeText)
Constructs a new Completion object. |
Method Summary | |
---|---|
void |
addCompletionModeListener(CompletionModeListener l)
Adds a CompletionModeListener to the listener list. |
protected void |
fireModeChanged(Class oldMode,
Class newMode)
Can be used by subclasses to fire a completion mode change in case they provide their own implementation of setMode(CompletionMode) . |
CompletionMode |
getMode()
Returns the currently active completion mode. |
CompletionModel |
getModel()
Returns the currently used model. |
String |
getText()
Returns the text which should be completed. |
JTextComponent |
getTextComponent()
Returns the text component this completion mode is responsible for |
boolean |
isEnabled()
Returns whether the currently set completion mode is enabled. |
boolean |
isWholeTextCompletion()
Returns whether this completion mode is supposed to complete the whole text of its text component made availabe through JTextComponent.getText() or just the last word before the cursor. |
void |
removeCompletionModeListener(CompletionModeListener l)
Removes a CompletionModeListener from the listener list. |
void |
setEnabled(boolean enabled)
Enables or disables the currently set completion mode. |
void |
setMode(CompletionMode newMode)
Sets a new completion mode for the managed text component and enables it if the completion is currently enabled. |
void |
setModel(CompletionModel model)
Sets the completion model. |
void |
setText(String text)
Convenience wrapper for setText(String, int, int) . |
protected void |
setText(String text,
int selectionStart,
int selectionEnd)
Sets the given text honoring the whole text mode. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Completion(JTextComponent textComponent, CompletionModel model, boolean wholeText)
GlobalDefaultCompletionMode
is set as the default completion mode.
textComponent
- the text component completion will be done formodel
- the completion model that provides the possible completionswholeText
- if true the whole text of the text component is used
for completion otherwise only the last word before the cursor is
completed.
NullPointerException
- if textComponent
is null.public Completion(JTextComponent textComponent, boolean wholeText)
Completion(JTextComponent,
CompletionModel, boolean)
.
The missing completion model defaults to the DefaultCompletionModel
.
public Completion(JTextComponent textComponent, CompletionModel model)
Completion(JTextComponent,
CompletionModel, boolean)
.
The missing boolean defaults to true
.
public Completion(JTextComponent textComponent)
Completion(JTextComponent, boolean)
.
The missing boolean defaults to true
.
Method Detail |
---|
public void setMode(CompletionMode newMode)
CompletionModeListeners
are notified of the mode change.
newMode
- the new completion mode
NullPointerException
- if newMode
is
null
public void setModel(CompletionModel model)
model
- the new completion model which will be used henceforthpublic void setEnabled(boolean enabled)
public boolean isEnabled()
public CompletionModel getModel()
public CompletionMode getMode()
public JTextComponent getTextComponent()
public final boolean isWholeTextCompletion()
JTextComponent.getText()
or just the last word before the cursor.
public void setText(String text)
setText(String, int, int)
.
Sets the text without any selection and setts the cursor to the end of
the set text.
text
- the text to setprotected void setText(String text, int selectionStart, int selectionEnd)
text
- the text to setselectionStart
- the offset of the selection start relative to the beginning of
the set text. Can be greater than selectionEnd
.selectionEnd
- the offset of the selection end relative to the beginning of
the set text. This is where the cursor is afterwards.
TODO why is this not public?public String getText()
JTextComponent.getText()
if wholeText is true
otherwise the word before the cursor.public void addCompletionModeListener(CompletionModeListener l)
l
- the CompletionModeListener to be addedpublic void removeCompletionModeListener(CompletionModeListener l)
l
- the CompletionModeListener to be removedprotected void fireModeChanged(Class oldMode, Class newMode)
setMode(CompletionMode)
.
oldMode
- the class of the old completion modenewMode
- the class of the new completion mode
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |