Class TextStyle


  • public class TextStyle
    extends java.lang.Object
    Defines a set of styles that can be applied to text. Instances of this class are immutable.
    Author:
    Matthew Hall
    • Constructor Summary

      Constructors 
      Constructor Description
      TextStyle()
      Constructs a new TextStyle with default font (device-dependent), black foreground, transparent background, default alignment, and the strikeout and underline flags set to false.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TextStyle align​(int alignment)
      Returns a copy of this TextStyle, with the alignment changed to the argument.
      TextStyle background​(int rgb)
      Returns a copy of this TextStyle, with the background changed to the color described by the argument.
      TextStyle background​(int red, int green, int blue)
      Returns a copy of this TextStyle, with the background changed to the color described by the arguments.
      TextStyle background​(org.eclipse.swt.graphics.RGB background)
      Returns a copy of this TextStyle, with the background changed to the argument.
      TextPrint create​(java.lang.String text)
      Returns a TextPrint of the given text in this text style
      boolean equals​(java.lang.Object obj)  
      TextStyle font​(java.lang.String name, int height, int style)
      Returns a copy of this TextStyle, with the font changed to the font described by the arguments.
      TextStyle font​(org.eclipse.swt.graphics.FontData fontData)
      Returns a copy of this TextStyle, with the font changed to the argument.
      TextStyle fontHeight​(int height)
      Returns a copy of this TextStyle, with the font height changed to the argument.
      TextStyle fontName​(java.lang.String name)
      Returns a copy of this TextStyle, with the font name changed to the argument.
      TextStyle fontStyle​(int style)
      Returns a copy of this TextStyle, with the font style changed to the argument.
      TextStyle foreground​(int rgb)
      Returns a copy of this TextStyle, with the foreground changed to the color described by the argument.
      TextStyle foreground​(int red, int green, int blue)
      Returns a copy of this TextStyle, with the foreground changed to the color described by the arguments.
      TextStyle foreground​(org.eclipse.swt.graphics.RGB foreground)
      Returns a copy of this TextStyle, with the foreground changed to the argument.
      int getAlignment()
      Returns the text alignment.
      org.eclipse.swt.graphics.RGB getBackground()
      Returns the text background color.
      org.eclipse.swt.graphics.FontData getFontData()
      Returns the font applied to the text.
      org.eclipse.swt.graphics.RGB getForeground()
      Returns the text foreground color.
      boolean getStrikeout()
      Returns the strikeout flag.
      boolean getUnderline()
      Returns the underline flag.
      int hashCode()  
      TextStyle strikeout()
      Returns a copy of this TextStyle, with the strikeout flag set to true.
      TextStyle strikeout​(boolean strikeout)
      Returns a copy of this TextStyle, with the strikeout flag set to the argument.
      TextStyle underline()
      Returns a copy of this TextStyle, with the underline flag set to true.
      TextStyle underline​(boolean underline)
      Returns a copy of this TextStyle, with the underline flag set to the argument.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TextStyle

        public TextStyle()
        Constructs a new TextStyle with default font (device-dependent), black foreground, transparent background, default alignment, and the strikeout and underline flags set to false.
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • font

        public TextStyle font​(java.lang.String name,
                              int height,
                              int style)
        Returns a copy of this TextStyle, with the font changed to the font described by the arguments. This method is equivalent to calling font( new FontData( name, height, style ) ).
        Parameters:
        name - the name of the font (must not be null)
        height - the font height in points
        style - a bit or combination of NORMAL, BOLD, ITALIC
        Returns:
        a copy of this TextStyle, with the font changed to the font described by the arguments.
      • font

        public TextStyle font​(org.eclipse.swt.graphics.FontData fontData)
        Returns a copy of this TextStyle, with the font changed to the argument.
        Parameters:
        fontData - the new font. A null value causes the font to be inherited from the enclosing elements of the document.
        Returns:
        a copy of this TextStyle, with the font changed to the argument.
      • fontName

        public TextStyle fontName​(java.lang.String name)
        Returns a copy of this TextStyle, with the font name changed to the argument.
        Parameters:
        name - the new font name (must not be null)
        Returns:
        a copy of this TextStyle, with the font name changed to the argument.
      • fontHeight

        public TextStyle fontHeight​(int height)
        Returns a copy of this TextStyle, with the font height changed to the argument.
        Parameters:
        height - the new font height in points
        Returns:
        a copy of this TextStyle, with the font height changed to the argument.
      • fontStyle

        public TextStyle fontStyle​(int style)
        Returns a copy of this TextStyle, with the font style changed to the argument.
        Parameters:
        style - a bit or combination of NORMAL, BOLD, ITALIC
        Returns:
        a copy of this TextStyle, with the font style changed to the argument.
      • foreground

        public TextStyle foreground​(org.eclipse.swt.graphics.RGB foreground)
        Returns a copy of this TextStyle, with the foreground changed to the argument.
        Parameters:
        foreground - the new foreground. A null value causes the foreground to be inherited from the enclosing elements of the document.
        Returns:
        a copy of this TextStyle, with the foreground changed to the argument.
      • foreground

        public TextStyle foreground​(int red,
                                    int green,
                                    int blue)
        Returns a copy of this TextStyle, with the foreground changed to the color described by the arguments. This method is equivalent to calling foreground(new RGB(red, green, blue)).
        Parameters:
        red - the red component of the new foreground color
        green - the green component of the new foreground color
        blue - the blue component of the new foreground color
        Returns:
        a copy of this TextStyle, with the foreground changed to the color described by the arguments.
      • foreground

        public TextStyle foreground​(int rgb)
        Returns a copy of this TextStyle, with the foreground changed to the color described by the argument.
        Parameters:
        rgb - an integer containing the red, green and blue components in the 0xFF0000, 0x00FF00, and 0x0000FF positions, respectively.
        Returns:
        a copy of this TextStyle, with the foreground changed to the color described by the argument.
      • background

        public TextStyle background​(org.eclipse.swt.graphics.RGB background)
        Returns a copy of this TextStyle, with the background changed to the argument.
        Parameters:
        background - the new background. A null value causes the text background to be transparent.
        Returns:
        a copy of this TextStyle, with the background changed to the argument.
      • background

        public TextStyle background​(int red,
                                    int green,
                                    int blue)
        Returns a copy of this TextStyle, with the background changed to the color described by the arguments. This method is equivalent to calling background(new RGB(red, green, blue)
        Parameters:
        red - the red component of the new background color
        green - the green component of the new background color
        blue - the blue component of the new background color
        Returns:
        a copy of this TextStyle, with the background changed to the color described by the arguments.
      • background

        public TextStyle background​(int rgb)
        Returns a copy of this TextStyle, with the background changed to the color described by the argument.
        Parameters:
        rgb - an integer containing the red, green and blue components in the 0xFF0000, 0x00FF00, and 0x0000FF positions, respectively.
        Returns:
        a copy of this TextStyle, with the background changed to the color described by the argument.
      • align

        public TextStyle align​(int alignment)
        Returns a copy of this TextStyle, with the alignment changed to the argument.
        Parameters:
        alignment - the new alignment. Must be one of SWT.LEFT, SWT.CENTER, or SWT.RIGHT. Invalid values will be changed to SWT.LEFT.
        Returns:
        a copy of this TextStyle, with the alignment changed to the argument.
      • underline

        public TextStyle underline()
        Returns a copy of this TextStyle, with the underline flag set to true.
        Returns:
        a copy of this TextStyle, with the underline flag set to true.
      • underline

        public TextStyle underline​(boolean underline)
        Returns a copy of this TextStyle, with the underline flag set to the argument.
        Parameters:
        underline - the new underline flag.
        Returns:
        a copy of this TextStyle, with the underline flag set to the argument.
      • strikeout

        public TextStyle strikeout()
        Returns a copy of this TextStyle, with the strikeout flag set to true.
        Returns:
        a copy of this TextStyle, with the strikeout flag set to true.
      • strikeout

        public TextStyle strikeout​(boolean strikeout)
        Returns a copy of this TextStyle, with the strikeout flag set to the argument.
        Parameters:
        strikeout - the new strikeout flag.
        Returns:
        a copy of this TextStyle, with the strikeout flag set to the argument.
      • getFontData

        public org.eclipse.swt.graphics.FontData getFontData()
        Returns the font applied to the text.
        Returns:
        the font applied to the text.
      • getForeground

        public org.eclipse.swt.graphics.RGB getForeground()
        Returns the text foreground color. A null value indicates that the foreground color will be inherited from the enclosing elements of the document.
        Returns:
        the text foreground color.
      • getBackground

        public org.eclipse.swt.graphics.RGB getBackground()
        Returns the text background color. A null value indicates that the background will be transparent.
        Returns:
        the text background color. A null value indicates that the background will be transparent.
      • getAlignment

        public int getAlignment()
        Returns the text alignment. Possible values include SWT.LEFT, SWT.CENTER, or SWT.RIGHT.
        Returns:
        the text alignment.
      • getUnderline

        public boolean getUnderline()
        Returns the underline flag.
        Returns:
        the underline flag.
      • getStrikeout

        public boolean getStrikeout()
        Returns the strikeout flag.
        Returns:
        the strikeout flag.
      • create

        public TextPrint create​(java.lang.String text)
        Returns a TextPrint of the given text in this text style
        Parameters:
        text - the text
        Returns:
        a TextPrint of the given text in this text style