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 |
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
|
Creates a new
|
|
Make the specified box this box's child. Equivalent to
|
|
Returns false if for any reason this box has negative dimensions |
|
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
|
|
This method is called after getting the box by calling
|
|
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
|
|
Get the absolute upper left location point for this box
|
|
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 the full string associated with a call to |
|
Get this box's parent box
|
|
Get the wrapped strings if this box was from a call to getStringBounds, otherwise this method returns null
|
|
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
|
|
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.
|
|
Returns true if this box has a parent. The 'world', or enclosing canvas is not considered a parent
|
|
For testing
|
|
Set the absolute upper left world location point for this box
|
|
Sets the full string associated with
|
|
Make the specified box this box's parent
|
|
Set the value of the string array
|
|
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
|
|
Used to align a String horizontally in the center of the box |
|
Used to align a String to the left in the box |
|
Used to aling a String to the right in a box |
|
Percent f line height to space lines |
|
Used to subtract a child from a box, *leaving* the bottom portion |
|
Used to subtract a child from a box, *leaving* the left portion |
|
Used to subtract a child from a box, *leaving" the right portion |
|
Used to subtract a child from a box, *leaving* the top portion |
|
Used to align a String at the bottom of the box |
|
Used to a align a String centered vertically |
|
Used to align a String at the top of the box |