/* * Aquarium Lab Series * * Class: AquaSimGUI * * License: * This program 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 program 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.neu.ccs.gui.BufferedPanel; import edu.neu.ccs.gui.Display; import edu.neu.ccs.gui.DisplayCollection; import edu.neu.ccs.gui.DisplayPanel; import edu.neu.ccs.gui.JPTFrame; import edu.neu.ccs.util.JPTUtilities; import java.awt.BorderLayout; import java.util.ArrayList; /** * Aquarium Lab Series: * The AquaSimGUI class provides a graphical user interface * to the Aquarium Lab Series. This class uses the Java * Power Tools (JPT) classes from Northeastern University to * build the graphical interface. In particular, it inherits * the repaint method (which does not appear in * the specification for this class) from the JPT DisplayPanel * class. The repaint method draws the * components in the graphical user interface. * * @author Alyce Brady * @version 10 July 2002 * @author Kelly Schultz * @version 24 March 2004 **/ public class AquaSimGUI extends DisplayPanel { ///////////////////////////////////////////////////////// // Static Data: Constants not tied to any one instance // ///////////////////////////////////////////////////////// private static final int VIEW_TIME = 1000; // allow viewer to see display private static final int WAIT_TIME = 100; // between Start button checks //////////////////////// // Instance Variables // //////////////////////// private Aquarium aqua = null; // aquarium in which fish swim private AquaView drawingObject = null; // to draw fish in aquarium ////////////////// // Constructors // ////////////////// /** Construct a simple graphical user interface for the Aquarium * SimulationKelly program. * @param aquarium the aquarium in which the fish swim **/ public AquaSimGUI(Aquarium aquarium) { init(aquarium); } /** Construct a simple graphical user interface for subclasses of the Aquarium * SimulationKelly program. **/ protected AquaSimGUI() { } /** Construct a simple graphical user interface for the Aquarium * SimulationKelly program. * @param aquarium the aquarium in which the fish swim **/ protected void init(Aquarium aquarium) { // Save aquarium info. in an instance variable. aqua = aquarium; // Set layout for entire panel. setLayout(new BorderLayout()); // Create two displays: one in which to view the aquarium // and one to contain the control panel. Add them to the // main panel of the GUI. add(getViewWindow(), BorderLayout.EAST); add(getControlPanel(),BorderLayout.WEST); // Clear window. reset(); // Put the GUI in a window, giving the window a title. JPTFrame.createQuickJPTFrame("Aquarium Lab Series", this); } ////////////////////////////////////////////////// // Drawing Methods (Delegated to drawingObject) // ////////////////////////////////////////////////// /** * Display all the AquaFish in the fishList array. * Paints the aquarium blue to cover up old fish and displays * the fish in the array. * @param fishList the array of AquaFish to be displayed **/ public void show(AquaFish[] fishList) { drawingObject.show(fishList); } /** * Display all the AquaFish in the fishList list. * Paints the aquarium blue to cover up old fish and displays * the fish in the list. * @param fishList the list of AquaFish to be displayed **/ public void show(ArrayList fishList) { drawingObject.show(fishList); } /** * Display only the Aquarium: paint the aquarium blue to cover * up old fish. Not necessary when displaying an entire vector * of fish. **/ public void showAquarium() { drawingObject.showAquarium(); } /** * Display a single AquaFish. * @param fish the fish to be displayed **/ public void showFish(AquaFish fish) { drawingObject.showFish(fish); } /** * Pause so user can view the display. **/ public void pauseToView() { JPTUtilities.pauseThread(VIEW_TIME); } ////////////////////////////// // Private Helper Methods // ////////////////////////////// /** * Construct and initialize display in which to view aquarium. **/ private Display getViewWindow() { // Create the panel in which to view the aquarium // and disable it (view panel is not interactive). // then put it in a display with a title. BufferedPanel aquaViewPanel = new BufferedPanel(aqua.width(), aqua.height()); aquaViewPanel.setEnabled(false); // Construct an object that knows how to draw the // aquarium in the viewing panel (used by other parts // of the Aquarium SimulationKelly program as well). drawingObject = new AquaView(aquaViewPanel, aqua); // Put the view panel in a titled display and return. return new Display(aquaViewPanel, null, "Aquarium"); } /** * Construct and initialize display that contains control panel. **/ protected Display getControlPanel() { DisplayCollection controlPanel = new DisplayCollection(); // Disable the control panel to start off. controlPanel.setEnabled(false); // Put the control panel in an untitled display and return. return new Display(controlPanel, null, null); } }