org.tigris.swidgets

Class Orientation

Known Direct Subclasses:
Horizontal, Vertical

public abstract class Orientation
extends java.lang.Object

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, position as x and offset as y.

Vertical treats length as height, breadth as width, position as y and offset as x.

    HORIZONTAL                                          VERTICAL

                                                    A
                                                    |
                                                 position = y
                                                    |
                                                    V
                +-------------+   A                 +-------------+   A
                |             |   |                 |             |   |
 <--position--> |             | breadth = height    |             | length =
    = x         |             |   |                 |             |   |height
                +-------------+   V                 +-------------+   V
                 <-- length-->                       <--breadth-->
                    = width                             = width
Author:
Bob Tarling

Method Summary

Dimension
addLength(Dimension original, Component add)
Create a new Dimension from an existing Dimension with its length increased by the length of a Component.
Dimension
addLength(Dimension original, Dimension add)
Create a new Dimension from an existing Dimension with its length increased by the length of another Dimension.
abstract Dimension
addLength(Dimension original, int add)
Create a new Dimension from an existing Dimension with its length increased by a given value.
Point
addToPosition(Point original, Component add)
Create a new Point from an existing Point with its length increased by the length of a Component.
Point
addToPosition(Point original, Dimension add)
Create a new Point from an existing Point with its length increased by the length of a Dimension.
abstract Point
addToPosition(Point original, int add)
Create a new Point from an existing Point with its position increased by a given value.
abstract int
getBreadth(Component comp)
Get the breadth of a Component.
abstract int
getBreadth(Dimension dim)
Get the breadth of a Dimension.
abstract Cursor
getCursor()
Get a cursor object pointing in the same direction as the orientation.
abstract ArrowButton
getEndArrowButton()
Get an arrow button pointing to the end of the orientation.
abstract int
getFirstUsableOffset(Container cont)
Determines the first usable offset in a Container.
abstract int
getLastUsablePosition(Container cont)
Determines the last usable position in a Container.
abstract int
getLength(Component comp)
Get the length of a Component.
abstract int
getLength(Dimension dim)
Get the length of a Dimension.
abstract int
getLengthMinusInsets(Container cont)
Get the usable length of a Container minus its insets.
abstract int
getOffset(Point point)
Get the offset of a Point.
abstract Orientation
getPerpendicular()
Get an instance of an Orientation perpendicular to this instance.
abstract int
getPosition(Component comp)
Get the position of a Component.
abstract int
getPosition(MouseEvent me)
Get the position of a MouseEvent.
abstract int
getPosition(Point point)
Get the position of a Point.
abstract ArrowButton
getStartArrowButton()
Get an arrow button pointing to the start of the orientation.
abstract Point
newPoint(int position, int offset)
Generate a new Point object from position and offset values.
abstract 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.
abstract Dimension
setBreadth(Dimension original, int breadth)
Create a new Dimension from an existing Dimension with its breadth changed to a given value.
abstract 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.
abstract Dimension
setLength(Dimension original, int length)
Create a new Dimension from an existing Dimension with its length changed to a given value.
abstract Point
setPosition(Point original, int position)
Create a new Point from an existing Point with its position changed to a given value.
Point
subtractFromPosition(Point original, Component subtract)
Create a new Point from an existing Point with its length decreased by the length of a Component.
Point
subtractFromPosition(Point original, Dimension subtract)
Create a new Point from an existing Point with its length decreased by the length of a Dimension.
Point
subtractFromPosition(Point original, int subtract)
Create a new Point from an existing Point with its position decreased by a given value.
Dimension
subtractLength(Dimension original, Component subtract)
Create a new Dimension from an existing Dimension with its length decreased by the length of a Component.
Dimension
subtractLength(Dimension original, Dimension subtract)
Create a new Dimension from an existing Dimension with its length decreased by the length of another Dimension.
Dimension
subtractLength(Dimension original, int subtract)
Create a new Dimension from an existing Dimension with its length decreased by a given value.

Method Details

addLength

public Dimension addLength(Dimension original,
                           Component add)
Create a new Dimension from an existing Dimension with its length increased by the length of a Component.
Returns:
The resulting Dimension.

addLength

public Dimension addLength(Dimension original,
                           Dimension add)
Create a new Dimension from an existing Dimension with its length increased by the length of another Dimension.
Returns:
The resulting Dimension.

addLength

public abstract Dimension addLength(Dimension original,
                                    int add)
Create a new Dimension from an existing Dimension with its length increased by a given value.
Returns:
The resulting Dimension.

addToPosition

public Point addToPosition(Point original,
                           Component add)
Create a new Point from an existing Point with its length increased by the length of a Component.
Returns:
The resulting Point.

addToPosition

public Point addToPosition(Point original,
                           Dimension add)
Create a new Point from an existing Point with its length increased by the length of a Dimension.
Returns:
The resulting Point.

addToPosition

public abstract Point addToPosition(Point original,
                                    int add)
Create a new Point from an existing Point with its position increased by a given value.
Returns:
The resulting Point.

getBreadth

public abstract int getBreadth(Component comp)
Get the breadth of a Component.
Returns:
The breadth of the Component.

getBreadth

public abstract int getBreadth(Dimension dim)
Get the breadth of a Dimension.
Returns:
The breadth of the Dimension.

getCursor

public abstract Cursor getCursor()
Get a cursor object pointing in the same direction as the orientation.
Returns:
The resulting Cursor.

getEndArrowButton

public abstract ArrowButton getEndArrowButton()
Get an arrow button pointing to the end of the orientation.
Returns:
The resulting ArrowButton.

getFirstUsableOffset

public abstract int getFirstUsableOffset(Container cont)
Determines the first usable offset in a Container. This takes into account the Insets of the Container.
Returns:
The offset of the Container.

getLastUsablePosition

public abstract int getLastUsablePosition(Container cont)
Determines the last usable position in a Container. This takes into account the Insets of the Container.
Returns:
The offset of the Container.

getLength

public abstract int getLength(Component comp)
Get the length of a Component.
Returns:
The length of the Component.

getLength

public abstract int getLength(Dimension dim)
Get the length of a Dimension.
Returns:
The length of the Dimension.

getLengthMinusInsets

public abstract int getLengthMinusInsets(Container cont)
Get the usable length of a Container minus its insets.
Returns:
The length of the Component.

getOffset

public abstract int getOffset(Point point)
Get the offset of a Point.
Returns:
The offset of the Point.

getPerpendicular

public abstract 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.

Returns:
A vertical or horizontal orientation.

getPosition

public abstract int getPosition(Component comp)
Get the position of a Component.
Returns:
The position of the Component.

getPosition

public abstract int getPosition(MouseEvent me)
Get the position of a MouseEvent.
Returns:
The position of the MouseEvent.

getPosition

public abstract int getPosition(Point point)
Get the position of a Point.
Returns:
The position of the Point.

getStartArrowButton

public abstract ArrowButton getStartArrowButton()
Get an arrow button pointing to the start of the orientation.
Returns:
The resulting ArrowButton.

newPoint

public abstract Point newPoint(int position,
                               int offset)
Generate a new Point object from position and offset values.
Returns:
The newly created Point object.

setBreadth

public abstract 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.
Returns:
The resulting Dimension.

setBreadth

public abstract Dimension setBreadth(Dimension original,
                                     int breadth)
Create a new Dimension from an existing Dimension with its breadth changed to a given value.
Returns:
The resulting Dimension.

setLength

public abstract 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.
Returns:
The resulting Dimension.

setLength

public abstract Dimension setLength(Dimension original,
                                    int length)
Create a new Dimension from an existing Dimension with its length changed to a given value.
Returns:
The resulting Dimension.

setPosition

public abstract Point setPosition(Point original,
                                  int position)
Create a new Point from an existing Point with its position changed to a given value.
Returns:
The resulting Point.

subtractFromPosition

public Point subtractFromPosition(Point original,
                                  Component subtract)
Create a new Point from an existing Point with its length decreased by the length of a Component.
Returns:
The resulting Point.

subtractFromPosition

public Point subtractFromPosition(Point original,
                                  Dimension subtract)
Create a new Point from an existing Point with its length decreased by the length of a Dimension.
Returns:
The resulting Point.

subtractFromPosition

public Point subtractFromPosition(Point original,
                                  int subtract)
Create a new Point from an existing Point with its position decreased by a given value.
Returns:
The resulting Point.

subtractLength

public Dimension subtractLength(Dimension original,
                                Component subtract)
Create a new Dimension from an existing Dimension with its length decreased by the length of a Component.
Returns:
The resulting Dimension.

subtractLength

public Dimension subtractLength(Dimension original,
                                Dimension subtract)
Create a new Dimension from an existing Dimension with its length decreased by the length of another Dimension.
Returns:
The resulting Dimension.

subtractLength

public Dimension subtractLength(Dimension original,
                                int subtract)
Create a new Dimension from an existing Dimension with its length decreased by a given value.
Returns:
The resulting Dimension.