Class ParameterizedCompletionContext

java.lang.Object
org.fife.ui.autocomplete.ParameterizedCompletionContext

class ParameterizedCompletionContext extends 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 Details

  • Constructor Details

  • Method Details

    • activate

      public void activate()
      Activates parameter completion support.
      See Also:
    • 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:
    • getArgumentText

      public 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 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:
    • 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:
    • getFirstHighlight

      private static int getFirstHighlight(List<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

      private static int getLastHighlight(List<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:
    • getParameterHighlights

      public List<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:
    • moveToNextParam

      private void moveToNextParam()
      Moves to and selects the next parameter.
      See Also:
    • moveToPreviousParam

      private void moveToPreviousParam()
      Moves to and selects the previous parameter.
      See Also:
    • possiblyUpdateParamCopies

      private void possiblyUpdateParamCopies(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 Highlighter.Highlight replaceHighlightedText(Document doc, Highlighter.Highlight h, 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:
    • updateToolTipText

      private 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.