Class TextSegment

  • All Implemented Interfaces:
    Segment

    public class TextSegment
    extends AbstractSegment
    One segment of a Line which should be displayed without changing attributes.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextSegment​(@NotNull java.lang.String text, boolean bold, boolean italic, boolean underline, @NotNull FontID font, @Nullable java.awt.Color color)
      Creates a new segment.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void draw​(@NotNull java.awt.Graphics g, int y, @NotNull Fonts fonts)
      Draws this segment to a Graphics instance.
      @NotNull java.awt.geom.RectangularShape getSize​(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context)
      Returns the size of this segment in pixels.
      @NotNull java.lang.String getText()
      Returns the text to display.
      boolean matches​(boolean bold, boolean italic, boolean underline, @NotNull FontID font, @Nullable java.awt.Color color)
      Returns whether this segment matches the given attributes.
      @NotNull java.lang.String toString()  
      void updateAttributes​(@NotNull Fonts fonts, @NotNull java.awt.font.FontRenderContext context)
      Updates the cached attributes of this segment.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TextSegment

        public TextSegment​(@NotNull
                           @NotNull java.lang.String text,
                           boolean bold,
                           boolean italic,
                           boolean underline,
                           @NotNull
                           @NotNull FontID font,
                           @Nullable
                           @Nullable java.awt.Color color)
        Creates a new segment.
        Parameters:
        text - the text to display
        bold - whether bold face is enabled
        italic - whether italic face is enabled
        underline - whether underlining is enabled
        font - the font to use
        color - the color to use; null means "default color"
    • Method Detail

      • getText

        @NotNull
        public @NotNull java.lang.String getText()
        Returns the text to display.
        Returns:
        the text to display
      • draw

        public void draw​(@NotNull
                         @NotNull java.awt.Graphics g,
                         int y,
                         @NotNull
                         @NotNull Fonts fonts)
        Description copied from interface: Segment
        Draws this segment to a Graphics instance.
        Parameters:
        g - the graphics to draw to
        y - the y-coordinate to draw to
        fonts - the fonts to use
      • updateAttributes

        public void updateAttributes​(@NotNull
                                     @NotNull Fonts fonts,
                                     @NotNull
                                     @NotNull java.awt.font.FontRenderContext context)
        Description copied from interface: Segment
        Updates the cached attributes of this segment.
        Parameters:
        fonts - the fonts instance to use
        context - the font render context to use
      • getSize

        @NotNull
        public @NotNull java.awt.geom.RectangularShape getSize​(@NotNull
                                                               @NotNull Fonts fonts,
                                                               @NotNull
                                                               @NotNull java.awt.font.FontRenderContext context)
        Description copied from interface: Segment
        Returns the size of this segment in pixels.
        Parameters:
        fonts - the fonts instance to use
        context - the font render context to use
        Returns:
        the size
      • matches

        public boolean matches​(boolean bold,
                               boolean italic,
                               boolean underline,
                               @NotNull
                               @NotNull FontID font,
                               @Nullable
                               @Nullable java.awt.Color color)
        Returns whether this segment matches the given attributes.
        Parameters:
        bold - the bold attribute
        italic - the italic attribute
        underline - the underline attribute
        font - the font attribute
        color - the color attribute
        Returns:
        whether all attributes do match
      • toString

        @NotNull
        public @NotNull java.lang.String toString()
        Overrides:
        toString in class java.lang.Object