JIDE 3.5.15

com.jidesoft.editor
Class AbstractCodeEditorIntelliHints

java.lang.Object
  extended by com.jidesoft.editor.AbstractCodeEditorIntelliHints
All Implemented Interfaces:
IntelliHints
Direct Known Subclasses:
AbstractListCodeEditorIntelliHints

public abstract class AbstractCodeEditorIntelliHints
extends Object
implements IntelliHints

AbstractCodeEditorIntelliHints is an abstract implementation of IntelliHints for CodeEditor. It covers functions such as showing the hint popup at the correct position, delegating keystrokes, updating and selecting hint. The only thing that is left out to subclasses is the creation of the hint popup.


Field Summary
 
Fields inherited from interface com.jidesoft.hints.IntelliHints
CLIENT_PROPERTY_INTELLI_HINTS
 
Constructor Summary
AbstractCodeEditorIntelliHints(CodeEditor codeEditor)
          Creates an IntelliHints object for a given JTextComponent.
 
Method Summary
 void acceptHint(Object selected)
          After user has selected a item in the hints popup, this method will update JTextComponent accordingly to accept the hint.
 void addShowHintsKeyStroke(KeyStroke keyStroke)
          Adds a new key stroke to show hints popup.
protected  JidePopup createPopup()
          Creates a popup.
 KeyStroke[] getAllShowHintsKeyStrokes()
          Gets all key strokes that will show hints popup.
protected  Rectangle getCaretRectangleForPopup()
          Gets the caret rectangle where caret is displayed.
 CodeEditor getCodeEditor()
          Gets the CodeEditor instance which use this class.
protected  Object getContext()
          Gets the context for hints.
abstract  JComponent getDelegateComponent()
          Gets the delegate component.
abstract  KeyStroke[] getDelegateKeyStrokes()
          Gets the delegate keystrokes.
 String getDelimiters()
          Gets the delimiters that is recognized by AbstractCodeEditorIntelliHints.
static AbstractCodeEditorIntelliHints getIntelliHints(JComponent component)
          Gets the IntelliHints object if it was installed on the component before.
protected  KeyStroke getShowHintsKeyStroke()
          Gets the default keystroke that will trigger the hint popup.
protected  void hideHintsPopup()
          Hides the hints popup.
 void install(CodeEditor editor)
          Install the IntelliHints to the code editor.
 boolean isAutoPopup()
          Returns whether the hints popup is automatically displayed.
 boolean isHintsPopupVisible()
          Checks if the hints popup is visible.
 void removeShowHintsKeyStroke(KeyStroke keyStroke)
          Removes a key stroke from the list to show hints popup.
 void setAutoPopup(boolean autoPopup)
          Sets whether the popup should be displayed automatically.
 void setDelimiters(String delimiters)
          Gets the delimiters that is recognized by AbstractCodeEditorIntelliHints.
 void setHintsEnabled(boolean enabled)
          Enables or disables the hints popup.
protected  void showHintsPopup()
          Shows the hints popup which contains the hints.
 void uninstall()
          Uninstalls the IntelliHints.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jidesoft.hints.IntelliHints
createHintsComponent, getSelectedHint, updateHints
 

Constructor Detail

AbstractCodeEditorIntelliHints

public AbstractCodeEditorIntelliHints(CodeEditor codeEditor)
Creates an IntelliHints object for a given JTextComponent.

Parameters:
codeEditor - the text component.
Method Detail

install

public void install(CodeEditor editor)
Install the IntelliHints to the code editor.

Parameters:
editor - the code editor
Since:
3.4.2

uninstall

public void uninstall()
Uninstalls the IntelliHints.

Since:
3.4.2

createPopup

protected JidePopup createPopup()
Creates a popup.

Returns:
the popup instance.

getCodeEditor

public CodeEditor getCodeEditor()
Gets the CodeEditor instance which use this class.

Returns:
the CodeEditor instance.

acceptHint

public void acceptHint(Object selected)
After user has selected a item in the hints popup, this method will update JTextComponent accordingly to accept the hint.

For JTextArea, the default implementation will insert the hint into current caret position. For JTextField, by default it will replace the whole content with the item user selected. Subclass can always choose to override it to accept the hint in a different way. For example, FileIntelliHints will append the selected item at the end of the existing text in order to complete a full file path.

Specified by:
acceptHint in interface IntelliHints
Parameters:
selected - the hint to be accepted.

showHintsPopup

protected void showHintsPopup()
Shows the hints popup which contains the hints. It will call IntelliHints.updateHints(Object). Only if it returns true, the popup will be shown.


getCaretRectangleForPopup

protected Rectangle getCaretRectangleForPopup()
                                       throws BadLocationException
Gets the caret rectangle where caret is displayed. The popup will be show around the area so that the returned rectangle area is always visible. This method will be called twice.

Returns:
the popup position relative to the text component.
Please note, this position is actually a rectangle area. The reason is the popup could be shown below or above the rectangle. Usually, the popup will be shown below the rectangle. In this case, the x and y of the rectangle will be the top-left corner of the popup. However if there isn't enough space for the popup because it's close to screen bottom border, we will show the popup above the rectangle. In this case, the bottom-left corner of the popup will be at x and (y - height). Simply speaking, the popup will never cover the area specified by the rectangle (either below it or above it).
Throws:
BadLocationException - if the given position does not represent a valid location in the associated document.

getContext

protected Object getContext()
Gets the context for hints. The context is the information that IntelliHints needs in order to generate a list of hints. For example, for code-completion, the context is current word the cursor is on. for file completion, the context is the full string starting from the file system root.

We provide a default context in AbstractIntelliHints. If it's a JTextArea, the context will be the string at the caret line from line beginning to the caret position. If it's a JTextField, the context will be whatever string in the text field. Subclass can always override it to return the context that is appropriate.

Returns:
the context.

hideHintsPopup

protected void hideHintsPopup()
Hides the hints popup.


setHintsEnabled

public void setHintsEnabled(boolean enabled)
Enables or disables the hints popup.

Parameters:
enabled - true to enable the hints popup. Otherwise false.

isHintsPopupVisible

public boolean isHintsPopupVisible()
Checks if the hints popup is visible.

Returns:
true if it's visible. Otherwise, false.

isAutoPopup

public boolean isAutoPopup()
Returns whether the hints popup is automatically displayed. Default is false

Returns:
true if the popup should be automatically displayed. False will never show it automatically and then need the user to manually activate it via the getShowHintsKeyStroke() key binding.
See Also:
setAutoPopup(boolean)

setAutoPopup

public void setAutoPopup(boolean autoPopup)
Sets whether the popup should be displayed automatically. If autoPopup is true then is the popup automatically displayed whenever updateHints() return true. If autoPopup is false it's not automatically displayed and will need the user to activate the key binding defined by getShowHintsKeyStroke().

Parameters:
autoPopup - true or false

getDelegateKeyStrokes

public abstract KeyStroke[] getDelegateKeyStrokes()
Gets the delegate keystrokes.

When hint popup is visible, the keyboard focus never leaves the text component. However the hint popup usually contains a component that user will try to use navigation key to select an item. For example, use UP and DOWN key to navigate the list. Those keystrokes, if the popup is visible, will be delegated to the the component that returns from getDelegateComponent().

Returns:
an array of keystrokes that will be delegate to getDelegateComponent() when hint popup is shown.

getDelegateComponent

public abstract JComponent getDelegateComponent()
Gets the delegate component.

Returns:
the delegate component.

getShowHintsKeyStroke

protected KeyStroke getShowHintsKeyStroke()
Gets the default keystroke that will trigger the hint popup. Usually the hints popup will be shown automatically when user types. Only when the hint popup is hidden accidentally, this keystroke will show the popup again.

By default, it's CTRL+SPACE. You could override this method to provide default key stroke to show hints.

Returns:
the keystroke that will trigger the hint popup.

addShowHintsKeyStroke

public void addShowHintsKeyStroke(KeyStroke keyStroke)
Adds a new key stroke to show hints popup.

Parameters:
keyStroke - the key stroke
Since:
3.2.2
See Also:
removeShowHintsKeyStroke(javax.swing.KeyStroke), getAllShowHintsKeyStrokes()

removeShowHintsKeyStroke

public void removeShowHintsKeyStroke(KeyStroke keyStroke)
Removes a key stroke from the list to show hints popup.

Parameters:
keyStroke - the key stroke
Since:
3.2.2

getAllShowHintsKeyStrokes

public KeyStroke[] getAllShowHintsKeyStrokes()
Gets all key strokes that will show hints popup.

Returns:
the key stroke array.
Since:
3.2.2

getDelimiters

public String getDelimiters()
Gets the delimiters that is recognized by AbstractCodeEditorIntelliHints. Each character is one delimiter.

Returns:
the delimiters.
Since:
3.3.8
See Also:
setDelimiters(String)

setDelimiters

public void setDelimiters(String delimiters)
Gets the delimiters that is recognized by AbstractCodeEditorIntelliHints.

By default, the value is " \t". Each character is one delimiter, which means SPACE and TAB are considered delimiters by default.

Parameters:
delimiters - the delimiters
Since:
3.3.8

getIntelliHints

public static AbstractCodeEditorIntelliHints getIntelliHints(JComponent component)
Gets the IntelliHints object if it was installed on the component before.

Parameters:
component - the component that has IntelliHints installed
Returns:
the IntelliHints.

JIDE 3.5.15