Package org.fife.ui.autocomplete
Class ParameterizedCompletionContext
- java.lang.Object
-
- org.fife.ui.autocomplete.ParameterizedCompletionContext
-
class ParameterizedCompletionContext extends java.lang.Object
Manages UI and state specific to parameterized completions - the parameter description tool tip, the parameter completion choices list, the actual highlights in the editor, etc. This component installs new key bindings when appropriate to allow the user to cycle through the parameters of the completion, and optionally cycle through completion choices for those parameters.- Version:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
ParameterizedCompletionContext.ClosingAction
Called when the user types the character marking the closing of the parameter list, such as ')
'.private class
ParameterizedCompletionContext.GotoEndAction
Called when the user presses Enter while entering parameters.private class
ParameterizedCompletionContext.HideAction
Action performed when the user hits the escape key.private class
ParameterizedCompletionContext.Listener
Listens for various events in the text component while this tool tip is visible.private class
ParameterizedCompletionContext.NextChoiceAction
Action performed when the user presses the up or down arrow keys and the parameter completion choices popup is visible.private class
ParameterizedCompletionContext.NextParamAction
Action performed when the user hits the tab key.private static class
ParameterizedCompletionContext.ParamCopyInfo
Information about a parameter.private class
ParameterizedCompletionContext.PrevParamAction
Action performed when the user hits shift+tab.
-
Field Summary
Fields Modifier and Type Field Description private AutoCompletion
ac
The parent AutoCompletion instance.private boolean
active
Whether parameterized completion assistance is active.private javax.swing.text.Position
defaultEndOffs
private javax.swing.text.Highlighter.HighlightPainter
endingP
private boolean
ignoringDocumentEvents
private static java.lang.String
IM_KEY_CLOSING
private static java.lang.String
IM_KEY_DOWN
private static java.lang.String
IM_KEY_ENTER
private static java.lang.String
IM_KEY_ESCAPE
private static java.lang.String
IM_KEY_SHIFT_TAB
private static java.lang.String
IM_KEY_TAB
private static java.lang.String
IM_KEY_UP
private int
lastSelectedParam
The currently "selected" parameter in the displayed text.private ParameterizedCompletionContext.Listener
listener
Listens for events in the text component while this window is visible.private javax.swing.text.Position
maxPos
The maximum offset into the document that the caret can move to before this tool tip disappears.private int
minPos
The minimum offset into the document that the caret can move to before this tool tip disappears.private javax.swing.Action
oldClosingAction
private java.lang.Object
oldClosingKey
private javax.swing.Action
oldDownAction
private java.lang.Object
oldDownKey
private javax.swing.Action
oldEnterAction
private java.lang.Object
oldEnterKey
private javax.swing.Action
oldEscapeAction
private java.lang.Object
oldEscapeKey
private javax.swing.Action
oldShiftTabAction
private java.lang.Object
oldShiftTabKey
private javax.swing.Action
oldTabAction
private java.lang.Object
oldTabKey
private javax.swing.Action
oldUpAction
private java.lang.Object
oldUpKey
private javax.swing.text.Highlighter.HighlightPainter
p
The painter to paint borders around the variables.private ParameterizedCompletionChoicesWindow
paramChoicesWindow
A small popup window giving likely choices for parameterized completions.private java.util.List<ParameterizedCompletionContext.ParamCopyInfo>
paramCopyInfos
private javax.swing.text.Highlighter.HighlightPainter
paramCopyP
private java.lang.String
paramPrefix
The text before the caret for the current parameter.private java.awt.Window
parentWindow
The parent window.private ParameterizedCompletion
pc
The completion being described.private java.util.List<java.lang.Object>
tags
The tags for the highlights around parameters.private ParameterizedCompletionDescriptionToolTip
tip
A tool tip displaying the currently edited parameter name and type.
-
Constructor Summary
Constructors Constructor Description ParameterizedCompletionContext(java.awt.Window owner, AutoCompletion ac, ParameterizedCompletion pc)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate()
Activates parameter completion support.private ParameterizedCompletionChoicesWindow
createParamChoicesWindow()
Creates the completion window offering suggestions for parameters.void
deactivate()
Hides any popup windows and terminates parameterized completion assistance.java.lang.String
getArgumentText(int offs)
Returns the text inserted for the parameter containing the specified offset.private javax.swing.text.Highlighter.Highlight
getCurrentParameterHighlight()
Returns the highlight of the current parameter.private int
getCurrentParameterIndex()
private int
getCurrentParameterStartOffset()
Returns the starting offset of the current parameter.private static int
getFirstHighlight(java.util.List<javax.swing.text.Highlighter.Highlight> highlights)
Returns the highlight from a list that comes "first" in a list.private static int
getLastHighlight(java.util.List<javax.swing.text.Highlighter.Highlight> highlights)
Returns the highlight from a list that comes "last" in that list.java.util.List<javax.swing.text.Highlighter.Highlight>
getParameterHighlights()
(package private) boolean
insertSelectedChoice()
Inserts the choice selected in the parameter choices window.private void
installKeyBindings()
Installs key bindings on the text component that facilitate the user editing this completion's parameters.private void
moveToNextParam()
Moves to and selects the next parameter.private void
moveToPreviousParam()
Moves to and selects the previous parameter.private void
possiblyUpdateParamCopies(javax.swing.text.Document doc)
private void
prepareParamChoicesWindow()
Updates the optional window listing likely completion choices.private void
removeParameterHighlights()
Removes the bounding boxes around parameters.private javax.swing.text.Highlighter.Highlight
replaceHighlightedText(javax.swing.text.Document doc, javax.swing.text.Highlighter.Highlight h, java.lang.String replacement)
Replaces highlighted text with new text.private void
uninstallKeyBindings()
Removes the key bindings we installed.private java.lang.String
updateToolTipText()
Updates the text in the tool tip to have the current parameter displayed in bold.private void
updateToolTipText(int selectedParam)
void
updateUI()
Updates theLookAndFeel
of all popup windows this context manages.
-
-
-
Field Detail
-
parentWindow
private java.awt.Window parentWindow
The parent window.
-
ac
private AutoCompletion ac
The parent AutoCompletion instance.
-
pc
private ParameterizedCompletion pc
The completion being described.
-
active
private boolean active
Whether parameterized completion assistance is active.
-
tip
private ParameterizedCompletionDescriptionToolTip tip
A tool tip displaying the currently edited parameter name and type.
-
p
private javax.swing.text.Highlighter.HighlightPainter p
The painter to paint borders around the variables.
-
endingP
private javax.swing.text.Highlighter.HighlightPainter endingP
-
paramCopyP
private javax.swing.text.Highlighter.HighlightPainter paramCopyP
-
tags
private java.util.List<java.lang.Object> tags
The tags for the highlights around parameters.
-
paramCopyInfos
private java.util.List<ParameterizedCompletionContext.ParamCopyInfo> paramCopyInfos
-
ignoringDocumentEvents
private transient boolean ignoringDocumentEvents
-
listener
private ParameterizedCompletionContext.Listener listener
Listens for events in the text component while this window is visible.
-
minPos
private int minPos
The minimum offset into the document that the caret can move to before this tool tip disappears.
-
maxPos
private javax.swing.text.Position maxPos
The maximum offset into the document that the caret can move to before this tool tip disappears.
-
defaultEndOffs
private javax.swing.text.Position defaultEndOffs
-
lastSelectedParam
private int lastSelectedParam
The currently "selected" parameter in the displayed text.
-
paramChoicesWindow
private ParameterizedCompletionChoicesWindow paramChoicesWindow
A small popup window giving likely choices for parameterized completions.
-
paramPrefix
private java.lang.String paramPrefix
The text before the caret for the current parameter. IfparamChoicesWindow
is non-null
, this is used to determine what parameter choices to actually show.
-
oldTabKey
private java.lang.Object oldTabKey
-
oldTabAction
private javax.swing.Action oldTabAction
-
oldShiftTabKey
private java.lang.Object oldShiftTabKey
-
oldShiftTabAction
private javax.swing.Action oldShiftTabAction
-
oldUpKey
private java.lang.Object oldUpKey
-
oldUpAction
private javax.swing.Action oldUpAction
-
oldDownKey
private java.lang.Object oldDownKey
-
oldDownAction
private javax.swing.Action oldDownAction
-
oldEnterKey
private java.lang.Object oldEnterKey
-
oldEnterAction
private javax.swing.Action oldEnterAction
-
oldEscapeKey
private java.lang.Object oldEscapeKey
-
oldEscapeAction
private javax.swing.Action oldEscapeAction
-
oldClosingKey
private java.lang.Object oldClosingKey
-
oldClosingAction
private javax.swing.Action oldClosingAction
-
IM_KEY_TAB
private static final java.lang.String IM_KEY_TAB
- See Also:
- Constant Field Values
-
IM_KEY_SHIFT_TAB
private static final java.lang.String IM_KEY_SHIFT_TAB
- See Also:
- Constant Field Values
-
IM_KEY_UP
private static final java.lang.String IM_KEY_UP
- See Also:
- Constant Field Values
-
IM_KEY_DOWN
private static final java.lang.String IM_KEY_DOWN
- See Also:
- Constant Field Values
-
IM_KEY_ESCAPE
private static final java.lang.String IM_KEY_ESCAPE
- See Also:
- Constant Field Values
-
IM_KEY_ENTER
private static final java.lang.String IM_KEY_ENTER
- See Also:
- Constant Field Values
-
IM_KEY_CLOSING
private static final java.lang.String IM_KEY_CLOSING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ParameterizedCompletionContext
ParameterizedCompletionContext(java.awt.Window owner, AutoCompletion ac, ParameterizedCompletion pc)
Constructor.
-
-
Method Detail
-
activate
public void activate()
Activates parameter completion support.- See Also:
deactivate()
-
createParamChoicesWindow
private ParameterizedCompletionChoicesWindow createParamChoicesWindow()
Creates the completion window offering suggestions for parameters.- Returns:
- The window.
-
deactivate
public void deactivate()
Hides any popup windows and terminates parameterized completion assistance.- See Also:
activate()
-
getArgumentText
public java.lang.String getArgumentText(int offs)
Returns the text inserted for the parameter containing the specified offset.- Parameters:
offs
- The offset into the document.- Returns:
- The text of the parameter containing the offset, or
null
if the offset is not in a parameter.
-
getCurrentParameterHighlight
private javax.swing.text.Highlighter.Highlight getCurrentParameterHighlight()
Returns the highlight of the current parameter.- Returns:
- The current parameter's highlight, or
null
if the caret is not in a parameter's bounds. - See Also:
getCurrentParameterStartOffset()
-
getCurrentParameterIndex
private int getCurrentParameterIndex()
-
getCurrentParameterStartOffset
private int getCurrentParameterStartOffset()
Returns the starting offset of the current parameter.- Returns:
- The current parameter's starting offset, or
-1
if the caret is not in a parameter's bounds. - See Also:
getCurrentParameterHighlight()
-
getFirstHighlight
private static int getFirstHighlight(java.util.List<javax.swing.text.Highlighter.Highlight> highlights)
Returns the highlight from a list that comes "first" in a list. Even though most parameter highlights are ordered, sometimes they aren't (e.g. the "cursor" parameter in a template completion is always last, even though it can be anywhere in the template).- Parameters:
highlights
- The list of highlights. Assumed to be non-empty.- Returns:
- The highlight that comes first in the document.
- See Also:
getLastHighlight(List)
-
getLastHighlight
private static int getLastHighlight(java.util.List<javax.swing.text.Highlighter.Highlight> highlights)
Returns the highlight from a list that comes "last" in that list. Even though most parameter highlights are ordered, sometimes they aren't (e.g. the "cursor" parameter in a template completion is always last, even though it can be anywhere in the template).- Parameters:
highlights
- The list of highlights. Assumed to be non-empty.- Returns:
- The highlight that comes last in the document.
- See Also:
getFirstHighlight(List)
-
getParameterHighlights
public java.util.List<javax.swing.text.Highlighter.Highlight> getParameterHighlights()
-
insertSelectedChoice
boolean insertSelectedChoice()
Inserts the choice selected in the parameter choices window.- Returns:
- Whether the choice was inserted. This will be
false
if the window is not visible, or no choice is selected.
-
installKeyBindings
private void installKeyBindings()
Installs key bindings on the text component that facilitate the user editing this completion's parameters.- See Also:
uninstallKeyBindings()
-
moveToNextParam
private void moveToNextParam()
Moves to and selects the next parameter.- See Also:
moveToPreviousParam()
-
moveToPreviousParam
private void moveToPreviousParam()
Moves to and selects the previous parameter.- See Also:
moveToNextParam()
-
possiblyUpdateParamCopies
private void possiblyUpdateParamCopies(javax.swing.text.Document doc)
-
prepareParamChoicesWindow
private void prepareParamChoicesWindow()
Updates the optional window listing likely completion choices.
-
removeParameterHighlights
private void removeParameterHighlights()
Removes the bounding boxes around parameters.
-
replaceHighlightedText
private javax.swing.text.Highlighter.Highlight replaceHighlightedText(javax.swing.text.Document doc, javax.swing.text.Highlighter.Highlight h, java.lang.String replacement)
Replaces highlighted text with new text. Takes special care so that the highlight stays just around the newly-highlighted text, since Swing'sHighlight
classes are funny about insertions at their start offsets.- Parameters:
doc
- The document.h
- The highlight whose text to change.replacement
- The new text to be in the highlight.- Returns:
- The replacement highlight for
h
.
-
uninstallKeyBindings
private void uninstallKeyBindings()
Removes the key bindings we installed.- See Also:
installKeyBindings()
-
updateToolTipText
private java.lang.String updateToolTipText()
Updates the text in the tool tip to have the current parameter displayed in bold. The "current parameter" is determined from the current caret position.- Returns:
- The "prefix" of text in the caret's parameter before the caret.
-
updateToolTipText
private void updateToolTipText(int selectedParam)
-
updateUI
public void updateUI()
Updates theLookAndFeel
of all popup windows this context manages.
-
-