Package swingtree.layout
Class Position
java.lang.Object
swingtree.layout.Position
An immutable value based class that represents a location in float based 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(double, double) factory method to create a new instance
or withX(double) and withY(double) to create a new instance
with a modified value.
-
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()minus(double dx, double dy) Creates a new location where the specifieddxanddyvalues are subtracted from the x- and y-coordinates of this location.Creates a new location where the x- and y-coordinates of the specifiedPositionare subtracted from the x- and y-coordinates of this location.static Positionof(double x, double 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 PositionA factory method that creates a new location from the supplied AWTPoint.static Positionorigin()plus(double dx, double dy) Creates a new location where the specifieddxanddyvalues are added to the x- and y-coordinates of this location.Creates a new location where the x- and y-coordinates of the specifiedPositionare added to the x- and y-coordinates of this location.toPoint()toString()withX(double 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(double 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.floatx()Exposes the x coordinate of this location in the form of a float, which describes the horizontal position in a two-dimensional coordinate system.floaty()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, aNullPointerExceptionis 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.
-
plus
Creates a new location where the specifieddxanddyvalues are added to the x- and y-coordinates of this location.- Parameters:
dx- The amount to increase the x-coordinate by.dy- The amount to increase the y-coordinate by.- Returns:
- A new location with the x- and y-coordinates of this location increased by the specified values.
-
plus
Creates a new location where the x- and y-coordinates of the specifiedPositionare added to the x- and y-coordinates of this location.- Parameters:
other- The location to add to this location.- Returns:
- A new location with the x- and y-coordinates of this location increased by the x- and y-coordinates of the specified location.
-
minus
Creates a new location where the specifieddxanddyvalues are subtracted from the x- and y-coordinates of this location.- Parameters:
dx- The amount to decrease the x-coordinate by.dy- The amount to decrease the y-coordinate by.- Returns:
- A new location with the x- and y-coordinates of this location decreased by the specified values.
-
minus
Creates a new location where the x- and y-coordinates of the specifiedPositionare subtracted from the x- and y-coordinates of this location.- Parameters:
other- The location to subtract from this location.- Returns:
- A new location with the x- and y-coordinates of this location decreased by the x- and y-coordinates of the specified location.
-
toPoint
APositionconsists of two x and y coordinates in 2D space, which is why this convenience method allows you to transform thisPositionobject to an AWTPoint.- Returns:
- A new AWT
Pointwith the same x- and y-coordinates as this location.
-
toString
-
equals
-
hashCode
public int hashCode()
-