Class RobotlApplet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----RobotlApplet
- public class RobotlApplet
- extends Applet
- implements ElJefe
The main applet that the user interacts with. This applet creates
a single parser to parse programs, a single RobotWorld
to run the programs and a new Thread for each execution.
It also keeps references to all of the interface elements in the
main window including the menu bar.
- Author:
- Peter Sagerson, petersag@wpi.edu
-
BLUES
- A constant defining a color set.
-
BUTTONS
- The number of buttons lined up below the code box.
-
canvas
- The component that draws the RoBOTL grid.
-
clearButton
-
-
code
- The text box into which the user enters code.
-
codeLabel
-
-
colors
- A list of color sets for the grid display.
-
COMPONENTS
- The total number of components.
-
defaultInfo
- Text displayed in the
gridInfo box when the mouse is not on the grid.
-
EXAMPLES_FILE
- The name of the example programs index file on the server.
-
examplesEntries
- The actual example programs (elements of type
IndexEntry).
-
examplesList
- The
List for the examples Browse window.
-
examplesMenu
- The Examples menu.
-
executing
- True when a program is executing.
-
exprogFrame
- The window used for the example programs.
-
FROG_LAND
- A constant defining a color set.
-
gridInfo
- The textbox in which information about the grid or individual robots
is displayed.
-
gridLabel
-
-
INDEX_FILE
-
-
indexEntries
- The actual modules in the tutorial index.
-
indexFrame
- The window used for the tutorial index.
-
indexList
- The
List for the tutorial Browse window.
-
infoLabel
-
-
infoLocked
- True when the
gridInfo box is locked onto an
InfoTarget.
-
initButton
- The button seen in the browser that will make the RoBOTL window visible.
-
keepMessages
- When true, the messages text box isn't cleared between runs.
-
killButton
-
-
lastColorItem
- A reference to the last item in the Color menu to be selected.
-
lastDelayItem
- A reference to the last item in the Delay menu to be selected.
-
lastInfoTarget
- A reference to the last
Cell or Robot
to be set for feedback.
-
menubar
- The main menu bar for the window.
-
messages
- The text box in which warnings, errors and other messages are displayed.
-
msgLabel
-
-
parseButton
-
-
parser
- An instance of the parser generated by JavaCC.
-
PEACHES
- A constant defining a color set.
-
prettyPrint
- When true,
DebugBox.format()
is called before parsing.
-
PURPLES
- A constant defining a color set.
-
REFERENCE_URL
- The URL for the reference guide.
-
robotlFrame
- The window that contains all of the interface components.
-
runButton
-
-
SEAFOAM
- A constant defining a color set.
-
soundOn
- True if the user wants to hear all of the sounds.
-
stepButton
-
-
stepField
- The Label that displays the next instruction to be executed.
-
steppingFont
- The default font for the applet.
-
thread
- The
Thread that executes a RoBOTL program.
-
TUTORIAL_FILE
- The name of the tutorial index file on the server.
-
tutorialEntries
- The actual modules in the tutorial.
-
tutorialFrame
- The window used for the tutorial.
-
tutorialList
- The
List for the tutorial Browse window.
-
tutorialMenu
- The Tutorial menu.
-
useRobotInfo
- True when the
gridInfo box displays robot information
instead of cell information.
-
world
- An instance of
RobotWorld to be used for all simulations.
-
RobotlApplet()
-
-
action(Event, Object)
- Responds to the buttons and menus.
-
activateTutorial(String)
- Creates the tutorial window, if it doesn't exist.
-
buildInfoString(InfoTarget, boolean)
- Returns the info string for the given target.
-
coordString(int, int)
- Converts x and y coodinates into a printable string.
-
formatCode()
- If
prettyPrint is true,
tells the code box to format the code.
-
getCode()
- Returns the contents of the code-entry text box.
-
getLockedObject()
-
If the
gridInfo window is locked,
returns the cell that it's locked on.
-
getParser()
- Returns a reference to the parser object.
-
getWorld()
- Returns a reference to the
world field.
-
haltExecution()
- Stops the execution thread, clears the "next instruction" field and
calls
setExecuting(false, false).
-
handleRunButton()
- Calls spawnExecution if we're not currently executing.
-
handleStepButton()
- Starts executing if we're not already and calls
RobotWorld.step().
-
init()
- Initializes the interface components and menus and calls
initFrame().
-
initFrame()
- Creates the RoBOTL window and adds all components.
-
killFrame(RobotlFrame)
- This is called by
RobotlFrame.cleanup().
-
lockGridFeedback(int, int)
- Locks the info box into displaying the given cell's information
regardless of the mouse position.
-
lockRobotFeedback(int, int)
- Locks the robot at the given location into the info box.
-
paintCell(int, int)
- Tells the
RobotlCanvas to paint the cell and updates the grid
feedback.
-
playSound(String, boolean)
- Plays a sound with the given name, if
soundOn is true or
conditional is false.
-
postMessage(String)
- Adds the given String to the end of the message box.
-
resetGridInfo()
- Called right after the array of cells has been destroyed and
recreated in
RobotWorld.execute().
-
retrieveCode(String)
- Retrieves the given text file from applet's directory on the server and
reads its contents into a string, which is returned.
-
robotlInFront()
- Calls
robotlFrame.toFront().
-
selectCodeLine(int)
- Selects the given line of code in the code entry box.
-
setColors(int)
- Sets the background color of
gridInfo and calls
canvas.setColors()
-
setExecuting(boolean, boolean)
- Called once when a new execution thread starts and again just before
it dies.
-
setGridFeedback(int, int, boolean)
- Tells the applet to display information on the given square
in the grid info box.
-
setNextInstruction(String, int)
- Displays the given string in the stepField Label and
highlights the given line.
-
setupDisplay(RobotWorld)
- Wrapper for canvas.reInit.
-
setupSupportData(Menu, List, Hashtable, String)
- The file
filename contains the information that is displayed in
a SupportFrame.
-
spawnExecution(boolean, boolean)
- Clears the message box, sets the delay time and starts a new
execution thread.
-
updateFeedback()
- Updates the info box if
lastInfoTarget is not null.
-
updateGridFeedback(int, int)
- Called by
paintCell whenever a grid cell changes.
-
updateRobotFeedback(Robot)
- Updates the info box if the given robot is the current info target.
-
useCode(String)
- Gets the contents of file
filename and puts them into
the code text box.
COMPONENTS
public static final int COMPONENTS
- The total number of components. Used by
RobotlLayout.
BUTTONS
public static final int BUTTONS
- The number of buttons lined up below the code box.
RobotlLayout.
TUTORIAL_FILE
final String TUTORIAL_FILE
- The name of the tutorial index file on the server.
EXAMPLES_FILE
final String EXAMPLES_FILE
- The name of the example programs index file on the server.
INDEX_FILE
final String INDEX_FILE
REFERENCE_URL
final String REFERENCE_URL
- The URL for the reference guide.
executing
boolean executing
- True when a program is executing.
soundOn
boolean soundOn
- True if the user wants to hear all of the sounds.
prettyPrint
boolean prettyPrint
- When true,
DebugBox.format()
is called before parsing.
keepMessages
boolean keepMessages
- When true, the messages text box isn't cleared between runs. This
feature was used for usability testing.
infoLocked
boolean infoLocked
- True when the
gridInfo box is locked onto an
InfoTarget.
- See Also:
- InfoTarget
useRobotInfo
boolean useRobotInfo
- True when the
gridInfo box displays robot information
instead of cell information.
lastInfoTarget
InfoTarget lastInfoTarget
- A reference to the last
Cell or Robot
to be set for feedback.
lastDelayItem
CheckboxMenuItem lastDelayItem
- A reference to the last item in the Delay menu to be selected. This is
needed because when a new item is selected, this one must be unmarked.
lastColorItem
CheckboxMenuItem lastColorItem
- A reference to the last item in the Color menu to be selected. This is
needed because when a new item is selected, this one must be unmarked.
colors
Color colors[][]
- A list of color sets for the grid display. In order, the colors are
for wall, beepers, world, robot, text box.
BLUES
public static final int BLUES
- A constant defining a color set.
FROG_LAND
public static final int FROG_LAND
- A constant defining a color set.
PURPLES
public static final int PURPLES
- A constant defining a color set.
SEAFOAM
public static final int SEAFOAM
- A constant defining a color set.
PEACHES
public static final int PEACHES
- A constant defining a color set.
parser
RoBOTL parser
- An instance of the parser generated by JavaCC.
world
RobotWorld world
- An instance of
RobotWorld to be used for all simulations.
thread
Thread thread
- The
Thread that executes a RoBOTL program.
robotlFrame
RobotlFrame robotlFrame
- The window that contains all of the interface components.
menubar
MenuBar menubar
- The main menu bar for the window.
tutorialFrame
TutorialFrame tutorialFrame
- The window used for the tutorial.
tutorialMenu
Menu tutorialMenu
- The Tutorial menu. Used by
action to identify items in this menu.
tutorialList
List tutorialList
- The
List for the tutorial Browse window.
tutorialEntries
Hashtable tutorialEntries
- The actual modules in the tutorial.
indexFrame
IndexFrame indexFrame
- The window used for the tutorial index.
indexList
List indexList
- The
List for the tutorial Browse window.
indexEntries
Hashtable indexEntries
- The actual modules in the tutorial index.
exprogFrame
ExamplesFrame exprogFrame
- The window used for the example programs.
examplesMenu
Menu examplesMenu
- The Examples menu. Used by
action to identify items in this menu.
examplesList
List examplesList
- The
List for the examples Browse window.
examplesEntries
Hashtable examplesEntries
- The actual example programs (elements of type
IndexEntry).
canvas
RobotlCanvas canvas
- The component that draws the RoBOTL grid.
code
DebugBox code
- The text box into which the user enters code.
messages
TextArea messages
- The text box in which warnings, errors and other messages are displayed.
steppingFont
static Font steppingFont
- The default font for the applet.
defaultInfo
final String defaultInfo
- Text displayed in the
gridInfo box when the mouse is not on the grid.
gridInfo
TextArea gridInfo
- The textbox in which information about the grid or individual robots
is displayed.
initButton
Button initButton
- The button seen in the browser that will make the RoBOTL window visible.
clearButton
Button clearButton
runButton
Button runButton
killButton
Button killButton
parseButton
Button parseButton
stepButton
Button stepButton
stepField
Label stepField
- The Label that displays the next instruction to be executed.
gridLabel
Label gridLabel
codeLabel
Label codeLabel
msgLabel
Label msgLabel
infoLabel
Label infoLabel
RobotlApplet
public RobotlApplet()
init
public void init()
- Initializes the interface components and menus and calls
initFrame().
- Overrides:
- init in class Applet
setupSupportData
void setupSupportData(Menu menu,
List list,
Hashtable table,
String filename)
- The file
filename contains the information that is displayed in
a SupportFrame. The titles are also displayed the given menu.
The arguments menu, list and tabe
are initialized here.
The file format is as follows:
{Title}\n{codeFile}[,{textFile}]\n{Summary}\n\n (repeat)
{Title} is displayed in the Examples or Tutorial and the list box in the
associated SupportFrame. {codeFile} is the name of the file
containing the code for this entry. {textFile} is optional and refers to
the file containing the text that the tutorial displays for that module.
{Summary} is displayed in the right-hand text box of the SupportFrame
when {Title} is selected in the list.
- See Also:
- SupportFrame, IndexEntry
initFrame
void initFrame()
- Creates the RoBOTL window and adds all components.
coordString
public static String coordString(int x,
int y)
- Converts x and y coodinates into a printable string. This is
in
RobotlApplet simply because there's no better place for it.
getParser
public RoBOTL getParser()
- Returns a reference to the parser object. Called by
RobotWorld.
getWorld
public RobotWorld getWorld()
- Returns a reference to the
world field.
- See Also:
- world
getCode
public String getCode()
- Returns the contents of the code-entry text box.
getLockedObject
public InfoTarget getLockedObject()
- If the
gridInfo window is locked,
returns the cell that it's locked on. Returns null otherwise.
formatCode
public String formatCode()
- If
prettyPrint is true,
tells the code box to format the code.
retrieveCode
public String retrieveCode(String name)
- Retrieves the given text file from applet's directory on the server and
reads its contents into a string, which is returned.
useCode
public void useCode(String filename)
- Gets the contents of file
filename and puts them into
the code text box. The main interface window is then
moved to the foreground.
activateTutorial
public void activateTutorial(String module)
- Creates the tutorial window, if it doesn't exist. if
module
is not the empty string, it tells the tutorial window to open the given
module window. If the tutorial window is created to launch a specific
module, then the tutorial window is told to remain hidden upon creation.
postMessage
public void postMessage(String str)
- Adds the given String to the end of the message box.
- Parameters:
- str - the message to add to the message box
playSound
public void playSound(String name,
boolean conditional)
- Plays a sound with the given name, if
soundOn is true or
conditional is false. The sounds are located in the
applet's directory on the server.
- Parameters:
- name - the name of the sound to play
- conditional - if true, the sound will only be played if the user
has sounds turned on. If false, the sound will be played regardless.
setNextInstruction
public void setNextInstruction(String str,
int line)
- Displays the given string in the stepField Label and
highlights the given line. This is used to indicate
the next instruction to be executed while stepping through
a program.
setupDisplay
public void setupDisplay(RobotWorld inWorld)
- Wrapper for canvas.reInit.
- Parameters:
- inWorld - the world to display
- See Also:
- reInit
setColors
public void setColors(int set)
- Sets the background color of
gridInfo and calls
canvas.setColors()
paintCell
public void paintCell(int x,
int y)
- Tells the
RobotlCanvas to paint the cell and updates the grid
feedback.
- See Also:
- paintCell, updateGridFeedback
selectCodeLine
public void selectCodeLine(int line)
- Selects the given line of code in the code entry box.
resetGridInfo
public void resetGridInfo()
- Called right after the array of cells has been destroyed and
recreated in
RobotWorld.execute().
If we were locked on a cell, the new cell in the old location is locked
into the info box. Otherwise, lastInfoTarget is set to null
and the info box is cleared.
buildInfoString
String buildInfoString(InfoTarget inTarget,
boolean robotInfo)
- Returns the info string for the given target.
- Parameters:
- target - the
Cell or Robot to get the
info string from.
- robotInfo - true if target is a Cell and we're
actually intersted in the info for the robot in the cell.
setGridFeedback
public void setGridFeedback(int x,
int y,
boolean robotInfo)
- Tells the applet to display information on the given square
in the grid info box.
updateGridFeedback
void updateGridFeedback(int x,
int y)
- Called by
paintCell whenever a grid cell changes. If the given cell
is currently being displayed in the info box, the info box is updated.
lockGridFeedback
public void lockGridFeedback(int x,
int y)
- Locks the info box into displaying the given cell's information
regardless of the mouse position.
lastInfoTarget will never be
null because we would either have to get a mouseMove event in a given cell
before getting a mouseDown event in it or we'd have a cell already locked.
updateRobotFeedback
void updateRobotFeedback(Robot r)
- Updates the info box if the given robot is the current info target.
- Parameters:
- r - the robot that may need to be updated.
lockRobotFeedback
public void lockRobotFeedback(int x,
int y)
- Locks the robot at the given location into the info box. If the robot
is already locked, it is unlocked and the info box returns to tracking
the mouse position.
updateFeedback
public void updateFeedback()
- Updates the info box if
lastInfoTarget is not null.
setExecuting
public void setExecuting(boolean b,
boolean inStepping)
- Called once when a new execution thread starts and again just before
it dies. This function disables, enables and sets labels of the
buttons and sets the
executing field.
- See Also:
- executing
spawnExecution
void spawnExecution(boolean execute,
boolean stepping)
- Clears the message box, sets the delay time and starts a new
execution thread.
- Parameters:
- execute - false if the thread should just parse the code
and return.
- stepping - true if the thread should pause execution
immediately after starting.
haltExecution
public void haltExecution()
- Stops the execution thread, clears the "next instruction" field and
calls
setExecuting(false, false).
- See Also:
- setExecuting
killFrame
public void killFrame(RobotlFrame frame)
- This is called by
RobotlFrame.cleanup(). It tells the applet
that the given window is going away and we should drop our reference to it.
- See Also:
- cleanup
robotlInFront
public void robotlInFront()
- Calls
robotlFrame.toFront().
handleRunButton
synchronized void handleRunButton()
- Calls spawnExecution if we're not currently executing. If we are
executing, iterrupts the execution, pausing or resuming, depending
on the current state (Calls
RobotWorld.interrupt()).
- See Also:
- interrupt
handleStepButton
synchronized void handleStepButton()
- Starts executing if we're not already and calls
RobotWorld.step().
- See Also:
- step
action
public boolean action(Event evt,
Object what)
- Responds to the buttons and menus.
- Overrides:
- action in class Component