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
27 import jalview.analysis.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.io.*;
\r
31 public class TreePanel extends Frame implements ActionListener, ItemListener
\r
38 TreeCanvas treeCanvas;
\r
42 public NJTree getTree()
\r
48 * Creates a new TreePanel object.
\r
50 * @param av DOCUMENT ME!
\r
51 * @param seqVector DOCUMENT ME!
\r
52 * @param type DOCUMENT ME!
\r
53 * @param pwtype DOCUMENT ME!
\r
54 * @param s DOCUMENT ME!
\r
55 * @param e DOCUMENT ME!
\r
57 public TreePanel(AlignViewport av, String type, String pwtype)
\r
62 this.setMenuBar(jMenuBar1);
\r
64 catch (Exception ex)
\r
66 ex.printStackTrace();
\r
69 initTreePanel(av, type, pwtype, null);
\r
73 * Creates a new TreePanel object.
\r
75 * @param av DOCUMENT ME!
\r
76 * @param seqVector DOCUMENT ME!
\r
77 * @param newtree DOCUMENT ME!
\r
78 * @param type DOCUMENT ME!
\r
79 * @param pwtype DOCUMENT ME!
\r
81 public TreePanel(AlignViewport av,
\r
89 this.setMenuBar(jMenuBar1);
\r
93 e.printStackTrace();
\r
96 initTreePanel(av, type, pwtype, newtree);
\r
100 void initTreePanel(AlignViewport av,
\r
103 NewickFile newTree)
\r
108 this.pwtype = pwtype;
\r
110 treeCanvas = new TreeCanvas(av, scrollPane);
\r
111 scrollPane.add(treeCanvas);
\r
114 TreeLoader tl = new TreeLoader(newTree);
\r
119 class TreeLoader extends Thread
\r
121 NewickFile newtree;
\r
123 public TreeLoader(NewickFile newtree)
\r
125 this.newtree = newtree;
\r
130 if (newtree != null)
\r
131 tree = new NJTree(av.alignment.getSequencesArray(),
\r
137 String [] seqStrings = null;
\r
138 // if (av.hasHiddenColumns)
\r
140 // seqStrings = av.getSelectionAsString();
\r
143 if(av.getSelectionGroup()==null)
\r
146 end = av.alignment.getWidth();
\r
147 seqs = av.alignment.getSequencesArray();
\r
151 start = av.getSelectionGroup().getStartRes();
\r
152 end = av.getSelectionGroup().getEndRes()+1;
\r
153 seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
\r
156 tree = new NJTree(seqs, seqStrings, type, pwtype, start, end);
\r
159 tree.reCount(tree.getTopNode());
\r
160 tree.findHeight(tree.getTopNode());
\r
161 treeCanvas.setTree(tree);
\r
164 distanceMenu.setState(newtree.HasDistances());
\r
165 bootstrapMenu.setState(newtree.HasBootstrap());
\r
166 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
\r
167 treeCanvas.setShowDistances(newtree.HasDistances());
\r
171 treeCanvas.repaint();
\r
173 av.setCurrentTree(tree);
\r
178 public void actionPerformed(ActionEvent evt)
\r
180 if(evt.getSource()==newickOutput)
\r
181 newickOutput_actionPerformed();
\r
182 else if(evt.getSource()==fontSize)
\r
183 fontSize_actionPerformed();
\r
186 public void itemStateChanged(ItemEvent evt)
\r
188 if(evt.getSource()==fitToWindow)
\r
189 treeCanvas.fitToWindow = fitToWindow.getState();
\r
191 else if(evt.getSource()==distanceMenu)
\r
192 treeCanvas.setShowDistances(distanceMenu.getState());
\r
194 else if(evt.getSource()==bootstrapMenu)
\r
195 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
\r
197 else if(evt.getSource()==placeholdersMenu)
\r
198 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
\r
200 treeCanvas.repaint();
\r
204 public void newickOutput_actionPerformed()
\r
206 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());
\r
207 String output = fout.print(false, true);
\r
208 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
\r
209 cap.setText(output);
\r
210 java.awt.Frame frame = new java.awt.Frame();
\r
212 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
\r
215 public java.awt.Font getTreeFont()
\r
217 return treeCanvas.font;
\r
220 public void setTreeFont(java.awt.Font font)
\r
222 treeCanvas.font = font;
\r
223 treeCanvas.repaint();
\r
226 protected void fontSize_actionPerformed()
\r
228 if( treeCanvas==null )
\r
231 new FontChooser(this);
\r
237 BorderLayout borderLayout1 = new BorderLayout();
\r
238 protected ScrollPane scrollPane = new ScrollPane();
\r
239 MenuBar jMenuBar1 = new MenuBar();
\r
240 Menu jMenu2 = new Menu();
\r
241 protected MenuItem fontSize = new MenuItem();
\r
242 protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem();
\r
243 protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem();
\r
244 protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem();
\r
245 protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem();
\r
246 Menu fileMenu = new Menu();
\r
247 MenuItem newickOutput = new MenuItem();
\r
249 private void jbInit() throws Exception {
\r
250 setLayout(borderLayout1);
\r
251 this.setBackground(Color.white);
\r
252 this.setFont(new java.awt.Font("Verdana", 0, 12));
\r
253 jMenu2.setLabel("View");
\r
254 fontSize.setLabel("Font...");
\r
255 fontSize.addActionListener(this);
\r
256 bootstrapMenu.setLabel("Show Bootstrap Values");
\r
257 bootstrapMenu.addItemListener(this);
\r
258 distanceMenu.setLabel("Show Distances");
\r
259 distanceMenu.addItemListener(this);
\r
260 placeholdersMenu.setLabel("Mark Unassociated Leaves");
\r
261 placeholdersMenu.addItemListener(this);
\r
262 fitToWindow.setState(true);
\r
263 fitToWindow.setLabel("Fit To Window");
\r
264 fitToWindow.addItemListener(this);
\r
265 fileMenu.setLabel("File");
\r
266 newickOutput.setLabel("Newick Format");
\r
267 newickOutput.addActionListener(this);
\r
269 add(scrollPane, BorderLayout.CENTER);
\r
270 jMenuBar1.add(fileMenu);
\r
271 jMenuBar1.add(jMenu2);
\r
272 jMenu2.add(fitToWindow);
\r
273 jMenu2.add(fontSize);
\r
274 jMenu2.add(distanceMenu);
\r
275 jMenu2.add(bootstrapMenu);
\r
276 jMenu2.add(placeholdersMenu);
\r
277 fileMenu.add(newickOutput);
\r