public void update() {
    graphicPanel.removeAll();
    graphicPanel.add(title);
    graphicPanel.add(mainMenuButton);
    graphicPanel.add(refreshButton);
    graphicPanel.add(logoutButton);
    graphicPanel.setLayout(new FlowLayout());

    JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
    separator.setPreferredSize(new Dimension(600, 10));
    graphicPanel.add(separator);

    if (page.matches("main")) {
      graphicPanel.add(reportLocationButton);
      graphicPanel.add(loadShipmentButton);
    } else if (page.matches("reportloc")) {
      locationComboBox = new JComboBox(driver.getLocation().getNeighbours().toArray());
      graphicPanel.add(locationComboBox);
      graphicPanel.add(reportButton);
    } else if (page.matches("loadShipment")) {
      shipmentList = new ArrayList<Shipment>();

      for (int i = 0; i < driverService.getAssignedShipments().size(); ++i) {
        if (driverService.canPickup(driver, driverService.getAssignedShipments().get(i))) {
          shipmentList.add(driverService.getAssignedShipments().get(i));
        }
      }

      Object[][] tableContent = new Object[shipmentList.size()][shipmentTableColumnTitles.length];
      for (int i = 0; i < shipmentList.size(); ++i) {
        tableContent[i][0] = shipmentList.get(i).getType();
        tableContent[i][1] = shipmentList.get(i).getApproximateWeight();
        tableContent[i][2] = shipmentList.get(i).getDueDate();
        tableContent[i][3] = shipmentList.get(i).getDestination();
      }

      shipmentTable = new JTable(tableContent, shipmentTableColumnTitles);
      shipmentTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      JScrollPane tablePane = new JScrollPane(shipmentTable);
      tablePane.setPreferredSize(new Dimension(550, 250));
      graphicPanel.add(tablePane);
      graphicPanel.add(pickupButton);
    }

    graphicPanel.validate();
    graphicPanel.repaint();
  }
Beispiel #2
0
  public CAMenuControl(RuleSet[] rules, String[] files) {

    super();

    // buttons
    randomB = new JButton("Create Simulation");
    randomB.addActionListener(handler);
    loadFileB = new JButton("Load Simulation");
    loadFileB.addActionListener(handler);
    helpB = new JButton("Help");
    helpB.addActionListener(handler);
    exitB = new JButton("Exit");
    exitB.addActionListener(handler);

    // comboboxes
    Integer[] populations = {10, 20, 30, 40, 50, 60, 70, 80, 90};
    populationCB = new JComboBox<Integer>(populations);
    rulesetCB = new JComboBox<RuleSet>(rules);
    rulesetCB.addActionListener(handler);
    filenameCB = new JComboBox<String>(files);

    // labels
    Font title = new Font("Ariel", Font.BOLD, 14);
    randomL = new JLabel("Create a simulation:", JLabel.CENTER);
    randomL.setFont(title);
    populationL = new JLabel("Population (%): ", JLabel.RIGHT);
    rulesetL = new JLabel("Ruleset to use: ", JLabel.RIGHT);

    loadL = new JLabel("Load simulation from xml file:", JLabel.CENTER);
    loadL.setFont(title);
    pathL = new JLabel("Select file: ", JLabel.RIGHT);

    sep1 = new JSeparator(JSeparator.HORIZONTAL);
    sep1.setPreferredSize(new Dimension(50, 5));
    sep1.setBackground(Color.DARK_GRAY);

    sep2 = new JSeparator(JSeparator.HORIZONTAL);
    sep2.setPreferredSize(new Dimension(50, 5));
    sep2.setBackground(Color.DARK_GRAY);

    buttonP = new JPanel();
    buttonP.setLayout(new GridLayout(1, 2, 1, 1));
    buttonP.add(helpB);
    buttonP.add(exitB);

    setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    // row1
    c.gridwidth = 2;
    add(randomL, c);
    // row2
    c.gridwidth = 1;
    c.gridy = 1;
    c.gridx = 0;
    add(rulesetL, c);
    c.gridx = 1;
    add(rulesetCB, c);
    // row3
    c.gridwidth = 1;
    c.gridy++;
    c.gridx = 0;
    add(populationL, c);
    c.gridx++;
    add(populationCB, c);
    c.gridy++;
    c.gridx = 1;
    add(randomB, c);
    // sep
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 2;
    add(sep1, c);
    // row4
    c.gridwidth = 2;
    c.gridy++;
    c.gridx = 0;
    add(loadL, c);
    // row5
    c.gridwidth = 1;
    c.gridy++;
    c.gridx = 0;
    add(pathL, c);
    c.gridx = 1;
    add(filenameCB, c);
    c.gridy++;
    c.gridx = 1;
    add(loadFileB, c);
    // sep
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 3;
    add(sep2, c);
    // row6
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 3;
    add(buttonP, c);

    setSize(500, 300);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
  }