Documentation of 'edu.rit.draw.item.Text' Java class
Text
edu.rit.draw.item

Class Text

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable


    public class Text
    extends DrawingItem
    implements java.io.Externalizable
    Class Text provides a textual DrawingItem. A text item has these attributes:
    • Text -- The text to be displayed. The text consists of one or more lines. A newline character ('\n') separates each line from the next.
    • Font -- The font in which to display the text. All the text is displayed in the same font.
    • Fill -- The fill paint with which to display the text.
    • Spacing -- The vertical distance between consecutive lines. This is specified as a factor which is multiplied by the font size to get the actual inter-line distance.
    • Alignment -- Whether multiple lines are aligned left, center, or right.
    • Bullet -- The bullet, if any, attached to the text. The bullet is always displayed to the left of the first line of the text.
    • Position -- The text occupies a rectangular area. The text's position is specified by giving the (x,y) coordinates of the text area's northwest, north, northeast, west, center, east, southwest, south, or southeast point.

    Class Text supports a subset of HTML for specifying attributes of characters. The following HTML tags may be embedded in the text:

    • <B>Bold</B>
    • <I>Italic</I>
    • <SUP>Superscript</SUP>
    • <SUB>Subscript</SUB>

    To get literal less-than, greater-than, and ampersand characters in the text, use the following HTML character entities:

    • &lt; -- Less-than (<)
    • &gt; -- Greater-than (>)
    • &amp; -- Ampersand (&)
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  Text.Alignment
      Enumeration Text.Alignment specifies the alignment of multiple lines in a Text item.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Text()
      Construct a new text item.
      Text(Text theItem)
      Construct a new text item with the same text, location, and attributes as the given text item.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      Text add()
      Add this text item to the end of the default drawing's sequence of drawing items.
      Text add(Drawing theDrawing)
      Add this text item to the end of the given drawing's sequence of drawing items.
      Text addFirst()
      Add this text item to the beginning of the default drawing's sequence of drawing items.
      Text addFirst(Drawing theDrawing)
      Add this text item to the beginning of the given drawing's sequence of drawing items.
      Text.Alignment align()
      Returns this text item's text alignment.
      Text align(Text.Alignment theAlignment)
      Set this text item's text alignment.
      Bullet bullet()
      Returns this text item's bullet.
      Text bullet(Bullet theBullet)
      Set this text item's bullet.
      Text c(double x, double y)
      Set the center point of this text item's bounding box.
      Text c(Point thePoint)
      Set the center point of this text item's bounding box.
      static Text.Alignment defaultAlign()
      Returns the default text alignment.
      static void defaultAlign(Text.Alignment theAlignment)
      Set the default text alignment.
      static Bullet defaultBullet()
      Returns the default bullet.
      static void defaultBullet(Bullet theBullet)
      Set the default bullet.
      static Fill defaultFill()
      Returns the default fill paint.
      static void defaultFill(Fill theFill)
      Set the default fill paint.
      static java.awt.Font defaultFont()
      Returns the default font.
      static void defaultFont(java.awt.Font theFont)
      Set the default font.
      static double defaultSpacing()
      Returns the default line spacing factor.
      static void defaultSpacing(double theSpacing)
      Set the default line spacing factor.
      void draw(java.awt.Graphics2D g2d)
      Draw this text item in the given graphics context.
      Text e(double x, double y)
      Set the east middle point of this text item's bounding box.
      Text e(Point thePoint)
      Set the east middle point of this text item's bounding box.
      Fill fill()
      Returns this text item's fill paint.
      Text fill(Fill theFill)
      Set this text item's fill paint.
      java.awt.Font font()
      Returns this text item's font.
      Text font(java.awt.Font theFont)
      Set this text item's font.
      double height()
      Returns the height of this text item's bounding box.
      Text n(double x, double y)
      Set the north middle point of this text item's bounding box.
      Text n(Point thePoint)
      Set the north middle point of this text item's bounding box.
      Text ne(double x, double y)
      Set the northeast corner point of this text item's bounding box.
      Text ne(Point thePoint)
      Set the northeast corner point of this text item's bounding box.
      Point nw()
      Returns the northwest corner point of this text item's bounding box.
      Text nw(double x, double y)
      Set the northwest corner point of this text item's bounding box.
      Text nw(Point thePoint)
      Set the northwest corner point of this text item's bounding box.
      void readExternal(java.io.ObjectInput in)
      Read this text item from the given object input stream.
      Text s(double x, double y)
      Set the south middle point of this text item's bounding box.
      Text s(Point thePoint)
      Set the south middle point of this text item's bounding box.
      Text se(double x, double y)
      Set the southeast corner point of this text item's bounding box.
      Text se(Point thePoint)
      Set the southeast corner point of this text item's bounding box.
      double spacing()
      Returns this text item's line spacing factor.
      Text spacing(double theSpacing)
      Set this text item's line spacing factor.
      Text sw(double x, double y)
      Set the southwest corner point of this text item's bounding box.
      Text sw(Point thePoint)
      Set the southwest corner point of this text item's bounding box.
      java.lang.String text()
      Returns this text item's text.
      Text text(java.lang.String theText)
      Set this text item's text.
      Text w(double x, double y)
      Set the west middle point of this text item's bounding box.
      Text w(Point thePoint)
      Set the west middle point of this text item's bounding box.
      double width()
      Returns the width of this text item's bounding box.
      void writeExternal(java.io.ObjectOutput out)
      Write this text item to the given object output stream.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NORMAL_FONT

        public static final java.awt.Font NORMAL_FONT
        The normal font (sanserif, plain, 12 point).
      • NORMAL_FILL

        public static final Fill NORMAL_FILL
        The normal fill paint (black).
      • NORMAL_SPACING

        public static final double NORMAL_SPACING
        The normal line spacing factor (7/6).
        See Also:
        Constant Field Values
      • NORMAL_ALIGNMENT

        public static final Text.Alignment NORMAL_ALIGNMENT
        The normal alignment (left).
      • NORMAL_BULLET

        public static final Bullet NORMAL_BULLET
        The normal bullet (none).
    • Constructor Detail

      • Text

        public Text()
        Construct a new text item. The text item's text is empty. The text item's northwest corner is located at (0,0). The text item's attributes have the default values.
      • Text

        public Text(Text theItem)
        Construct a new text item with the same text, location, and attributes as the given text item.
        Parameters:
        theItem - Text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theItem is null.
    • Method Detail

      • defaultFont

        public static java.awt.Font defaultFont()
        Returns the default font.
        Returns:
        Default font.
      • defaultFont

        public static void defaultFont(java.awt.Font theFont)
        Set the default font. Before calling this method the first time, the default font is sanserif, plain, 12 point.
        Parameters:
        theFont - Default font.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theFont is null.
      • defaultFill

        public static Fill defaultFill()
        Returns the default fill paint.
        Returns:
        Default fill paint.
      • defaultFill

        public static void defaultFill(Fill theFill)
        Set the default fill paint. Before calling this method the first time, the default fill paint is black.
        Parameters:
        theFill - Default fill paint.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theFill is null.
      • defaultSpacing

        public static double defaultSpacing()
        Returns the default line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.
        Returns:
        Default line spacing factor.
      • defaultSpacing

        public static void defaultSpacing(double theSpacing)
        Set the default line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance. Before calling this method the first time, the default line spacing factor is 7/6.
        Parameters:
        theSpacing - Default line spacing factor.
        Throws:
        java.lang.IllegalArgumentException - (unchecked exception) Thrown if theSpacing is less than 0.
      • defaultAlign

        public static Text.Alignment defaultAlign()
        Returns the default text alignment.
        Returns:
        Default text alignment.
      • defaultAlign

        public static void defaultAlign(Text.Alignment theAlignment)
        Set the default text alignment. Before calling this method the first time, the default text alignment is left alignment.
        Parameters:
        theAlignment - Default text alignment.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theAlignment is null.
      • defaultBullet

        public static Bullet defaultBullet()
        Returns the default bullet.
        Returns:
        Default bullet.
      • defaultBullet

        public static void defaultBullet(Bullet theBullet)
        Set the default bullet. Before calling this method the first time, the default bullet is none.
        Parameters:
        theBullet - Default bullet.
      • text

        public java.lang.String text()
        Returns this text item's text. Newline characters ('\n') separate multiple lines within the text.
        Returns:
        Text (may be null).
      • text

        public Text text(java.lang.String theText)
        Set this text item's text. Newline characters ('\n') separate multiple lines within the text.
        Parameters:
        theText - Text (may be null).
        Returns:
        This text item.
      • font

        public java.awt.Font font()
        Returns this text item's font.
        Returns:
        Font.
      • font

        public Text font(java.awt.Font theFont)
        Set this text item's font.
        Parameters:
        theFont - Font.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theFont is null.
      • fill

        public Fill fill()
        Returns this text item's fill paint.
        Returns:
        Fill paint.
      • fill

        public Text fill(Fill theFill)
        Set this text item's fill paint.
        Parameters:
        theFill - Fill paint.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theFill is null.
      • spacing

        public double spacing()
        Returns this text item's line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.
        Returns:
        Line spacing factor.
      • spacing

        public Text spacing(double theSpacing)
        Set this text item's line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.
        Parameters:
        theSpacing - Line spacing factor.
        Returns:
        This text item.
        Throws:
        java.lang.IllegalArgumentException - (unchecked exception) Thrown if theSpacing is less than 0.
      • align

        public Text.Alignment align()
        Returns this text item's text alignment.
        Returns:
        Text alignment.
      • align

        public Text align(Text.Alignment theAlignment)
        Set this text item's text alignment.
        Parameters:
        theAlignment - Text alignment.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theAlignment is null.
      • bullet

        public Bullet bullet()
        Returns this text item's bullet.
        Returns:
        Bullet.
      • bullet

        public Text bullet(Bullet theBullet)
        Set this text item's bullet.
        Parameters:
        theBullet - Default bullet.
        Returns:
        This text item.
      • width

        public double width()
        Returns the width of this text item's bounding box.
        Specified by:
        width in class DrawingItem
        Returns:
        Width.
      • height

        public double height()
        Returns the height of this text item's bounding box.
        Specified by:
        height in class DrawingItem
        Returns:
        Height.
      • nw

        public Point nw()
        Returns the northwest corner point of this text item's bounding box.
        Specified by:
        nw in class DrawingItem
        Returns:
        Northwest corner point.
      • nw

        public Text nw(double x,
                       double y)
        Set the northwest corner point of this text item's bounding box.
        Parameters:
        x - X coordinate of northwest corner point.
        y - Y coordinate of northwest corner point.
        Returns:
        This text item.
      • nw

        public Text nw(Point thePoint)
        Set the northwest corner point of this text item's bounding box.
        Parameters:
        thePoint - Northwest corner point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • n

        public Text n(double x,
                      double y)
        Set the north middle point of this text item's bounding box.
        Parameters:
        x - X coordinate of north middle point.
        y - Y coordinate of north middle point.
        Returns:
        This text item.
      • n

        public Text n(Point thePoint)
        Set the north middle point of this text item's bounding box.
        Parameters:
        thePoint - North middle point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • ne

        public Text ne(double x,
                       double y)
        Set the northeast corner point of this text item's bounding box.
        Parameters:
        x - X coordinate of northeast corner point.
        y - Y coordinate of northeast corner point.
        Returns:
        This text item.
      • ne

        public Text ne(Point thePoint)
        Set the northeast corner point of this text item's bounding box.
        Parameters:
        thePoint - Northeast corner point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • w

        public Text w(double x,
                      double y)
        Set the west middle point of this text item's bounding box.
        Parameters:
        x - X coordinate of west middle point.
        y - Y coordinate of west middle point.
        Returns:
        This text item.
      • w

        public Text w(Point thePoint)
        Set the west middle point of this text item's bounding box.
        Parameters:
        thePoint - West middle point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • c

        public Text c(double x,
                      double y)
        Set the center point of this text item's bounding box.
        Parameters:
        x - X coordinate of center point.
        y - Y coordinate of center point.
        Returns:
        This text item.
      • c

        public Text c(Point thePoint)
        Set the center point of this text item's bounding box.
        Parameters:
        thePoint - Center point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • e

        public Text e(double x,
                      double y)
        Set the east middle point of this text item's bounding box.
        Parameters:
        x - X coordinate of east middle point.
        y - Y coordinate of east middle point.
        Returns:
        This text item.
      • e

        public Text e(Point thePoint)
        Set the east middle point of this text item's bounding box.
        Parameters:
        thePoint - East middle point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • sw

        public Text sw(double x,
                       double y)
        Set the southwest corner point of this text item's bounding box.
        Parameters:
        x - X coordinate of southwest corner point.
        y - Y coordinate of southwest corner point.
        Returns:
        This text item.
      • sw

        public Text sw(Point thePoint)
        Set the southwest corner point of this text item's bounding box.
        Parameters:
        thePoint - Southwest corner point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • s

        public Text s(double x,
                      double y)
        Set the south middle point of this text item's bounding box.
        Parameters:
        x - X coordinate of south middle point.
        y - Y coordinate of south middle point.
        Returns:
        This text item.
      • s

        public Text s(Point thePoint)
        Set the south middle point of this text item's bounding box.
        Parameters:
        thePoint - South middle point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • se

        public Text se(double x,
                       double y)
        Set the southeast corner point of this text item's bounding box.
        Parameters:
        x - X coordinate of southeast corner point.
        y - Y coordinate of southeast corner point.
        Returns:
        This text item.
      • se

        public Text se(Point thePoint)
        Set the southeast corner point of this text item's bounding box.
        Parameters:
        thePoint - Southeast corner point.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if thePoint is null.
      • add

        public Text add()
        Add this text item to the end of the default drawing's sequence of drawing items.
        Overrides:
        add in class DrawingItem
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no default drawing.
        See Also:
        Drawing.defaultDrawing()
      • add

        public Text add(Drawing theDrawing)
        Add this text item to the end of the given drawing's sequence of drawing items.
        Overrides:
        add in class DrawingItem
        Parameters:
        theDrawing - Drawing.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theDrawing is null.
      • addFirst

        public Text addFirst()
        Add this text item to the beginning of the default drawing's sequence of drawing items.
        Overrides:
        addFirst in class DrawingItem
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if there is no default drawing.
        See Also:
        Drawing.defaultDrawing()
      • addFirst

        public Text addFirst(Drawing theDrawing)
        Add this text item to the beginning of the given drawing's sequence of drawing items.
        Overrides:
        addFirst in class DrawingItem
        Parameters:
        theDrawing - Drawing.
        Returns:
        This text item.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if theDrawing is null.
      • writeExternal

        public void writeExternal(java.io.ObjectOutput out)
                           throws java.io.IOException
        Write this text item to the given object output stream.
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class DrawingItem
        Parameters:
        out - Object output stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
      • readExternal

        public void readExternal(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Read this text item from the given object input stream.
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class DrawingItem
        Parameters:
        in - Object input stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
        java.lang.ClassNotFoundException - Thrown if any class needed to deserialize this text item cannot be found.
      • draw

        public void draw(java.awt.Graphics2D g2d)
        Draw this text item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.
        Overrides:
        draw in class DrawingItem
        Parameters:
        g2d - 2-D graphics context.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.