public abstract class AbstractIntelliHints extends java.lang.Object implements IntelliHints
AbstractIntelliHints
is an abstract implementation of IntelliHints
. 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.CLIENT_PROPERTY_INTELLI_HINTS
Constructor and Description |
---|
AbstractIntelliHints(javax.swing.text.JTextComponent textComponent)
Creates an IntelliHints object for a given JTextComponent.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptHint(java.lang.Object selected)
After user has selected a item in the hints popup, this method will update JTextComponent accordingly to accept
the hint.
|
protected JidePopup |
createPopup() |
protected int |
getCaretPositionForPopup()
Gets the caret position which is used as the anchor point to display the popup.
|
protected java.awt.Rectangle |
getCaretRectangleForPopup(int caretPosition)
Gets the caret rectangle where caret is displayed.
|
protected java.lang.Object |
getContext()
Gets the context for hints.
|
protected abstract javax.swing.JComponent |
getDelegateComponent()
Gets the delegate component in the hint popup.
|
protected abstract javax.swing.KeyStroke[] |
getDelegateKeyStrokes()
Gets the delegate keystrokes.
|
static IntelliHints |
getIntelliHints(javax.swing.JComponent component)
Gets the IntelliHints object if it was installed on the component before.
|
protected javax.swing.KeyStroke |
getShowHintsKeyStroke()
Gets the keystroke that will trigger the hint popup.
|
javax.swing.text.JTextComponent |
getTextComponent() |
protected void |
hideHintsPopup()
Hides the hints popup.
|
boolean |
isAutoPopup()
Returns whether the hints popup is automatically displayed.
|
boolean |
isFollowCaret()
Should the hints popup follows the caret.
|
boolean |
isHintsPopupVisible()
Checks if the hints popup is visible.
|
protected boolean |
isMultilineTextComponent()
Returns whether this IntelliHints'
JTextComponent supports single-line text or multi-line text. |
void |
setAutoPopup(boolean autoPopup)
Sets whether the popup should be displayed automatically.
|
void |
setFollowCaret(boolean followCaret)
Sets the position of the hints popup.
|
void |
setHintsEnabled(boolean enabled)
Enables or disables the hints popup.
|
void |
showHints()
Shows the hints popup which contains the hints.
|
protected void |
showHintsPopup()
This method will call
showHints() if and only if the text component is enabled and has focus. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createHintsComponent, getSelectedHint, updateHints
public AbstractIntelliHints(javax.swing.text.JTextComponent textComponent)
textComponent
- the text component.protected JidePopup createPopup()
public javax.swing.text.JTextComponent getTextComponent()
public void acceptHint(java.lang.Object selected)
FileIntelliHints
will append the
selected item at the end of the existing text in order to complete a full file path.acceptHint
in interface IntelliHints
selected
- the hint to be accepted.protected boolean isMultilineTextComponent()
JTextComponent
supports single-line text or multi-line text.true
if the component supports multiple text lines, false
otherwiseprotected void showHintsPopup()
showHints()
if and only if the text component is enabled and has focus.public void showHints()
IntelliHints.updateHints(Object)
. Only if it returns
true, the popup will be shown. You can call this method to fore the hints to be displayed.protected java.awt.Rectangle getCaretRectangleForPopup(int caretPosition) throws javax.swing.text.BadLocationException
caretPosition
- the caret position.javax.swing.text.BadLocationException
- if the given position does not represent a valid location in the associated
document.protected int getCaretPositionForPopup()
isFollowCaret()
is true, it will return caret position. Otherwise it will return the caret position at the
beginning of the caret line. Subclass can override to return any caret position.protected java.lang.Object getContext()
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.
protected void hideHintsPopup()
public void setHintsEnabled(boolean enabled)
enabled
- true to enable the hints popup. Otherwise false.public boolean isHintsPopupVisible()
public boolean isFollowCaret()
public void setFollowCaret(boolean followCaret)
followCaret
- true or false.public boolean isAutoPopup()
public void setAutoPopup(boolean autoPopup)
autoPopup
- true or falseprotected abstract javax.swing.KeyStroke[] getDelegateKeyStrokes()
getDelegateComponent()
.getDelegateComponent()
when hint popup is
shown.protected abstract javax.swing.JComponent getDelegateComponent()
protected javax.swing.KeyStroke getShowHintsKeyStroke()
public static IntelliHints getIntelliHints(javax.swing.JComponent component)
component
- the component that has IntelliHints installed