Load and Save trees.
authorjprocter <Jim Procter>
Fri, 18 Mar 2005 16:56:21 +0000 (16:56 +0000)
committerjprocter <Jim Procter>
Fri, 18 Mar 2005 16:56:21 +0000 (16:56 +0000)
src/jalview/gui/TreePanel.java

index 58c668f..73ef46b 100755 (executable)
@@ -66,6 +66,38 @@ public class TreePanel extends GTreePanel
     scrollPane.setViewportView(treeCanvas);\r
 \r
   }\r
+  public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree,\r
+                   String type, String pwtype)\r
+    {\r
+      super();\r
+      // These are probably only  arbitrary strings reflecting source of tree\r
+      this.type = type;\r
+      this.pwtype = pwtype;\r
+\r
+      start = 0;\r
+      end = seqVector.size();\r
+\r
+      String longestName = "";\r
+      seq = new Sequence [seqVector.size()];\r
+      for (int i=0;i < seqVector.size();i++)\r
+      {\r
+        seq[i] = (Sequence) seqVector.elementAt(i);\r
+        if(seq[i].getName().length()>longestName.length())\r
+          longestName = seq[i].getName();\r
+      }\r
+      // This constructor matches sequence names to treenodes and sets up the tree layouts.\r
+      tree = new NJTree(seq, newtree);\r
+      av.setCurrentTree(tree);\r
+\r
+      propertiesInit();\r
+\r
+      tree.reCount(tree.getTopNode());\r
+      tree.findHeight(tree.getTopNode());\r
+\r
+      treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName);\r
+      scrollPane.setViewportView(treeCanvas);\r
+\r
+    }\r
 \r
 \r
 public void drawPostscript(PostscriptProperties pp) {\r
@@ -256,7 +288,26 @@ public void propertiesInit() {
 \r
   protected void saveMenu_actionPerformed(ActionEvent e)\r
   {\r
-\r
+    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+        getProperty("LAST_DIRECTORY"));\r
+    chooser.setFileView(new JalviewFileView());\r
+    chooser.setDialogTitle("Save tree as newick file");\r
+    chooser.setToolTipText("Save");\r
+    int value = chooser.showSaveDialog(null);\r
+    if (value == JalviewFileChooser.APPROVE_OPTION) {\r
+      String choice =  chooser.getSelectedFile().getPath();\r
+      jalview.bin.Cache.setProperty("LAST_DIRECTORY",  choice);\r
+      try{\r
+        jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());\r
+        String output = fout.print(false,true); // distances only\r
+        java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice )  );\r
+        out.println(output);\r
+        out.close();\r
+      }\r
+      catch (Exception ex) {\r
+        ex.printStackTrace();\r
+      }\r
+    }\r
   }\r
 \r
   protected void printMenu_actionPerformed(ActionEvent e)\r