Package org.apache.pivot.wtk
Class Point
- java.lang.Object
-
- org.apache.pivot.wtk.Point
-
- All Implemented Interfaces:
java.io.Serializable
public final class Point extends java.lang.Object implements java.io.SerializableAn immutable class representing the location of an object.This class is immutable (unlike a
Point), so that thetranslate(int, int)method returns a new object, rather than modifying the original (for instance).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description intxThe (integer) X-value of this point, representing a distance from the left of the parent object.static java.lang.StringX_KEYMap key used to access the X-value.intyThe (integer) Y-value of this point, representing a distance down from the top of the parent object.static java.lang.StringY_KEYMap key used to access the Y-value.
-
Constructor Summary
Constructors Constructor Description Point(int xValue, int yValue)Construct a point given the X/Y coordinates.Point(Dictionary<java.lang.String,?> point)Construct a point from a dictionary containing the X- and Y-position values as entries.Point(Sequence<?> point)Construct a point from a sequence of two number values for the X- and Y-positions respectively.Point(Point point)A "copy" constructor to duplicate a point value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Pointdecode(java.lang.String value)Decode a string value (which could be a JSON-formatted string (map or list)) that contains the two values for a new point.booleanequals(java.lang.Object object)inthashCode()java.lang.StringtoString()Pointtranslate(int dx, int dy)Return a newPointobject which represents this point moved to a new location,dxanddyaway from the original.
-
-
-
Field Detail
-
x
public final int x
The (integer) X-value of this point, representing a distance from the left of the parent object.
-
y
public final int y
The (integer) Y-value of this point, representing a distance down from the top of the parent object.
-
X_KEY
public static final java.lang.String X_KEY
Map key used to access the X-value.- See Also:
- Constant Field Values
-
Y_KEY
public static final java.lang.String Y_KEY
Map key used to access the Y-value.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Point
public Point(int xValue, int yValue)Construct a point given the X/Y coordinates.- Parameters:
xValue- The X-position for the point.yValue- The Y-position for the point.
-
Point
public Point(Point point)
A "copy" constructor to duplicate a point value.- Parameters:
point- The other point to copy.
-
Point
public Point(Dictionary<java.lang.String,?> point)
Construct a point from a dictionary containing the X- and Y-position values as entries.
-
Point
public Point(Sequence<?> point)
Construct a point from a sequence of two number values for the X- and Y-positions respectively.- Parameters:
point- The source sequence containing the values (values must beNumbers).- Throws:
java.lang.IllegalArgumentException- if the input isnull.
-
-
Method Detail
-
translate
public Point translate(int dx, int dy)
Return a newPointobject which represents this point moved to a new location,dxanddyaway from the original.- Parameters:
dx- The distance to move in the horizontal direction (positive or negative).dy- The distance to move in the vertical direction (positive moves downward on the screen, and negative to move upward).- Returns:
- A new object represented the translated location.
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
decode
public static Point decode(java.lang.String value)
Decode a string value (which could be a JSON-formatted string (map or list)) that contains the two values for a new point.The format of a JSON map would be:
{ "x":nnn, "y":nnn }The format for a JSON list would be:
[ x, y ]
Or the string can simply be two numbers:
x [,;] y
- Parameters:
value- The string to be interpreted (must not benull).- Returns:
- The new Point object if the string can be decoded successfully.
- Throws:
java.lang.IllegalArgumentException- if the input isnullor if the value could not be successfully decoded as a JSON map or list, or simply two values.- See Also:
Point(Dictionary),Point(Sequence),Point(int, int)
-
-