|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.awt.Align
public class Align
A "calculator" used to align rectangular regions.
This object provides a "calculator" of sorts with the ability of
computing the top left corner of where a
rectangular region should be drawn. It can be very helpful when
drawing text onto graphical areas and can be effectively combined
with the MultiLineText object to lay out text on a
graphical drawing surface. Currently, it takes the following into
acount:
parse the definition from a
string (which allows one to dynamically configure these things with
property files).
The above sounds rather complicated - but maybe it will provide a little insight.
MultiLineText,
parse(java.lang.String)| Field Summary | |
|---|---|
static int |
ABSOLUTE
Constant used to indicate absolute anchor point. |
static int |
BOTTOM
Constant used to indicate BOTTOM alignment. |
static int |
CENTER
Constant used to indicate CENTER alignment. |
static int |
LEFT
Constant used to indicate LEFT alignment. |
static int |
RIGHT
Constant used to indicate RIGHT alignment. |
static int |
TOP
Constant used to indicate TOP alignment. |
| Constructor Summary | |
|---|---|
Align()
Create a alignment calculator which will compute "centered" coordinates. |
|
| Method Summary | |
|---|---|
void |
compute(int dx,
int dy,
int dw,
int dh,
int w,
int h)
Compute the (X,Y) coordinates of where a object should be placed. |
double |
getHorizontalAnchor()
Get the horizontal anchor point |
int |
getHorizontalMode()
Get current mode for horizontal alignment |
double |
getVerticalAnchor()
Get the vertical anchor point |
int |
getVerticalMode()
Get current mode for vertical alignment |
int |
getX()
Get currently computed X coordinate |
int |
getY()
Get currently computed Y coordinate |
boolean |
parse(String val)
Parse the setup information for the object from a string. |
boolean |
parseHorizontal(String val)
Parse the horizontal mode and anchor from a string. |
boolean |
parseVertical(String val)
Parse the vertical mode and anchor from a string. |
void |
setHorizontalAnchor(double val)
Set the horizontal anchor point This method allows one to specify the horizontal anchor point which will be used when computing the final location of the drawn object to be drawn. |
void |
setHorizontalMode(int val)
Set current mode for horizontal alignment You can use this method to how you want your coordinates computed relative to the horizontal anchor
point. |
void |
setVerticalAnchor(double val)
Set the vertical anchor point This method allows one to specify the vertical anchor point which will be used when computing the final location of the object to be drawn. |
void |
setVerticalMode(int val)
Set current mode for vertical alignment You can use this method to how you want your coordinates computed relative to the vertical anchor
point. |
void |
setX(int val)
Set currently computed X coordinate |
void |
setY(int val)
Set currently computed Y coordinate |
String |
toString()
Get a string representation of the object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int CENTER
setHorizontalMode(int),
setVerticalMode(int),
Constant Field Valuespublic static final int ABSOLUTE
setHorizontalAnchor(double),
setVerticalAnchor(double),
Constant Field Valuespublic static final int TOP
setVerticalMode(int),
Constant Field Valuespublic static final int BOTTOM
setVerticalMode(int),
Constant Field Valuespublic static final int LEFT
setHorizontalMode(int),
Constant Field Valuespublic static final int RIGHT
setHorizontalMode(int),
Constant Field Values| Constructor Detail |
|---|
public Align()
compute method
will result in fully centered alignment. It is as if you passed
"cp.5,cp.5" to the parse method. You can use the
various methods contained to adjust this.
parse(java.lang.String),
compute(int, int, int, int, int, int)| Method Detail |
|---|
public void compute(int dx,
int dy,
int dw,
int dh,
int w,
int h)
This method allows one to determine the top left corner where an object of a specific size (width/height) should be drawn onto a "drawing area". You do this by specifying a "drawing area" (rectangle defined by a top left starting point and width/height) and the size of an object which you wish to draw. Computations are then made (based upon the settings of this object) to determine the top left (x,y) where your object should be drawn.
After invoking this method, use getX() and
getY() to retrieve the determined top left
coordinates for where your object should be drawn.
dx - The x coordinate of the top left corner of the drawing area (0
is common).dy - The y coordinate of the top left corner of the drawing area (0
is common).dw - The width (in pixels) of the drawing area (the size of your
drawing area is common).dh - The height (in pixels) of the drawing area (the size of your
drawing area is common).w - The width of the object (in pixels) you wish to place onto the
drawing area.h - The height of the object (in pixels) you wish to place onto the
drawing area.getX(),
getY()public String toString()
string representation of the object.
This method returns the information about the object in a string form which is suitable for parsing (you can refer
to parse(java.lang.String) for details on how the string will look).
toString in class Objectparse(java.lang.String).parse(java.lang.String)public boolean parse(String val)
mode/anchor and vertical mode/anchor from a
string value. The string passed should contain two components
(one for the horizontal and one for the vertical compontents. The
two values will be ordered like "HOR,VER" in the string
passed. Refer to parseHorizontal(java.lang.String) for specifics about the
form of the "HOR" component. Refer to parseVertical(java.lang.String) for
specifics about the form of the "VER" component. Here are some
examples:
val - The string to parse (two components separated by commas). It
is safe to pass null - you'll get false back.
toString(),
parseHorizontal(java.lang.String),
parseVertical(java.lang.String)public boolean parseHorizontal(String val)
mode and anchor from a string.
This method parses the horizontal mode
and anchor from a string. The string
passed MUST contain three components "MPV" and must not contain
any white space. Valid values look like "cp.5", "ra-10" and "la200". Here
are the specifics:centering), 'l' (for left alignment), or
'r' (for right alignment).
If the value specified ("V" from "MPV" as described above) for
the anchor point is negative, then the anchor point will be
computed from the right edge of the drawing area.
val - String value to parse.
parse(java.lang.String)public boolean parseVertical(String val)
mode and anchor from a string.
This method parses the vertical mode
and anchor from a string. The string
passed MUST contain three components "MPV" and must not contain
any white space. Valid values look like "cp.5" and "ta200". Here
are the specifics:centering), 't' (for top alignment), or
'b' (for bottom alignment).
If the value specified ("V" from "MPV" as described above) for
the anchor point is negative, then the anchor point will be
computed from the bottom edge of the drawing area.
val - String value to parse.
parse(java.lang.String)public void setHorizontalMode(int val)
horizontal anchor
point. You can specify any combination of the ABSOLUTE,
CENTER, LEFT and/or RIGHT flags.
val - New byte value (combination of flags) to assign.getHorizontalMode()public int getHorizontalMode()
setHorizontalMode(int)public void setVerticalMode(int val)
vertical anchor
point. You can specify any combination of the ABSOLUTE,
CENTER, TOP and/or BOTTOM flags.
val - New byte value (combination of flags) to assign.getVerticalMode()public int getVerticalMode()
setVerticalMode(int)public void setHorizontalAnchor(double val)
ABSOLUTE flag is set or not.ABSOLUTE flag is NOT set in the
horizontal mode, then this value will
be treated as a "percent" (typically in the range of
[-1.0,1.0]). This "percent" value will then be used to compute the
anchor point based upon the size of the area we will be drawing
on (this is the preferred way to specify an anchor
point).
ABSOLUTE flag is set, this value
will be interpretted as an absolute pixel offset (it won't scale
if the size of the area we are drawing into changes).
Positive values result in computations from
the left edge of the "drawing area". Negative values result in
computations from the right edge of the "drawing area".
val - New float value to assign.getHorizontalAnchor()public double getHorizontalAnchor()
setHorizontalAnchor(double)public void setVerticalAnchor(double val)
ABSOLUTE flag is set or not.ABSOLUTE flag is NOT set in the
vertical mode, then this value will
be treated as a "percent" (typically in the range of
[-1.0,1.0]). This "percent" value will then be used to compute the
anchor point based upon the size of the area we will be drawing
the object onto (this is the preferred way to specify an anchor
point).
ABSOLUTE flag is set, this value
will be interpretted as an absolute pixel offset (it won't scale
if the size of the area we are drawing into changes).
Positive values result in computations from
the top edge of the "drawing area". Negative values result in
computations from the bottom edge of the "drawing area".
val - New float value to assign.getVerticalAnchor()public double getVerticalAnchor()
setVerticalAnchor(double)public void setX(int val)
val - New int value to assign.getX()public int getX()
setX(int)public void setY(int val)
val - New int value to assign.getY()public int getY()
setY(int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||