// Class ObstCourseWindow // // Author: Alyce Brady // // This class is based on the College Board's MBSGUIFrame class, // as allowed by the GNU General Public License. MBSGUIFrame // is a black-box class within the AP(r) CS Marine Biology Simulation // case study (see www.collegeboard.com/ap/students/compsci). // // License Information: // This class is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation. // // This class is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. import edu.kzoo.grid.Grid; import edu.kzoo.grid.gui.ActiveGridAppController; import edu.kzoo.grid.gui.ControlButton; import edu.kzoo.grid.gui.EnabledDisabledStates; import edu.kzoo.grid.gui.GridDataFileHandler; import edu.kzoo.grid.gui.SteppedGridAppController; import edu.kzoo.grid.gui.SteppedGridAppFrame; import edu.kzoo.grid.gui.nuggets.BasicGridFileMenu; /** * Obstacle Course Program:
* * An ObstCourseWindow is a window containing the graphical * display of a grid with a slider, and a menu that allows the * user to edit the grid. * * @author Alyce Brady * @version 1 December 2002 **/ public class ObstCourseWindow extends SteppedGridAppFrame { private static final boolean REDISPLAY = true; private ObstCourseFileMenuActionHandler menuActionHandler; // constructors and initialization methods /** Creates a window in which to run an obstacle race. **/ public ObstCourseWindow() { // This is an active grid frame with Step, N Steps, // Run and Stop buttons, but not a Restart button. super(new ActiveGridAppController(), REDISPLAY); SteppedGridAppController controller = getController(); GridDataFileHandler fileHandler = new ObstCourseDataFileHandler(); menuActionHandler = new ObstCourseFileMenuActionHandler(this, fileHandler); includeMenu(new BasicGridFileMenu(this, menuActionHandler, fileHandler)); includeControlComponent( new ControlButton(this, "New Grid", REDISPLAY) { public void act() { menuActionHandler.createNewGrid(); }}, EnabledDisabledStates.NEEDS_APP_WAITING); includeControlComponent( new ControlButton(this, "Add Racers", REDISPLAY) { public void act() { invokeEditor(); }}, EnabledDisabledStates.NEEDS_GRID_AND_APP_WAITING); includeStepOnceButton(); includeStepNTimesButton(); includeRunButton(); includeStopButton(REDISPLAY); includeSpeedSlider(); constructWindowContents("Obstacle Race", null, 0, 0, 0); // Tool tips should show object info, not just location. getDisplay().makeToolTipsReportObject(); } // redefined methods from GridAppFrame /** Sets the Grid being displayed. * (Precondition: grid is not null.) * @param grid the Grid to display **/ public void setGrid(Grid grid) { super.setGrid(grid); showGrid(); } // methods that implement button actions /** Invokes the obstacle course editor for placing racers. * */ protected void invokeEditor() { new ObstCourseEditor(this); } /** Advances the application one step. **/ public void step() { super.step(); showGrid(); } }