From 3e63bb86ad0e6f4bc86197053f921cb67b341567 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 18 Mar 2005 16:56:21 +0000 Subject: [PATCH] Load and Save trees. --- src/jalview/gui/TreePanel.java | 53 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 58c668f..73ef46b 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -66,6 +66,38 @@ public class TreePanel extends GTreePanel scrollPane.setViewportView(treeCanvas); } + public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree, + String type, String pwtype) + { + super(); + // These are probably only arbitrary strings reflecting source of tree + this.type = type; + this.pwtype = pwtype; + + start = 0; + end = seqVector.size(); + + String longestName = ""; + seq = new Sequence [seqVector.size()]; + for (int i=0;i < seqVector.size();i++) + { + seq[i] = (Sequence) seqVector.elementAt(i); + if(seq[i].getName().length()>longestName.length()) + longestName = seq[i].getName(); + } + // This constructor matches sequence names to treenodes and sets up the tree layouts. + tree = new NJTree(seq, newtree); + av.setCurrentTree(tree); + + propertiesInit(); + + tree.reCount(tree.getTopNode()); + tree.findHeight(tree.getTopNode()); + + treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName); + scrollPane.setViewportView(treeCanvas); + + } public void drawPostscript(PostscriptProperties pp) { @@ -256,7 +288,26 @@ public void propertiesInit() { protected void saveMenu_actionPerformed(ActionEvent e) { - + JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache. + getProperty("LAST_DIRECTORY")); + chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle("Save tree as newick file"); + chooser.setToolTipText("Save"); + int value = chooser.showSaveDialog(null); + if (value == JalviewFileChooser.APPROVE_OPTION) { + String choice = chooser.getSelectedFile().getPath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice); + try{ + jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode()); + String output = fout.print(false,true); // distances only + java.io.PrintWriter out = new java.io.PrintWriter( new java.io.FileWriter( choice ) ); + out.println(output); + out.close(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } } protected void printMenu_actionPerformed(ActionEvent e) -- 1.7.10.2