so that infomation on cells and
robots can be displayed accordingly.
- Author:
- Peter Sagerson, petersag@wpi.edu.
-
applet
- A reference to the
RobotlApplet running the show.
-
cellSize
- The size in pixels of one cell, including buffer space.
-
colors
- A list of color sets for the grid display.
-
colorSet
- The color set currently being used.
-
drawSize
- The size in pixels of one cell, excluding buffer space.
-
emptySpace
- The verticle space of the component in pixels that is not used
for drawing.
-
mapSize
- The number of cells on one side of the map.
-
metrics
- Used to find the width of strings in
paintCell.
-
points
- All of the points needed to draw a robot in cell (0, 19).
-
world
- The array of
Cells.
-
RobotlCanvas(RobotlApplet, Color[][])
- Sets
applet and colors.
-
calculateGrid()
- Calculates the size of each grid square and sets up
points.
-
getMapSize()
-
-
mouseDown(Event, int, int)
- Calls
lockRobotFeedback() or lockGridFeedback()
in the applet, depending on the state of the shift key.
-
mouseEnter(Event, int, int)
- Calls
mouseMove() with the same arguments.
-
mouseExit(Event, int, int)
- Tells the applet to clear the info window, if it's not locked.
-
mouseMove(Event, int, int)
- Calls
setGridFeedback() in the applet.
-
paint(Graphics)
- Paints the entire world.
-
paintCell(Graphics, int, int)
- Paints the given cell.
-
pixelToGrid(int, int)
- Returns the grid cell that a given pixel falls inside of.
-
reInit(RobotWorld)
- Called every time a new program is run.
-
reshape(int, int, int, int)
- Ensures that this Component will always be square.
-
setColors(int)
- Sets
colorSet and redraws the grid.
mapSize
int mapSize
- The number of cells on one side of the map.
cellSize
int cellSize
- The size in pixels of one cell, including buffer space.
drawSize
int drawSize
- The size in pixels of one cell, excluding buffer space.
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.
applet
RobotlApplet applet
- A reference to the
RobotlApplet running the show.
world
Cell world[][]
- The array of
Cells.
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.
points
int points[][]
- All of the points needed to draw a robot in cell (0, 19).
colors
Color colors[][]
- A list of color sets for the grid display. In order, the colors are
for wall, beepers, world, robot, text box.
colorSet
int colorSet
- The color set currently being used.
RobotlCanvas
public RobotlCanvas(RobotlApplet inApplet,
Color inColors[][])
- Sets
applet and colors.
calculateGrid
public void calculateGrid()
- Calculates the size of each grid square and sets up
points.
Assumes that the component is square.
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
getMapSize
public int getMapSize()
- Returns:
-
mapSize.
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
setColors
public void setColors(int set)
- Sets
colorSet and redraws the grid.
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.
mouseEnter
public boolean mouseEnter(Event evt,
int x,
int y)
- Calls
mouseMove() with the same arguments.
- Overrides:
- mouseEnter in class Component
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
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
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
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
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