Class RobotlCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----RobotlCanvas

public class RobotlCanvas
extends Canvas
RobotlCanvas comprises the primary display system of the interpreter. It displays the RoBOTL grid of squares and all of the contents. it also reports mouse events to the so that infomation on cells and robots can be displayed accordingly.

Author:
Peter Sagerson, petersag@wpi.edu.

Variable Index

 o applet
A reference to the RobotlApplet running the show.
 o cellSize
The size in pixels of one cell, including buffer space.
 o colors
A list of color sets for the grid display.
 o colorSet
The color set currently being used.
 o drawSize
The size in pixels of one cell, excluding buffer space.
 o emptySpace
The verticle space of the component in pixels that is not used for drawing.
 o mapSize
The number of cells on one side of the map.
 o metrics
Used to find the width of strings in paintCell.
 o points
All of the points needed to draw a robot in cell (0, 19).
 o world
The array of Cells.

Constructor Index

 o RobotlCanvas(RobotlApplet, Color[][])
Sets applet and colors.

Method Index

 o calculateGrid()
Calculates the size of each grid square and sets up points.
 o getMapSize()
 o mouseDown(Event, int, int)
Calls lockRobotFeedback() or lockGridFeedback() in the applet, depending on the state of the shift key.
 o mouseEnter(Event, int, int)
Calls mouseMove() with the same arguments.
 o mouseExit(Event, int, int)
Tells the applet to clear the info window, if it's not locked.
 o mouseMove(Event, int, int)
Calls setGridFeedback() in the applet.
 o paint(Graphics)
Paints the entire world.
 o paintCell(Graphics, int, int)
Paints the given cell.
 o pixelToGrid(int, int)
Returns the grid cell that a given pixel falls inside of.
 o reInit(RobotWorld)
Called every time a new program is run.
 o reshape(int, int, int, int)
Ensures that this Component will always be square.
 o setColors(int)
Sets colorSet and redraws the grid.

Variables

 o mapSize
 int mapSize
The number of cells on one side of the map.

 o cellSize
 int cellSize
The size in pixels of one cell, including buffer space.

 o drawSize
 int drawSize
The size in pixels of one cell, excluding buffer space.

 o emptySpace
 int emptySpace
The verticle space of the component in pixels that is not used for drawing. This arises because x pixels may not divide evenly among n map cells.

 o applet
 RobotlApplet applet
A reference to the RobotlApplet running the show.

 o world
 Cell world[][]
The array of Cells.

 o metrics
 FontMetrics metrics
Used to find the width of strings in paintCell. If the string representing the number of beepers in a cell is wider than the drawing space available, an asterisk is used instead.

 o points
 int points[][]
All of the points needed to draw a robot in cell (0, 19).

 o colors
 Color colors[][]
A list of color sets for the grid display. In order, the colors are for wall, beepers, world, robot, text box.

 o colorSet
 int colorSet
The color set currently being used.

Constructors

 o RobotlCanvas
 public RobotlCanvas(RobotlApplet inApplet,
                     Color inColors[][])
Sets applet and colors.

Methods

 o calculateGrid
 public void calculateGrid()
Calculates the size of each grid square and sets up points. Assumes that the component is square.

 o reInit
 public void reInit(RobotWorld inWorld)
Called every time a new program is run. Calculates the dimensions of the grid squares and does a full update.

Parameters:
inWorld - the world that this RobotlCanvas is to display
 o getMapSize
 public int getMapSize()
Returns:
mapSize.
 o reshape
 public synchronized void reshape(int x,
                                  int y,
                                  int width,
                                  int height)
Ensures that this Component will always be square.

Overrides:
reshape in class Component
 o setColors
 public void setColors(int set)
Sets colorSet and redraws the grid.

 o pixelToGrid
 Point pixelToGrid(int x,
                   int y)
Returns the grid cell that a given pixel falls inside of. This cell may be outside the range of existing cells.

 o mouseEnter
 public boolean mouseEnter(Event evt,
                           int x,
                           int y)
Calls mouseMove() with the same arguments.

Overrides:
mouseEnter in class Component
 o mouseExit
 public boolean mouseExit(Event evt,
                          int x,
                          int y)
Tells the applet to clear the info window, if it's not locked.

Overrides:
mouseExit in class Component
 o mouseMove
 public boolean mouseMove(Event evt,
                          int x,
                          int y)
Calls setGridFeedback() in the applet. The applet will update the info window if the mouse has moved into a new grid square.

Overrides:
mouseMove in class Component
See Also:
setGridFeedback
 o mouseDown
 public boolean mouseDown(Event evt,
                          int x,
                          int y)
Calls lockRobotFeedback() or lockGridFeedback() in the applet, depending on the state of the shift key. The applet will lock the info window, if appropriate.

Overrides:
mouseDown in class Component
 o paintCell
 public void paintCell(Graphics g,
                       int m,
                       int n)
Paints the given cell.

Parameters:
m - the x coordinate to paint, in grid coordinates
n - the y coordinate to paint, in grid coordinates
 o paint
 public void paint(Graphics g)
Paints the entire world. This should only be called by the interpreter at the beginning of an execution.

Overrides:
paint in class Canvas