net.sourceforge.swtlayeredgraph
Class GraphPoint

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

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

Defines a point on the graph defined by a coordinate system. Also provides for getting the coordinates as another coordinate type and converting to other systems.

Author:
davija
See Also:
Serialized Form

Constructor Summary
GraphPoint()
          Default constructor.
GraphPoint(CoordinateType type)
          Constructor to use specific coordinate type.
GraphPoint(java.lang.Double x, java.lang.Double y)
          Constructor to use specific X & Y coordinates.
GraphPoint(java.lang.Double x, java.lang.Double y, CoordinateType type)
          Constructor to fully specify point.
 
Method Summary
 GraphPoint clone()
          Creates a deep copy of this object.
 java.lang.Double convert(java.lang.Double value, CoordinateType source, CoordinateType target)
          Converts the passed in value to specified coordinate system.
 void convertTo(CoordinateType type)
          Converts this coordinate to the specified coordinate system.
 void copy(GraphPoint source)
          Does a shallow copy from the passed in point.
 boolean equals(java.lang.Object other)
           
 GraphPoint get(CoordinateType type)
          Gets a new GraphPoint in the specified system.
 CoordinateType getCoordinateType()
          Gets the current coordinate system type.
 java.lang.Double getX()
          Gets the local X value in the current coordinate type.
 java.lang.Double getX(CoordinateType type)
          Gets the local X value converted to the specified coordinate type.
 java.lang.Double getY()
          Gets the local Y value in the current coordinate type.
 java.lang.Double getY(CoordinateType type)
          Gets the local Y value converted to the specified coordinate type.
 int hashCode()
          Returns the hash code for this point.
 void setX(java.lang.Double x)
          Sets the X coordinate to the specified value.
 void setX(java.lang.Double x, CoordinateType type)
          Sets the X coordinate to the specified value after converting from the specified system.
 void setY(java.lang.Double y)
          Sets the Y coordinate to the specified value.
 void setY(java.lang.Double y, CoordinateType type)
          Sets the Y coordinate to the specified value after converting from the specified system.
 java.lang.String toString()
          Returns a human readable version of the coordinate.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphPoint

public GraphPoint()
Default constructor. Sets X & Y to 0.0 and uses Inches.


GraphPoint

public GraphPoint(CoordinateType type)
           throws java.lang.IllegalArgumentException
Constructor to use specific coordinate type. Sets X & Y to 0.0.

Parameters:
type - Type of coordinate to use.
Throws:
java.lang.IllegalArgumentException - If type is null.

GraphPoint

public GraphPoint(java.lang.Double x,
                  java.lang.Double y)
           throws java.lang.IllegalArgumentException
Constructor to use specific X & Y coordinates. Defaults to Inches.

Parameters:
x - X coordinate to use.
y - Y coordinate to use.
Throws:
java.lang.IllegalArgumentException - if x or y is null.

GraphPoint

public GraphPoint(java.lang.Double x,
                  java.lang.Double y,
                  CoordinateType type)
           throws java.lang.IllegalArgumentException
Constructor to fully specify point.

Parameters:
x - X coordinate to use.
y - Y coordinate to use
type - Type of coordinate to use
Throws:
java.lang.IllegalArgumentException - if x, y or type is null.
Method Detail

clone

public GraphPoint clone()
Creates a deep copy of this object.

Overrides:
clone in class java.lang.Object

convert

public java.lang.Double convert(java.lang.Double value,
                                CoordinateType source,
                                CoordinateType target)
                         throws java.lang.IllegalArgumentException
Converts the passed in value to specified coordinate system.

Parameters:
value - Coordinate value to convert.
source - Coordinate type of value.
destination - Coordinate type to convert value to.
Returns:
Returns a converted coordinate value.
Throws:
java.lang.IllegalArgumentException - if value, source or target is null.

convertTo

public void convertTo(CoordinateType type)
               throws java.lang.IllegalArgumentException
Converts this coordinate to the specified coordinate system.

Parameters:
type - The system to convert to.
Throws:
java.lang.IllegalArgumentException - if type is null.

copy

public void copy(GraphPoint source)
          throws java.lang.IllegalArgumentException
Does a shallow copy from the passed in point.

Parameters:
source - Object to copy values from.
Throws:
java.lang.IllegalArgumentException - if source is null.

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

get

public GraphPoint get(CoordinateType type)
               throws java.lang.IllegalArgumentException
Gets a new GraphPoint in the specified system. The values for X & Y are converted to that system.

Parameters:
type - Type of coordinate system to use.
Returns:
Returns a new GraphPoint of the specified system with converted X & Y values.
Throws:
java.lang.IllegalArgumentException - if type is null.

getCoordinateType

public CoordinateType getCoordinateType()
Gets the current coordinate system type.

Returns:
Returns the current coordinate system type.

getX

public java.lang.Double getX()
Gets the local X value in the current coordinate type.

Returns:
Returns the local X value in the current coordinate type.

getX

public java.lang.Double getX(CoordinateType type)
                      throws java.lang.IllegalArgumentException
Gets the local X value converted to the specified coordinate type.

Parameters:
type - Coordinate system to use.
Returns:
Returns the local X value converted to the specified coordinate type.
Throws:
java.lang.IllegalArgumentException - if type is null.

getY

public java.lang.Double getY()
Gets the local Y value in the current coordinate type.

Returns:
Returns the local Y value in the current coordinate type.

getY

public java.lang.Double getY(CoordinateType type)
                      throws java.lang.IllegalArgumentException
Gets the local Y value converted to the specified coordinate type.

Parameters:
type - Coordinate system to use.
Returns:
Returns the local Y value converted to the specified coordinate type.
Throws:
java.lang.IllegalArgumentException - if type is null.

hashCode

public int hashCode()
Returns the hash code for this point. It is generated by converting to like coordinate system and then running hash code on it's string value. This should satisfy requirement that equal points have equal hash codes.

Overrides:
hashCode in class java.lang.Object

setX

public void setX(java.lang.Double x)
          throws java.lang.IllegalArgumentException
Sets the X coordinate to the specified value.

Parameters:
x - X value to use for new coordinate. It is assumed to be of the current coordinate system.
Throws:
java.lang.IllegalArgumentException - if x is null.

setX

public void setX(java.lang.Double x,
                 CoordinateType type)
          throws java.lang.IllegalArgumentException
Sets the X coordinate to the specified value after converting from the specified system.

Parameters:
x - The new X coordinate.
type - The system that the X coordinate is currently in.
Throws:
java.lang.IllegalArgumentException - if x or type is null.

setY

public void setY(java.lang.Double y)
          throws java.lang.IllegalArgumentException
Sets the Y coordinate to the specified value.

Parameters:
y - Y value to use for new coordinate. It is assumed to be of the current coordinate system.
Throws:
java.lang.IllegalArgumentException - if y is null.

setY

public void setY(java.lang.Double y,
                 CoordinateType type)
          throws java.lang.IllegalArgumentException
Sets the Y coordinate to the specified value after converting from the specified system.

Parameters:
y - The new Y coordinate.
type - The system that the Y coordinate is currently in.
Throws:
java.lang.IllegalArgumentException - if y or type is null.

toString

public java.lang.String toString()
Returns a human readable version of the coordinate.

Overrides:
toString in class java.lang.Object


Copyright © 2009. All Rights Reserved.