示例#1
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());
    }
  }
示例#2
0
 protected void AlgorithmDropListActionPerformed(ActionEvent evt) {
   if (simStarted) controller.setAlgorithm(AlgorithmDropList.getSelectedIndex());
   AlgorithmDescBox.setText(controller.getAlgorithmDesc(AlgorithmDropList.getSelectedIndex()));
 }
示例#3
0
  private void initComponents() {

    Start_Stop_button = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    MsgBox = new javax.swing.JTextPane();
    SimStatusLabel = new javax.swing.JLabel();
    simStatusLabel = new javax.swing.JLabel();
    SimTimeLabel = new javax.swing.JLabel();
    simTimeLabel = new javax.swing.JLabel();
    ElevatorPane = new javax.swing.JTabbedPane();
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    AlgorithmDropList = new javax.swing.JComboBox(controller.getAlgorithms());
    jScrollPane2 = new javax.swing.JScrollPane();
    AlgorithmDescBox = new javax.swing.JTextPane();
    PassengerPane = new javax.swing.JTabbedPane();
    jScrollPane3 = new javax.swing.JScrollPane();
    passengerTable = new javax.swing.JTable();
    jPanel3 = new javax.swing.JPanel();
    jScrollPane4 = new javax.swing.JScrollPane();
    FloorPassengerTable = new javax.swing.JTable();
    jLabel2 = new javax.swing.JLabel();
    floorDropDownList = new javax.swing.JComboBox();
    surroundSimViewPanel = new javax.swing.JPanel();
    SimViewPanel = new javax.swing.JPanel(new BorderLayout());
    mainMenuBar = new javax.swing.JMenuBar();
    FileMenu = new javax.swing.JMenu();
    file_newSim = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JPopupMenu.Separator();
    file_quit = new javax.swing.JMenuItem();
    SimViewMenu = new javax.swing.JMenu();
    resetSimView = new javax.swing.JMenuItem();
    jSeparator3 = new javax.swing.JPopupMenu.Separator();
    ElevatorFocusSubMenu = new javax.swing.JMenu();
    jMenuItem5 = new javax.swing.JMenuItem();
    EventsMenu = new javax.swing.JMenu();
    inject_passenger = new javax.swing.JMenuItem();
    jMenu3 = new javax.swing.JMenu();
    injectEmergMenu = new javax.swing.JMenu();
    jMenuItem1 = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    inject_fault = new javax.swing.JMenuItem();
    resolve_fault = new javax.swing.JMenuItem();
    jSeparator4 = new javax.swing.JPopupMenu.Separator();
    setup_randomEvents = new javax.swing.JMenuItem();
    halt_randomEvents = new javax.swing.JMenuItem();
    RemoteServerMenu = new javax.swing.JMenu();
    startRemoteServer = new javax.swing.JMenuItem();
    maintenance = new javax.swing.JMenu();
    maintenanceMenu = new javax.swing.JMenu();
    jMenuItem14 = new javax.swing.JMenuItem();
    returnToActiveMenu = new javax.swing.JMenu();
    jMenuItem15 = new javax.swing.JMenuItem();
    jSeparator5 = new javax.swing.JPopupMenu.Separator();
    returnAlltoActive = new javax.swing.JMenuItem();
    jMenu1 = new javax.swing.JMenu();
    graphs_waitTime = new javax.swing.JMenuItem();
    graphs_rideTime = new javax.swing.JMenuItem();
    jSeparator6 = new javax.swing.JSeparator();
    graphs_elevatorPositions = new javax.swing.JMenuItem();
    graphs_distance = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Boss Lift");

    Start_Stop_button.setText("Start/Stop");
    Start_Stop_button.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            Start_Stop_buttonActionPerformed(evt);
          }
        });

    MsgBox.setEditable(false);
    jScrollPane1.setViewportView(MsgBox);

    SimStatusLabel.setText("Simulation Status:");

    simStatusLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
    simStatusLabel.setForeground(new java.awt.Color(255, 0, 0));
    simStatusLabel.setText("NOT RUNNING");

    SimTimeLabel.setText("Simulation Time:");

    simTimeLabel.setText("00:00:00");

    jLabel1.setText("Algorithm:");

    AlgorithmDropList.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            AlgorithmDropListActionPerformed(evt);
          }
        });

    AlgorithmDescBox.setBackground(new java.awt.Color(240, 240, 240));
    jScrollPane2.setViewportView(AlgorithmDescBox);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jScrollPane2,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                245,
                                Short.MAX_VALUE)
                            .addGroup(
                                jPanel1Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        AlgorithmDropList,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap()));
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel1Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(
                                AlgorithmDropList,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                    .addContainerGap()));

    ElevatorPane.addTab("Algorithms", jPanel1);

    passengerTable.setModel(new PassengerTableModel());
    passengerTable.setShowHorizontalLines(false);
    passengerTable.setShowVerticalLines(false);
    passengerTable.getTableHeader().setReorderingAllowed(false);
    jScrollPane3.setViewportView(passengerTable);

    PassengerPane.addTab("Passengers", jScrollPane3);

    FloorPassengerTable.setModel(new PassengerTableModel());
    FloorPassengerTable.setShowHorizontalLines(false);
    FloorPassengerTable.setShowVerticalLines(false);
    FloorPassengerTable.getTableHeader().setReorderingAllowed(false);
    jScrollPane4.setViewportView(FloorPassengerTable);

    jLabel2.setText("Floor:");

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel3Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel3Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(
                                jScrollPane4,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                245,
                                Short.MAX_VALUE)
                            .addGroup(
                                jPanel3Layout
                                    .createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        floorDropDownList,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap()));
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel3Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        jPanel3Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(
                                floorDropDownList,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                    .addContainerGap()));

    PassengerPane.addTab("Floors", jPanel3);

    SimViewPanel.setBackground(new java.awt.Color(0, 0, 0));

    javax.swing.GroupLayout surroundSimViewPanelLayout =
        new javax.swing.GroupLayout(surroundSimViewPanel);
    surroundSimViewPanel.setLayout(surroundSimViewPanelLayout);
    surroundSimViewPanelLayout.setHorizontalGroup(
        surroundSimViewPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                surroundSimViewPanelLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        SimViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
                    .addContainerGap()));
    surroundSimViewPanelLayout.setVerticalGroup(
        surroundSimViewPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                surroundSimViewPanelLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        SimViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
                    .addContainerGap()));

    FileMenu.setText("File");

    file_newSim.setText("New Simulation");
    file_newSim.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            file_newSimActionPerformed(evt);
          }
        });
    FileMenu.add(file_newSim);
    FileMenu.add(jSeparator2);

    file_quit.setText("Quit");
    file_quit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            file_quitActionPerformed(evt);
          }
        });
    FileMenu.add(file_quit);

    mainMenuBar.add(FileMenu);

    SimViewMenu.setText("Sim View");

    resetSimView.setText("Reset View to Default");
    resetSimView.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            resetSimViewActionPerformed(evt);
          }
        });
    SimViewMenu.add(resetSimView);
    SimViewMenu.add(jSeparator3);

    ElevatorFocusSubMenu.setText("Focus on Elevator...");

    jMenuItem5.setText("(none)");
    jMenuItem5.setEnabled(false);
    ElevatorFocusSubMenu.add(jMenuItem5);

    SimViewMenu.add(ElevatorFocusSubMenu);

    mainMenuBar.add(SimViewMenu);

    EventsMenu.setText("Events");

    inject_passenger.setText("Inject Passenger");
    inject_passenger.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            inject_passengerActionPerformed(evt);
          }
        });
    EventsMenu.add(inject_passenger);

    jMenu3.setText("Passenger Emergency");

    injectEmergMenu.setText("Inject Emergency");

    jMenuItem1.setText("(none)");
    jMenuItem1.setEnabled(false);
    injectEmergMenu.add(jMenuItem1);

    jMenu3.add(injectEmergMenu);

    EventsMenu.add(jMenu3);

    jMenu2.setText("Hardware Faults");

    inject_fault.setText("Inject Fault");
    inject_fault.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            inject_faultActionPerformed(evt);
          }
        });
    jMenu2.add(inject_fault);

    resolve_fault.setText("Resolve Fault");
    resolve_fault.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            resolve_faultActionPerformed(evt);
          }
        });
    jMenu2.add(resolve_fault);

    EventsMenu.add(jMenu2);
    EventsMenu.add(jSeparator4);

    setup_randomEvents.setText("Setup Random Events");
    setup_randomEvents.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            setup_randomEventsActionPerformed(evt);
          }
        });
    EventsMenu.add(setup_randomEvents);

    halt_randomEvents.setText("Halt Random Events");
    halt_randomEvents.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            halt_randomEventsActionPerformed(evt);
          }
        });
    EventsMenu.add(halt_randomEvents);

    mainMenuBar.add(EventsMenu);

    RemoteServerMenu.setText("Remote Server");

    startRemoteServer.setText("Start");
    startRemoteServer.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            startRemoteServerActionPerformed(evt);
          }
        });
    RemoteServerMenu.add(startRemoteServer);

    mainMenuBar.add(RemoteServerMenu);

    maintenance.setText("Maintenance");

    maintenanceMenu.setText("Set Elevator to Maintenance Mode");

    jMenuItem14.setText("(none)");
    jMenuItem14.setEnabled(false);
    maintenanceMenu.add(jMenuItem14);

    maintenance.add(maintenanceMenu);

    returnToActiveMenu.setText("Return Elevator to Active Mode");

    jMenuItem15.setText("(none)");
    jMenuItem15.setEnabled(false);
    returnToActiveMenu.add(jMenuItem15);

    maintenance.add(returnToActiveMenu);
    maintenance.add(jSeparator5);

    returnAlltoActive.setText("Return All to Active Mode");
    returnAlltoActive.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            returnAlltoActiveActionPerformed(evt);
          }
        });
    maintenance.add(returnAlltoActive);

    mainMenuBar.add(maintenance);

    jMenu1.setText("Graphs");

    graphs_waitTime.setText("View Avg. Passenger Wait Time");
    graphs_waitTime.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphs_waitTimeActionPerformed(evt);
          }
        });
    jMenu1.add(graphs_waitTime);

    graphs_rideTime.setText("View Avg. Passenger Riding Time");
    graphs_rideTime.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphs_rideTimeActionPerformed(evt);
          }
        });
    jMenu1.add(graphs_rideTime);
    jMenu1.add(jSeparator6);

    graphs_elevatorPositions.setText("View Elevator Positions ");
    graphs_elevatorPositions.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphs_elevatorPositionsActionPerformed(evt);
          }
        });
    jMenu1.add(graphs_elevatorPositions);

    graphs_distance.setText("View Elevator Distance Traveled");
    graphs_distance.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphs_distanceActionPerformed(evt);
          }
        });
    jMenu1.add(graphs_distance);

    mainMenuBar.add(jMenu1);

    setJMenuBar(mainMenuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        surroundSimViewPanel,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(
                                                ElevatorPane,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                278,
                                                Short.MAX_VALUE)
                                            .addComponent(PassengerPane, 0, 278, Short.MAX_VALUE)))
                            .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        jScrollPane1,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        489,
                                        Short.MAX_VALUE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(simStatusLabel)
                                            .addComponent(SimStatusLabel)
                                            .addComponent(
                                                Start_Stop_button,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                172,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addComponent(SimTimeLabel)
                                                    .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement
                                                            .UNRELATED)
                                                    .addComponent(simTimeLabel)))))
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addComponent(
                                        ElevatorPane,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        165,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        PassengerPane,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        119,
                                        Short.MAX_VALUE))
                            .addComponent(
                                surroundSimViewPanel,
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(SimTimeLabel)
                                            .addComponent(simTimeLabel))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(SimStatusLabel)
                                    .addGap(3, 3, 3)
                                    .addComponent(simStatusLabel)
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(
                                        Start_Stop_button,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        51,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(
                                jScrollPane1,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                108,
                                Short.MAX_VALUE))
                    .addContainerGap()));

    pack();
  }