Package swingtree.layout
Class Location
java.lang.Object
swingtree.layout.Location
An immutable value based class that represents a location in a two-dimensional
coordinate system specified in float precision and specifically designed
for Swing components.
It can be used as an alternative to the AWT
Point
class,
but in situations where immutability is desired (which should be most cases).
Use the of(float, float)
factory method to create a new instance
or withX(int)
and withY(int)
to create a new instance
with a modified value.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
static Location
of
(float x, float y) A factory method that creates a new location with the specified x- and y-coordinates or returns theorigin()
constant if both coordinates are zero.static Location
A factory method that creates a new location from the supplied AWTPoint
.static Location
origin()
toPoint()
toString()
withX
(int x) Allows you to create an updated version of this location with the specified x-coordinate and the same y-coordinate as this location instance.withY
(int y) Allows you to create an updated version of this location with the specified y-coordinate and the same x-coordinate as this location instance.float
x()
Exposes the x coordinate of this location in the form of a float, which describes the horizontal position in a two-dimensional coordinate system.float
y()
Exposes the y coordinate of this location in the form of a float, which describes the vertical position in a two-dimensional coordinate system.
-
Method Details
-
of
A factory method that creates a new location with the specified x- and y-coordinates or returns theorigin()
constant if both coordinates are zero.- Parameters:
x
- The x-coordinate of the location to create.y
- The y-coordinate of the location to create.- Returns:
- A new location with the specified x- and y-coordinates.
If both coordinates are zero, the
origin()
is returned.
-
of
A factory method that creates a new location from the supplied AWTPoint
. If the point is null, aNullPointerException
is thrown.- Parameters:
p
- The point to create a location from.- Returns:
- A new location with the x- and y-coordinates of the specified point.
If both coordinates are zero, the
origin()
is returned.
-
origin
-
x
public float x()Exposes the x coordinate of this location in the form of a float, which describes the horizontal position in a two-dimensional coordinate system. So the larger the x value of the location, the further to the right it is.- Returns:
- The x-coordinate of this location.
-
y
public float y()Exposes the y coordinate of this location in the form of a float, which describes the vertical position in a two-dimensional coordinate system. So the larger the y value of the location, the further down it is.- Returns:
- The y-coordinate of this location.
-
withY
Allows you to create an updated version of this location with the specified y-coordinate and the same x-coordinate as this location instance.- Parameters:
y
- The y-coordinate of the location to create.- Returns:
- A new location with the same x-coordinate as this location and the specified y-coordinate.
-
withX
Allows you to create an updated version of this location with the specified x-coordinate and the same y-coordinate as this location instance.- Parameters:
x
- The x-coordinate of the location to create.- Returns:
- A new location with the same y-coordinate as this location and the specified x-coordinate.
-
toPoint
ALocation
consists of two x and y coordinates in 2D space, which is why this convenience method allows you to transform thisLocation
object to an AWTPoint
.- Returns:
- A new AWT
Point
with the same x- and y-coordinates as this location.
-
toString
-
equals
-
hashCode
public int hashCode()
-