public class DrawString extends Drawable implements Computable
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.
Modifier and Type | Field and Description |
---|---|
protected Color |
backgroundColor
If backgroundColor is non-null, then a rectangle of this color is filled
as a background for the string;
|
protected String |
baseString
String, possibly with \n and #'s.
|
static int |
BOTTOM_CENTER
Specify string location in rect
|
static int |
BOTTOM_LEFT
Specify string location in rect
|
static int |
BOTTOM_RIGHT
Specify string location in rect
|
static int |
CENTER
For specifying justification of lines in multiline strings.
|
static int |
CENTER_CENTER
Specify string location in rect
|
static int |
CENTER_LEFT
Specify string location in rect
|
static int |
CENTER_RIGHT
Specify string location in rect
|
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.
|
static int |
LEFT
For specifying justification of lines in multiline strings.
|
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
one of the constants defined in this class for specifying position
|
static int |
RIGHT
For specifying justification of lines in multiline strings.
|
protected String[] |
strings
The actual lines to draw, derived from baseString.
|
static int |
TOP_CENTER
Specify string location in rect
|
static int |
TOP_LEFT
Specify string location in rect
|
static int |
TOP_RIGHT
Specify string location in rect
|
protected Value[] |
values
Values to be substituted for #'s in the baseString.
|
protected Value |
xPos
xy-coords for drawing the string.
|
protected Value |
yPos
xy-coords for drawing the string.
|
Constructor and Description |
---|
DrawString()
Create a DrawString object that initially has no string to draw.
|
DrawString(String str)
Create a DrawString for drawing a black string in the top left corner of the coordinate rect.
|
DrawString(String str,
int pos)
Create a DrawString for drawing a black string in the position specified.
|
DrawString(String str,
int pos,
Value[] values)
Create a DrawString for drawing a black string in the specified position.
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
compute()
The compute method sets up the array of strings that is actually displayed.
|
void |
draw(Graphics g,
boolean coordsChanged)
Draws the string.
|
Color |
getBackgroundColor()
Get the color that is used to fill a rectangle on which the string is drawn.
|
boolean |
getClamp()
Returns true if the string is set to be clamped to lie within the CoordinateRect.
|
Color |
getColor()
Get the non-null color that is used for drawing the string.
|
Font |
getFont()
Return the font that is used for drawing the string.
|
Color |
getFrameColor()
Get the color that is used to draw a frame around the string.
|
int |
getFrameWidth()
Get the width, in pixels, of the frame that is drawn around the string.
|
int |
getJustification()
Get the justification that is used for a multiple-line string.
|
int |
getNumSize()
Return the desired maximum number of characters in displayed numbers.
|
int |
getOffset()
Get the distance of the bounding box of the string from the reference
point where it is drawn.
|
int |
getPositioning()
Return the positioning, as set by setPositioning().
|
String |
getString()
Get a copy of the display string (with \n's #'s, not with substitued values.)
|
Value[] |
getValues()
Return the array of values that are substituted for #'s in the string.
|
Value |
getXPos()
Return the Value object that gives the x-coordinate of the reference
point of this string.
|
Value |
getYPos()
Return the Value object that gives the y-coordinate of the reference
point of this string.point of this string.
|
void |
setBackgroundColor(Color color)
Set the color that is used to fill a rectangle on which the string is drawn.
|
void |
setClamp(boolean clamp)
Set the "clamp" property of the DrawString.
|
void |
setColor(Color c)
Set the color for the string.
|
void |
setFont(Font f)
Set the font that is used for drawing this string.
|
void |
setFrameColor(Color color)
Set the color that is used to draw a frame around the string.
|
void |
setFrameWidth(int width)
Set the width, in pixels, of a frame to draw around the string.
|
void |
setJustification(int j)
Set the justification to be used if there are multiple lins in the string.
|
void |
setNumSize(int size)
Set the desired maximum number of characters in displayed numbers.
|
void |
setOffset(int b)
Set the distance of the bounding box of the string from the reference
point where it is drawn.
|
void |
setPositioning(int pos)
Set the positioning of the string.
|
void |
setReferencePoint(Value x,
Value y)
Set the values of the (x,y) coordinates of the
reference point for the stirng.
|
void |
setString(String str)
Set the string that is displayed.
|
void |
setValues(Value[] v)
Set the Values that are substituted for (single) #'s in the string.
|
getVisible, needsRedraw, setOwnerData, setVisible
public static final int TOP_LEFT
public static final int TOP_CENTER
public static final int TOP_RIGHT
public static final int CENTER_LEFT
public static final int CENTER_CENTER
public static final int CENTER_RIGHT
public static final int BOTTOM_LEFT
public static final int BOTTOM_CENTER
public static final int BOTTOM_RIGHT
public static final int CENTER
public static final int LEFT
public static final int RIGHT
protected int position
protected String baseString
protected String[] strings
protected Value[] values
protected Value xPos
protected Value yPos
protected Color color
protected Font font
protected int offset
protected boolean clamp
protected int justification
protected int numSize
protected Color backgroundColor
protected int frameWidth
protected Color frameColor
public DrawString()
public DrawString(String str)
str
- The string to draw, which can contain \n's to indicate line breaks.public DrawString(String str, int pos)
str
- The string to draw, which can contain \n's to indicate line breaks.pos
- The positioning of the string in the coordinate rect. One of the positioning constants such as TOP_LEFT or BOTTOM_RIGHT.public DrawString(String str, int pos, Value[] values)
str
- The string to draw, which can contain \n's to indicate line breaks and #'s to be replaced by numeric values.pos
- The positioning of the string in the coordinate rect. One of the positioning constants such as TOP_LEFT or BOTTOM_RIGHT.values
- Value objects associated with #'s in the string.public DrawString(String str, int pos, Value xPos, Value yPos, Value[] values)
str
- The string to draw, which can contain \n's to indicate line breaks and #'s to be replaced by numeric values.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.xPos
- x-coordinate relative to which the string is drawn (or null for absolute hoizontal positioning).yPos
- y-coordinate relative to which the string is drawn (or null for absolute vertical positioning).values
- Value objects associated with #'s in the string.public void setColor(Color c)
public Color getColor()
public void setFont(Font f)
public Font getFont()
public void setValues(Value[] v)
public Value[] getValues()
public void setPositioning(int pos)
public int getPositioning()
public void setReferencePoint(Value x, Value y)
public Value getXPos()
public Value getYPos()
public void setString(String str)
public String getString()
public void setOffset(int b)
public int getOffset()
public void setClamp(boolean clamp)
public boolean getClamp()
public void setJustification(int j)
public int getJustification()
public void setNumSize(int size)
public int getNumSize()
public Color getBackgroundColor()
public void setBackgroundColor(Color color)
public Color getFrameColor()
public void setFrameColor(Color color)
public int getFrameWidth()
public void setFrameWidth(int width)
public void compute()
compute
in interface Computable
public void draw(Graphics g, boolean coordsChanged)
draw
in class Drawable
g
- The graphics context in which the Drawble is to be drawn. (The drawing
can change the color in g, but should not permanently change font, painting mode, etc.
Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.