uchicago.src.sim.gui
Class TextDisplay

java.lang.Object
  extended by uchicago.src.sim.gui.Display
      extended by uchicago.src.sim.gui.TextDisplay
All Implemented Interfaces:
Displayable, Probeable

public class TextDisplay
extends Display
implements Probeable

A Display class that can be used to display lines of text on a DisplaySurface. The text is optionally displayed enclosed in a rectangle. The text can remain static or can be changed by calling clearLines or clearLine and then adding new lines.

Version:
$Revision: 1.6 $ $Date: 2004/11/03 19:50:59 $
Author:
Nick Collier

Nested Class Summary
static class TextDisplay.Box
           
 
Field Summary
protected  TextDisplay.Box box
           
protected  java.awt.Font curFont
           
protected  boolean drawBox
           
protected  java.lang.String header
           
protected  java.util.ArrayList text
           
protected  java.awt.Color textColor
           
 
Fields inherited from class uchicago.src.sim.gui.Display
height, view, width
 
Fields inherited from interface uchicago.src.sim.gui.Displayable
TOGGLE_LINKS, TOGGLE_NODES, TOGGLE_UPDATE_LAYOUT, TOGGLE_VIEW, TOGGLE_WRAP
 
Constructor Summary
TextDisplay(int x, int y, java.awt.Color textColor)
          Constructs a TextDisplay to display text at the specified coordinates in the specified color.
TextDisplay(int width, int height, int x, int y, java.awt.Color textColor)
          Constructs a TextDisplay to display text at the specified coordinates in the specified color.
 
Method Summary
 void addLine(java.lang.String val)
          Adds a line of text to be displayed.
 void addLine(java.lang.String val, int index)
          Adds a line of text at the specified index (relative to the other lines.
 void clearLine(int index)
          Removes the line at the specified index.
 void clearLines()
          Clears the list of lines to be displayed.
 void drawDisplay(SimGraphics g)
          Does the actual drawing using the SimGraphics parameter.
 TextDisplay.Box getBoundingBox()
          Returns the Box that bounds the displayed text in this TextDisplay.
 java.util.ArrayList getDisplayableInfo()
          Gets a list of the DisplayInfo object associated with this Display.
 int getFontSize()
          Gets the current font size.
 java.util.ArrayList getObjectsAt(int x, int y)
          Gets the objects at the coordinate x, y.
 int getX()
          Gets the x coordinate for displaying text.
 int getY()
          Gets the y coordinate for displaying text.
 void setBoxVisible(boolean val)
          Sets whether the text should be drawn enclosed in a retangle.
 void setColor(java.awt.Color c)
          Sets the color of the text and box.
 void setFontSize(int val)
          Sets the font size of the text.
 void setHeader(java.lang.String header)
          Sets an optional header for the displayed text.
 void setMoveableXY(Moveable moveable, int x, int y)
          Sets the new coordinates for specified moveable.
 void setTextCoordinates(int x, int y)
          Sets the coordinates for displaying the lines of text.
 void setX(int x)
          Sets the x coordinate for displaying text.
 void setY(int y)
          Sets the Y coordinate for displaying text.
 void viewEventPerformed(ViewEvent evt)
          Invoked when a viewEvent for this display is fired by the DisplaySurface.
 
Methods inherited from class uchicago.src.sim.gui.Display
getSize, reSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textColor

protected java.awt.Color textColor

drawBox

protected boolean drawBox

text

protected java.util.ArrayList text

header

protected java.lang.String header

curFont

protected java.awt.Font curFont

box

protected TextDisplay.Box box
Constructor Detail

TextDisplay

public TextDisplay(int x,
                   int y,
                   java.awt.Color textColor)
Constructs a TextDisplay to display text at the specified coordinates in the specified color. If the text is to be drawing inside a box (see setBoxVisible(), x and y mark the top left corner of this box. If the text is not drawn inside a box then x and y mark the position of the baseline of left-most character in the first string to be drawn.

Parameters:
x - the x coordinate
y - the y coordinate
textColor - the color to draw the text and box

TextDisplay

public TextDisplay(int width,
                   int height,
                   int x,
                   int y,
                   java.awt.Color textColor)
Constructs a TextDisplay to display text at the specified coordinates in the specified color. If the TextDisplay is the first Display added to a DisplaySurface then width and height must be specified. If the text is to be drawing inside a box (see setBoxVisible(), x and y mark the top left corner of this box. If the text is not drawn inside a box then x and y mark the position of the baseline of left-most character in the first string to be drawn.

Parameters:
width - the width of the display
height - the height of the display
x - the x coordinate
y - the y coordinate
textColor - the color to draw the text and box
Method Detail

setBoxVisible

public void setBoxVisible(boolean val)
Sets whether the text should be drawn enclosed in a retangle.


setHeader

public void setHeader(java.lang.String header)
Sets an optional header for the displayed text.

Parameters:
header - the header

addLine

public void addLine(java.lang.String val)
Adds a line of text to be displayed. Lines will be displayed in the order they are added. First added will be displayed first. Multiple lines can be added by separating the lines with the "\n" character.

Parameters:
val - the line to add

addLine

public void addLine(java.lang.String val,
                    int index)
Adds a line of text at the specified index (relative to the other lines. Lines will be displayed in the order they are added. First added will be displayed first. Multiple lines can be added by separating the lines with the "\n" character.

Parameters:
val - the line to add
index - where to add the line relative to other lines

clearLines

public void clearLines()
Clears the list of lines to be displayed.


clearLine

public void clearLine(int index)
Removes the line at the specified index.

Parameters:
index - the index of the line to remove

setColor

public void setColor(java.awt.Color c)
Sets the color of the text and box.

Parameters:
c - the color of the text and box

setFontSize

public void setFontSize(int val)
Sets the font size of the text.

Parameters:
val - the font size

getFontSize

public int getFontSize()
Gets the current font size.


setTextCoordinates

public void setTextCoordinates(int x,
                               int y)
Sets the coordinates for displaying the lines of text.

Parameters:
x - the x coordinate
y - the y coordinate

getX

public int getX()
Gets the x coordinate for displaying text.


setX

public void setX(int x)
Sets the x coordinate for displaying text.

Parameters:
x - the x coordinate

getY

public int getY()
Gets the y coordinate for displaying text.


setY

public void setY(int y)
Sets the Y coordinate for displaying text.

Parameters:
y - the y coordinate

getBoundingBox

public TextDisplay.Box getBoundingBox()
Returns the Box that bounds the displayed text in this TextDisplay.

Returns:

drawDisplay

public void drawDisplay(SimGraphics g)
Does the actual drawing using the SimGraphics parameter.

Specified by:
drawDisplay in interface Displayable
Specified by:
drawDisplay in class Display
Parameters:
g - the graphics context with which to draw

getDisplayableInfo

public java.util.ArrayList getDisplayableInfo()
Gets a list of the DisplayInfo object associated with this Display.

Specified by:
getDisplayableInfo in interface Displayable
Overrides:
getDisplayableInfo in class Display
See Also:
DisplayInfo

viewEventPerformed

public void viewEventPerformed(ViewEvent evt)
Invoked when a viewEvent for this display is fired by the DisplaySurface.

Specified by:
viewEventPerformed in interface Displayable
Overrides:
viewEventPerformed in class Display

getObjectsAt

public java.util.ArrayList getObjectsAt(int x,
                                        int y)
Description copied from interface: Probeable
Gets the objects at the coordinate x, y. X and Y are screen coordinates.

Specified by:
getObjectsAt in interface Probeable
Parameters:
x - the x screen coordinate.
y - the y screen coordinate.
Returns:
the object at the x, y coordinate.

setMoveableXY

public void setMoveableXY(Moveable moveable,
                          int x,
                          int y)
Sets the new coordinates for specified moveable. This goes through probeable as some translation between screen pixel coordinates and the simulation coordinates may be necessary.

Specified by:
setMoveableXY in interface Probeable
Parameters:
moveable - the moveable whose coordinates are changed
x - the x coordinate in pixels
y - the y coordinate in pixels