示例#1
0
  /** This is the popup for creating a new state label */
  private static void createNewLabelPopup() {
    StateLabelManager.stateLabelDialog =
        new JDialog(StateLabelManager.popupDialog, "Create New State Label", true);

    // text panel
    JPanel stateLabelNamePanel = new JPanel();
    stateLabelNamePanel.setLayout(new SpringLayout());
    JLabel stateLabelSelectionLabel = new JLabel("New State Label: ", SwingConstants.TRAILING);
    stateLabelNamePanel.add(stateLabelSelectionLabel);
    stateLabelNamePanel.add(StateLabelManager.stateLabelTextField);
    StateLabelManager.stateLabelDialog.add(stateLabelNamePanel);
    SpringLayoutUtilities.makeCompactGrid(stateLabelNamePanel, 1, 2, 6, 6, 6, 6);

    // button panel
    JPanel stateLabelButtonsPanel = new JPanel();
    JButton createNewLabelButton = new JButton("Create State Label");
    StateLabelManager.stateLabelDialog.getRootPane().setDefaultButton(createNewLabelButton);
    ActionListener createNewLabelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // create state label
            if (StateLabelManager.stateLabelTextField.getText().equals("")
                || !StateLabelManager.containsText(StateLabelManager.stateLabelTextField.getText()))
              JOptionPane.showMessageDialog(null, "Please specify a state label name");
            else {
              if (!QueryManager.getData()
                  .stateLabelExistsAlready(StateLabelManager.stateLabelTextField.getText())) {
                String newStateLabelName = StateLabelManager.stateLabelTextField.getText();
                QueryManager.getData().addStateLabel(newStateLabelName, null);
                StateLabelManager.setCurrentStateLabel(newStateLabelName);
                StateLabelManager.update();
                StateLabelManager.stateLabelDialog.dispose();
              } else {
                JOptionPane.showMessageDialog(
                    QueryManager.getEditor().getContentPane(),
                    "The state state label name you have specified exists \n"
                        + "already. Please choose a different name for your label.",
                    "Warning",
                    JOptionPane.ERROR_MESSAGE);
              }
            }
          }
        };
    createNewLabelButton.addActionListener(createNewLabelButtonListener);
    JButton cancelButton = new JButton("Cancel");
    ActionListener cancelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            StateLabelManager.update();
            StateLabelManager.stateLabelDialog.dispose();
          }
        };
    cancelButton.addActionListener(cancelButtonListener);
    stateLabelButtonsPanel.add(createNewLabelButton);
    stateLabelButtonsPanel.add(cancelButton);

    // main panel
    JPanel stateLabelPanel = new JPanel();
    stateLabelPanel.setBorder(new EtchedBorder());
    stateLabelPanel.setLayout(new BoxLayout(stateLabelPanel, BoxLayout.Y_AXIS));
    stateLabelPanel.add(stateLabelNamePanel);
    stateLabelPanel.add(stateLabelButtonsPanel);
    StateLabelManager.stateLabelDialog.add(stateLabelPanel);

    // make popup visible
    StateLabelManager.stateLabelDialog.pack();
    StateLabelManager.stateLabelDialog.setLocationRelativeTo(null);
    StateLabelManager.stateLabelDialog.setVisible(true);
  }
示例#2
0
  private static void createEditLabelPopup() {
    StateLabelManager.stateLabelDialog =
        new JDialog(StateLabelManager.popupDialog, "Edit State Label", true);

    // text panel
    JPanel stateLabelNamePanel = new JPanel();
    stateLabelNamePanel.setLayout(new SpringLayout());
    JLabel stateLabelSelectionLabel = new JLabel("State Label: ", SwingConstants.TRAILING);
    stateLabelNamePanel.add(stateLabelSelectionLabel);
    StateLabelManager.stateLabelTextField.setText(StateLabelManager.currentStateLabel);
    stateLabelNamePanel.add(StateLabelManager.stateLabelTextField);
    StateLabelManager.stateLabelDialog.add(stateLabelNamePanel);
    SpringLayoutUtilities.makeCompactGrid(stateLabelNamePanel, 1, 2, 6, 6, 6, 6);

    // button panel
    JPanel stateLabelButtonsPanel = new JPanel();
    String[] buttonNames = {"OK", "Cancel"};
    ActionListener okButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // create state label
            if (StateLabelManager.stateLabelTextField.getText().equals("")
                || !StateLabelManager.containsText(StateLabelManager.stateLabelTextField.getText()))
              JOptionPane.showMessageDialog(null, "Please specify a state label name");
            else {
              if (!StateLabelManager.stateLabelTextField
                      .getText()
                      .equals(StateLabelManager.currentStateLabel)
                  && !QueryManager.getData()
                      .stateLabelExistsAlready(StateLabelManager.stateLabelTextField.getText())) {
                // we're trying to rename the state label to something
                // that doesn't exist yet
                String newStateLabelName = StateLabelManager.stateLabelTextField.getText();
                QueryManager.getData()
                    .renameStateLabel(StateLabelManager.currentStateLabel, newStateLabelName);
                StateLabelManager.setCurrentStateLabel(newStateLabelName);
                StateLabelManager.update();
                StateLabelManager.stateLabelDialog.dispose();
              } else if (!StateLabelManager.stateLabelTextField
                      .getText()
                      .equals(StateLabelManager.currentStateLabel)
                  && QueryManager.getData()
                      .stateLabelExistsAlready(StateLabelManager.stateLabelTextField.getText())) {
                // we're trying to rename the state label to something
                // that is not itself and exists
                // already
                JOptionPane.showMessageDialog(
                    QueryManager.getEditor().getContentPane(),
                    "The name you are trying to rename the state label to \n"
                        + "exists already. Please choose a different name.",
                    "Warning",
                    JOptionPane.ERROR_MESSAGE);
              } else if (StateLabelManager.stateLabelTextField
                  .getText()
                  .equals(StateLabelManager.currentStateLabel)) {
                // no change
                StateLabelManager.stateLabelDialog.dispose();
              }
            }
          }
        };
    ActionListener cancelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            StateLabelManager.clearAll();
            StateLabelManager.stateLabelDialog.dispose();
          }
        };
    ActionListener[] buttonListeners = {okButtonListener, cancelButtonListener};
    stateLabelButtonsPanel.add(new ButtonBar(buttonNames, buttonListeners));

    // main panel
    JPanel stateLabelPanel = new JPanel();
    stateLabelPanel.setBorder(new EtchedBorder());
    stateLabelPanel.setLayout(new BoxLayout(stateLabelPanel, BoxLayout.Y_AXIS));
    stateLabelPanel.add(stateLabelNamePanel);
    stateLabelPanel.add(stateLabelButtonsPanel);
    StateLabelManager.stateLabelDialog.add(stateLabelPanel);

    // make popup visible
    StateLabelManager.stateLabelDialog.pack();
    StateLabelManager.stateLabelDialog.setLocationRelativeTo(null);
    StateLabelManager.stateLabelDialog.setVisible(true);
  }
示例#3
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;
  }