2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
23 import java.awt.event.*;
\r
25 import jalview.analysis.*;
\r
26 import jalview.datamodel.*;
\r
27 import jalview.io.*;
\r
29 public class TreePanel
\r
30 extends Frame implements ActionListener, ItemListener
\r
37 TreeCanvas treeCanvas;
\r
41 public NJTree getTree()
\r
47 * Creates a new TreePanel object.
\r
49 * @param av DOCUMENT ME!
\r
50 * @param seqVector DOCUMENT ME!
\r
51 * @param type DOCUMENT ME!
\r
52 * @param pwtype DOCUMENT ME!
\r
53 * @param s DOCUMENT ME!
\r
54 * @param e DOCUMENT ME!
\r
56 public TreePanel(AlignViewport av, String type, String pwtype)
\r
61 this.setMenuBar(jMenuBar1);
\r
63 catch (Exception ex)
\r
65 ex.printStackTrace();
\r
68 initTreePanel(av, type, pwtype, null);
\r
72 * Creates a new TreePanel object.
\r
74 * @param av DOCUMENT ME!
\r
75 * @param seqVector DOCUMENT ME!
\r
76 * @param newtree DOCUMENT ME!
\r
77 * @param type DOCUMENT ME!
\r
78 * @param pwtype DOCUMENT ME!
\r
80 public TreePanel(AlignViewport av,
\r
88 this.setMenuBar(jMenuBar1);
\r
92 e.printStackTrace();
\r
95 initTreePanel(av, type, pwtype, newtree);
\r
98 void initTreePanel(AlignViewport av,
\r
101 NewickFile newTree)
\r
106 this.pwtype = pwtype;
\r
108 treeCanvas = new TreeCanvas(av, scrollPane);
\r
109 scrollPane.add(treeCanvas);
\r
111 TreeLoader tl = new TreeLoader(newTree);
\r
116 void showOriginalData()
\r
118 // decide if av alignment is sufficiently different to original data to warrant a new window to be created
\r
119 // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
\r
120 // or create a selection box around columns in alignment view
\r
121 // test Alignment(SeqCigar[])
\r
122 if (tree.seqData != null)
\r
124 Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(av.
\r
125 getGapCharacter());
\r
127 if (alAndColsel != null && alAndColsel[0] != null)
\r
129 Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);
\r
130 AlignFrame af = new AlignFrame(al,
\r
132 "Original Data for Tree",
\r
135 af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1]);
\r
140 System.out.println("Original Tree Data not available");
\r
147 NewickFile newtree;
\r
148 jalview.datamodel.AlignmentView odata = null;
\r
150 public TreeLoader(NewickFile newtree)
\r
152 this.newtree = newtree;
\r
157 if (newtree != null)
\r
161 tree = new NJTree(av.alignment.getSequencesArray(),
\r
166 tree = new NJTree(av.alignment.getSequencesArray(), odata, newtree);
\r
174 AlignmentView seqStrings = av.getAlignmentView(av.getSelectionGroup() != null);
\r
175 if (av.getSelectionGroup() == null)
\r
178 end = av.alignment.getWidth();
\r
179 seqs = av.alignment.getSequencesArray();
\r
183 start = av.getSelectionGroup().getStartRes();
\r
184 end = av.getSelectionGroup().getEndRes() + 1;
\r
185 seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
\r
188 tree = new NJTree(seqs, seqStrings, type, pwtype, start, end);
\r
191 tree.reCount(tree.getTopNode());
\r
192 tree.findHeight(tree.getTopNode());
\r
193 treeCanvas.setTree(tree);
\r
194 if (newtree != null)
\r
196 distanceMenu.setState(newtree.HasDistances());
\r
197 bootstrapMenu.setState(newtree.HasBootstrap());
\r
198 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
\r
199 treeCanvas.setShowDistances(newtree.HasDistances());
\r
202 treeCanvas.repaint();
\r
204 av.setCurrentTree(tree);
\r
209 public void actionPerformed(ActionEvent evt)
\r
211 if (evt.getSource() == newickOutput)
\r
213 newickOutput_actionPerformed();
\r
215 else if (evt.getSource() == fontSize)
\r
217 fontSize_actionPerformed();
\r
219 else if (evt.getSource() == inputData)
\r
221 showOriginalData();
\r
225 public void itemStateChanged(ItemEvent evt)
\r
227 if (evt.getSource() == fitToWindow)
\r
229 treeCanvas.fitToWindow = fitToWindow.getState();
\r
232 else if (evt.getSource() == distanceMenu)
\r
234 treeCanvas.setShowDistances(distanceMenu.getState());
\r
237 else if (evt.getSource() == bootstrapMenu)
\r
239 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
\r
242 else if (evt.getSource() == placeholdersMenu)
\r
244 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
\r
247 treeCanvas.repaint();
\r
250 public void newickOutput_actionPerformed()
\r
252 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());
\r
253 String output = fout.print(false, true);
\r
254 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
\r
255 cap.setText(output);
\r
256 java.awt.Frame frame = new java.awt.Frame();
\r
258 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
\r
261 public java.awt.Font getTreeFont()
\r
263 return treeCanvas.font;
\r
266 public void setTreeFont(java.awt.Font font)
\r
268 treeCanvas.font = font;
\r
269 treeCanvas.repaint();
\r
272 protected void fontSize_actionPerformed()
\r
274 if (treeCanvas == null)
\r
279 new FontChooser(this);
\r
282 BorderLayout borderLayout1 = new BorderLayout();
\r
283 protected ScrollPane scrollPane = new ScrollPane();
\r
284 MenuBar jMenuBar1 = new MenuBar();
\r
285 Menu jMenu2 = new Menu();
\r
286 protected MenuItem fontSize = new MenuItem();
\r
287 protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem();
\r
288 protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem();
\r
289 protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem();
\r
290 protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem();
\r
291 Menu fileMenu = new Menu();
\r
292 MenuItem newickOutput = new MenuItem();
\r
293 MenuItem inputData = new MenuItem();
\r
295 private void jbInit()
\r
298 setLayout(borderLayout1);
\r
299 this.setBackground(Color.white);
\r
300 this.setFont(new java.awt.Font("Verdana", 0, 12));
\r
301 jMenu2.setLabel("View");
\r
302 fontSize.setLabel("Font...");
\r
303 fontSize.addActionListener(this);
\r
304 bootstrapMenu.setLabel("Show Bootstrap Values");
\r
305 bootstrapMenu.addItemListener(this);
\r
306 distanceMenu.setLabel("Show Distances");
\r
307 distanceMenu.addItemListener(this);
\r
308 placeholdersMenu.setLabel("Mark Unassociated Leaves");
\r
309 placeholdersMenu.addItemListener(this);
\r
310 fitToWindow.setState(true);
\r
311 fitToWindow.setLabel("Fit To Window");
\r
312 fitToWindow.addItemListener(this);
\r
313 fileMenu.setLabel("File");
\r
314 newickOutput.setLabel("Newick Format");
\r
315 newickOutput.addActionListener(this);
\r
316 inputData.setLabel("Input Data...");
\r
318 add(scrollPane, BorderLayout.CENTER);
\r
319 jMenuBar1.add(fileMenu);
\r
320 jMenuBar1.add(jMenu2);
\r
321 jMenu2.add(fitToWindow);
\r
322 jMenu2.add(fontSize);
\r
323 jMenu2.add(distanceMenu);
\r
324 jMenu2.add(bootstrapMenu);
\r
325 jMenu2.add(placeholdersMenu);
\r
326 fileMenu.add(newickOutput);
\r
327 fileMenu.add(inputData);
\r
328 inputData.addActionListener(this);
\r