com.lowagie.text.pdf

Class BaseField

public abstract class BaseField extends Object

Common field variables.

Author: Paulo Soares (psoares@consiste.pt)

Field Summary
protected intalignment
protected ColorbackgroundColor
protected ColorborderColor
protected intborderStyle
protected floatborderWidth
protected Rectanglebox
static floatBORDER_WIDTH_MEDIUM
A medium border with 2 point width.
static floatBORDER_WIDTH_THICK
A thick border with 3 point width.
static floatBORDER_WIDTH_THIN
A thin border with 1 point width.
static intCOMB
combo box flag.
static intDO_NOT_SCROLL
The field will not scroll (horizontally for single-line fields, vertically for multiple-line fields) to accommodate more text than will fit within its annotation rectangle.
static intDO_NOT_SPELL_CHECK
The text entered in the field will not be spell-checked.
static intEDIT
If set the combo box includes an editable text box as well as a drop list; if clear, it includes only a drop list.
static HashMapfieldKeys
protected StringfieldName
Holds value of property fieldName.
protected BaseFontfont
protected floatfontSize
static intFILE_SELECTION
The text entered in the field represents the pathname of a file whose contents are to be submitted as the value of the field.
static intHIDDEN
The field is hidden.
static intHIDDEN_BUT_PRINTABLE
The field is hidden but is printable.
protected intmaxCharacterLength
Holds value of property maxCharacterLength.
static intMULTILINE
The field may contain multiple lines of text.
protected intoptions
Holds value of property options.
static intPASSWORD
The field is intended for entering a secure password that should not be echoed visibly to the screen.
protected introtation
Holds value of property rotation.
static intREAD_ONLY
The user may not change the value of the field.
static intREQUIRED
The field must have a value at the time it is exported by a submit-form action.
protected Stringtext
protected ColortextColor
protected intvisibility
Holds value of property visibility.
static intVISIBLE
The field is visible.
static intVISIBLE_BUT_DOES_NOT_PRINT
The field is visible but does not print.
protected PdfWriterwriter
Constructor Summary
BaseField(PdfWriter writer, Rectangle box, String fieldName)
Creates a new TextField.
Method Summary
protected static ArrayListbreakLines(ArrayList breaks, BaseFont font, float fontSize, float width)
voiddrawBottomFrame(PdfAppearance app)
voiddrawTopFrame(PdfAppearance app)
intgetAlignment()
Gets the text horizontal alignment.
ColorgetBackgroundColor()
Gets the background color.
protected PdfAppearancegetBorderAppearance()
ColorgetBorderColor()
Gets the border color.
intgetBorderStyle()
Gets the border style.
floatgetBorderWidth()
Gets the border width in points.
RectanglegetBox()
Gets the field dimension and position.
StringgetFieldName()
Gets the field name.
BaseFontgetFont()
Gets the text font.
floatgetFontSize()
Gets the font size.
protected static ArrayListgetHardBreaks(String text)
intgetMaxCharacterLength()
Gets the maximum length of the fields text, in characters.
intgetOptions()
Gets the option flags.
protected BaseFontgetRealFont()
intgetRotation()
Gets the field rotation.
StringgetText()
Gets the text.
ColorgetTextColor()
Gets the text color.
intgetVisibility()
Gets the field visibility flag.
PdfWritergetWriter()
Getter for property writer.
static voidmoveFields(PdfDictionary from, PdfDictionary to)
Moves the field keys from from to to.
voidsetAlignment(int alignment)
Sets the text horizontal alignment.
voidsetBackgroundColor(Color backgroundColor)
Sets the background color.
voidsetBorderColor(Color borderColor)
Sets the border color.
voidsetBorderStyle(int borderStyle)
Sets the border style.
voidsetBorderWidth(float borderWidth)
Sets the border width in points.
voidsetBox(Rectangle box)
Sets the field dimension and position.
voidsetFieldName(String fieldName)
Sets the field name.
voidsetFont(BaseFont font)
Sets the text font.
voidsetFontSize(float fontSize)
Sets the font size.
voidsetMaxCharacterLength(int maxCharacterLength)
Sets the maximum length of the fields text, in characters.
voidsetOptions(int options)
Sets the option flags.
voidsetRotation(int rotation)
Sets the field rotation.
voidsetRotationFromPage(Rectangle page)
Convenience method to set the field rotation the same as the page rotation.
voidsetText(String text)
Sets the text for text fields.
voidsetTextColor(Color textColor)
Sets the text color.
voidsetVisibility(int visibility)
Sets the field visibility flag.
voidsetWriter(PdfWriter writer)
Setter for property writer.
protected static voidtrimRight(StringBuffer buf)

Field Detail

alignment

protected int alignment

backgroundColor

protected Color backgroundColor

borderColor

protected Color borderColor

borderStyle

protected int borderStyle

borderWidth

protected float borderWidth

box

protected Rectangle box

BORDER_WIDTH_MEDIUM

public static final float BORDER_WIDTH_MEDIUM
A medium border with 2 point width.

BORDER_WIDTH_THICK

public static final float BORDER_WIDTH_THICK
A thick border with 3 point width.

BORDER_WIDTH_THIN

public static final float BORDER_WIDTH_THIN
A thin border with 1 point width.

COMB

public static final int COMB
combo box flag.

DO_NOT_SCROLL

public static final int DO_NOT_SCROLL
The field will not scroll (horizontally for single-line fields, vertically for multiple-line fields) to accommodate more text than will fit within its annotation rectangle. Once the field is full, no further text will be accepted.

DO_NOT_SPELL_CHECK

public static final int DO_NOT_SPELL_CHECK
The text entered in the field will not be spell-checked. This flag is meaningful only in text fields and in combo fields with the EDIT flag set.

EDIT

public static final int EDIT
If set the combo box includes an editable text box as well as a drop list; if clear, it includes only a drop list. This flag is only meaningful with combo fields.

fieldKeys

private static final HashMap fieldKeys

fieldName

protected String fieldName
Holds value of property fieldName.

font

protected BaseFont font

fontSize

protected float fontSize

FILE_SELECTION

public static final int FILE_SELECTION
The text entered in the field represents the pathname of a file whose contents are to be submitted as the value of the field.

HIDDEN

public static final int HIDDEN
The field is hidden.

HIDDEN_BUT_PRINTABLE

public static final int HIDDEN_BUT_PRINTABLE
The field is hidden but is printable.

maxCharacterLength

protected int maxCharacterLength
Holds value of property maxCharacterLength.

MULTILINE

public static final int MULTILINE
The field may contain multiple lines of text. This flag is only meaningful with text fields.

options

protected int options
Holds value of property options.

PASSWORD

public static final int PASSWORD
The field is intended for entering a secure password that should not be echoed visibly to the screen.

rotation

protected int rotation
Holds value of property rotation.

READ_ONLY

public static final int READ_ONLY
The user may not change the value of the field.

REQUIRED

public static final int REQUIRED
The field must have a value at the time it is exported by a submit-form action.

text

protected String text

textColor

protected Color textColor

visibility

protected int visibility
Holds value of property visibility.

VISIBLE

public static final int VISIBLE
The field is visible.

VISIBLE_BUT_DOES_NOT_PRINT

public static final int VISIBLE_BUT_DOES_NOT_PRINT
The field is visible but does not print.

writer

protected PdfWriter writer

Constructor Detail

BaseField

public BaseField(PdfWriter writer, Rectangle box, String fieldName)
Creates a new TextField.

Parameters: writer the document PdfWriter box the field location and dimensions fieldName the field name. If null only the widget keys will be included in the field allowing it to be used as a kid field.

Method Detail

breakLines

protected static ArrayList breakLines(ArrayList breaks, BaseFont font, float fontSize, float width)

drawBottomFrame

private void drawBottomFrame(PdfAppearance app)

drawTopFrame

private void drawTopFrame(PdfAppearance app)

getAlignment

public int getAlignment()
Gets the text horizontal alignment.

Returns: the text horizontal alignment

getBackgroundColor

public Color getBackgroundColor()
Gets the background color.

Returns: the background color

getBorderAppearance

protected PdfAppearance getBorderAppearance()

getBorderColor

public Color getBorderColor()
Gets the border color.

Returns: the border color

getBorderStyle

public int getBorderStyle()
Gets the border style.

Returns: the border style

getBorderWidth

public float getBorderWidth()
Gets the border width in points.

Returns: the border width in points

getBox

public Rectangle getBox()
Gets the field dimension and position.

Returns: the field dimension and position

getFieldName

public String getFieldName()
Gets the field name.

Returns: the field name

getFont

public BaseFont getFont()
Gets the text font.

Returns: the text font

getFontSize

public float getFontSize()
Gets the font size.

Returns: the font size

getHardBreaks

protected static ArrayList getHardBreaks(String text)

getMaxCharacterLength

public int getMaxCharacterLength()
Gets the maximum length of the fields text, in characters.

Returns: the maximum length of the fields text, in characters.

getOptions

public int getOptions()
Gets the option flags.

Returns: the option flags

getRealFont

protected BaseFont getRealFont()

getRotation

public int getRotation()
Gets the field rotation.

Returns: the field rotation

getText

public String getText()
Gets the text.

Returns: the text

getTextColor

public Color getTextColor()
Gets the text color.

Returns: the text color

getVisibility

public int getVisibility()
Gets the field visibility flag.

Returns: the field visibility flag

getWriter

public PdfWriter getWriter()
Getter for property writer.

Returns: Value of property writer.

moveFields

public static void moveFields(PdfDictionary from, PdfDictionary to)
Moves the field keys from from to to. The moved keys are removed from from.

Parameters: from the source to the destination. It may be null

setAlignment

public void setAlignment(int alignment)
Sets the text horizontal alignment. It can be Element.ALIGN_LEFT, Element.ALIGN_CENTER and Element.ALIGN_RIGHT.

Parameters: alignment the text horizontal alignment

setBackgroundColor

public void setBackgroundColor(Color backgroundColor)
Sets the background color. Set to null for transparent background.

Parameters: backgroundColor the background color

setBorderColor

public void setBorderColor(Color borderColor)
Sets the border color. Set to null to remove the border.

Parameters: borderColor the border color

setBorderStyle

public void setBorderStyle(int borderStyle)
Sets the border style. The styles are found in PdfBorderDictionary and can be STYLE_SOLID, STYLE_DASHED, STYLE_BEVELED, STYLE_INSET and STYLE_UNDERLINE.

Parameters: borderStyle the border style

setBorderWidth

public void setBorderWidth(float borderWidth)
Sets the border width in points. To eliminate the border set the border color to null.

Parameters: borderWidth the border width in points

setBox

public void setBox(Rectangle box)
Sets the field dimension and position.

Parameters: box the field dimension and position

setFieldName

public void setFieldName(String fieldName)
Sets the field name.

Parameters: fieldName the field name. If null only the widget keys will be included in the field allowing it to be used as a kid field.

setFont

public void setFont(BaseFont font)
Sets the text font. If null then Helvetica will be used.

Parameters: font the text font

setFontSize

public void setFontSize(float fontSize)
Sets the font size. If 0 then auto-sizing will be used but only for text fields.

Parameters: fontSize the font size

setMaxCharacterLength

public void setMaxCharacterLength(int maxCharacterLength)
Sets the maximum length of the fields text, in characters. It is only meaningful for text fields.

Parameters: maxCharacterLength the maximum length of the fields text, in characters

setOptions

public void setOptions(int options)
Sets the option flags. The option flags can be a combination by oring of READ_ONLY, REQUIRED, MULTILINE, DO_NOT_SCROLL, PASSWORD, FILE_SELECTION, DO_NOT_SPELL_CHECK and EDIT.

Parameters: options the option flags

setRotation

public void setRotation(int rotation)
Sets the field rotation. This value should be the same as the page rotation where the field will be shown.

Parameters: rotation the field rotation

setRotationFromPage

public void setRotationFromPage(Rectangle page)
Convenience method to set the field rotation the same as the page rotation.

Parameters: page the page

setText

public void setText(String text)
Sets the text for text fields.

Parameters: text the text

setTextColor

public void setTextColor(Color textColor)
Sets the text color. If null the color used will be black.

Parameters: textColor the text color

setVisibility

public void setVisibility(int visibility)
Sets the field visibility flag. This flags can be one of VISIBLE, HIDDEN, VISIBLE_BUT_DOES_NOT_PRINT and HIDDEN_BUT_PRINTABLE.

Parameters: visibility field visibility flag

setWriter

public void setWriter(PdfWriter writer)
Setter for property writer.

Parameters: writer New value of property writer.

trimRight

protected static void trimRight(StringBuffer buf)