コード例 #1
1
 public void redrawTree(boolean doRepaint) {
   displayText = false;
   if (argument == null) return;
   if (argument.isMultiRoots()) {
     argument.deleteDummyRoot();
     argument.setMultiRoots(false);
   }
   TreeVertex root = null;
   Vector roots = argument.getTree().getRoots();
   if (roots.size() > 1) {
     if (argument.getDummyRoot() == null) {
       argument.addDummyRoot(roots);
     }
     root = argument.getDummyRoot();
   } else if (roots.size() == 1) {
     root = (TreeVertex) roots.firstElement();
   }
   // if root == null, the entire tree has been erased,
   // so call emptyTree() to clean things up and
   // clear the display
   if (root == null) {
     argument.emptyTree(false);
   } else {
     calcTreeShape(root);
   }
   if (doRepaint) {
     repaint();
   }
   /*
   if (displayFrame.getMainDiagramPanel() == this)
   {
     searchFrame.updateDisplays(false);
   }
    */
 }
コード例 #2
0
  public void addNewEdge() {
    if (!canCreateEdge) {
      //      refreshDisplay();
      return;
    }
    canCreateEdge = false;
    Vector vertexList = argument.getTree().getVertexList();
    boolean addNewEdge = false;
    if (!vertexList.contains(startVertex)) {
      addNewEdge = true;
      argument.getTree().addVertex(startVertex);
      argument.getFreeVertexList().remove(startVertex);
    }
    if (!vertexList.contains(endVertex)) {
      addNewEdge = true;
      argument.getTree().addVertex(endVertex);
      argument.getFreeVertexList().remove(endVertex);
    }
    if (addNewEdge) {
      argument.getTree().addEdge(endVertex, startVertex);
      // If addNewEdge is true here, either or both vertexes are new
      // to the tree, so new edge must be OK
      startVertex.setHasParent(true);

      calcSubtreeShapes();
      displayFrame.controlFrame.updateDisplays(true);
      //      displayFrame.controlFrame.getUndoStack().push(new
      // EditAction(displayFrame.controlFrame, "adding a support"));
    }

    // If reach this far, tree already contains both vertices.
    // No need to check if edge already exists since have checked if
    // vertex has a parent. Just need to check if new edge creates a
    // cycle. If it does, we delete the edge we just added.
    if (argument.isMultiRoots()) {
      argument.deleteDummyRoot();
      argument.setMultiRoots(false);
    }
    argument.getTree().addEdge(endVertex, startVertex);
    startVertex.setHasParent(true);
    TreeVertex root;
    Vector roots = argument.getTree().getRoots();
    if (roots.size() == 0) {
      deleteCycle(startVertex, endVertex);
      return;
    }
    if (roots.size() > 1) {
      argument.addDummyRoot(roots);
      root = argument.getDummyRoot();
    } else {
      root = (TreeVertex) roots.firstElement();
    }
    try {
      argument.getTree().breadthFirstTopSort(root);
    } catch (GraphException e) {
      deleteCycle(startVertex, endVertex);
      return;
    }
    // If we survive the cycle test, the edge is OK.
    redrawTree(true);
  }