Class SimpleColoredComponent

All Implemented Interfaces:
ColoredTextContainer, ImageObserver, MenuContainer, Serializable, Accessible

public class SimpleColoredComponent extends JComponent implements Accessible, ColoredTextContainer
This is high performance Swing component which represents an icon with a colored text. The text consists of fragments. Each text fragment has its own color (foreground) and font style.
See Also:
  • Field Details

    • SHADOW_COLOR

      public static final Color SHADOW_COLOR
    • STYLE_SEARCH_MATCH_BACKGROUND

      public static final Color STYLE_SEARCH_MATCH_BACKGROUND
    • FRAGMENT_ICON

      public static final int FRAGMENT_ICON
      See Also:
    • myIconTextGap

      protected int myIconTextGap
      Gap between icon and text. It is used only if icon is defined.
  • Constructor Details

    • SimpleColoredComponent

      public SimpleColoredComponent()
  • Method Details

    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent
    • iterator

    • isIconOnTheRight

      public boolean isIconOnTheRight()
    • setIconOnTheRight

      public void setIconOnTheRight(boolean iconOnTheRight)
    • append

      @NotNull public final SimpleColoredComponent append(@NotNull String fragment)
    • append

      public final void append(@NotNull String fragment, @NotNull SimpleTextAttributes attributes)
      Appends string fragments to existing ones. Appended string will have specified attributes.
      Specified by:
      append in interface ColoredTextContainer
      Parameters:
      fragment - text fragment
      attributes - text attributes
    • append

      public final void append(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, int padding, int align)
      Appends text fragment and sets it's end offset and alignment. See SimpleColoredComponent#appendTextPadding for details
      Parameters:
      fragment - text fragment
      attributes - text attributes
      padding - end offset of the text
      align - alignment between current offset and padding
    • append

      public void append(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, boolean isMainText)
      Appends string fragments to existing ones. Appended string will have specified attributes.
      Parameters:
      fragment - text fragment
      attributes - text attributes
      isMainText - main text of not
    • append

      public void append(@NotNull String fragment, @NotNull SimpleTextAttributes attributes, Object tag)
      Specified by:
      append in interface ColoredTextContainer
    • appendFixedTextFragmentWidth

      @Deprecated public void appendFixedTextFragmentWidth(int width)
      Deprecated.
      remove in IDEA 16
      fragment width isn't a right name, it is actually a padding
    • appendTextPadding

      public void appendTextPadding(int padding)
    • appendTextPadding

      public void appendTextPadding(int padding, int align)
      Parameters:
      padding - end offset that will be set after drawing current text fragment
      align - alignment of the current text fragment, if it is SwingConstants.RIGHT or SwingConstants.TRAILING then the text fragment will be aligned to the right at the padding, otherwise it will be aligned to the left
    • setTextAlign

      public void setTextAlign(int align)
    • clear

      public void clear()
      Clear all special attributes of SimpleColoredComponent. They are icon, text fragments and their attributes, "paint focus border".
    • getIcon

      public final Icon getIcon()
      Returns:
      component's icon. This method returns null if there is no icon.
    • setIcon

      public final void setIcon(@Nullable Icon icon)
      Sets a new component icon
      Specified by:
      setIcon in interface ColoredTextContainer
      Parameters:
      icon - icon
    • getIpad

      @NotNull public Insets getIpad()
      Returns:
      "leave" (internal) internal paddings of the component
    • setIpad

      public void setIpad(@NotNull Insets ipad)
      Sets specified internal paddings
      Parameters:
      ipad - insets
    • getIconTextGap

      public int getIconTextGap()
      Returns:
      gap between icon and text
    • setIconTextGap

      public void setIconTextGap(int iconTextGap)
      Sets a new gap between icon and text
      Parameters:
      iconTextGap - the gap between text and icon
      Throws:
      IllegalArgumentException - if the iconTextGap has a negative value
    • getMyBorder

      public Border getMyBorder()
    • setMyBorder

      public void setMyBorder(@Nullable Border border)
    • setPaintFocusBorder

      protected final void setPaintFocusBorder(boolean paintFocusBorder)
      Sets whether focus border is painted or not
      Parameters:
      paintFocusBorder - true or false
    • setFocusBorderAroundIcon

      protected final void setFocusBorderAroundIcon(boolean focusBorderAroundIcon)
      Sets whether focus border extends to icon or not. If so then component also extends the selection.
      Parameters:
      focusBorderAroundIcon - true or false
    • isIconOpaque

      public boolean isIconOpaque()
    • setIconOpaque

      public void setIconOpaque(boolean iconOpaque)
    • getPreferredSize

      @NotNull public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • getMinimumSize

      @NotNull public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • getFragmentTag

      @Nullable public Object getFragmentTag(int index)
    • computePreferredSize

      @NotNull public final Dimension computePreferredSize(boolean mainTextOnly)
    • findFragmentAt

      public int findFragmentAt(int x)
      Returns the index of text fragment at the specified X offset.
      Parameters:
      x - the offset
      Returns:
      the index of the fragment, FRAGMENT_ICON if the icon is at the offset, or -1 if nothing is there.
    • getFragmentTagAt

      @Nullable public Object getFragmentTagAt(int x)
    • formatToLabel

      @NotNull protected JLabel formatToLabel(@NotNull JLabel label)
    • paintComponent

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

      protected void doPaint(Graphics2D g)
    • paintBackground

      protected void paintBackground(Graphics2D g, int x, int width, int height)
    • doPaintIcon

      protected void doPaintIcon(@NotNull Graphics2D g, @NotNull Icon icon, int offset)
    • doPaintText

      protected int doPaintText(Graphics2D g, int offset, boolean focusAroundIcon)
    • shouldDrawMacShadow

      protected boolean shouldDrawMacShadow()
    • shouldDrawDimmed

      protected boolean shouldDrawDimmed()
    • shouldDrawBackground

      protected boolean shouldDrawBackground()
    • paintIcon

      protected void paintIcon(@NotNull Graphics g, @NotNull Icon icon, int offset)
    • applyAdditionalHints

      protected void applyAdditionalHints(@NotNull Graphics2D g)
    • getBaseline

      public int getBaseline(int width, int height)
      Overrides:
      getBaseline in class JComponent
    • isTransparentIconBackground

      public boolean isTransparentIconBackground()
    • setTransparentIconBackground

      public void setTransparentIconBackground(boolean transparentIconBackground)
    • getTextBaseLine

      public static int getTextBaseLine(@NotNull FontMetrics metrics, int height)
    • setBorderInsets

      protected void setBorderInsets(Insets insets)
    • getCharSequence

      @NotNull public CharSequence getCharSequence(boolean mainOnly)
    • toString

      public String toString()
      Overrides:
      toString in class Component
    • change

      public void change(@NotNull Runnable runnable, boolean autoInvalidate)
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component