Class 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
    • Field Detail

      • parentWindow

        private java.awt.Window parentWindow
        The parent window.
      • active

        private boolean active
        Whether parameterized completion assistance is active.
      • 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.
      • ignoringDocumentEvents

        private transient boolean ignoringDocumentEvents
      • 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.
      • paramPrefix

        private java.lang.String paramPrefix
        The text before the caret for the current parameter. If paramChoicesWindow 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_SHIFT_TAB

        private static final java.lang.String IM_KEY_SHIFT_TAB
        See Also:
        Constant Field Values
    • 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's Highlight 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 the LookAndFeel of all popup windows this context manages.