Ejemplo n.º 1
0
  private void destroyWorld() {
    if (simStarted) {
      simStarted = false;

      // reset safety thread
      safety.interrupt();

      // destroy elevator system
      controller.interrupt();
      controller.destroy();

      // stop random events
      randomEventGen.interrupt();

      // reset logs
      Log.printStatusReport();
      Log.cleanLogs();

      // reset MsgBox
      deleteAllMsgs();

      // reset tabs, passenger table
      for (int i = ElevatorPane.getTabCount() - 1; i > 0; i--) ElevatorPane.remove(i);
      elevatorTabs = null;
      floorDropDownList.removeAllItems();
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              passengerTable.setModel(new PassengerTableModel());
              FloorPassengerTable.setModel(new PassengerTableModel());
            }
          });

      // clean up simulation view
      view.cleanup();
      view.restart();

      // reset timer
      simTimeLabel.setText("00:00:00");

      // recreate objects
      controller = new Controller();
      safety = new Safety(controller);
      try {
        randomEventGen = new RandomEventGenerator(controller, safety, 0.0f, 0.0f, 0.0f);
      } catch (ProbabilityOutofBoundsException e) {
        displayError(e.getMessage());
      }
    }
  }
Ejemplo n.º 2
0
 /*
  * focusViewOnElevator(int id)
  *
  * Informs the ElevatorSimView class which elevator to focus the view on.
  */
 public void focusViewOnElevator(int id) {
   try {
     view.focusViewOnElevator(id);
   } catch (BossLiftGeneralException e) {
     displayError(e.getMessage());
   }
 }
Ejemplo n.º 3
0
  public mainWindow(Controller c, RandomEventGenerator r, Safety s) {

    // use system look and feel
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // do nothing
    }

    view = new ElevatorSimView();
    safety = s;
    controller = c;
    randomEventGen = r;
    simStarted = false;

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    initComponents();

    setGUIEnabled(false);

    SimViewPanel.add(view.getCanvas(), BorderLayout.CENTER);
    this.validate();

    AlgorithmDescBox.setText(controller.getAlgorithmDesc(0));

    doc = MsgBox.getStyledDocument();

    Style style = MsgBox.addStyle("Faults", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setItalic(style, true);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Passengers", null);
    StyleConstants.setForeground(style, new Color(0, 204, 204));
    StyleConstants.setItalic(style, true);

    style = MsgBox.addStyle("Normal", null);

    style = MsgBox.addStyle("Elevators", null);
    StyleConstants.setForeground(style, new Color(51, 255, 0));
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Emergs", null);
    StyleConstants.setForeground(style, Color.red);
    StyleConstants.setBold(style, true);

    style = MsgBox.addStyle("Maintenance", null);
    StyleConstants.setForeground(style, Color.ORANGE);
    StyleConstants.setBold(style, true);

    // Hijack the keyboard manager
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyDispatcher(this));

    // add window listener
    this.addWindowListener(new mainWindowListener());
  }
Ejemplo n.º 4
0
  public void createWorld(
      int numElevators, int numFloors, Boolean penthouse, Vector<Integer>[] bounds) {
    if (simStarted) destroyWorld();

    try {
      controller.setFloors(numFloors);
      controller.createElevators(numElevators);

      if (penthouse) controller.addPenthouse();
      for (int e = 0; e < bounds.length; e++) {
        for (int f = 0; f < bounds[e].size(); f++) controller.lockFloor(e, bounds[e].get(f));
      }

      view.createWorld(numElevators, numFloors, penthouse, bounds);

      controller.setSimView(this, view);
      controller.start();
      safety.start();
      randomEventGen.start();

      postGeneralEventMsg("Welcome to BOSS LIFT Elevator Simulator!");
      postGeneralEventMsg("The simulation is PAUSED");
      simStatusLabel.setText("PAUSED");
      simStatusLabel.setForeground(new java.awt.Color(255, 0, 0));

      elevatorTabs = new ElevatorInfoPanel[numElevators];
      for (int i = 0; i < numElevators; i++) {
        elevatorTabs[i] = new ElevatorInfoPanel();
        if (bounds[i].size() > 0)
          elevatorTabs[i].setElevatorBounds(controller.getElevatorBounds(i));
        JScrollPane p = new JScrollPane();
        p.setViewportView(elevatorTabs[i]);
        ElevatorPane.addTab("E" + i, p);
      }

      setGUIEnabled(true);
      populateElevatorMenus(numElevators);

      for (int i = 0; i < numFloors; i++) {
        floorDropDownList.addItem(i);
      }

      simStarted = true;

      controller.setAlgorithm(AlgorithmDropList.getSelectedIndex());
    } catch (BossLiftGeneralException e1) {
      displayError(e1.getMessage());
    }
  }
Ejemplo n.º 5
0
 protected void file_quitActionPerformed(ActionEvent evt) {
   view.cleanup();
   Log.printStatusReport();
   System.exit(0);
 }
Ejemplo n.º 6
0
 public void zoomOutSimView() {
   view.zoomOut();
 }
Ejemplo n.º 7
0
 public void zoomInSimView() {
   view.zoomIn();
 }
Ejemplo n.º 8
0
 public void rotateSimViewLeft() {
   view.rotateViewLeft();
 }
Ejemplo n.º 9
0
 /*
  * The following rotate and zoom the 3D when the user combines CTRL with the arrow keys.
  * Called by KeyDispatcher class.
  */
 public void rotateSimViewRight() {
   view.rotateViewRight();
 }
Ejemplo n.º 10
0
 /*
  * resetSimViewActionPerformed(ActionEvent evt)
  *
  * Called when "Reset View" menu item selected.  Resets the 3D view to default.
  */
 protected void resetSimViewActionPerformed(ActionEvent evt) {
   view.resetView();
 }