org.xnap.gui.component
Class CompletionMode

java.lang.Object
  extended by org.xnap.gui.component.CompletionMode
Direct Known Subclasses:
DropDownListCompletionMode, EmacsCompletionMode, ManualCompletionMode, NoCompletionMode, ShortAutomaticCompletionMode

public abstract class CompletionMode
extends java.lang.Object

This class handles the way completion is actually done. It decides when and how to offer completion to the user. Completion may be triggered using a special key, it may be visible all the time, it may use a CompletionPopup to present all possibilities or may insert the text directly.


Constructor Summary
CompletionMode(javax.swing.text.JTextComponent textComponent)
           
CompletionMode(javax.swing.text.JTextComponent textComponent, boolean wholeText)
           
CompletionMode(javax.swing.text.JTextComponent textComponent, CompletionModel model)
           
CompletionMode(javax.swing.text.JTextComponent textComponent, CompletionModel model, boolean wholeText)
           
 
Method Summary
protected abstract  void disable()
          Disables the completion mode letting it remove its listeners from the text component.
protected abstract  void enable()
          Enables the completion mode letting it add its listeners to the text component.
 CompletionModel getModel()
          Returns the currently used model.
abstract  java.lang.String getName()
          Returns the name of this completion mode.
protected  java.lang.String getText()
          Returns the text which should be completed.
 javax.swing.text.JTextComponent getTextComponent()
          Returns the text component this completion mode is responsible for
 boolean isEnabled()
          Returns true if the 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 setEnabled(boolean enabled)
          Enables or disables the completion mode.
 void setModel(CompletionModel model)
          Sets the completion model.
protected  void setText(java.lang.String text)
          Convenience wrapper for setText(String, int, int).
protected  void setText(java.lang.String text, int selectionStart, int selectionEnd)
          Sets the given text honoring the whole text mode.
 void setTextComponent(javax.swing.text.JTextComponent jtc)
          Sets a new text component for this completion mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompletionMode

public CompletionMode(javax.swing.text.JTextComponent textComponent,
                      CompletionModel model,
                      boolean wholeText)

CompletionMode

public CompletionMode(javax.swing.text.JTextComponent textComponent,
                      boolean wholeText)

CompletionMode

public CompletionMode(javax.swing.text.JTextComponent textComponent,
                      CompletionModel model)

CompletionMode

public CompletionMode(javax.swing.text.JTextComponent textComponent)
Method Detail

getName

public abstract java.lang.String getName()
Returns the name of this completion mode. This should be localized since it's shown to the user.


enable

protected abstract void enable()
Enables the completion mode letting it add its listeners to the text component.


disable

protected abstract void disable()
Disables the completion mode letting it remove its listeners from the text component.


setEnabled

public final void setEnabled(boolean enabled)
Enables or disables the completion mode.

Parameters:
enabled - true to enable the completion mode, false to disable it

isEnabled

public final boolean isEnabled()
Returns true if the completion mode is enabled.


setModel

public void setModel(CompletionModel model)
Sets the completion model. If the completion mode is currently enabled, it will be disabled before the model is set and enabled afterwards. Thus subclasses have a chance of being notified of the model change in their disable() enable() methods.

Parameters:
model - the new completion model which will be used henceforth

getModel

public CompletionModel getModel()
Returns the currently used model.


setTextComponent

public void setTextComponent(javax.swing.text.JTextComponent jtc)
Sets a new text component for this completion mode. If the completion mode is currently enabled disable() and enable() are called to give listeners a chance to remove themselves from the old text component add themselves to the new text component.


getTextComponent

public javax.swing.text.JTextComponent getTextComponent()
Returns the text component this completion mode is responsible for


isWholeTextCompletion

public final 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.


setText

protected void setText(java.lang.String text)
Convenience wrapper for setText(String, int, int). Sets the text without any selection and setts the cursor to the end of the set text.

Parameters:
text - the text to set

setText

protected void setText(java.lang.String text,
                       int selectionStart,
                       int selectionEnd)
Sets the given text honoring the whole text mode.

Parameters:
text - the text to set
selectionStart - 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.

getText

protected java.lang.String getText()
Returns the text which should be completed.

Returns:
Returns JTextComponent.getText() if wholeText is true otherwise the word before the cursor.


Copyright © 2001-2005 XNap Team. All Rights Reserved.