示例#1
0
  /**
   * Creates the state label assignment manager
   *
   * @return
   */
  private static JPanel getStatesAssignmentManagerPanel() {
    JPanel stateAssignmentManagerPanel = new JPanel();
    stateAssignmentManagerPanel.setBorder(
        (new TitledBorder(new EtchedBorder(), "State Label Definition")));
    stateAssignmentManagerPanel.setLayout(
        new BoxLayout(stateAssignmentManagerPanel, BoxLayout.Y_AXIS));

    // panel to hold the state definitions and state label panels, as well
    // as the assignment buttons
    JPanel stateAssignmentPanel = new JPanel();
    stateAssignmentPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

    // Create button panel
    JPanel stateButtonsPanel = new JPanel();
    JButton createStateDefinitionButton = new JButton("Define State Group");
    ActionListener createStateDefinitionButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            // check whether places have been defined on the underlying
            // model
            boolean okToProceed = QueryManager.getData().checkCurrentData("States");
            if (okToProceed) {
              // bring up the state editor popup
              StateGroupEditor stateEditor = new StateGroupEditor();
              PetriNetView pnModel =
                  ApplicationSettings.getApplicationView().getCurrentPetriNetView();
              stateEditor.addState(pnModel);
              StateLabelManager.update();
            }
          }
        };
    createStateDefinitionButton.addActionListener(createStateDefinitionButtonListener);
    JButton editStateDefinitionButton = new JButton("Edit State Group");
    ActionListener editStateDefinitionButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int[] selectedIndices = StateLabelManager.stateGroupsList.getSelectedIndices();
            if (selectedIndices.length > 0) {
              if (selectedIndices.length > 1) {
                JOptionPane.showMessageDialog(
                    QueryManager.getEditor().getContentPane(),
                    "To edit a state group, please select a single state \n"
                        + "group from the list of states defined on the model.",
                    "Warning",
                    JOptionPane.INFORMATION_MESSAGE);
              } else {
                int selectedIndex = selectedIndices[0];
                // bring up the state editor popup
                String selectedStateName =
                    (String)
                        StateLabelManager.stateGroupsList.getModel().getElementAt(selectedIndex);
                StateGroup selectedState = StateLabelManager.getStateGroup(selectedStateName);
                StateGroupEditor stateEditor = new StateGroupEditor();
                PetriNetView pnModel =
                    ApplicationSettings.getApplicationView().getCurrentPetriNetView();
                stateEditor.editState(pnModel, selectedState);
                StateLabelManager.update();
              }
            } else {
              JOptionPane.showMessageDialog(
                  QueryManager.getEditor().getContentPane(),
                  "To edit a state group, please select a single state \n"
                      + "group from the list of states defined on the model.",
                  "Warning",
                  JOptionPane.INFORMATION_MESSAGE);
            }
          }
        };
    editStateDefinitionButton.addActionListener(editStateDefinitionButtonListener);
    JButton deleteStateDefinitionButton = new JButton("Delete State Group");
    ActionListener deleteStateDefinitionButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int[] stateGroupsListSelectedIndices =
                StateLabelManager.stateGroupsList.getSelectedIndices();
            if (stateGroupsListSelectedIndices.length > 0) {
              PetriNetView pnModel =
                  ApplicationSettings.getApplicationView().getCurrentPetriNetView();
              for (int selectionIndex : stateGroupsListSelectedIndices) {
                String selectedStateName =
                    (String)
                        StateLabelManager.stateGroupsList.getModel().getElementAt(selectionIndex);
                StateGroup state = StateLabelManager.getStateGroup(selectedStateName);
                // remove state from _dataLayer
                pnModel.removeStateGroup(state);
                // remove all references to the state in all state
                // labels
                QueryManager.getData().removeStateFromAllLabels(selectedStateName);
              }
              StateLabelManager.update();
            } else {
              JOptionPane.showMessageDialog(
                  QueryManager.getEditor().getContentPane(),
                  "To delete a state group, please select it from the list \n"
                      + "of defined state groups on the left panel.",
                  "Warning",
                  JOptionPane.INFORMATION_MESSAGE);
            }
          }
        };
    deleteStateDefinitionButton.addActionListener(deleteStateDefinitionButtonListener);
    stateButtonsPanel.add(createStateDefinitionButton);
    stateButtonsPanel.add(editStateDefinitionButton);
    stateButtonsPanel.add(deleteStateDefinitionButton);

    // panel for the state definitions
    JPanel stateDefinitionsPanel = new JPanel();
    stateDefinitionsPanel.setBorder(
        (new TitledBorder(new EtchedBorder(), "State Groups Defined On The Model")));
    StateLabelManager.stateGroupsList.setLayoutOrientation(JList.VERTICAL);
    StateLabelManager.stateGroupsList.setSelectionModel(new ToggleSelectionModel());
    StateLabelManager.stateGroupsList.setVisibleRowCount(-1);
    StateLabelManager.populateStateGroupsList();
    JScrollPane stateDefinitionsListScroller = new JScrollPane(StateLabelManager.stateGroupsList);
    stateDefinitionsListScroller.setPreferredSize(new Dimension(300, 200));
    stateDefinitionsPanel.add(stateDefinitionsListScroller);
    stateAssignmentPanel.add(stateDefinitionsPanel);

    // panel for the assignment buttons
    JPanel assignmentButtonsPanel = new JPanel();
    assignmentButtonsPanel.setLayout(new BoxLayout(assignmentButtonsPanel, BoxLayout.Y_AXIS));
    JButton assignStateToStateLabelButton = new JButton("->");
    ActionListener assignStateToStateLabelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (StateLabelManager.currentStateLabel != null) {
              int[] stateGroupsListSelectedIndices =
                  StateLabelManager.stateGroupsList.getSelectedIndices();
              if (stateGroupsListSelectedIndices.length > 0) {
                for (int selectionIndex : stateGroupsListSelectedIndices) {
                  String selectedStateName =
                      (String)
                          StateLabelManager.stateGroupsList.getModel().getElementAt(selectionIndex);
                  // assign state to state label
                  QueryManager.getData()
                      .addStateLabel(StateLabelManager.currentStateLabel, selectedStateName);
                }
                StateLabelManager.update();
              }
            } else {
              JOptionPane.showMessageDialog(
                  QueryManager.getEditor().getContentPane(),
                  "Before you can assign state groups to a state label, you have \n"
                      + "to specify the state label. Please choose a label from the \n"
                      + "dropdown menu.\n",
                  "Warning",
                  JOptionPane.INFORMATION_MESSAGE);
            }
          }
        };
    assignStateToStateLabelButton.addActionListener(assignStateToStateLabelButtonListener);
    assignmentButtonsPanel.add(assignStateToStateLabelButton);
    JButton removeStateFromStateLabelButton = new JButton("<-");
    ActionListener removeStateFromStateLabelButtonListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (StateLabelManager.currentStateLabel != null) {
              int[] statesAssignedSelectedIndices =
                  StateLabelManager.statesAssignedToLabelList.getSelectedIndices();
              if (statesAssignedSelectedIndices.length > 0) {
                for (int selectionIndex : statesAssignedSelectedIndices) {
                  String selectedStateName =
                      (String)
                          StateLabelManager.statesAssignedToLabelList
                              .getModel()
                              .getElementAt(selectionIndex);
                  // remove state from label
                  QueryManager.getData()
                      .removeStateFromStateLabel(
                          StateLabelManager.currentStateLabel, selectedStateName);
                }
              }
              StateLabelManager.update();
            }
          }
        };
    removeStateFromStateLabelButton.addActionListener(removeStateFromStateLabelButtonListener);
    assignmentButtonsPanel.add(removeStateFromStateLabelButton);
    stateAssignmentPanel.add(assignmentButtonsPanel);

    // panel for the states assigned to the state label
    JPanel statesAssignedToStateLabelPanel = new JPanel();
    statesAssignedToStateLabelPanel.setBorder(
        (new TitledBorder(new EtchedBorder(), "State Groups Assigned To Label")));
    StateLabelManager.statesAssignedToLabelList.setLayoutOrientation(JList.VERTICAL);
    StateLabelManager.statesAssignedToLabelList.setSelectionModel(new ToggleSelectionModel());
    StateLabelManager.statesAssignedToLabelList.setVisibleRowCount(-1);
    StateLabelManager.populateStatesAssignedToLabelList(null);
    JScrollPane statesAssignedListScroller =
        new JScrollPane(StateLabelManager.statesAssignedToLabelList);
    statesAssignedListScroller.setPreferredSize(new Dimension(300, 200));
    statesAssignedToStateLabelPanel.add(statesAssignedListScroller);
    stateAssignmentPanel.add(statesAssignedToStateLabelPanel);

    // Add components to panel
    stateAssignmentManagerPanel.add(stateButtonsPanel);
    stateAssignmentManagerPanel.add(stateAssignmentPanel);

    return stateAssignmentManagerPanel;
  }
示例#2
0
 /**
  * This method loads the names of the state groups and adds them to the source / destination
  * JLists
  */
 private static void populateLists() {
   StateLabelManager.populateStateGroupsList();
   StateLabelManager.populateStatesAssignedToLabelList(StateLabelManager.currentStateLabel);
 }