org.icepdf.core.pobjects
Class PRectangle

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.geom.Rectangle2D.Float
              extended by org.icepdf.core.pobjects.PRectangle
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable

public class PRectangle
extends java.awt.geom.Rectangle2D.Float

A rectangle in a PDF document is slightly different than the Rectangle class in Java. A PDF rectangle is written as an array of four numbers giving the coordinates of a pair of diagonally opposite corners. Typically, the array takes the form:

This specifies the lower-left x, lower-left y, upper-right x, and upper-right y coordinates of the rectangle, in that order. However, this format is not guaranteed and this class normalizes such rectangles.

Another very important difference between PRectangles Rectangles is that PRectangles use the Cartesian Coordinate system, where Rectangles use the Java2D coordinates system. As a result, the user of this class must know the context in which the PRectangle is being used. For example there is a significant difference between the inherited method createIntersection and PRectangles createCartesianIntersection.

Since:
2.0
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
 
Fields inherited from class java.awt.geom.Rectangle2D.Float
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
PRectangle(java.util.List coordinates)
          Creates a new PRectangle object.
PRectangle(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2)
          Creates a new PRectangle object.
 
Method Summary
 PRectangle createCartesianIntersection(PRectangle src2)
          Returns a new PRectangle object representing the intersection of this PRectangle with the specified PRectangle using the Cartesian coordinate system.
 java.awt.geom.Rectangle2D.Float getOriginalPoints()
          Gets the orgional two points that created the PRectangle object.
static java.util.List getPRectangleVector(java.awt.geom.Rectangle2D rect)
          Converts a rectangle defined in user page in Java2D coordinates back to PDF space and in the vector for of the rectangle.
 java.awt.geom.Rectangle2D.Float toJava2dCoordinates()
          Converts the Cartesian representation of the Rectangle into Rectangle in the Java2D coordinate space.
 
Methods inherited from class java.awt.geom.Rectangle2D.Float
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect, setRect, toString
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PRectangle

public PRectangle(java.awt.geom.Point2D.Float p1,
                  java.awt.geom.Point2D.Float p2)

Creates a new PRectangle object. The points are automatically normalized by the constructor. These two coordinates represent the diagonal corners of the rectangle.

Parameters:
p1 - first point of diagonal, in the Cartesian coordinate space
p2 - second point of diagonal, in the Cartesian coordinate space

PRectangle

public PRectangle(java.util.List coordinates)
           throws java.lang.IllegalArgumentException
Creates a new PRectangle object. The points are automatically normalized by the constructor.

Parameters:
coordinates - a vector containing four elements where the first and second elements represent the x and y coordinates of one point and the third and fourth elements represent the x and y cooordinates of the second point. These two coordinates represent the diagonal corners of the rectangle.
Throws:
java.lang.IllegalArgumentException - thrown if coordinates is null or does not have four elements
Method Detail

createCartesianIntersection

public PRectangle createCartesianIntersection(PRectangle src2)
Returns a new PRectangle object representing the intersection of this PRectangle with the specified PRectangle using the Cartesian coordinate system. If a Java2D coordinate system is used, then the rectangle should be first converted to that space toJava2dCoordinates().

Parameters:
src2 - the Rectangle2D to be intersected with this Rectangle2D.
Returns:
object representing the intersection of the two PRectangles.

getOriginalPoints

public java.awt.geom.Rectangle2D.Float getOriginalPoints()

Gets the orgional two points that created the PRectangle object. The first point is represented by the the rectangle positions x, y and the second poitn is represented by the width and height of the rectangle.

Returns:
rectangle representing the PRectangle object initial two point.

toJava2dCoordinates

public java.awt.geom.Rectangle2D.Float toJava2dCoordinates()

Converts the Cartesian representation of the Rectangle into Rectangle in the Java2D coordinate space.

Returns:
rectangle in the Java2D coordinate space.

getPRectangleVector

public static java.util.List getPRectangleVector(java.awt.geom.Rectangle2D rect)
Converts a rectangle defined in user page in Java2D coordinates back to PDF space and in the vector for of the rectangle.

Parameters:
rect - user space rectangle in Java2D coordinates space.
Returns:
vector notation of rectangle in PDF space.