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 void showOriginalData()
\r
121 // decide if av alignment is sufficiently different to original data to warrant a new window to be created
\r
122 // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
\r
123 // or create a selection box around columns in alignment view
\r
124 // test Alignment(SeqCigar[])
\r
125 if(tree.seqData!=null)
\r
127 Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(av.
\r
128 getGapCharacter());
\r
130 if (alAndColsel != null && alAndColsel[0] != null)
\r
132 Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);
\r
133 AlignFrame af = new AlignFrame(al,
\r
135 "Original Data for Tree",
\r
138 af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1]);
\r
142 System.out.println("Original Tree Data not available");
\r
145 class TreeLoader extends Thread
\r
147 NewickFile newtree;
\r
148 jalview.datamodel.AlignmentView odata=null;
\r
150 public TreeLoader(NewickFile newtree)
\r
152 this.newtree = newtree;
\r
160 tree = new NJTree(av.alignment.getSequencesArray(),
\r
163 tree = new NJTree(av.alignment.getSequencesArray(), odata, newtree);
\r
170 AlignmentView seqStrings = av.getAlignmentView(av.getSelectionGroup()!=null);
\r
171 if(av.getSelectionGroup()==null)
\r
174 end = av.alignment.getWidth();
\r
175 seqs = av.alignment.getSequencesArray();
\r
179 start = av.getSelectionGroup().getStartRes();
\r
180 end = av.getSelectionGroup().getEndRes()+1;
\r
181 seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
\r
184 tree = new NJTree(seqs, seqStrings, type, pwtype, start, end);
\r
187 tree.reCount(tree.getTopNode());
\r
188 tree.findHeight(tree.getTopNode());
\r
189 treeCanvas.setTree(tree);
\r
192 distanceMenu.setState(newtree.HasDistances());
\r
193 bootstrapMenu.setState(newtree.HasBootstrap());
\r
194 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
\r
195 treeCanvas.setShowDistances(newtree.HasDistances());
\r
199 treeCanvas.repaint();
\r
201 av.setCurrentTree(tree);
\r
206 public void actionPerformed(ActionEvent evt)
\r
208 if(evt.getSource()==newickOutput)
\r
209 newickOutput_actionPerformed();
\r
210 else if(evt.getSource()==fontSize)
\r
211 fontSize_actionPerformed();
\r
212 else if(evt.getSource()==inputData)
\r
213 showOriginalData();
\r
216 public void itemStateChanged(ItemEvent evt)
\r
218 if(evt.getSource()==fitToWindow)
\r
219 treeCanvas.fitToWindow = fitToWindow.getState();
\r
221 else if(evt.getSource()==distanceMenu)
\r
222 treeCanvas.setShowDistances(distanceMenu.getState());
\r
224 else if(evt.getSource()==bootstrapMenu)
\r
225 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
\r
227 else if(evt.getSource()==placeholdersMenu)
\r
228 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
\r
230 treeCanvas.repaint();
\r
234 public void newickOutput_actionPerformed()
\r
236 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());
\r
237 String output = fout.print(false, true);
\r
238 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
\r
239 cap.setText(output);
\r
240 java.awt.Frame frame = new java.awt.Frame();
\r
242 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
\r
245 public java.awt.Font getTreeFont()
\r
247 return treeCanvas.font;
\r
250 public void setTreeFont(java.awt.Font font)
\r
252 treeCanvas.font = font;
\r
253 treeCanvas.repaint();
\r
256 protected void fontSize_actionPerformed()
\r
258 if( treeCanvas==null )
\r
261 new FontChooser(this);
\r
267 BorderLayout borderLayout1 = new BorderLayout();
\r
268 protected ScrollPane scrollPane = new ScrollPane();
\r
269 MenuBar jMenuBar1 = new MenuBar();
\r
270 Menu jMenu2 = new Menu();
\r
271 protected MenuItem fontSize = new MenuItem();
\r
272 protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem();
\r
273 protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem();
\r
274 protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem();
\r
275 protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem();
\r
276 Menu fileMenu = new Menu();
\r
277 MenuItem newickOutput = new MenuItem();
\r
278 MenuItem inputData = new MenuItem();
\r
280 private void jbInit() throws Exception {
\r
281 setLayout(borderLayout1);
\r
282 this.setBackground(Color.white);
\r
283 this.setFont(new java.awt.Font("Verdana", 0, 12));
\r
284 jMenu2.setLabel("View");
\r
285 fontSize.setLabel("Font...");
\r
286 fontSize.addActionListener(this);
\r
287 bootstrapMenu.setLabel("Show Bootstrap Values");
\r
288 bootstrapMenu.addItemListener(this);
\r
289 distanceMenu.setLabel("Show Distances");
\r
290 distanceMenu.addItemListener(this);
\r
291 placeholdersMenu.setLabel("Mark Unassociated Leaves");
\r
292 placeholdersMenu.addItemListener(this);
\r
293 fitToWindow.setState(true);
\r
294 fitToWindow.setLabel("Fit To Window");
\r
295 fitToWindow.addItemListener(this);
\r
296 fileMenu.setLabel("File");
\r
297 newickOutput.setLabel("Newick Format");
\r
298 newickOutput.addActionListener(this);
\r
299 inputData.setLabel("Input Data...");
\r
301 add(scrollPane, BorderLayout.CENTER);
\r
302 jMenuBar1.add(fileMenu);
\r
303 jMenuBar1.add(jMenu2);
\r
304 jMenu2.add(fitToWindow);
\r
305 jMenu2.add(fontSize);
\r
306 jMenu2.add(distanceMenu);
\r
307 jMenu2.add(bootstrapMenu);
\r
308 jMenu2.add(placeholdersMenu);
\r
309 fileMenu.add(newickOutput);
\r
310 fileMenu.add(inputData);
\r
311 inputData.addActionListener(this);
\r