예제 #1
0
파일: PtolemyQuery.java 프로젝트: ptII/ptII
 /**
  * Override the base class to put a button on the right if the Settable object for which we are
  * adding an entry itself contains Settable parameters.
  *
  * @param name The name of the entry.
  * @param label The label.
  * @param widget The interactive entry to the right of the label.
  * @param entry The object that contains user data.
  */
 protected void _addPair(String name, JLabel label, Component widget, Object entry) {
   if (_addingStyledEntryFor != null) {
     List<Settable> settables = ((NamedObj) _addingStyledEntryFor).attributeList(Settable.class);
     if (settables == null || settables.size() == 0) {
       super._addPair(name, label, widget, entry);
     } else {
       // Check to make sure at least one of the contained
       // parameters is visible.
       boolean foundOne = false;
       for (Settable settable : settables) {
         if (Configurer.isVisible((NamedObj) _addingStyledEntryFor, settable)) {
           foundOne = true;
           break;
         }
       }
       if (foundOne) {
         HierarchicalConfigurer configurer =
             new HierarchicalConfigurer(PtolemyQuery.this, name, _addingStyledEntryFor, widget);
         super._addPair(name, label, configurer, entry);
       } else {
         super._addPair(name, label, widget, entry);
       }
     }
   } else {
     super._addPair(name, label, widget, entry);
   }
 }
예제 #2
0
    /** Perform the action. */
    public void actionPerformed(ActionEvent e) {
      super.actionPerformed(e);
      // Dialog to ask for a case name.
      Query query = new Query();
      List refinements = _case.entityList(Refinement.class);
      if (refinements.size() < 2) {
        MessageHandler.error("No cases to remove.");
      } else {
        String[] caseNames = new String[refinements.size() - 1];
        Iterator cases = refinements.iterator();
        int i = 0;
        while (cases.hasNext()) {
          String name = ((Nameable) cases.next()).getName();
          if (!name.equals("default")) {
            caseNames[i] = name;
            i++;
          }
        }
        query.addChoice("case", "Remove case", caseNames, caseNames[0]);
        ComponentDialog dialog = new ComponentDialog(CaseGraphFrame.this, "Remove Case", query);
        if (dialog.buttonPressed().equals("OK")) {
          final String name = query.getStringValue("case");
          String moml = "<deleteEntity name=\"" + StringUtilities.escapeForXML(name) + "\"/>";

          // The following is, regrettably, copied from ModalTransitionController.
          MoMLChangeRequest change =
              new MoMLChangeRequest(this, _case, moml) {
                protected void _execute() throws Exception {
                  super._execute();
                  // Find the tabbed pane that matches the name and remove it.
                  int count = _tabbedPane.getTabCount();
                  for (int i = 0; i < count; i++) {
                    if (name.equals(_tabbedPane.getTitleAt(i))) {
                      _tabbedPane.remove(i);
                      break;
                    }
                  }
                }
              };
          _case.requestChange(change);
        }
      }
    }
예제 #3
0
    /** Perform the action. */
    public void actionPerformed(ActionEvent e) {
      super.actionPerformed(e);
      // Dialog to ask for a case name.
      Query query = new Query();
      query.addLine("case", "Pattern that the control input must match", "");
      ComponentDialog dialog = new ComponentDialog(CaseGraphFrame.this, "Add Case", query);
      if (dialog.buttonPressed().equals("OK")) {
        final String pattern = query.getStringValue("case");
        // NOTE: We do not use a TransitionRefinement because we don't
        // want the sibling input ports that come with output ports.
        String moml =
            "<entity name=\""
                + StringUtilities.escapeForXML(pattern)
                + "\" class=\""
                + _case.refinementClassName()
                + "\"/>";

        // The following is, regrettably, copied from ModalTransitionController.
        MoMLChangeRequest change =
            new MoMLChangeRequest(this, _case, moml) {
              protected void _execute() throws Exception {
                super._execute();

                // Mirror the ports of the container in the refinement.
                // Note that this is done here rather than as part of
                // the MoML because we have set protected variables
                // in the refinement to prevent it from trying to again
                // mirror the changes in the container.
                Refinement entity = (Refinement) _case.getEntity(pattern);

                // Get the initial port configuration from the container.
                Iterator ports = _case.portList().iterator();

                while (ports.hasNext()) {
                  Port port = (Port) ports.next();
                  // No need to mirror the control port, as it's a PortParameter.
                  // Hence, its value is available as a parameter.
                  if (port == _case.control.getPort()) {
                    continue;
                  }

                  try {
                    entity.setMirrorDisable(true);
                    Port newPort = entity.newPort(port.getName());
                    if (newPort instanceof RefinementPort && port instanceof IOPort) {
                      try {
                        ((RefinementPort) newPort).setMirrorDisable(true);

                        if (((IOPort) port).isInput()) {
                          ((RefinementPort) newPort).setInput(true);
                        }

                        if (((IOPort) port).isOutput()) {
                          ((RefinementPort) newPort).setOutput(true);
                        }

                        if (((IOPort) port).isMultiport()) {
                          ((RefinementPort) newPort).setMultiport(true);
                        }
                      } finally {
                        ((RefinementPort) newPort).setMirrorDisable(false);
                      }
                    }
                  } finally {
                    entity.setMirrorDisable(false);
                  }
                }
                _addTabbedPane(entity, true);
              }
            };

        _case.requestChange(change);
      }
    }