2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
22 import java.awt.event.*;
23 import java.util.Hashtable;
25 import jalview.analysis.*;
26 import jalview.datamodel.*;
29 public class TreePanel extends EmbmenuFrame implements ActionListener,
42 TreeCanvas treeCanvas;
48 public NJTree getTree()
54 * Creates a new TreePanel object.
69 public TreePanel(AlignViewport av, String type, String pwtype)
74 this.setMenuBar(jMenuBar1);
75 } catch (Exception ex)
80 initTreePanel(av, type, pwtype, null);
84 * Creates a new TreePanel object.
97 public TreePanel(AlignViewport av, String type, String pwtype,
103 this.setMenuBar(jMenuBar1);
104 } catch (Exception e)
109 initTreePanel(av, type, pwtype, newtree);
112 void initTreePanel(AlignViewport av, String type, String pwtype,
118 this.pwtype = pwtype;
120 treeCanvas = new TreeCanvas(av, scrollPane);
121 TreeLoader tl = new TreeLoader(newTree);
123 embedMenuIfNeeded(treeCanvas);
124 scrollPane.add(treeCanvas, BorderLayout.CENTER);
127 void showOriginalData()
129 // decide if av alignment is sufficiently different to original data to
130 // warrant a new window to be created
131 // create new alignmnt window with hidden regions (unhiding hidden regions
132 // yields unaligned seqs)
133 // or create a selection box around columns in alignment view
134 // test Alignment(SeqCigar[])
135 if (tree.seqData != null)
140 // we try to get the associated view's gap character
141 // but this may fail if the view was closed...
142 gc = av.getGapCharacter();
143 } catch (Exception ex)
147 Object[] alAndColsel = tree.seqData
148 .getAlignmentAndColumnSelection(gc);
150 if (alAndColsel != null && alAndColsel[0] != null)
152 Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
153 AlignFrame af = new AlignFrame(al, av.applet,
154 "Original Data for Tree", false);
156 af.viewport.setHiddenColumns((ColumnSelection) alAndColsel[1]);
161 System.out.println("Original Tree Data not available");
165 class TreeLoader extends Thread
169 jalview.datamodel.AlignmentView odata = null;
171 public TreeLoader(NewickFile newtree)
173 this.newtree = newtree;
182 tree = new NJTree(av.alignment.getSequencesArray(), newtree);
186 tree = new NJTree(av.alignment.getSequencesArray(), odata,
195 AlignmentView seqStrings = av.getAlignmentView(av
196 .getSelectionGroup() != null);
197 if (av.getSelectionGroup() == null)
200 end = av.alignment.getWidth();
201 seqs = av.alignment.getSequencesArray();
205 start = av.getSelectionGroup().getStartRes();
206 end = av.getSelectionGroup().getEndRes() + 1;
207 seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
210 tree = new NJTree(seqs, seqStrings, type, pwtype, start, end);
213 tree.reCount(tree.getTopNode());
214 tree.findHeight(tree.getTopNode());
215 treeCanvas.setTree(tree);
218 distanceMenu.setState(newtree.HasDistances());
219 bootstrapMenu.setState(newtree.HasBootstrap());
220 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
221 treeCanvas.setShowDistances(newtree.HasDistances());
224 treeCanvas.repaint();
226 av.setCurrentTree(tree);
231 public void actionPerformed(ActionEvent evt)
233 if (evt.getSource() == newickOutput)
235 newickOutput_actionPerformed();
237 else if (evt.getSource() == fontSize)
239 fontSize_actionPerformed();
241 else if (evt.getSource() == inputData)
247 public void itemStateChanged(ItemEvent evt)
249 if (evt.getSource() == fitToWindow)
251 treeCanvas.fitToWindow = fitToWindow.getState();
254 else if (evt.getSource() == distanceMenu)
256 treeCanvas.setShowDistances(distanceMenu.getState());
259 else if (evt.getSource() == bootstrapMenu)
261 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
264 else if (evt.getSource() == placeholdersMenu)
266 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
269 treeCanvas.repaint();
272 public void newickOutput_actionPerformed()
274 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree
276 String output = fout.print(false, true);
277 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
279 java.awt.Frame frame = new java.awt.Frame();
281 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
284 public java.awt.Font getTreeFont()
286 return treeCanvas.font;
289 public void setTreeFont(java.awt.Font font)
291 treeCanvas.font = font;
292 treeCanvas.repaint();
295 protected void fontSize_actionPerformed()
297 if (treeCanvas == null)
302 new FontChooser(this);
305 BorderLayout borderLayout1 = new BorderLayout();
307 protected ScrollPane scrollPane = new ScrollPane();
309 MenuBar jMenuBar1 = new MenuBar();
311 Menu jMenu2 = new Menu();
313 protected MenuItem fontSize = new MenuItem();
315 protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem();
317 protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem();
319 protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem();
321 protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem();
323 Menu fileMenu = new Menu();
325 MenuItem newickOutput = new MenuItem();
327 MenuItem inputData = new MenuItem();
329 private void jbInit() throws Exception
331 setLayout(borderLayout1);
332 this.setBackground(Color.white);
333 this.setFont(new java.awt.Font("Verdana", 0, 12));
334 jMenu2.setLabel("View");
335 fontSize.setLabel("Font...");
336 fontSize.addActionListener(this);
337 bootstrapMenu.setLabel("Show Bootstrap Values");
338 bootstrapMenu.addItemListener(this);
339 distanceMenu.setLabel("Show Distances");
340 distanceMenu.addItemListener(this);
341 placeholdersMenu.setLabel("Mark Unassociated Leaves");
342 placeholdersMenu.addItemListener(this);
343 fitToWindow.setState(true);
344 fitToWindow.setLabel("Fit To Window");
345 fitToWindow.addItemListener(this);
346 fileMenu.setLabel("File");
347 newickOutput.setLabel("Newick Format");
348 newickOutput.addActionListener(this);
349 inputData.setLabel("Input Data...");
351 add(scrollPane, BorderLayout.CENTER);
352 jMenuBar1.add(fileMenu);
353 jMenuBar1.add(jMenu2);
354 jMenu2.add(fitToWindow);
355 jMenu2.add(fontSize);
356 jMenu2.add(distanceMenu);
357 jMenu2.add(bootstrapMenu);
358 jMenu2.add(placeholdersMenu);
359 fileMenu.add(newickOutput);
360 fileMenu.add(inputData);
361 inputData.addActionListener(this);