Module platform

Class CompletionCellRenderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ListCellRenderer<Object>, SwingConstants

public class CompletionCellRenderer extends DefaultListCellRenderer
A cell renderer that adds some pizazz when rendering the standard Completion types, like Eclipse and NetBeans do. Specifically, this renderer handles:
Version:
1.0
Author:
Robert Futrell
See Also:
  • Constructor Details

    • CompletionCellRenderer

      public CompletionCellRenderer()
      Constructor.
    • CompletionCellRenderer

      public CompletionCellRenderer(DefaultListCellRenderer delegate)
      Constructor. This is primarily a hook for Substance, or any other Look and Feel whose renderers look drastically different from standard DefaultListCellRenderers. Everything except for the text rendering will be done by the delegate. In almost all scenarios, you will want to use the no-argument constructor instead of this one.
      Parameters:
      delegate - The delegate renderer.
      See Also:
  • Method Details

    • appendShortDescription

      protected void appendShortDescription(StringBuilder sb, String definition)
      Utility function to append a short description to a string buffer. Useful to ensure consistency when rendering completions that display a trailing description of the completion.
      Parameters:
      sb - The string buffer to append to.
      definition - The text to append.
      See Also:
    • appendTypeIfNecessary

      protected void appendTypeIfNecessary(StringBuilder sb, VariableCompletion varOrFunctionCompletion)
      Utility function that appends a variable or function completion's type to a string buffer if getShowTypes() is true.
      Parameters:
      sb - The string buffer to possibly append to.
      varOrFunctionCompletion - The completion to examine.
      See Also:
    • createEmptyIcon

      protected Icon createEmptyIcon()
      Creates the icon to use if no icon is found for a specific completion. The default implementation returns a 16x16 empty icon.
      Returns:
      The icon.
      See Also:
    • delegateToSubstanceRenderer

      public void delegateToSubstanceRenderer() throws Exception
      Attempts to delegate rendering to a Substance cell renderer. This should only be called if Substance is known to be on the classpath.
      Throws:
      Exception - If Substance is not on the classpath, or some other error occurs creating the Substance cell renderer.
      See Also:
    • getAlternateBackground

      public static Color getAlternateBackground()
      Returns the background color to use on alternating lines.
      Returns:
      The alternate background color. If this is null, alternating colors are not used.
      See Also:
    • getDelegateRenderer

      public DefaultListCellRenderer getDelegateRenderer()
      Returns the delegate renderer, or null if there is none.
      Returns:
      The delegate renderer.
      See Also:
    • getDisplayFont

      public Font getDisplayFont()
      Returns the font used when rendering completions.
      Returns:
      The font. If this is null, then the default list font is used.
      See Also:
    • getEmptyIcon

      protected Icon getEmptyIcon()
      Returns the icon to use if no icon is found for a specific completion. This icon is lazily created if necessary.
      Returns:
      The icon.
      See Also:
    • getIcon

      protected Icon getIcon(String resource)
      Returns an icon.
      Parameters:
      resource - The icon to retrieve. This should either be a file, or a resource loadable by the current ClassLoader.
      Returns:
      The icon.
    • getListCellRendererComponent

      public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus)
      Returns the renderer.
      Specified by:
      getListCellRendererComponent in interface ListCellRenderer<Object>
      Overrides:
      getListCellRendererComponent in class DefaultListCellRenderer
      Parameters:
      list - The list of choices being rendered.
      value - The Completion being rendered.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • getShowTypes

      public boolean getShowTypes()
      Returns whether the types of fields and return types of methods are shown in the completion text.
      Returns:
      Whether to show the types.
      See Also:
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • prepareForFunctionCompletion

      protected void prepareForFunctionCompletion(JList<?> list, FunctionCompletion fc, int index, boolean selected, boolean hasFocus)
      Prepares this renderer to display a function completion.
      Parameters:
      list - The list of choices being rendered.
      fc - The completion to render.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • prepareForMarkupTagCompletion

      protected void prepareForMarkupTagCompletion(JList<?> list, MarkupTagCompletion mc, int index, boolean selected, boolean hasFocus)
      Prepares this renderer to display a markup tag completion.
      Parameters:
      list - The list of choices being rendered.
      mc - The completion to render.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • prepareForClassCompletion

      protected void prepareForClassCompletion(JList<?> list, ClassCompletion mc, int index, boolean selected, boolean hasFocus)
      TODO: CHANGE THIS FOR DISPLAY DEPENDING ON THE CONTEXT
    • prepareForOtherCompletion

      protected void prepareForOtherCompletion(JList<?> list, Completion c, int index, boolean selected, boolean hasFocus)
      Prepares this renderer to display a completion not specifically handled elsewhere.
      Parameters:
      list - The list of choices being rendered.
      c - The completion to render.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • prepareForTemplateCompletion

      protected void prepareForTemplateCompletion(JList<?> list, TemplateCompletion tc, int index, boolean selected, boolean hasFocus)
      Prepares this renderer to display a template completion.
      Parameters:
      list - The list of choices being rendered.
      tc - The completion to render.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • prepareForVariableCompletion

      protected void prepareForVariableCompletion(JList<?> list, VariableCompletion vc, int index, boolean selected, boolean hasFocus)
      Prepares this renderer to display a variable completion.
      Parameters:
      list - The list of choices being rendered.
      vc - The completion to render.
      index - The index into list being rendered.
      selected - Whether the item is selected.
      hasFocus - Whether the item has focus.
    • setAlternateBackground

      public static void setAlternateBackground(Color altBG)
      Sets the background color to use on alternating lines.
      Parameters:
      altBG - The new alternate background color. If this is null, alternating lines will not use different background colors.
      See Also:
    • setDelegateRenderer

      public void setDelegateRenderer(DefaultListCellRenderer delegate)
      Sets the delegate renderer. Most users will never use this method; it is primarily a hook for Substance and other Look and Feels whose renderers look drastically different from the standard DefaultListCellRenderer.
      Parameters:
      delegate - The new delegate renderer. If this is null, the default rendering of this component is used.
      See Also:
    • setDisplayFont

      public void setDisplayFont(Font font)
      Sets the font to use when rendering completion items.
      Parameters:
      font - The font to use. If this is null, then the default list font is used.
      See Also:
    • setIconWithDefault

      protected void setIconWithDefault(Completion completion)
      Sets the icon to display based off of a completion, falling back to the empty icon if the completion has no icon.
      Parameters:
      completion - The completion to check.
      See Also:
    • setIconWithDefault

      protected void setIconWithDefault(Completion completion, Icon defaultIcon)
      Sets the icon to display based off of a completion, falling back to a default icon if the completion has no icon.
      Parameters:
      completion - The completion to check.
      defaultIcon - The icon to use if completion does not specify an icon.
      See Also:
    • setParamColor

      public void setParamColor(Color color)
      Sets the color to use for function arguments.
      Parameters:
      color - The color to use. This is ignored if null.
      See Also:
    • setShowTypes

      public void setShowTypes(boolean show)
      Sets whether the types of fields and return types of methods are shown in the completion text.
      Parameters:
      show - Whether to show the types.
      See Also:
    • setTypeColor

      public void setTypeColor(Color color)
      Sets the color to use for function/field types. Note that if getShowTypes() returns false, this property effectively does nothing.
      Parameters:
      color - The color to use for types. This is ignored if null.
      See Also:
    • updateUI

      public void updateUI()
      Overridden to update our delegate, if necessary.
      Overrides:
      updateUI in class JLabel