|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectciips.animation.Drawable
ciips.animation.ComBox
This class composes a commentary box to be drawn on any drawing panel/canvas. The width of the commentary box will be determined by the length of the text string being displayed.
Since this object implements DrawingObj
, it can be added
into the DrawingPanel
by using either the addCom
or addDrawingObj
method. An added commentary box can be
removed by calling the removeCom
or removeObj
method of the DrawingPanel
class.
If the addCom
method
is called, the added commentary box is guaranteed to be displayed on
top of all drawing objects added to the panel using
addDrawingObj
.
Otherwise, if the commentary box is added to the panel using
addDrawingObj
, the last added object will be on top.
Typically, a commentary box can be initialized and added to a
drawing panel and displayed by using the following statements:
It is removed from the drawing panel by:
ComBox com = new ComBox(x, y, "Example Comment", font);
drawingPanel.addCom(com);
drawingPanel.redraw();
where
drawingPanel.removeCom(com);
drawingPanel
is an instance of the class object
DrawingPanel
, x
and y
define
the top left position of the commentary box and font
is an instance of the Font
object, typically a fixed font,
which is declared as follows:
Note that the size-12 courier font is recommended for all situation
since the width of the com box is calculated based on this particular
size font. Otherwise, the dimension has to be modified.
Font font = new Font("Courier", Font.PLAIN, 12);
DrawingPanel
,
DrawingPanel.addCom(ciips.animation.ComBox)
,
DrawingPanel.addDrawingObj(ciips.animation.DrawingObj)
,
DrawingPanel.redraw()
Field Summary |
Fields inherited from class ciips.animation.Drawable |
colour, DEFAULT_START, grey, highlight, label, x, y |
Constructor Summary | |
ComBox(DrawingObj z,
java.awt.Point offset,
java.lang.String s,
java.awt.Color fg,
java.awt.Color bg)
Creates a commentary box near another object: use this method when more than one box may be associated with an object |
|
ComBox(DrawingObj z,
java.lang.String s)
Creates a commentary box near another object |
|
ComBox(int tlx,
int tly,
java.lang.String s)
|
|
ComBox(int topLeftX,
int topLeftY,
java.lang.String str,
java.awt.Color fg,
java.awt.Color bg,
java.awt.Font font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String
parameter, using the foreground and background colors indicated by
the fourth and fifth parameters. |
|
ComBox(int topLeftX,
int topLeftY,
java.lang.String str,
java.awt.Font font)
Creates a commentary box with its topleft corner at (topLeftX, topLeftY) and the commentary text specified by the third String
parameter. |
Method Summary | |
void |
draw(java.awt.Graphics g)
This method is to be called from the paint(Graphics g)
method of the drawing panel/canvas. |
java.lang.String |
getText()
This method is called to obtain the current text string to be displayed in the commentary box. |
int |
getX()
X coordinate of the top left position of the commentary box. |
int |
getY()
Y coordinate of the top left position of the commentary box. |
void |
move(int x,
int y)
Move the top left position of the commentary box. |
void |
setBackground(java.awt.Color col)
Set the background color of the commentary box. |
void |
setColor(java.awt.Color col)
Set the text color of the commentary box. |
void |
setText(java.lang.String str)
Set the text string to be displayed on the commentary box. |
void |
setTopLeft(DrawingObj z)
Set the position of the commentary box relative to another object |
void |
setTopLeft(int topLeftX,
int topLeftY)
Set the top left position of the commentary box. |
Methods inherited from class ciips.animation.Drawable |
getCurrentColour, setGrey, setHighlight |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ComBox(int topLeftX, int topLeftY, java.lang.String str, java.awt.Font font)
String
parameter. By default, the background color is yellow and
the text is displayed in blue.
topLeftX
- Integer value specifying the horizontal position of the
topleft corner of the commentary box.topLeftY
- Integer value specifying the vertical position of the
topleft corner of the commentary box.str
- The text string to be displayed on the commentary box.public ComBox(int tlx, int tly, java.lang.String s)
public ComBox(int topLeftX, int topLeftY, java.lang.String str, java.awt.Color fg, java.awt.Color bg, java.awt.Font font)
String
parameter, using the foreground and background colors indicated by
the fourth and fifth parameters.
topLeftX
- Integer value specifying the horizontal position of the
topleft corner of the commentary box.topLeftY
- Integer value specifying the vertical position of the
topleft corner of the commentary box.str
- The text string to be displayed on the commentary box.fg
- Color of the text in the commentary box.bg
- Color of the commentary box background.public ComBox(DrawingObj z, java.lang.String s)
z
- Drawing object to which this commentary box referss
- Comment stringpublic ComBox(DrawingObj z, java.awt.Point offset, java.lang.String s, java.awt.Color fg, java.awt.Color bg)
z
- Drawing object to which this commentary box refersoffset
- Offset from objects
- Comment stringfg
- Text colourbg
- Background colourMethod Detail |
public void setText(java.lang.String str)
setText
in class Drawable
str
- Text string in the form of class Stringpublic void setTopLeft(int topLeftX, int topLeftY)
topLeftX
- Horizontal position of the top left corner.topLeftY
- Vertical position of the top left corner.public void setTopLeft(DrawingObj z)
public void setBackground(java.awt.Color col)
java.awt.Color
.
col
- Background color, instance of java.awt.colorColor
public void setColor(java.awt.Color col)
java.awt.Color
.
col
- Foreground color, instance of java.awt.colorColor
public void draw(java.awt.Graphics g)
paint(Graphics g)
method of the drawing panel/canvas. It uses the graphical context
of the drawing panel/canvas to construct the commentary box on
the drawing panel/canvas.
draw
in interface DrawingObj
draw
in class Drawable
g
- Graphical context from the paint(Graphics g)
method of the drawing panel/canvas.Graphics
public void move(int x, int y)
move
in interface DrawingObj
move
in class Drawable
x
- Horizontal position of the top left corner.y
- Vertical position of the top left corner.setTopLeft(int, int)
public int getX()
getX
in interface DrawingObj
getX
in class Drawable
public int getY()
getY
in interface DrawingObj
getY
in class Drawable
public java.lang.String getText()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |