gishur.gui2
Class Alignment

java.lang.Object
  |
  +--gishur.gui2.Alignment
Direct Known Subclasses:
MouseAlignment, ScreenAlignment

public class Alignment
extends java.lang.Object

Class, that makes alignments esiear.

Version:
1.0
Author:
Thomas Wolf

Field Summary
static byte BOTTOM
          Bottom-alignment constant (==RIGHT).
static byte CENTER
          Center-alignment constant.
static byte LEFT
          Left-alignment constant.
static byte RIGHT
          Right-alignment constant.
static byte SOURCE
          Source-alignment constant (==LEFT).
static byte TARGET
          Target-alignment constant (==RIGHT).
static byte TOP
          Top-alignment constant (==LEFT).
 
Constructor Summary
protected Alignment(int x, int y, java.lang.Object source_object, byte h_align, byte v_align, byte h_t_align, byte v_t_align)
          Constructs a new Alignment.
  Alignment(int x, int y, java.lang.String source_painter_name, byte h_align, byte v_align)
          Constructs a new Alignment.
  Alignment(int x, int y, java.lang.String source_painter_name, byte h_align, byte v_align, byte h_t_align, byte v_t_align)
          Constructs a new Alignment.
 
Method Summary
 void align(DrawObject source, Painter target)
          Aligns the given target-Painter according to this Alignment relatively to the given source-Painter.
 void align(int x, int y, Painter painter)
          Aligns the given Painter according to this Alignment relatively to the given absolute point (ignoring source-alignment settings).
static double convertAlignmentToPercent(byte align)
          Returns the given alignment value as double value between 0 and 1.
static Alignment createCenterAlignment(java.lang.String source_painter_name)
           
static Alignment createLeftTopAlignment(java.lang.String source_painter_name)
           
static java.awt.Point getReferencePoint(java.awt.Point p, byte h_align, byte v_align, int x, int y, int width, int height)
          Calculates a reference point on a line according to the given alignment value.
static java.awt.Point getReferencePoint(java.awt.Point p, byte align, int x1, int y1, int x2, int y2)
          Calculates a reference point on a line according to the given alignment value.
 int getX()
          Returns the x-coordinate of the distance vector.
 int getY()
          Returns the y-coordinate of the distance vector.
 byte hSourceAlignment()
          Returns the horizontal alignment.
 double hSourceAlignmentPercent()
          Returns the vertical alignment as double value between 0 and 1.
 byte hTargetAlignment()
          Returns the horizontal alignment for the target.
 double hTargetAlignmentPercent()
          Returns the vertical alignment as double value between 0 and 1.
 java.lang.String toString()
          Overrides java.lang.Object.toString().
 java.awt.Point vector()
          Returns the distance vector.
 byte vSourceAlignment()
          Returns the vertical alignment.
 double vSourceAlignmentPercent()
          Returns the vertical alignment as double value between 0 and 1.
 byte vTargetAlignment()
          Returns the vertical alignment for the target.
 double vTargetAlignmentPercent()
          Returns the vertical alignment as double value between 0 and 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

public static final byte LEFT
Left-alignment constant.

RIGHT

public static final byte RIGHT
Right-alignment constant.

CENTER

public static final byte CENTER
Center-alignment constant.

TOP

public static final byte TOP
Top-alignment constant (==LEFT).

BOTTOM

public static final byte BOTTOM
Bottom-alignment constant (==RIGHT).

SOURCE

public static final byte SOURCE
Source-alignment constant (==LEFT).

TARGET

public static final byte TARGET
Target-alignment constant (==RIGHT).
Constructor Detail

Alignment

protected Alignment(int x,
                    int y,
                    java.lang.Object source_object,
                    byte h_align,
                    byte v_align,
                    byte h_t_align,
                    byte v_t_align)
Constructs a new Alignment. The point to align to is located relatively to the source area or line as specified via the vertical and horizontal alignment constants. An object will be aligned at the specified distance vector from this point.
Parameters:
x,y - distance vector
source_object - the source alignment object
h_align - horizontal alignment constant (for the source object)
v_align - vertical alignment constant (for the source object)
h_t_align - horizontal alignment constant (for the target object)
v_t_align - vertical alignment constant (for the target object)

Alignment

public Alignment(int x,
                 int y,
                 java.lang.String source_painter_name,
                 byte h_align,
                 byte v_align,
                 byte h_t_align,
                 byte v_t_align)
Constructs a new Alignment. The point to align to is located relatively to the source area or line as specified via the vertical and horizontal alignment constants. An object will be aligned at the specified distance vector from this point.
Parameters:
x,y - distance vector
source_painter_name - the name of the painter to align to
h_align - horizontal alignment constant (for the source object)
v_align - vertical alignment constant (for the source object)
h_t_align - horizontal alignment constant (for the target object)
v_t_align - vertical alignment constant (for the target object)

Alignment

public Alignment(int x,
                 int y,
                 java.lang.String source_painter_name,
                 byte h_align,
                 byte v_align)
Constructs a new Alignment. The point to align to is located relatively to the source area or line as specified via the vertical and horizontal alignment constants. An object will be aligned at the specified distance vector from this point.
Parameters:
x,y - distance vector
source_painter_name - the name of the painter to align to
h_align - horizontal alignment constant (for the source object)
v_align - vertical alignment constant (for the source object)
Method Detail

createLeftTopAlignment

public static final Alignment createLeftTopAlignment(java.lang.String source_painter_name)

createCenterAlignment

public static final Alignment createCenterAlignment(java.lang.String source_painter_name)

toString

public java.lang.String toString()
Overrides java.lang.Object.toString().
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

vSourceAlignment

public byte vSourceAlignment()
Returns the vertical alignment.
Returns:
the vertical alignment.

vSourceAlignmentPercent

public double vSourceAlignmentPercent()
Returns the vertical alignment as double value between 0 and 1. The value 0 means TOP alignment, the value 1 BOTTOM, e.g the value 0.5 CENTER.
Returns:
the vertical alignment.

hSourceAlignment

public byte hSourceAlignment()
Returns the horizontal alignment.
Returns:
the horizontal alignment.

hSourceAlignmentPercent

public double hSourceAlignmentPercent()
Returns the vertical alignment as double value between 0 and 1. The value 0 means LEFT alignment, the value 1 RIGHT, e.g the value 0.5 CENTER.
Returns:
the horizontal alignment.

vTargetAlignment

public byte vTargetAlignment()
Returns the vertical alignment for the target.
Returns:
the vertical alignment for the target.

vTargetAlignmentPercent

public double vTargetAlignmentPercent()
Returns the vertical alignment as double value between 0 and 1. The value 0 means TOP alignment, the value 1 BOTTOM, e.g the value 0.5 CENTER.
Returns:
the vertical alignment.

hTargetAlignment

public byte hTargetAlignment()
Returns the horizontal alignment for the target.
Returns:
the horizontal alignment for the target.

hTargetAlignmentPercent

public double hTargetAlignmentPercent()
Returns the vertical alignment as double value between 0 and 1. The value 0 means LEFT alignment, the value 1 RIGHT, e.g the value 0.5 CENTER.
Returns:
the horizontal alignment.

getX

public int getX()
Returns the x-coordinate of the distance vector.
Returns:
the x-coordinate of the distance vector.

getY

public int getY()
Returns the y-coordinate of the distance vector.
Returns:
the y-coordinate of the distance vector.

vector

public java.awt.Point vector()
Returns the distance vector.
Returns:
the distance vector.

convertAlignmentToPercent

public static double convertAlignmentToPercent(byte align)
Returns the given alignment value as double value between 0 and 1. The value 0 means LEFT==TOP==SOURCE alignment, the value 1 RIGHT==BOTTOM==TARGET, e.g the value 0.5 CENTER.
Returns:
the alignment as double value

getReferencePoint

public static final java.awt.Point getReferencePoint(java.awt.Point p,
                                                     byte align,
                                                     int x1,
                                                     int y1,
                                                     int x2,
                                                     int y2)
Calculates a reference point on a line according to the given alignment value.
Parameters:
p - a Point object where to store the calculated point or null.
align - an alignment value (-128==SOURCE≤0==CENTER≤127==TARGET)
x1,y1 - source point of the line
x2,y2 - target point of the line
Returns:
the calculated reference point (p, if p!=null)

getReferencePoint

public static final java.awt.Point getReferencePoint(java.awt.Point p,
                                                     byte h_align,
                                                     byte v_align,
                                                     int x,
                                                     int y,
                                                     int width,
                                                     int height)
Calculates a reference point on a line according to the given alignment value.
Parameters:
p - a Point object where to store the calculated point or null.
h_align - an alignment value (-128==LEFT≤0==CENTER≤127==RIGHT) for the horizontal alignment
v_align - an alignment value (-128==TOP≤0==CENTER≤127==BOTTOM) for the vertical alignment
x,y - the top left point of the rectangular area
width - the with of the rectangular area
height - the height of the rectangular area
Returns:
the calculated reference point (p, if p!=null)

align

public void align(int x,
                  int y,
                  Painter painter)
Aligns the given Painter according to this Alignment relatively to the given absolute point (ignoring source-alignment settings).
Parameters:
x,y - absolute point to align to
painter - the Painter to align

align

public void align(DrawObject source,
                  Painter target)
Aligns the given target-Painter according to this Alignment relatively to the given source-Painter.
Parameters:
source - the source Painter (already positioned)
target - the target Painter to align