ciips.animation
Class ComBox

java.lang.Object
  extended byciips.animation.Drawable
      extended byciips.animation.ComBox
All Implemented Interfaces:
DrawingObj

public class ComBox
extends Drawable

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:

      ComBox com = new ComBox(x, y, "Example Comment", font);
      drawingPanel.addCom(com);
      drawingPanel.redraw();
 
It is removed from the drawing panel by:
      drawingPanel.removeCom(com);
 
where 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:
      Font font = new Font("Courier", Font.PLAIN, 12);
 
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.

See Also:
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

ComBox

public 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. By default, the background color is yellow and the text is displayed in blue.

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.

ComBox

public ComBox(int tlx,
              int tly,
              java.lang.String s)

ComBox

public 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.

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.

ComBox

public ComBox(DrawingObj z,
              java.lang.String s)
Creates a commentary box near another object

Parameters:
z - Drawing object to which this commentary box refers
s - Comment string

ComBox

public 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

Parameters:
z - Drawing object to which this commentary box refers
offset - Offset from object
s - Comment string
fg - Text colour
bg - Background colour
Method Detail

setText

public void setText(java.lang.String str)
Set the text string to be displayed on the commentary box.

Overrides:
setText in class Drawable
Parameters:
str - Text string in the form of class String

setTopLeft

public void setTopLeft(int topLeftX,
                       int topLeftY)
Set the top left position of the commentary box.

Parameters:
topLeftX - Horizontal position of the top left corner.
topLeftY - Vertical position of the top left corner.

setTopLeft

public void setTopLeft(DrawingObj z)
Set the position of the commentary box relative to another object


setBackground

public void setBackground(java.awt.Color col)
Set the background color of the commentary box. The background color of commentary box is specified by java.awt.Color.

Parameters:
col - Background color, instance of java.awt.color
See Also:
Color

setColor

public void setColor(java.awt.Color col)
Set the text color of the commentary box. This foreground color (text color) is specified by java.awt.Color.

Parameters:
col - Foreground color, instance of java.awt.color
See Also:
Color

draw

public void draw(java.awt.Graphics g)
This method is to be called from the 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.

Specified by:
draw in interface DrawingObj
Specified by:
draw in class Drawable
Parameters:
g - Graphical context from the paint(Graphics g) method of the drawing panel/canvas.
See Also:
Graphics

move

public void move(int x,
                 int y)
Move the top left position of the commentary box.

Specified by:
move in interface DrawingObj
Overrides:
move in class Drawable
Parameters:
x - Horizontal position of the top left corner.
y - Vertical position of the top left corner.
See Also:
setTopLeft(int, int)

getX

public int getX()
X coordinate of the top left position of the commentary box.

Specified by:
getX in interface DrawingObj
Overrides:
getX in class Drawable
Returns:
The X coordinate of the top left corner of the commentary box.

getY

public int getY()
Y coordinate of the top left position of the commentary box.

Specified by:
getY in interface DrawingObj
Overrides:
getY in class Drawable
Returns:
The Y coordinate of the top left corner of the commentary box.

getText

public java.lang.String getText()
This method is called to obtain the current text string to be displayed in the commentary box.

Returns:
The text string to be displayed on the commentary box.