Java Doc for BoundingBox.java in  » PDF » gnujpdf » gnu » jpdf » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » gnujpdf » gnu.jpdf 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.awt.Rectangle
   gnu.jpdf.BoundingBox

BoundingBox
public class BoundingBox extends Rectangle (Code)

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:
   $Author: ezb $
version:
   $Revision: 1.8 $, $Date: 2002/02/05 19:25:35 $


Field Summary
final public static  intHORIZ_ALIGN_CENTER
    
final public static  intHORIZ_ALIGN_LEFT
    
final public static  intHORIZ_ALIGN_RIGHT
    
final public static  intLINE_SPACING_PERCENTAGE
    
final public static  intSUBTRACT_FROM_BOTTOM
    
final public static  intSUBTRACT_FROM_LEFT
    
final public static  intSUBTRACT_FROM_RIGHT
    
final public static  intSUBTRACT_FROM_TOP
    
final public static  intVERT_ALIGN_BOTTOM
    
final public static  intVERT_ALIGN_CENTER
    
final public static  intVERT_ALIGN_TOP
    

Constructor Summary
public  BoundingBox(Point p, Dimension d)
     Creates a new BoundingBox instance.

Method Summary
public  voidadd(BoundingBox child)
    

Make the specified box this box's child.

public  booleanboxExists()
    
public  voiddrawChoppedString(Graphics g, FontMetrics fm, int padding, int hAlign)
    

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.

public  voiddrawWrappedString(Graphics g, FontMetrics fm, int padding, int hAlign)
    

This method is called after getting the box by calling getStringBounds on the parent.

public  voiddrawWrappedStringTruncate(Graphics g, FontMetrics fm, int padding, int hAlign)
    

Draws lines from the wrapped string until there is no more room and then stops.

public  PointgetAbsoluteLocation()
    
public  PointgetDrawingPoint()
    

Gets the drawing point to use in Graphics drawing methods.

public  StringgetFullString()
    
public  BoundingBoxgetParent()
    
public  String[]getStringArray()
    
public  BoundingBoxgetStringBounds(String string, int hAlign, int vAlign, FontMetrics fm, int padding, boolean enforce)
    

Gets the location of a String after it is adjusted for alignment within this box.

public  BoundingBoxgetStringBounds(String string, int hAlign, int vAlign, FontMetrics fm, int padding)
    

Gets the location of a String after it is adjusted for alignment within this box.

public  booleanhasParent()
    

Returns true if this box has a parent.

public static  voidmain(String[] args)
    
public  voidsetAbsoluteLocation(Point point)
    
public  voidsetFullString(String string)
    
public  voidsetParent(BoundingBox parent)
    
public  voidsetStringArray(String[] strArray)
    
public  BoundingBoxsubtract(BoundingBox child, int subtractFrom)
    

Removes the child box from this parent box.


Field Detail
HORIZ_ALIGN_CENTER
final public static int HORIZ_ALIGN_CENTER(Code)
Used to align a String horizontally in the center of the box



HORIZ_ALIGN_LEFT
final public static int HORIZ_ALIGN_LEFT(Code)
Used to align a String to the left in the box



HORIZ_ALIGN_RIGHT
final public static int HORIZ_ALIGN_RIGHT(Code)
Used to aling a String to the right in a box



LINE_SPACING_PERCENTAGE
final public static int LINE_SPACING_PERCENTAGE(Code)
Percent f line height to space lines



SUBTRACT_FROM_BOTTOM
final public static int SUBTRACT_FROM_BOTTOM(Code)
Used to subtract a child from a box, *leaving* the bottom portion



SUBTRACT_FROM_LEFT
final public static int SUBTRACT_FROM_LEFT(Code)
Used to subtract a child from a box, *leaving* the left portion



SUBTRACT_FROM_RIGHT
final public static int SUBTRACT_FROM_RIGHT(Code)
Used to subtract a child from a box, *leaving" the right portion



SUBTRACT_FROM_TOP
final public static int SUBTRACT_FROM_TOP(Code)
Used to subtract a child from a box, *leaving* the top portion



VERT_ALIGN_BOTTOM
final public static int VERT_ALIGN_BOTTOM(Code)
Used to align a String at the bottom of the box



VERT_ALIGN_CENTER
final public static int VERT_ALIGN_CENTER(Code)
Used to a align a String centered vertically



VERT_ALIGN_TOP
final public static int VERT_ALIGN_TOP(Code)
Used to align a String at the top of the box




Constructor Detail
BoundingBox
public BoundingBox(Point p, Dimension d)(Code)
Creates a new BoundingBox instance.
Parameters:
  p - a Point, upper left coords
Parameters:
  d - a Dimension, used to determine height and width




Method Detail
add
public void add(BoundingBox child)(Code)

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'



boxExists
public boolean boxExists()(Code)

Returns false if for any reason this box has negative dimensions




drawChoppedString
public void drawChoppedString(Graphics g, FontMetrics fm, int padding, int hAlign)(Code)

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
Parameters:
  fm - the FontMetrics object to use for string sizing
Parameters:
  padding - the int amount of padding around the string
Parameters:
  hAlign - the int horizontal alignment



drawWrappedString
public void drawWrappedString(Graphics g, FontMetrics fm, int padding, int hAlign) throws IllegalArgumentException, StringTooLongException(Code)

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
Parameters:
  fm - the FontMetrics to use for sizing
Parameters:
  padding - an int, the padding around the strings
Parameters:
  hAlign - the int horizontal alignment IllegalArgumentException if the args are invalid StringTooLongException if the string won't fit this will only happen if the fm or padding has been changed since getStringBounds was called succesfully



drawWrappedStringTruncate
public void drawWrappedStringTruncate(Graphics g, FontMetrics fm, int padding, int hAlign)(Code)

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
Parameters:
  fm - the FontMetrics object to use for string sizing
Parameters:
  padding - the int amount of padding around the string
Parameters:
  hAlign - the int horizontal alignment



getAbsoluteLocation
public Point getAbsoluteLocation()(Code)

Get the absolute upper left location point for this box

a Point value



getDrawingPoint
public Point getDrawingPoint()(Code)

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())

a Point



getFullString
public String getFullString()(Code)

Returns the full string associated with a call to getStringBounds




getParent
public BoundingBox getParent()(Code)

Get this box's parent box

a BoundingBox value



getStringArray
public String[] getStringArray()(Code)

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

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



getStringBounds
public BoundingBox getStringBounds(String string, int hAlign, int vAlign, FontMetrics fm, int padding, boolean enforce) throws IllegalArgumentException, StringTooLongException(Code)

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
Parameters:
  hAlign - an int, HORIZ_ALIGN_CENTER, HORIZ_ALIGN_LEFT, HORIX_ALIGN_RIGHT
Parameters:
  vAlign - an int, VERT_ALIGN_CENTER, VERT_ALIGN_TOP, VERT_ALIGN_BOTTOM
Parameters:
  fm - a FontMetrics object for this String
Parameters:
  padding - an int, the padding around the String
Parameters:
  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 a Point, the coords to use in drawString()
See Also:   BoundingBox.HORIZ_ALIGN_LEFT
See Also:   BoundingBox.HORIZ_ALIGN_CENTER
See Also:   BoundingBox.HORIZ_ALIGN_RIGHT
See Also:   BoundingBox.VERT_ALIGN_TOP
See Also:   BoundingBox.VERT_ALIGN_CENTER
See Also:   BoundingBox.VERT_ALIGN_BOTTOM IllegalArgumentException if the args are invalid StringTooLongException 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



getStringBounds
public BoundingBox getStringBounds(String string, int hAlign, int vAlign, FontMetrics fm, int padding) throws StringTooLongException, IllegalArgumentException(Code)

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
Parameters:
  hAlign - an int, HORIZ_ALIGN_CENTER, HORIZ_ALIGN_LEFT, HORIX_ALIGN_RIGHT
Parameters:
  vAlign - an int, VERT_ALIGN_CENTER, VERT_ALIGN_TOP, VERT_ALIGN_BOTTOM
Parameters:
  fm - a FontMetrics object for this String
Parameters:
  padding - an int, the padding around the String a Point, the coords to use in drawString() IllegalArgumentException if the args are invalid StringTooLongException if the string won't fit



hasParent
public boolean hasParent()(Code)

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

a boolean value



main
public static void main(String[] args)(Code)
For testing
Parameters:
  args - a String[] value



setAbsoluteLocation
public void setAbsoluteLocation(Point point)(Code)

Set the absolute upper left world location point for this box


Parameters:
  point - a Point value



setFullString
public void setFullString(String string)(Code)

Sets the full string associated with getStringBounds


Parameters:
  string - a String



setParent
public void setParent(BoundingBox parent)(Code)

Make the specified box this box's parent


Parameters:
  parent - a BoundingBox value



setStringArray
public void setStringArray(String[] strArray)(Code)

Set the value of the string array


Parameters:
  strArray - a String array



subtract
public BoundingBox subtract(BoundingBox child, int subtractFrom)(Code)

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 int an int, SUBTRACT_FROM_LEFT, SUBTRACT_FROM_RIGHT, SUBTRACT_FROM_TOP,SUBTRACT_FROM_BOTTOM a BoundingBox value
See Also:   BoundingBox.SUBTRACT_FROM_LEFT
See Also:   BoundingBox.SUBTRACT_FROM_RIGHT
See Also:   BoundingBox.SUBTRACT_FROM_TOP
See Also:   BoundingBox.SUBTRACT_FROM_BOTTOM



Fields inherited from java.awt.Rectangle
public int height(Code)(Java Doc)
public int width(Code)(Java Doc)
public int x(Code)(Java Doc)
public int y(Code)(Java Doc)

Methods inherited from java.awt.Rectangle
public void add(int newx, int newy)(Code)(Java Doc)
public void add(Point pt)(Code)(Java Doc)
public void add(Rectangle r)(Code)(Java Doc)
public boolean contains(Point p)(Code)(Java Doc)
public boolean contains(int x, int y)(Code)(Java Doc)
public boolean contains(Rectangle r)(Code)(Java Doc)
public boolean contains(int X, int Y, int W, int H)(Code)(Java Doc)
public Rectangle2D createIntersection(Rectangle2D r)(Code)(Java Doc)
public Rectangle2D createUnion(Rectangle2D r)(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
public Rectangle getBounds()(Code)(Java Doc)
public Rectangle2D getBounds2D()(Code)(Java Doc)
public double getHeight()(Code)(Java Doc)
public Point getLocation()(Code)(Java Doc)
public Dimension getSize()(Code)(Java Doc)
public double getWidth()(Code)(Java Doc)
public double getX()(Code)(Java Doc)
public double getY()(Code)(Java Doc)
public void grow(int h, int v)(Code)(Java Doc)
public boolean inside(int X, int Y)(Code)(Java Doc)
public Rectangle intersection(Rectangle r)(Code)(Java Doc)
public boolean intersects(Rectangle r)(Code)(Java Doc)
public boolean isEmpty()(Code)(Java Doc)
public void move(int x, int y)(Code)(Java Doc)
public int outcode(double x, double y)(Code)(Java Doc)
public void reshape(int x, int y, int width, int height)(Code)(Java Doc)
public void resize(int width, int height)(Code)(Java Doc)
public void setBounds(Rectangle r)(Code)(Java Doc)
public void setBounds(int x, int y, int width, int height)(Code)(Java Doc)
public void setLocation(Point p)(Code)(Java Doc)
public void setLocation(int x, int y)(Code)(Java Doc)
public void setRect(double x, double y, double width, double height)(Code)(Java Doc)
public void setSize(Dimension d)(Code)(Java Doc)
public void setSize(int width, int height)(Code)(Java Doc)
public String toString()(Code)(Java Doc)
public void translate(int dx, int dy)(Code)(Java Doc)
public Rectangle union(Rectangle r)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.