Esempio n. 1
0
  public synchronized void swap(RootedTree destTree, PhyloNode destNode) {
    synchronized (destTree) {
      /*
       * If we're swapping within the same tree, then it's easy:
       */
      if (origTree == destTree && origVertex != null) {
        Object p1 = origTree.getParentOf(origVertex);
        Object p2 = origTree.getParentOf(destNode);
        if (p1 != null && p2 != null) {
          origTree.removeEdge(p1, origVertex);
          origTree.removeEdge(p2, destNode);
          origTree.addEdge(p1, destNode);
          origTree.addEdge(p2, origVertex);
        }
      } else {
        /*
         * If we're swapping with an "external" clipboard, then it's also easy.
         */
        PhyloTree clipTree = loadClip();
        setClip(destTree, destNode);
        setClipFromJS(newickString);

        Object p1 = destTree.getParentOf(destNode);
        destTree.deleteSubtree(destNode);
        Graphs.addGraph(destTree, clipTree);
        if (p1 == null) {
          destTree.setRoot(clipTree.getRoot());
        } else {
          destTree.addEdge(p1, clipTree.getRoot());
        }
      }
    }
  }
Esempio n. 2
0
 public void uiEvent(UIEvent e) {
   if (e.getID() == UIEvent.TEXT_VALUE) {
     PhyloWidget.cfg.search = getText();
     PhyloTree t = (PhyloTree) PhyloWidget.trees.getTree();
     if (t != null) {
       t.searchAndMarkFound(getText());
     }
   }
 }
Esempio n. 3
0
  PhyloTree loadClip() {
    if (newickString == null || newickString.length() == 0) {
      /*
       * Try loading a tree from the system clipboard.
       */
      newickString = StringClipboard.instance.fromClipboard();
    }
    if (newickString == null || newickString.length() == 0)
      throw new Error("Called TreeClipboard.paste() with empty clipboard");

    PhyloTree clipTree = new PhyloTree();
    TreeIO.parseNewickString(clipTree, newickString);

    if (origTree != null && origVertex != null) {
      setPositionRecursive(clipTree, (PhyloNode) clipTree.getRoot(), origVertex);
    }
    return clipTree;
  }
Esempio n. 4
0
  public synchronized void paste(CachedRootedTree destTree, PhyloNode destNode) {
    // Translate the newick string into a RooteTree.
    PhyloTree tree = loadClip();
    // Add the clone's vertices and edges to the destination tree.

    synchronized (destTree) {
      destTree.setHoldCalculations(true);
      Graphs.addGraph(destTree, tree);
      // Insert the clone's root vertex into the midpoint above destNode.
      if (destTree.getParentOf(destNode) == null) {
        destTree.addEdge(destNode, tree.getRoot());
      } else {
        DefaultVertex internalVertex = destTree.createAndAddVertex();
        ((PhyloNode) internalVertex).setPosition(origVertex);
        destTree.insertNodeBetween(destTree.getParentOf(destNode), destNode, internalVertex);
        destTree.addEdge(internalVertex, tree.getRoot());
      }
      destTree.setHoldCalculations(false);
      destTree.modPlus();

      clearCutNodes();
    }
  }