|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component net.sourceforge.webcompmath.draw.Drawable net.sourceforge.webcompmath.draw.DrawString
public class DrawString
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected java.awt.Color |
backgroundColor
If backgroundColor is non-null, then a rectangle of this color is filled as a background for the string; |
protected java.lang.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 java.awt.Color |
color
Color of string. |
protected java.awt.Font |
font
Font for drawing string. |
protected java.awt.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 java.lang.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. |
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
canvas, coords |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
DrawString()
Create a DrawString object that initially has no string to draw. |
|
DrawString(java.lang.String str)
Create a DrawString for drawing a black string in the top left corner of the coordinate rect. |
|
DrawString(java.lang.String str,
int pos)
Create a DrawString for drawing a black string in the position specified. |
|
DrawString(java.lang.String str,
int pos,
Value[] values)
Create a DrawString for drawing a black string in the specified position. |
|
DrawString(java.lang.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. |
Method Summary | |
---|---|
void |
compute()
The compute method sets up the array of strings that is actually displayed. |
void |
draw(java.awt.Graphics g,
boolean coordsChanged)
Draws the string. |
java.awt.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. |
java.awt.Color |
getColor()
Get the non-null color that is used for drawing the string. |
java.awt.Font |
getFont()
Return the font that is used for drawing the string. |
java.awt.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(). |
java.lang.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(java.awt.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(java.awt.Color c)
Set the color for the string. |
void |
setFont(java.awt.Font f)
Set the font that is used for drawing this string. |
void |
setFrameColor(java.awt.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(java.lang.String str)
Set the string that is displayed. |
void |
setValues(Value[] v)
Set the Values that are substituted for (single) #'s in the string. |
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable |
---|
getVisible, needsRedraw, setOwnerData, setVisible |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
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 java.lang.String baseString
protected java.lang.String[] strings
protected Value[] values
protected Value xPos
protected Value yPos
protected java.awt.Color color
protected java.awt.Font font
protected int offset
protected boolean clamp
protected int justification
protected int numSize
protected java.awt.Color backgroundColor
protected int frameWidth
protected java.awt.Color frameColor
Constructor Detail |
---|
public DrawString()
public DrawString(java.lang.String str)
str
- The string to draw, which can contain \n's to indicate line
breaks.public DrawString(java.lang.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(java.lang.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(java.lang.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.Method Detail |
---|
public void setColor(java.awt.Color c)
c
- string colorpublic java.awt.Color getColor()
public void setFont(java.awt.Font f)
setFont
in class java.awt.Component
f
- fontpublic java.awt.Font getFont()
getFont
in interface java.awt.MenuContainer
getFont
in class java.awt.Component
public void setValues(Value[] v)
v
- array of values to substitutepublic Value[] getValues()
public void setPositioning(int pos)
pos
- positioning constantpublic int getPositioning()
public void setReferencePoint(Value x, Value y)
x
- x coord of ref. pointy
- y coord of ref. pointpublic Value getXPos()
public Value getYPos()
public void setString(java.lang.String str)
str
- string to displaypublic java.lang.String getString()
public void setOffset(int b)
b
- bounding box offsetpublic int getOffset()
public void setClamp(boolean clamp)
clamp
- true or falsepublic boolean getClamp()
public void setJustification(int j)
j
- LEFT, RIGHT, CENTERpublic int getJustification()
public void setNumSize(int size)
size
- max number of chars.public int getNumSize()
public java.awt.Color getBackgroundColor()
public void setBackgroundColor(java.awt.Color color)
color
- background colorpublic java.awt.Color getFrameColor()
public void setFrameColor(java.awt.Color color)
color
- frame colorpublic int getFrameWidth()
public void setFrameWidth(int width)
width
- frame widthpublic void compute()
compute
in interface Computable
public void draw(java.awt.Graphics g, boolean coordsChanged)
draw
in class Drawable
g
- graphics contextcoordsChanged
- true or false
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |