Various utilities to aid components that are aware of their
horizontal/vertical orientation. The Singleton pattern is used to
ensure that only one instance of a horizontal and one instance of a
vertical
Orientation
exist.
Operations performed using length or breadth are transposed to
width and height depending on whether this is a vertical or
horizontal orientation.
Horizontal treats length as width, breadth as height and position
as x.
Vertical treats length as height, breadth as width and position as
y.
HORIZONTAL VERTICAL
A
|
position = y
|
V
+-------------+ A +-------------+ A
| | | | | |
<--position--> | | breadth = height | | length =
= x | | | | | |height
+-------------+ V +-------------+ V
<-- length--> <--breadth-->
= width = width
addLength
public Dimension addLength(Dimension original,
int add)
Create a new Dimension
from an existing
Dimension
with its length increased by a given
value.
- addLength in interface Orientation
addToPosition
public Point addToPosition(Point original,
int add)
Create a new Point
from an existing
Point
with its position increased by a given
value.
- addToPosition in interface Orientation
getBreadth
public int getBreadth(Component comp)
Get the breadth of a Component
.
- getBreadth in interface Orientation
- The breadth of the
Component
.
getBreadth
public int getBreadth(Dimension dim)
Get the breadth of a Dimension
.
- getBreadth in interface Orientation
- The breadth of the
Dimension
.
getCursor
public Cursor getCursor()
Get a cursor object pointing in the same direction as the orientation.
- getCursor in interface Orientation
getFirstUsableOffset
public int getFirstUsableOffset(Container cont)
Determines the first usable offset in a
Container
. This takes into account the
Insets
of the Container
.
- getFirstUsableOffset in interface Orientation
- The offset of the
Container
.
getInstance
public static Orientation getInstance()
Get an instance of an Orientation
object.
- An instance of
Orientation
.
getLastUsablePosition
public int getLastUsablePosition(Container cont)
Determines the last usable position in a
Container
. This takes into account the
Insets
of the Container
.
- getLastUsablePosition in interface Orientation
- The offset of the
Container
.
getLength
public int getLength(Component comp)
Get the length of a Component
.
- getLength in interface Orientation
- The length of the
Component
.
getLength
public int getLength(Dimension dim)
Get the length of a Dimension
.
- getLength in interface Orientation
- The length of the
Dimension
.
getLengthMinusInsets
public int getLengthMinusInsets(Container cont)
Get the usable length of a Container
minus its
insets
.
- getLengthMinusInsets in interface Orientation
- The length of the
Component
.
getOffset
public int getOffset(Point point)
Get the offset of a Point
.
- getOffset in interface Orientation
- The position of the
Point
.
getPerpendicular
public Orientation getPerpendicular()
Get an instance of an
Orientation
perpendicular to
this instance.
If called on a horizontal instance then a vertical instance is
returned.
If called on a vertical instance then a horizontal instance is
returned.
- getPerpendicular in interface Orientation
- A vertical or horizontal orientation.
getPosition
public int getPosition(Component comp)
Get the position of a Component
.
- getPosition in interface Orientation
- The position of the
Component
.
getPosition
public int getPosition(MouseEvent me)
Get the position of a MouseEvent
.
- getPosition in interface Orientation
- The position of the
MouseEvent
.
getPosition
public int getPosition(Point point)
Get the position of a Point
.
- getPosition in interface Orientation
- The position of the
Point
.
newPoint
public Point newPoint(int position,
int offset)
Generate a new Point
object from position and offset values.
- newPoint in interface Orientation
- The newly created
Point
object.
setBreadth
public Dimension setBreadth(Dimension original,
Dimension breadth)
Create a new Dimension
from an existing
Dimension
with its breadth changed to the breadth
of another given Dimension
.
- setBreadth in interface Orientation
setBreadth
public Dimension setBreadth(Dimension original,
int breadth)
Create a new Dimension
from an existing
Dimension
with its breadth changed to a given
value.
- setBreadth in interface Orientation
setLength
public Dimension setLength(Dimension original,
Dimension length)
Create a new Dimension
from an existing
Dimension
with its length changed to the length of
another given Dimension
.
- setLength in interface Orientation
setLength
public Dimension setLength(Dimension original,
int length)
Create a new Dimension
from an existing
Dimension
with its length changed to a given
value.
- setLength in interface Orientation
setPosition
public Point setPosition(Point original,
int position)
Create a new Point
from an existing
Point
with its position changed to a given value.
- setPosition in interface Orientation