示例#1
0
 public static void update() {
   // clear the new label text field
   StateLabelManager.stateLabelTextField.setText("");
   // refresh state group array
   StateLabelManager.availableStateGroups =
       ApplicationSettings.getApplicationView().getCurrentPetriNetView().getStateGroups();
   // refresh dropdown menu
   StateLabelManager.populateStateLabelDropdown();
   // refresh the list of state group names
   StateLabelManager.populateLists();
 }
示例#2
0
  /**
   * Creates the top bit of the interface, which is choosing a state label name
   *
   * @param withStateLabelControlButtons
   * @return
   */
  private static JPanel getStateLabelManagementPanel(boolean withStateLabelControlButtons) {
    JPanel stateLabelManagementPanel = new JPanel();
    stateLabelManagementPanel.setLayout(new BoxLayout(stateLabelManagementPanel, BoxLayout.Y_AXIS));
    stateLabelManagementPanel.setBorder((new TitledBorder(new EtchedBorder(), "State Label")));

    JPanel stateLabelSelectionPanel = new JPanel();
    stateLabelSelectionPanel.setLayout(new SpringLayout());
    if (StateLabelManager.node != null) {
      String assignedStateLabel = StateLabelManager.node.getStateLabel();
      if (assignedStateLabel != null) StateLabelManager.setCurrentStateLabel(assignedStateLabel);
    }
    StateLabelManager.populateStateLabelDropdown();
    ActionListener stateLabelsComboListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            String stateLabel = (String) cb.getSelectedItem();
            if (!stateLabel.equals("-- Select --")) {
              // indicate that this is the state label that we're dealing
              // with now
              StateLabelManager.setCurrentStateLabel(stateLabel);
              StateLabelManager.populateLists();
            }
          }
        };
    StateLabelManager.stateLabelDropdown.addActionListener(stateLabelsComboListener);
    stateLabelSelectionPanel.add(StateLabelManager.stateLabelDropdown);
    SpringLayoutUtilities.makeCompactGrid(stateLabelSelectionPanel, 1, 1, 6, 6, 6, 6);
    stateLabelManagementPanel.add(stateLabelSelectionPanel);

    ActionListener createStateLabelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            StateLabelManager.createNewLabelPopup();
          }
        };

    if (!withStateLabelControlButtons) {
      // just a create state label button - used when right-clicking on a
      // StatesNode
      JPanel stateLabelButtonPanel = new JPanel();
      stateLabelButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
      String[] buttonNames = {"Create State Label"};
      ActionListener[] buttonListeners = {createStateLabelButtonListener};
      stateLabelButtonPanel.add(new ButtonBar(buttonNames, buttonListeners));
      stateLabelManagementPanel.add(stateLabelButtonPanel);
    } else {
      // have a delete and edit state label button as well - used when the
      // state label manager is
      // invoked from the Tools menu
      JPanel stateLabelButtonPanel = new JPanel();
      stateLabelButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
      String[] buttonNames = {"Create State Label", "Edit State Label", "Delete State Label"};
      ActionListener editStateLabelButtonListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              String selectedStateLabel =
                  (String) StateLabelManager.stateLabelDropdown.getSelectedItem();
              if (!selectedStateLabel.equals("-- Select --")
                  && !selectedStateLabel.equals("CREATE NEW STATE LABEL")) {
                StateLabelManager.createEditLabelPopup();
              }
            }
          };
      ActionListener deleteStateLabelButtonListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              String selectedStateLabel =
                  (String) StateLabelManager.stateLabelDropdown.getSelectedItem();
              if (!selectedStateLabel.equals("-- Select --")
                  && !selectedStateLabel.equals("CREATE NEW STATE LABEL")) {
                QueryManager.getData().removeStateLabel(selectedStateLabel);
                StateLabelManager.setCurrentStateLabel(null);
                StateLabelManager.update();
              }
            }
          };
      ActionListener[] buttonListeners = {
        createStateLabelButtonListener, editStateLabelButtonListener, deleteStateLabelButtonListener
      };
      stateLabelButtonPanel.add(new ButtonBar(buttonNames, buttonListeners));
      stateLabelManagementPanel.add(stateLabelButtonPanel);
    }

    return stateLabelManagementPanel;
  }