edu.umd.cs.piccolo.util
Class PBounds

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.geom.Rectangle2D.Double
              extended by edu.umd.cs.piccolo.util.PBounds
All Implemented Interfaces:
Shape, Serializable, Cloneable

public class PBounds
extends Rectangle2D.Double
implements Serializable

PBounds is simply a Rectangle2D.Double with extra methods that more properly deal with the case when the rectangle is "empty". A PBounds has an extra bit to store emptiness. In this state, adding new geometry replaces the current geometry. A PBounds is emptied with the reset() method. A useful side effect of the reset method is that it only modifies the fIsEmpty variable, the other x, y, with, height variables are left alone. This is used by Piccolo's layout management system to see if a the full bounds of a node has really changed when it is recomputed. See PNode.validateLayout.

Version:
1.0
Author:
Jesse Grosjean
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
 
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
PBounds()
          Creates an empty bounds.
PBounds(double x, double y, double width, double height)
          Constructs a PBounds object at the given coordinates with the given dimensions.
PBounds(PBounds aBounds)
          Creates a bounds identical to the one provided.
PBounds(Point2D aCenterPoint, double insetX, double insetY)
          Constructs a PBounds object with the given center point and the specified insets.
PBounds(Rectangle2D aBounds)
          Creates a bounds with the same shape as the rectangle provided.
 
Method Summary
 void add(double newx, double newy)
          Grows the bounds to contain the coordinate provided.
 void add(PBounds bounds)
          Changes this bounds to contain the provided bounds.
 void add(Rectangle2D r)
          Grows bounds to contain the rectangle if needed.
 Object clone()
          Returns a clone of this node.
 PDimension deltaRequiredToCenter(Rectangle2D targetBounds)
          Returns the required translation in order for this bounds origin to sit on the center of the provided rectangle.
 PDimension deltaRequiredToContain(Rectangle2D targetBounds)
          Returns the required translation in order for these to contain the bounds provided.
 void expandNearestIntegerDimensions()
          Rounds the rectangle to the next largest bounds who's measurements are integers.
 Point2D getCenter2D()
          Returns the midpoint of the bounds.
 Point2D getOrigin()
          Returns the x,y coordinate of the bounds.
 Dimension2D getSize()
          Returns the size of the bounds.
 PBounds inset(double dx, double dy)
          Adjust the measurements of this bounds so that they are the amounts given "in" from their previous border.
 boolean isEmpty()
          Returns true if this bounds has been flagged as empty.
 PBounds moveBy(double dx, double dy)
          Translates the bounds by the given deltas.
 PBounds reset()
          Flags this bounds as empty.
 PBounds resetToZero()
          Resets the bounds to (0,0,0,0) and flags it as empty.
 PBounds setOrigin(double x, double y)
          Changes the origin of these bounds.
 void setRect(double x, double y, double width, double height)
          Sets the shape of the bounds to the position and dimension provided.
 void setRect(PBounds b)
          Sets the bounds to the same shape as the bounds provided.
 void setRect(Rectangle2D r)
          Sets the bounds to the same shape as the rectangle.
 void setSize(double width, double height)
          Changes the size of the bounds, but retains the origin.
 String toString()
          Returns a string representation of this PBounds for debugging purposes.
 
Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, outcode
 
Methods inherited from class java.awt.geom.Rectangle2D
add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class java.awt.geom.RectangularShape
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

PBounds

public PBounds()
Creates an empty bounds.


PBounds

public PBounds(PBounds aBounds)
Creates a bounds identical to the one provided.

Parameters:
aBounds - bounds to be copied

PBounds

public PBounds(Rectangle2D aBounds)
Creates a bounds with the same shape as the rectangle provided.

Parameters:
aBounds - rectangle to be copied

PBounds

public PBounds(Point2D aCenterPoint,
               double insetX,
               double insetY)
Constructs a PBounds object with the given center point and the specified insets.

Parameters:
aCenterPoint - resulting center point of the PBounds object
insetX - distance from left and right the center should be
insetY - distance from top and bottom the center should be

PBounds

public PBounds(double x,
               double y,
               double width,
               double height)
Constructs a PBounds object at the given coordinates with the given dimensions.

Parameters:
x - left of bounds
y - top of bounds
width - width of bounds
height - height of bounds
Method Detail

clone

public Object clone()
Returns a clone of this node.

Overrides:
clone in class RectangularShape
Returns:
cloned copy of this bounds

isEmpty

public boolean isEmpty()
Returns true if this bounds has been flagged as empty. Not necessarily if it is empty.

Overrides:
isEmpty in class Rectangle2D.Double
Returns:
true if bounds marked as empty

reset

public PBounds reset()
Flags this bounds as empty.

Returns:
itself for chaining

resetToZero

public PBounds resetToZero()
Resets the bounds to (0,0,0,0) and flags it as empty.

Returns:
itself for chaining

setRect

public void setRect(Rectangle2D r)
Sets the bounds to the same shape as the rectangle. And flags the bounds as not empty.

Overrides:
setRect in class Rectangle2D.Double
Parameters:
r - rectangle to copy

setRect

public void setRect(PBounds b)
Sets the bounds to the same shape as the bounds provided. And flags the bounds as not empty.

Parameters:
b - bounds to copy

setRect

public void setRect(double x,
                    double y,
                    double width,
                    double height)
Sets the shape of the bounds to the position and dimension provided.

Overrides:
setRect in class Rectangle2D.Double
Parameters:
x - new left of bounds
y - new top of bounds
width - new width of bounds
height - new height of bounds

add

public void add(double newx,
                double newy)
Grows the bounds to contain the coordinate provided.

Overrides:
add in class Rectangle2D
Parameters:
newx - x component of point
newy - y component of point

add

public void add(Rectangle2D r)
Grows bounds to contain the rectangle if needed.

Overrides:
add in class Rectangle2D
Parameters:
r - rectangle being added

add

public void add(PBounds bounds)
Changes this bounds to contain the provided bounds.

Parameters:
bounds - bounds being added

getOrigin

public Point2D getOrigin()
Returns the x,y coordinate of the bounds.

Returns:
coordinate of the bounds

setOrigin

public PBounds setOrigin(double x,
                         double y)
Changes the origin of these bounds. And flags it as non-empty.

Parameters:
x - new x component of bounds
y - new y component of the bounds
Returns:
the modified PBounds with its new origin

getSize

public Dimension2D getSize()
Returns the size of the bounds.

Returns:
size of the bounds

setSize

public void setSize(double width,
                    double height)
Changes the size of the bounds, but retains the origin.

Parameters:
width - new width of the bounds
height - new height of the bounds

getCenter2D

public Point2D getCenter2D()
Returns the midpoint of the bounds.

Returns:
midpoint of the bounds

moveBy

public PBounds moveBy(double dx,
                      double dy)
Translates the bounds by the given deltas.

Parameters:
dx - amount to move x
dy - amount to move y
Returns:
itself for chaining

expandNearestIntegerDimensions

public void expandNearestIntegerDimensions()
Rounds the rectangle to the next largest bounds who's measurements are integers. Note: this is not the same as rounding its measurements.


inset

public PBounds inset(double dx,
                     double dy)
Adjust the measurements of this bounds so that they are the amounts given "in" from their previous border.

Parameters:
dx - amount to move in from border along horizontal axis
dy - amount to move in from border along vertical axis
Returns:
itself for chaining

deltaRequiredToCenter

public PDimension deltaRequiredToCenter(Rectangle2D targetBounds)
Returns the required translation in order for this bounds origin to sit on the center of the provided rectangle.

Parameters:
targetBounds - rectangle to measure the center of
Returns:
the delta required to move to center of the targetBounds

deltaRequiredToContain

public PDimension deltaRequiredToContain(Rectangle2D targetBounds)
Returns the required translation in order for these to contain the bounds provided.

Parameters:
targetBounds - rectangle to measure the center of
Returns:
the delta required in order for the bounds to overlap completely the targetBounds

toString

public String toString()
Returns a string representation of this PBounds for debugging purposes.

Overrides:
toString in class Rectangle2D.Double
Returns:
string representation of this PBounds


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.