2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
24 import java.awt.event.*;
\r
26 import jalview.analysis.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.io.*;
\r
29 import jalview.jbappletgui.*;
\r
31 public class TreePanel
\r
40 TreeCanvas treeCanvas;
\r
43 public NJTree getTree()
\r
48 public TreePanel(AlignViewport av, Vector seqVector, String type,
\r
49 String pwtype, int s, int e)
\r
54 this.pwtype = pwtype;
\r
59 String longestName = "";
\r
60 seq = new Sequence[seqVector.size()];
\r
61 for (int i = 0; i < seqVector.size(); i++)
\r
63 seq[i] = (Sequence) seqVector.elementAt(i);
\r
64 if (seq[i].getName().length() > longestName.length())
\r
66 longestName = seq[i].getName();
\r
70 tree = new NJTree(seq, type, pwtype, start, end);
\r
72 treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName);
\r
74 tree.reCount(tree.getTopNode());
\r
75 tree.findHeight(tree.getTopNode());
\r
76 scrollPane.add(treeCanvas);
\r
80 public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree,
\r
81 String type, String pwtype)
\r
84 // These are probably only arbitrary strings reflecting source of tree
\r
86 this.pwtype = pwtype;
\r
89 end = seqVector.size();
\r
91 String longestName = "";
\r
92 seq = new Sequence[seqVector.size()];
\r
93 for (int i = 0; i < seqVector.size(); i++)
\r
95 seq[i] = (Sequence) seqVector.elementAt(i);
\r
97 // This constructor matches sequence names to treenodes and sets up the tree layouts.
\r
98 tree = new NJTree(seq, newtree);
\r
99 // Now have to calculate longest name based on the leaves
\r
100 Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector());
\r
102 for (int i = 0; i < leaves.size(); i++)
\r
104 if (longestName.length() <
\r
105 ( (Sequence) ( (SequenceNode) leaves.elementAt(i)).element()).getName().
\r
108 longestName = TreeCanvas.PLACEHOLDER +
\r
109 ( (Sequence) ( (SequenceNode) leaves.elementAt(i)).element()).
\r
114 tree.reCount(tree.getTopNode());
\r
115 tree.findHeight(tree.getTopNode());
\r
117 treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName);
\r
118 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
\r
119 treeCanvas.setShowDistances(newtree.HasDistances());
\r
120 distanceMenu.setState(newtree.HasDistances());
\r
121 bootstrapMenu.setState(newtree.HasBootstrap());
\r
122 if (true) // JBPNote TODO: preference for always marking placeholders in new associated tree
\r
124 placeholdersMenu.setState(treeCanvas.markPlaceholders);
\r
126 scrollPane.add(treeCanvas);
\r
130 public String getText(String format)
\r
135 protected void fitToWindow_actionPerformed(ActionEvent e)
\r
137 treeCanvas.fitToWindow = fitToWindow.getState();
\r
141 public void newickOutput_actionPerformed(ActionEvent actionEvent)
\r
143 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());
\r
144 String output = fout.print(false, true);
\r
145 CutAndPasteTransfer cap = new CutAndPasteTransfer(false);
\r
146 cap.setText(output);
\r
147 java.awt.Frame frame = new java.awt.Frame();
\r
149 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
\r
152 protected void fontSize_actionPerformed(ActionEvent e)
\r
154 /* if( treeCanvas==null )
\r
157 String size = fontSize.getLabel().substring( fontSize.getLabel().indexOf("-")+1);
\r
159 Object selection = JOptionPane.showInternalInputDialog(Desktop.desktop,
\r
160 "Select font size",
\r
162 JOptionPane.QUESTION_MESSAGE,
\r
163 null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"}
\r
164 ,"Font Size - "+size);
\r
165 if(selection!=null)
\r
167 fontSize.setText("Font Size - " + selection);
\r
169 int i = Integer.parseInt(selection.toString());
\r
170 treeCanvas.setFontSize(i);
\r
172 scrollPane.setViewportView(treeCanvas);
\r
176 protected void distanceMenu_actionPerformed(ActionEvent e)
\r
178 treeCanvas.setShowDistances(distanceMenu.getState());
\r
181 protected void bootstrapMenu_actionPerformed(ActionEvent e)
\r
183 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
\r
186 protected void placeholdersMenu_actionPerformed(ActionEvent e)
\r
188 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
\r