| java.lang.Object edu.hws.jcm.draw.Drawable edu.hws.jcm.draw.DrawString
DrawString | public class DrawString extends Drawable implements Computable(Code) | | A DrawString object displays a string, possibly multi-line, in a DisplayCanvas,
inside the rectangular region of a CoordinateRect. The location of the string
can be specified in two ways. First, by giving the coordinates of a reference
point together with a constant that says how the string is positioned with
respect to that reference point. The coordintes are given as Value objects
and the values are interepreted in the coordinate system of the CoordinateRect.
The positioning object is one of the constants TOP_LEFT, TOP_CENTER, ...,
BOTTOM_RIGHT defined in this class. This says where the REFERENCE POINT
is -- at the top left of the string, at the top center, etc.
The second way to specify the position of the string is to set the reference
point coordinates to null. In that case, the postioning constant gives
the location of the STRING in the CorrdinateRect. A value of TOP_LEFT
says that the string is in the top left corner of the rect, etc.
An array of Value objects can be specified to be displayed in the string.
Their values are substituted for #'s in the string. (A double # in the string,
however, is displayed as a literal single #.)
It is possible to set the color, font and justification of the string.
A DisplayString implements the Computable interface, so it can be added to
a Controller. The values of the Value objects used by the string are recomputed
only when its compute() method is called.
|
Field Summary | |
final public static int | CENTER For specifying justification of lines in multiline strings. | final public static int | LEFT For specifying justification of lines in multiline strings. | final public static int | RIGHT For specifying justification of lines in multiline strings. | final public static int | TOP_LEFTTOP_CENTERTOP_RIGHTCENTER_LEFTCENTER_CENTERCENTER_RIGHTBOTTOM_LEFTBOTTOM_CENTERBOTTOM_RIGHT | protected Color | backgroundColor | protected String | baseString String, possibly with \n and #'s. | protected boolean | clamp If true, the string is clamped to lie within the CoordinateRect. | protected Color | color Color of string. | protected Font | font Font for drawing string. | protected Color | frameColor If frameWidth is greate than zero, then a frame is drawn around the string in this
color. | protected int | frameWidth If frameWidth is greater than zero, then a frame of this width is drawn around the
string in the color given by frameColor. | protected int | justification Left, right, or center justification of lines in the text. | protected int | numSize Maximum number of characters desired in numbers; actual number might actually be larger. | protected int | offset If absolute positioning is used, then this gives a gap between the string and edge of rect. | protected int | position | protected String[] | strings The actual lines to draw, derived from baseString. | protected Value[] | values Values to be substituted for #'s in the baseString. | protected Value | xPosyPos xy-coords for drawing the string. |
Constructor Summary | |
public | DrawString() Create a DrawString object that initially has no string to draw. | public | DrawString(String str) Create a DrawString for drawing a black string in the top left corner of the coordinate rect.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks. | public | DrawString(String str, int pos) Create a DrawString for drawing a black string in the position specified.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks. | public | DrawString(String str, int pos, Value[] values) Create a DrawString for drawing a black string in the specified position.
The number of #'s in the string should match values.length. | public | DrawString(String str, int pos, Value xPos, Value yPos, Value[] values) Create a string that is displayed at the reference point (xPos,yPos);
The positioning constant, pos, gives the positioning relative to this point, if xPos or yPos is non-null.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks and #'s to be replaced by numeric values. |
Method Summary | |
public void | compute() The compute method sets up the array of strings that is actually displayed. | public void | draw(Graphics g, boolean coordsChanged) Draws the string. | public Color | getBackgroundColor() Get the color that is used to fill a rectangle on which the string is drawn. | public boolean | getClamp() Returns true if the string is set to be clamped to lie within the CoordinateRect. | public Color | getColor() Get the non-null color that is used for drawing the string. | public Font | getFont() Return the font that is used for drawing the string. | public Color | getFrameColor() Get the color that is used to draw a frame around the string. | public int | getFrameWidth() Get the width, in pixels, of the frame that is drawn around the string. | public int | getJustification() Get the justification that is used for a multiple-line string. | public int | getNumSize() Return the desired maximum number of characters in displayed numbers. | public int | getOffset() Get the distance of the bounding box of the string from the reference
point where it is drawn. | public int | getPositioning() Return the positioning, as set by setPositioning(). | public String | getString() | public Value[] | getValues() Return the array of values that are substituted for #'s in the string. | public Value | getXPos() Return the Value object that gives the x-coordinate of the reference
point of this string. | public Value | getYPos() Return the Value object that gives the y-coordinate of the reference
point of this string.point of this string. | public void | setBackgroundColor(Color color) Set the color that is used to fill a rectangle on which the string is drawn. | public void | setClamp(boolean clamp) Set the "clamp" property of the DrawString. | public void | setColor(Color c) Set the color for the string. | public void | setFont(Font f) Set the font that is used for drawing this string. | public void | setFrameColor(Color color) Set the color that is used to draw a frame around the string. | public void | setFrameWidth(int width) Set the width, in pixels, of a frame to draw around the string. | public void | setJustification(int j) Set the justification to be used if there are multiple lins in the string. | public void | setNumSize(int size) Set the desired maximum number of characters in displayed numbers.
Actual size might be larger. | public void | setOffset(int b) Set the distance of the bounding box of the string from the reference
point where it is drawn. | public void | setPositioning(int pos) Set the positioning of the string. | public void | setReferencePoint(Value x, Value y) Set the values of the (x,y) coordinates of the
reference point for the stirng. | public void | setString(String str) Set the string that is displayed. | public void | setValues(Value[] v) Set the Values that are substituted for (single) #'s in the string.
If the array of Values is null, then no substitution is done. |
CENTER | final public static int CENTER(Code) | | For specifying justification of lines in multiline strings.
(But can also be used as a synonym for CENTER_CENTER to specify the position of the string).
|
LEFT | final public static int LEFT(Code) | | For specifying justification of lines in multiline strings.
(But can also be used as a synonym for TOP_LEFT to specify the position of the string).
|
RIGHT | final public static int RIGHT(Code) | | For specifying justification of lines in multiline strings.
(But can also be used as a synonym for TOP_RIGHT to specify the position of the string).
|
TOP_LEFTTOP_CENTERTOP_RIGHTCENTER_LEFTCENTER_CENTERCENTER_RIGHTBOTTOM_LEFTBOTTOM_CENTERBOTTOM_RIGHT | final public static int TOP_LEFTTOP_CENTERTOP_RIGHTCENTER_LEFTCENTER_CENTERCENTER_RIGHTBOTTOM_LEFTBOTTOM_CENTERBOTTOM_RIGHT(Code) | | Specify string location in rect
|
backgroundColor | protected Color backgroundColor(Code) | | If backgroundColor is non-null, then a rectangle of this color is filled
as a background for the string;
|
baseString | protected String baseString(Code) | | String, possibly with \n and #'s. This is used as a base to get the actual string that is drawn.
|
clamp | protected boolean clamp(Code) | | If true, the string is clamped to lie within the CoordinateRect.
|
color | protected Color color(Code) | | Color of string. If null, black is used as the default.
|
font | protected Font font(Code) | | Font for drawing string. If null, get font from graphics context.
|
frameColor | protected Color frameColor(Code) | | If frameWidth is greate than zero, then a frame is drawn around the string in this
color. If the value is null, then the color will be the same as the color of the string.
|
frameWidth | protected int frameWidth(Code) | | If frameWidth is greater than zero, then a frame of this width is drawn around the
string in the color given by frameColor.
|
justification | protected int justification(Code) | | Left, right, or center justification of lines in the text.
|
numSize | protected int numSize(Code) | | Maximum number of characters desired in numbers; actual number might actually be larger.
|
offset | protected int offset(Code) | | If absolute positioning is used, then this gives a gap between the string and edge of rect.
For relative positioning, this gives an offset from the value of xPos yPos.
|
position | protected int position(Code) | | one of the constants defined in this class for specifying position
|
strings | protected String[] strings(Code) | | The actual lines to draw, derived from baseString.
|
values | protected Value[] values(Code) | | Values to be substituted for #'s in the baseString.
|
xPosyPos | protected Value xPosyPos(Code) | | xy-coords for drawing the string. If non-null then relative positioning is used.
If null, then positioning is absolute.
|
DrawString | public DrawString()(Code) | | Create a DrawString object that initially has no string to draw.
|
DrawString | public DrawString(String str)(Code) | | Create a DrawString for drawing a black string in the top left corner of the coordinate rect.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks. |
DrawString | public DrawString(String str, int pos)(Code) | | Create a DrawString for drawing a black string in the position specified.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks. Parameters: pos - The positioning of the string in the coordinate rect. One of the positioning constants such as TOP_LEFT or BOTTOM_RIGHT. |
DrawString | public DrawString(String str, int pos, Value[] values)(Code) | | Create a DrawString for drawing a black string in the specified position.
The number of #'s in the string should match values.length. The values
are computed and substituted for the #'s.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks and #'s to be replaced by numeric values. Parameters: pos - The positioning of the string in the coordinate rect. One of the positioning constants such as TOP_LEFT or BOTTOM_RIGHT. Parameters: values - Value objects associated with #'s in the string. |
DrawString | public DrawString(String str, int pos, Value xPos, Value yPos, Value[] values)(Code) | | Create a string that is displayed at the reference point (xPos,yPos);
The positioning constant, pos, gives the positioning relative to this point, if xPos or yPos is non-null.
Parameters: str - The string to draw, which can contain \n's to indicate line breaks and #'s to be replaced by numeric values. Parameters: pos - The positioning of the string. One of the positioning constants such as TOP_LEFT or BOTTOM_RIGHT.If xPos or yPos is non-nul, this is interpreted relative to their values. Parameters: xPos - x-coordinate relative to which the string is drawn (or null for absolute hoizontal positioning). Parameters: yPos - y-coordinate relative to which the string is drawn (or null for absolute vertical positioning). Parameters: values - Value objects associated with #'s in the string. |
compute | public void compute()(Code) | | The compute method sets up the array of strings that is actually displayed.
This is required by the Computable interface and is usually called by a
Controller rather than directly.
|
draw | public void draw(Graphics g, boolean coordsChanged)(Code) | | Draws the string.
|
getBackgroundColor | public Color getBackgroundColor()(Code) | | Get the color that is used to fill a rectangle on which the string is drawn. Null
indicates that no rectangle is filled so the stuff in back of the string shows though.
The default value is null.
|
getClamp | public boolean getClamp()(Code) | | Returns true if the string is set to be clamped to lie within the CoordinateRect.
|
getColor | public Color getColor()(Code) | | Get the non-null color that is used for drawing the string.
|
getFont | public Font getFont()(Code) | | Return the font that is used for drawing the string. If the return
value is null, then the font is taken from the Graphics context.
|
getFrameColor | public Color getFrameColor()(Code) | | Get the color that is used to draw a frame around the string. This is only done if the
frameWidth property is greater than zero. If the value is null, the frame is the same color
as the string.
|
getFrameWidth | public int getFrameWidth()(Code) | | Get the width, in pixels, of the frame that is drawn around the string.
The default width is zero. The largest possible value is 25.
|
getJustification | public int getJustification()(Code) | | Get the justification that is used for a multiple-line string. The value
is one of the constants DrawString.LEFT, DrawString.RIGHT, or DrawString.CENTER
|
getNumSize | public int getNumSize()(Code) | | Return the desired maximum number of characters in displayed numbers.
|
getOffset | public int getOffset()(Code) | | Get the distance of the bounding box of the string from the reference
point where it is drawn.
|
getPositioning | public int getPositioning()(Code) | | Return the positioning, as set by setPositioning().
|
getString | public String getString()(Code) | | Get a copy of the display string (with \n's #'s, not with substitued values.)
|
getValues | public Value[] getValues()(Code) | | Return the array of values that are substituted for #'s in the string.
|
getXPos | public Value getXPos()(Code) | | Return the Value object that gives the x-coordinate of the reference
point of this string.
|
getYPos | public Value getYPos()(Code) | | Return the Value object that gives the y-coordinate of the reference
point of this string.point of this string.
|
setBackgroundColor | public void setBackgroundColor(Color color)(Code) | | Set the color that is used to fill a rectangle on which the string is drawn. If the
value is null, no rectangle is filled and the string just overlays whatever is in back
of it on the canvas.
|
setClamp | public void setClamp(boolean clamp)(Code) | | Set the "clamp" property of the DrawString.
If set to true, the string will be clamped to lie entirely within the CoordinateRect
(unless it doens't fit -- then it can stick out on the right and bottom).
The default value is true.
|
setColor | public void setColor(Color c)(Code) | | Set the color for the string. If c is null, Color.black is used.
|
setFont | public void setFont(Font f)(Code) | | Set the font that is used for drawing this string. If f is null,
then the font is obtained from the Graphics context in which the
string is drawn.
|
setFrameColor | public void setFrameColor(Color color)(Code) | | Set the color that is used to draw a frame around the string. This is only done if the
frameWidth property is greater than zero. If the value is null, the frame is the same color
as the string.
|
setFrameWidth | public void setFrameWidth(int width)(Code) | | Set the width, in pixels, of a frame to draw around the string. If the value is zero,
no frame is drawn. The default value is zero. The the value is clamped
to the range 0 to 25.
|
setJustification | public void setJustification(int j)(Code) | | Set the justification to be used if there are multiple lins in the string.
Possible value are DrawString.LEFT, DrawString.RIGHT, and DrawString.CENTER.
|
setNumSize | public void setNumSize(int size)(Code) | | Set the desired maximum number of characters in displayed numbers.
Actual size might be larger. Value is clamped to the range
6 to 25.
|
setOffset | public void setOffset(int b)(Code) | | Set the distance of the bounding box of the string from the reference
point where it is drawn. The default value is 3.
|
setPositioning | public void setPositioning(int pos)(Code) | | Set the positioning of the string. The parameter should be one of the positioning
contstants defined in this class, such as TOP_LEFT. (If it is not,
TOP_LEFT is used by default.)
|
setReferencePoint | public void setReferencePoint(Value x, Value y)(Code) | | Set the values of the (x,y) coordinates of the
reference point for the stirng. If a value is null,
absolute positioning is used. If a value is
undefined, the string is not drawn.
|
setString | public void setString(String str)(Code) | | Set the string that is displayed. Note that it can include '\n' to
represent a line break, and it can contain #'s which will be replaced
by computed values.
|
setValues | public void setValues(Value[] v)(Code) | | Set the Values that are substituted for (single) #'s in the string.
If the array of Values is null, then no substitution is done. The length of the array should match
the number of #'s, but it is not an error if they do not match.
Extra values will be ignored; extra #'s will be shown as "undefined".
|
|
|