Class AttributedString

  • Direct Known Subclasses:
    CompositeAttributedString

    public class AttributedString
    extends java.lang.Object
    An object that wraps a string and provides data that describes how to render that string.

    This class was created as a place to house attributes of rendering that are not described by Java's Font object, like underlining.

    • Constructor Summary

      Constructors 
      Constructor Description
      AttributedString​(java.lang.String text, java.awt.Color textColor, java.awt.FontMetrics fontMetrics)
      Creates an attributed string with the given text, color and metrics with no other attributes, like highlighting or underlining.
      AttributedString​(java.lang.String text, java.awt.Color textColor, java.awt.FontMetrics fontMetrics, boolean underline, java.awt.Color underlineColor)
      Creates an attributed string with the given text, color and metrics with other attributes, like highlighting and underlining.
      AttributedString​(javax.swing.Icon icon, java.lang.String text, java.awt.Color textColor, java.awt.FontMetrics fontMetrics, boolean underline, java.awt.Color underlineColor)
      Creates an attributed string with the given text, color, icon and metrics with other attributes, like highlighting and underlining.
    • Constructor Detail

      • AttributedString

        public AttributedString​(java.lang.String text,
                                java.awt.Color textColor,
                                java.awt.FontMetrics fontMetrics)
        Creates an attributed string with the given text, color and metrics with no other attributes, like highlighting or underlining.
        Parameters:
        text - The text that this class describes.
        textColor - The color to paint the text.
        fontMetrics - The font metrics used to draw the text.
      • AttributedString

        public AttributedString​(java.lang.String text,
                                java.awt.Color textColor,
                                java.awt.FontMetrics fontMetrics,
                                boolean underline,
                                java.awt.Color underlineColor)
        Creates an attributed string with the given text, color and metrics with other attributes, like highlighting and underlining.
        Parameters:
        text - The text that this class describes.
        textColor - The color to paint the text.
        fontMetrics - The font metrics used to draw the text.
        underline - True if text should be underlined.
        underlineColor - the color to use for underlining.
      • AttributedString

        public AttributedString​(javax.swing.Icon icon,
                                java.lang.String text,
                                java.awt.Color textColor,
                                java.awt.FontMetrics fontMetrics,
                                boolean underline,
                                java.awt.Color underlineColor)
        Creates an attributed string with the given text, color, icon and metrics with other attributes, like highlighting and underlining.
        Parameters:
        icon - icon image to be displayed to the left of the text
        text - The text that this class describes.
        textColor - The color to paint the text.
        fontMetrics - The font metrics used to draw the text.
        underline - True if text should be underlined.
        underlineColor - the color to use for underlining.
    • Method Detail

      • getText

        public java.lang.String getText()
      • getIcon

        public javax.swing.Icon getIcon()
      • length

        public int length()
      • getStringWidth

        public int getStringWidth()
      • getHeightAbove

        public int getHeightAbove()
      • getHeightBelow

        public int getHeightBelow()
      • getColumnPosition

        public int getColumnPosition​(int width)
      • getFontMetrics

        public java.awt.FontMetrics getFontMetrics​(int charIndex)
      • getColor

        public java.awt.Color getColor​(int charIndex)
      • replaceAll

        public AttributedString replaceAll​(char[] targets,
                                           char repacement)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • paint

        public void paint​(javax.swing.JComponent c,
                          java.awt.Graphics g,
                          int x,
                          int y)
      • deriveAttributedString

        public AttributedString deriveAttributedString​(java.lang.String newText)