Class TextBox

java.lang.Object
net.atthegate.server.service.pdf.TextBox
All Implemented Interfaces:
Drawable

public class TextBox extends Object implements Drawable
A box containing line-wrapped text.

Defaults:
x = 0f
y = 0f
width = 300f
height = 0f
alignment = Align.LEFT
valign = Align.TOP
spacing = 3f
margin = 1f

This class was originally developed by Ronald Bourret. It was completely rewritten in 2013 by Eugene Dragoev.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Font
     
    protected float
     
    protected float
     
    protected float
     
    protected String
     
    protected float
     
    protected float
     
    protected float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TextBox(Font font)
    Creates a text box and sets the font.
    TextBox(Font font, String text)
    Creates a text box and sets the font.
    TextBox(Font font, String text, double width, double height)
    Creates a text box and sets the font and the text.
    TextBox(Font font, String text, float width, float height)
    Creates a text box and sets the font and the text.
  • Method Summary

    Modifier and Type
    Method
    Description
    float[]
    drawOn(Page page)
    Draws this text box on the specified page.
    float[]
    drawOn(Page page, boolean draw)
    Draws this text box on the specified page.
    int
    Returns the background color.
    boolean
    getBorder(int border)
    Returns the text box border.
    int
    Returns the brush color.
     
    Returns the font used by this text box.
    float
    Returns the text box height.
    float
    Returns the border line width.
    float
    Returns the text box margin.
    int
    Returns the pen color as 0xRRGGBB integer.
    float
    Returns the spacing between lines of text.
    boolean
    Returns the strikeout flag.
    Returns the text box text.
    int
    Returns the text alignment.
     
    boolean
    Whether the text will be underlined.
    int
     
    float
    Returns the text box width.
    float
    Gets the x coordinate where this text box will be drawn on the page.
    float
    Gets the y coordinate where this text box will be drawn on the page.
    void
    setBgColor(double[] color)
    Sets the background to the specified color.
    void
    setBgColor(int color)
    Sets the background to the specified color.
    void
    setBgColor(int[] color)
    Sets the background to the specified color.
    void
    setBorder(int border, boolean visible)
    Sets the TextBox border object.
    void
    setBrushColor(double[] color)
    Sets the brush color.
    void
    setBrushColor(int color)
    Sets the brush color.
    void
    setBrushColor(int[] color)
    Sets the brush color.
    void
     
    void
    setFgColor(double[] color)
    Sets the foreground pen and brush colors to the specified color.
    void
    setFgColor(int color)
    Sets the pen and brush colors to the specified color.
    void
    setFgColor(int[] color)
    Sets the pen and brush colors to the specified color.
    void
    setFont(Font font)
    Sets the font for this text box.
    void
    setHeight(double height)
    Sets the height of this text box.
    void
    setHeight(float height)
    Sets the height of this text box.
    void
    setLineWidth(double lineWidth)
    Sets the border line width.
    void
    setLineWidth(float lineWidth)
    Sets the border line width.
    void
    setLocation(float x, float y)
    Sets the location where this text box will be drawn on the page.
    void
    setMargin(double margin)
    Sets the margin of this text box.
    void
    setMargin(float margin)
    Sets the margin of this text box.
    void
    Sets all borders to be invisible.
    void
    setPenColor(double[] color)
    Sets the pen color.
    void
    setPenColor(int color)
    Sets the pen color.
    void
    setPenColor(int[] color)
    Sets the pen color.
    void
    setPosition(double x, double y)
    Sets the position where this text box will be drawn on the page.
    void
    setPosition(float x, float y)
    Sets the position where this text box will be drawn on the page.
    void
    setSpacing(double spacing)
    Sets the spacing between lines of text.
    void
    setSpacing(float spacing)
    Sets the spacing between lines of text.
    void
    setStrikeout(boolean strikeout)
    Sets the srikeout flag.
    void
    Sets the text box text.
    void
    setTextAlignment(int alignment)
    Sets the cell text alignment.
    void
     
    void
    setUnderline(boolean underline)
    Sets the underline variable.
    void
    setVerticalAlignment(int alignment)
    Sets the vertical alignment of the text in this TextBox.
    void
    setWidth(double width)
    Sets the width of this text box.
    void
    setWidth(float width)
    Sets the width of this text box.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • font

      protected Font font
    • text

      protected String text
    • x

      protected float x
    • y

      protected float y
    • width

      protected float width
    • height

      protected float height
    • spacing

      protected float spacing
    • margin

      protected float margin
  • Constructor Details

    • TextBox

      public TextBox(Font font)
      Creates a text box and sets the font.
      Parameters:
      font - the font.
    • TextBox

      public TextBox(Font font, String text)
      Creates a text box and sets the font.
      Parameters:
      font - the font.
      text - the text.
    • TextBox

      public TextBox(Font font, String text, double width, double height)
      Creates a text box and sets the font and the text.
      Parameters:
      font - the font.
      text - the text.
      width - the width.
      height - the height.
    • TextBox

      public TextBox(Font font, String text, float width, float height)
      Creates a text box and sets the font and the text.
      Parameters:
      font - the font.
      text - the text.
      width - the width.
      height - the height.
  • Method Details

    • setFont

      public void setFont(Font font)
      Sets the font for this text box.
      Parameters:
      font - the font.
    • getFont

      public Font getFont()
      Returns the font used by this text box.
      Returns:
      the font.
    • setText

      public void setText(String text)
      Sets the text box text.
      Parameters:
      text - the text box text.
    • getText

      public String getText()
      Returns the text box text.
      Returns:
      the text box text.
    • setPosition

      public void setPosition(double x, double y)
      Sets the position where this text box will be drawn on the page.
      Parameters:
      x - the x coordinate of the top left corner of the text box.
      y - the y coordinate of the top left corner of the text box.
    • setPosition

      public void setPosition(float x, float y)
      Sets the position where this text box will be drawn on the page.
      Parameters:
      x - the x coordinate of the top left corner of the text box.
      y - the y coordinate of the top left corner of the text box.
    • setLocation

      public void setLocation(float x, float y)
      Sets the location where this text box will be drawn on the page.
      Parameters:
      x - the x coordinate of the top left corner of the text box.
      y - the y coordinate of the top left corner of the text box.
    • getX

      public float getX()
      Gets the x coordinate where this text box will be drawn on the page.
      Returns:
      the x coordinate of the top left corner of the text box.
    • getY

      public float getY()
      Gets the y coordinate where this text box will be drawn on the page.
      Returns:
      the y coordinate of the top left corner of the text box.
    • setWidth

      public void setWidth(double width)
      Sets the width of this text box.
      Parameters:
      width - the specified width.
    • setWidth

      public void setWidth(float width)
      Sets the width of this text box.
      Parameters:
      width - the specified width.
    • getWidth

      public float getWidth()
      Returns the text box width.
      Returns:
      the text box width.
    • setHeight

      public void setHeight(double height)
      Sets the height of this text box.
      Parameters:
      height - the specified height.
    • setHeight

      public void setHeight(float height)
      Sets the height of this text box.
      Parameters:
      height - the specified height.
    • getHeight

      public float getHeight()
      Returns the text box height.
      Returns:
      the text box height.
    • setMargin

      public void setMargin(double margin)
      Sets the margin of this text box.
      Parameters:
      margin - the margin between the text and the box
    • setMargin

      public void setMargin(float margin)
      Sets the margin of this text box.
      Parameters:
      margin - the margin between the text and the box
    • getMargin

      public float getMargin()
      Returns the text box margin.
      Returns:
      the margin between the text and the box
    • setLineWidth

      public void setLineWidth(double lineWidth)
      Sets the border line width.
      Parameters:
      lineWidth - double
    • setLineWidth

      public void setLineWidth(float lineWidth)
      Sets the border line width.
      Parameters:
      lineWidth - float
    • getLineWidth

      public float getLineWidth()
      Returns the border line width.
      Returns:
      float the line width.
    • setSpacing

      public void setSpacing(double spacing)
      Sets the spacing between lines of text.
      Parameters:
      spacing - the spacing
    • setSpacing

      public void setSpacing(float spacing)
      Sets the spacing between lines of text.
      Parameters:
      spacing -
    • getSpacing

      public float getSpacing()
      Returns the spacing between lines of text.
      Returns:
      float the spacing.
    • setBgColor

      public void setBgColor(int color)
      Sets the background to the specified color.
      Parameters:
      color - the color specified as 0xRRGGBB integer.
    • setBgColor

      public void setBgColor(int[] color)
      Sets the background to the specified color.
      Parameters:
      color - the color specified as array of integer values from 0x00 to 0xFF.
    • setBgColor

      public void setBgColor(double[] color)
      Sets the background to the specified color.
      Parameters:
      color - the color specified as array of double values from 0.0 to 1.0.
    • getBgColor

      public int getBgColor()
      Returns the background color.
      Returns:
      int the color as 0xRRGGBB integer.
    • setFgColor

      public void setFgColor(int color)
      Sets the pen and brush colors to the specified color.
      Parameters:
      color - the color specified as 0xRRGGBB integer.
    • setFgColor

      public void setFgColor(int[] color)
      Sets the pen and brush colors to the specified color.
      Parameters:
      color - the color specified as 0xRRGGBB integer.
    • setFgColor

      public void setFgColor(double[] color)
      Sets the foreground pen and brush colors to the specified color.
      Parameters:
      color - the color specified as an array of double values from 0.0 to 1.0.
    • setPenColor

      public void setPenColor(int color)
      Sets the pen color.
      Parameters:
      color - the color specified as 0xRRGGBB integer.
    • setPenColor

      public void setPenColor(int[] color)
      Sets the pen color.
      Parameters:
      color - the color specified as an array of int values from 0x00 to 0xFF.
    • setPenColor

      public void setPenColor(double[] color)
      Sets the pen color.
      Parameters:
      color - the color specified as an array of double values from 0.0 to 1.0.
    • getPenColor

      public int getPenColor()
      Returns the pen color as 0xRRGGBB integer.
      Returns:
      int the pen color.
    • setBrushColor

      public void setBrushColor(int color)
      Sets the brush color.
      Parameters:
      color - the color specified as 0xRRGGBB integer.
    • setBrushColor

      public void setBrushColor(int[] color)
      Sets the brush color.
      Parameters:
      color - the color specified as an array of int values from 0x00 to 0xFF.
    • setBrushColor

      public void setBrushColor(double[] color)
      Sets the brush color.
      Parameters:
      color - the color specified as an array of double values from 0.0 to 1.0.
    • getBrushColor

      public int getBrushColor()
      Returns the brush color.
      Returns:
      int the brush color specified as 0xRRGGBB integer.
    • setBorder

      public void setBorder(int border, boolean visible)
      Sets the TextBox border object.
      Parameters:
      border - the border object.
    • getBorder

      public boolean getBorder(int border)
      Returns the text box border.
      Returns:
      boolean the text border object.
    • setNoBorders

      public void setNoBorders()
      Sets all borders to be invisible. This cell will have no borders when drawn on the page.
    • setTextAlignment

      public void setTextAlignment(int alignment)
      Sets the cell text alignment.
      Parameters:
      alignment - the alignment code. Supported values: Align.LEFT, Align.RIGHT and Align.CENTER.
    • getTextAlignment

      public int getTextAlignment()
      Returns the text alignment.
      Returns:
      alignment the alignment code. Supported values: Align.LEFT, Align.RIGHT and Align.CENTER.
    • setUnderline

      public void setUnderline(boolean underline)
      Sets the underline variable. If the value of the underline variable is 'true' - the text is underlined.
      Parameters:
      underline - the underline flag.
    • getUnderline

      public boolean getUnderline()
      Whether the text will be underlined.
      Returns:
      whether the text will be underlined
    • setStrikeout

      public void setStrikeout(boolean strikeout)
      Sets the srikeout flag. In the flag is true - draw strikeout line through the text.
      Parameters:
      strikeout - the strikeout flag.
    • getStrikeout

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

      public void setFallbackFont(Font font)
    • getFallbackFont

      public Font getFallbackFont()
    • setVerticalAlignment

      public void setVerticalAlignment(int alignment)
      Sets the vertical alignment of the text in this TextBox.
      Parameters:
      alignment - - valid values areAlign.TOP, Align.BOTTOM and Align.CENTER
    • getVerticalAlignment

      public int getVerticalAlignment()
    • setTextColors

      public void setTextColors(Map<String,Integer> colors)
    • getTextColors

      public Map<String,Integer> getTextColors()
    • drawOn

      public float[] drawOn(Page page) throws Exception
      Draws this text box on the specified page.
      Specified by:
      drawOn in interface Drawable
      Parameters:
      page - the Page where the TextBox is to be drawn.
      Returns:
      x and y coordinates of the bottom right corner of this component.
      Throws:
      Exception
    • drawOn

      public float[] drawOn(Page page, boolean draw) throws Exception
      Draws this text box on the specified page.
      Parameters:
      page - the Page where the TextBox is to be drawn.
      draw - flag specifying if this component should actually be drawn on the page.
      Returns:
      x and y coordinates of the bottom right corner of this component.
      Throws:
      Exception