示例#1
0
  /**
   * Construct a Unit Solver Dialog.
   *
   * @param dialogTableau The DialogTableau.
   * @param owner The object that, per the user, appears to be generating the dialog.
   * @param target The object whose units are being solved.
   * @param configuration The configuration to use to open the help screen.
   */
  public UnitSolverDialog(
      DialogTableau dialogTableau, Frame owner, Entity target, Configuration configuration) {
    super("Solve units for " + target.getName(), dialogTableau, owner, target, configuration);

    SelectionRenderer tempSelectionRenderer = null;
    _tableau = ((TableauFrame) owner).getTableau();

    _model = (TypedCompositeActor) target;

    // ((TypedCompositeActor) (((PtolemyEffigy) (_tableau.getContainer()))
    //      .getModel()));
    BasicGraphFrame parent = (BasicGraphFrame) (_tableau.getFrame());
    JGraph jGraph = parent.getJGraph();
    GraphPane graphPane = jGraph.getGraphPane();
    _controller = graphPane.getGraphController();
    _selectionModel = _controller.getSelectionModel();

    Interactor interactor = _controller.getEdgeController(new Object()).getEdgeInteractor();
    _graphModel = (AbstractBasicGraphModel) _controller.getGraphModel();
    _selectionInteractor = (SelectionInteractor) interactor;
    _defaultSelectionRenderer = _selectionInteractor.getSelectionRenderer();
    tempSelectionRenderer = new BasicSelectionRenderer(new BasicEdgeHighlighter());

    if (_model == getTarget()) {
      _entities = _getSelectedNodes();
      _relations = _getSelectedRelations();

      if (_entities.isEmpty() && _relations.isEmpty()) {
        _entities = new Vector(_model.entityList(ComponentEntity.class));
        _relations = new Vector(_model.relationList());
      }
    } else {
      _entities = new Vector();
      _entities.add(getTarget());
      _relations = new Vector();
    }

    _selectionModel.clearSelection();
    _selectionInteractor.setSelectionRenderer(tempSelectionRenderer);
    _showComponents();
    _selectionModel.addSelectionListener(this);

    JPanel fullSolverPanel = new JPanel();
    fullSolverPanel.setLayout(new BoxLayout(fullSolverPanel, BoxLayout.Y_AXIS));
    fullSolverPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Full Solution"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    _runFullSolverButton.addActionListener(this);
    fullSolverPanel.add(_runFullSolverButton);
    _fullSolutionResult.setOpaque(true);
    _fullSolutionResult.setBackground(Color.white);
    fullSolverPanel.add(_fullSolutionResult);

    JPanel componentsPanel = new JPanel();
    componentsPanel.setLayout(new BoxLayout(componentsPanel, BoxLayout.Y_AXIS));
    componentsPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Components"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    _setToSelectedButton.setEnabled(false);
    componentsPanel.add(_setToSelectedButton);
    _setToSelectedButton.addActionListener(this);
    componentsPanel.add(_showComponentsButton);
    _showComponentsButton.addActionListener(this);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
    topPanel.add(fullSolverPanel);
    topPanel.add(componentsPanel);

    JPanel minimalSpanPanel = new JPanel(new BorderLayout());
    minimalSpanPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Minimal Spanning Solutions"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    minimalSpanPanel.add(_runMinimalSpanSolverButton, BorderLayout.NORTH);
    _runMinimalSpanSolverButton.addActionListener(this);
    _solutionsListModel = new SolutionListModel();
    _solutionsList = new JList(_solutionsListModel);
    _solutionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _solutionsList.addListSelectionListener(this);

    JScrollPane scrollPane = new JScrollPane(_solutionsList);
    minimalSpanPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel mainPane = new JPanel();
    mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
    mainPane.add(topPanel);
    mainPane.add(minimalSpanPanel);
    setContents(mainPane);
  }