net.sourceforge.swtlayeredgraph
Class GraphRectangle

java.lang.Object
  extended by net.sourceforge.swtlayeredgraph.GraphRectangle
All Implemented Interfaces:
java.io.Serializable

public class GraphRectangle
extends java.lang.Object
implements java.io.Serializable

Defines a rectangle that uses coordinate types.

Author:
davija
See Also:
Serialized Form

Constructor Summary
GraphRectangle()
          Default constructor.
GraphRectangle(GraphPoint origin, java.lang.Double width, java.lang.Double height, CoordinateType type)
          Builds a graph rectangle with the specified attributes.
 
Method Summary
 java.lang.Boolean contains(GraphPoint point)
          Checks if this rectangle contains the given point.
 java.lang.Boolean contains(GraphRectangle rectangle)
          Checks if this rectangle fully contains the specified rectangle.
 boolean equals(java.lang.Object other)
          Checks if this rectangle is equal to another.
 CoordinateType getCoordinateType()
          Gets the coordinate system type for width and height.
 java.lang.Double getHeight()
          Gets the height of this rectangle.
 GraphPoint getOrigin()
          Gets the point that is relative to width/height.
 java.lang.Double getWidth()
          Gets the width of this rectangle.
 GraphPoint getX2Y2()
          Gets the point opposite of origin (origin + GraphPoint(width, height)).
 void merge(GraphRectangle toMerge)
          Merges the two rectangles.
 java.lang.Boolean overlaps(GraphRectangle rectangle)
          Checks if this rectangle overlaps the one passed in.
 void setCoordinateType(CoordinateType type)
          Sets the coordinate system for this rectangle.
 void setHeight(java.lang.Double height)
          Sets the new height for this rectangle.
 void setOrigin(GraphPoint origin)
          Sets the new origin/reference point for width/height.
 void setWidth(java.lang.Double width)
          Sets the new width for this rectangle.
 java.lang.String toString()
          Converts this rectangle to a human readable version.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphRectangle

public GraphRectangle()
Default constructor.


GraphRectangle

public GraphRectangle(GraphPoint origin,
                      java.lang.Double width,
                      java.lang.Double height,
                      CoordinateType type)
Builds a graph rectangle with the specified attributes.

Parameters:
origin - The starting point (upper left) relative to width/height.
width - Width of the rectangle.
height - Height of the rectangle.
type - Type of units for width and height. The origin will also be converted to this system.
Throws:
java.lang.IllegalArgumentException - If any of the arguments are null.
Method Detail

equals

public boolean equals(java.lang.Object other)
Checks if this rectangle is equal to another.

Overrides:
equals in class java.lang.Object

getCoordinateType

public CoordinateType getCoordinateType()
Gets the coordinate system type for width and height.

Returns:
Returns the coordinate system type for width and height

getHeight

public java.lang.Double getHeight()
Gets the height of this rectangle.

Returns:
Returns the height of this rectangle.

getOrigin

public GraphPoint getOrigin()
Gets the point that is relative to width/height. Typically this should be the lower left corner (smallest x & y value).

Returns:
Returns the point that is relative to width/height.

getWidth

public java.lang.Double getWidth()
Gets the width of this rectangle.

Returns:
Returns the width of this rectangle.

getX2Y2

public GraphPoint getX2Y2()
Gets the point opposite of origin (origin + GraphPoint(width, height)).

Returns:
Returns the point opposite of origin (origin + GraphPoint(width, height)).

merge

public void merge(GraphRectangle toMerge)
Merges the two rectangles. The end result with be the minimal rectangle that contains the previous two.

Parameters:
toMerge - Rectangle to merge into this one.
Throws:
java.lang.IllegalArgumentException - If toMerge is null.

setCoordinateType

public void setCoordinateType(CoordinateType type)
Sets the coordinate system for this rectangle.

Parameters:
type - New coordinate system to use.
Throws:
java.lang.IllegalArgumentException - If type is null.

setHeight

public void setHeight(java.lang.Double height)
Sets the new height for this rectangle.

Parameters:
height - New height for rectangle.
Throws:
java.lang.IllegalArgumentException - If height is null.

setOrigin

public void setOrigin(GraphPoint origin)
Sets the new origin/reference point for width/height.

Parameters:
origin - New reference point.
Throws:
java.lang.IllegalArgumentException - If origin is null.

setWidth

public void setWidth(java.lang.Double width)
Sets the new width for this rectangle.

Parameters:
width - New width for this rectangle.
Throws:
java.lang.IllegalArgumentException - If width is null.

toString

public java.lang.String toString()
Converts this rectangle to a human readable version.

Overrides:
toString in class java.lang.Object

contains

public java.lang.Boolean contains(GraphPoint point)
Checks if this rectangle contains the given point.

Parameters:
point - Point to test.
Returns:
Returns true if the specified point is contained within the bounds of this rectangle, false otherwise.
Throws:
java.lang.IllegalArgumentException - If point is null.

contains

public java.lang.Boolean contains(GraphRectangle rectangle)
Checks if this rectangle fully contains the specified rectangle.

Parameters:
rectangle - Rectangle to test for inclusion
Returns:
Returns true if rectangle is contained within this one, false otherwise.
Throws:
java.lang.IllegalArgumentException - If rectangle is null.

overlaps

public java.lang.Boolean overlaps(GraphRectangle rectangle)
Checks if this rectangle overlaps the one passed in. Shared edges are considered an overlap.

Parameters:
rectangle - Rectangle to test for overlap.
Returns:
Returns true if rectangle overlaps with this one, false otherwise.
Throws:
java.lang.IllegalArgumentException - If rectangle is null.


Copyright © 2009. All Rights Reserved.