Main Page | Namespace List | Class Hierarchy | Class List | Class Members | Related Pages

gnu::jpdf::BoundingBox Class Reference

Collaboration diagram for gnu::jpdf::BoundingBox:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BoundingBox (Point p, Dimension d)
boolean hasParent ()
BoundingBox getParent ()
void add (BoundingBox child)
void setParent (BoundingBox parent)
String[] getStringArray ()
void setStringArray (String[] strArray)
void setAbsoluteLocation (Point point)
boolean boxExists ()
Point getAbsoluteLocation ()
String getFullString ()
void setFullString (String string)
BoundingBox getStringBounds (String string, int hAlign, int vAlign, FontMetrics fm, int padding, boolean enforce) throws IllegalArgumentException, StringTooLongException
BoundingBox getStringBounds (String string, int hAlign, int vAlign, FontMetrics fm, int padding) throws StringTooLongException, IllegalArgumentException
void drawWrappedString (Graphics g, FontMetrics fm, int padding, int hAlign) throws IllegalArgumentException, StringTooLongException
void drawWrappedStringTruncate (Graphics g, FontMetrics fm, int padding, int hAlign)
void drawChoppedString (Graphics g, FontMetrics fm, int padding, int hAlign)
BoundingBox subtract (BoundingBox child, int subtractFrom)
Point getDrawingPoint ()

Static Public Member Functions

void main (String[] args)

Static Public Attributes

final int LINE_SPACING_PERCENTAGE = 20
final int VERT_ALIGN_CENTER = 0
final int VERT_ALIGN_TOP = 1
final int VERT_ALIGN_BOTTOM = 2
final int HORIZ_ALIGN_CENTER = 3
final int HORIZ_ALIGN_LEFT = 4
final int HORIZ_ALIGN_RIGHT = 5
final int SUBTRACT_FROM_TOP = 6
final int SUBTRACT_FROM_BOTTOM = 7
final int SUBTRACT_FROM_LEFT = 8
final int SUBTRACT_FROM_RIGHT = 9

Detailed Description

This class simplifies the placement of Strings within a canvas area where the placement of objects is absolute

A BoundingBox is just a Rectangle that knows how to find the coordinates for a String based on the desired alignment and FontMetrics. For each new String, a new child BoundingBox is made that can be subtracted from the original box so new Strings can be added

One of the more helpful features of this class is the string wrap feature of getStringBounds. The box returned by that method will contain an array of strings that have been broken down to fit the box. The box's coordinates and size will reflect the size of the entire group of strings if it is laid out as expected. Using the returned box and iterating through the array of strings from top to bottom, getting new bounding boxes for each one (with upper left alignment and no padding) will result in the correct string wrap.

Note that you will need to have Xvfb running on a Unix server to use this class

Author:
Eric Z. Beard, ericzbeard@hotmail.com

Author
ezb
Version:
Revision
1.8
,
Date
2002/02/05 19:25:35


Constructor & Destructor Documentation

gnu::jpdf::BoundingBox::BoundingBox Point  p,
Dimension  d
[inline]
 

Creates a new BoundingBox instance.

Parameters:
p a Point, upper left coords
d a Dimension, used to determine height and width


Member Function Documentation

void gnu::jpdf::BoundingBox::add BoundingBox  child  )  [inline]
 

Make the specified box this box's child. Equivalent to child.setParent(parent) where the specified 'parent' is this instance

Parameters:
child a BoundingBox, any box that can fit inside this one. The results of calling getAbsoluteLocation() on the child will be altered after this to take into account the child's new location in the 'world'

boolean gnu::jpdf::BoundingBox::boxExists  )  [inline]
 

Returns false if for any reason this box has negative dimensions

void gnu::jpdf::BoundingBox::drawChoppedString Graphics  g,
FontMetrics  fm,
int  padding,
int  hAlign
[inline]
 

Take the first line of the string (if it is wrapped, otherwise just take the whole string) and chop the end of it off to make it fit in the box. If the box is smaller than one letter, draw nothing

Parameters:
g the Graphics object to draw to
fm the FontMetrics object to use for string sizing
padding the int amount of padding around the string
hAlign the int horizontal alignment

void gnu::jpdf::BoundingBox::drawWrappedString Graphics  g,
FontMetrics  fm,
int  padding,
int  hAlign
throws IllegalArgumentException, StringTooLongException [inline]
 

This method is called after getting the box by calling getStringBounds on the parent. Wraps the string at word boundaries and draws it to the specified Graphics context. Make sure padding is the same as specified for the getStringBounds call, or you may get an unexpected gnu.jpdf.StringTooLongException

Parameters:
g the Graphics object
fm the FontMetrics to use for sizing
padding an int, the padding around the strings
hAlign the int horizontal alignment
Exceptions:
<code>IllegalArgumentException</code> if the args are invalid
<code>StringTooLongException</code> if the string won't fit this will only happen if the fm or padding has been changed since getStringBounds was called succesfully

void gnu::jpdf::BoundingBox::drawWrappedStringTruncate Graphics  g,
FontMetrics  fm,
int  padding,
int  hAlign
[inline]
 

Draws lines from the wrapped string until there is no more room and then stops. If there is no string or the box is too small for anything to be drawn, does nothing

Parameters:
g the Graphics object to draw to
fm the FontMetrics object to use for string sizing
padding the int amount of padding around the string
hAlign the int horizontal alignment

Point gnu::jpdf::BoundingBox::getAbsoluteLocation  )  [inline]
 

Get the absolute upper left location point for this box

Returns:
a Point value

Point gnu::jpdf::BoundingBox::getDrawingPoint  )  [inline]
 

Gets the drawing point to use in Graphics drawing methods. After getting a new BoundingBox with getStringBounds(), calling this method will give you an absolute point, accounting for alignment and padding, etc, from which to start drawing the String

If getStringBounds was not called (this is a parent box), the upper left coordinates will be returned (this.getLocation())

Returns:
a Point

String gnu::jpdf::BoundingBox::getFullString  )  [inline]
 

Returns the full string associated with a call to getStringBounds

BoundingBox gnu::jpdf::BoundingBox::getParent  )  [inline]
 

Get this box's parent box

Returns:
a BoundingBox value

String [] gnu::jpdf::BoundingBox::getStringArray  )  [inline]
 

Get the wrapped strings if this box was from a call to getStringBounds, otherwise this method returns null

Returns:
a String[] array of strings, top to bottom in layout

BoundingBox gnu::jpdf::BoundingBox::getStringBounds String  string,
int  hAlign,
int  vAlign,
FontMetrics  fm,
int  padding
throws StringTooLongException, IllegalArgumentException [inline]
 

Gets the location of a String after it is adjusted for alignment within this box. The point's coordinates are either within this box or within the enclosing area.

By default, this method enforces string length and throws the exception if it is too long

Parameters:
string a String, the String to be placed
hAlign an int, HORIZ_ALIGN_CENTER, HORIZ_ALIGN_LEFT, HORIX_ALIGN_RIGHT
vAlign an int, VERT_ALIGN_CENTER, VERT_ALIGN_TOP, VERT_ALIGN_BOTTOM
fm a FontMetrics object for this String
padding an int, the padding around the String
Returns:
a Point, the coords to use in drawString()
Exceptions:
<code>IllegalArgumentException</code> if the args are invalid
<code>StringTooLongException</code> if the string won't fit

BoundingBox gnu::jpdf::BoundingBox::getStringBounds String  string,
int  hAlign,
int  vAlign,
FontMetrics  fm,
int  padding,
boolean  enforce
throws IllegalArgumentException, StringTooLongException [inline]
 

Gets the location of a String after it is adjusted for alignment within this box. The point's coordinates are either within this box or within the enclosing area.

Parameters:
string a String, the String to be placed
hAlign an int, HORIZ_ALIGN_CENTER, HORIZ_ALIGN_LEFT, HORIX_ALIGN_RIGHT
vAlign an int, VERT_ALIGN_CENTER, VERT_ALIGN_TOP, VERT_ALIGN_BOTTOM
fm a FontMetrics object for this String
padding an int, the padding around the String
enforce a boolean, if true the method will throw an exception when the string is too big, if not true it will break the string down and overrun the bottom of the box. If the box is too small for even one word, the exception will be thrown
Returns:
a Point, the coords to use in drawString()
See also:
HORIZ_ALIGN_LEFT

HORIZ_ALIGN_CENTER

HORIZ_ALIGN_RIGHT

VERT_ALIGN_TOP

VERT_ALIGN_CENTER

VERT_ALIGN_BOTTOM

Exceptions:
<code>IllegalArgumentException</code> if the args are invalid
<code>StringTooLongException</code> if the string won't fit and enforce is set to true. The exception can still be thrown if enforce is false, but only in cases such as the box having no height or width

boolean gnu::jpdf::BoundingBox::hasParent  )  [inline]
 

Returns true if this box has a parent. The 'world', or enclosing canvas is not considered a parent

Returns:
a boolean value

void gnu::jpdf::BoundingBox::main String[]  args  )  [inline, static]
 

For testing

Parameters:
args a String[] value

void gnu::jpdf::BoundingBox::setAbsoluteLocation Point  point  )  [inline]
 

Set the absolute upper left world location point for this box

Parameters:
point a Point value

void gnu::jpdf::BoundingBox::setFullString String  string  )  [inline]
 

Sets the full string associated with getStringBounds

Parameters:
string a String

void gnu::jpdf::BoundingBox::setParent BoundingBox  parent  )  [inline]
 

Make the specified box this box's parent

Parameters:
parent a BoundingBox value

void gnu::jpdf::BoundingBox::setStringArray String[]  strArray  )  [inline]
 

Set the value of the string array

Parameters:
strArray a String array

BoundingBox gnu::jpdf::BoundingBox::subtract BoundingBox  child,
int  subtractFrom
[inline]
 

Removes the child box from this parent box. The child must have this object as its parent or the method does nothing. The BoundingBox returned will be cut by an area equal to the child area plus the horizontal or vertical strip in which it sits, depending on the 'subtractFrom' value passed in

Parameters:
child a BoundingBox value
subtractFrom an int, SUBTRACT_FROM_LEFT, SUBTRACT_FROM_RIGHT, SUBTRACT_FROM_TOP, SUBTRACT_FROM_BOTTOM
Returns:
a BoundingBox value
See also:
SUBTRACT_FROM_LEFT

SUBTRACT_FROM_RIGHT

SUBTRACT_FROM_TOP

SUBTRACT_FROM_BOTTOM


Member Data Documentation

final int gnu::jpdf::BoundingBox::HORIZ_ALIGN_CENTER = 3 [static]
 

Used to align a String horizontally in the center of the box

final int gnu::jpdf::BoundingBox::HORIZ_ALIGN_LEFT = 4 [static]
 

Used to align a String to the left in the box

final int gnu::jpdf::BoundingBox::HORIZ_ALIGN_RIGHT = 5 [static]
 

Used to aling a String to the right in a box

final int gnu::jpdf::BoundingBox::LINE_SPACING_PERCENTAGE = 20 [static]
 

Percent f line height to space lines

final int gnu::jpdf::BoundingBox::SUBTRACT_FROM_BOTTOM = 7 [static]
 

Used to subtract a child from a box, *leaving* the bottom portion

final int gnu::jpdf::BoundingBox::SUBTRACT_FROM_LEFT = 8 [static]
 

Used to subtract a child from a box, *leaving* the left portion

final int gnu::jpdf::BoundingBox::SUBTRACT_FROM_RIGHT = 9 [static]
 

Used to subtract a child from a box, *leaving" the right portion

final int gnu::jpdf::BoundingBox::SUBTRACT_FROM_TOP = 6 [static]
 

Used to subtract a child from a box, *leaving* the top portion

final int gnu::jpdf::BoundingBox::VERT_ALIGN_BOTTOM = 2 [static]
 

Used to align a String at the bottom of the box

final int gnu::jpdf::BoundingBox::VERT_ALIGN_CENTER = 0 [static]
 

Used to a align a String centered vertically

final int gnu::jpdf::BoundingBox::VERT_ALIGN_TOP = 1 [static]
 

Used to align a String at the top of the box


The documentation for this class was generated from the following file:
Generated on Wed Jan 19 16:58:06 2005 by  doxygen 1.3.9.1