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, Vector seqVector, String type,
\r
58 String pwtype, int s, int e)
\r
63 this.setMenuBar(jMenuBar1);
\r
65 catch (Exception ex)
\r
67 ex.printStackTrace();
\r
70 initTreePanel(av, seqVector, type, pwtype, s, e, null);
\r
74 * Creates a new TreePanel object.
\r
76 * @param av DOCUMENT ME!
\r
77 * @param seqVector DOCUMENT ME!
\r
78 * @param newtree DOCUMENT ME!
\r
79 * @param type DOCUMENT ME!
\r
80 * @param pwtype DOCUMENT ME!
\r
82 public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree,
\r
83 String type, String pwtype)
\r
88 this.setMenuBar(jMenuBar1);
\r
92 e.printStackTrace();
\r
95 initTreePanel(av, seqVector, type, pwtype, 0, seqVector.size(), newtree);
\r
99 void initTreePanel(AlignViewport av, Vector seqVector, String type,
\r
100 String pwtype, int s, int e, NewickFile newTree)
\r
105 this.pwtype = pwtype;
\r
110 seq = new Sequence[seqVector.size()];
\r
111 for(int i=0; i<seqVector.size(); i++)
\r
112 seq[i] = (SequenceI)seqVector.elementAt(i);
\r
115 treeCanvas = new TreeCanvas(av, scrollPane);
\r
116 scrollPane.add(treeCanvas);
\r
119 TreeLoader tl = new TreeLoader(newTree);
\r
124 class TreeLoader extends Thread
\r
126 NewickFile newtree;
\r
128 public TreeLoader(NewickFile newtree)
\r
130 this.newtree = newtree;
\r
136 tree = new NJTree(seq, newtree);
\r
138 tree = new NJTree(seq, type, pwtype, start, end);
\r
140 tree.reCount(tree.getTopNode());
\r
141 tree.findHeight(tree.getTopNode());
\r
142 treeCanvas.setTree(tree);
\r
145 distanceMenu.setState(newtree.HasDistances());
\r
146 bootstrapMenu.setState(newtree.HasBootstrap());
\r
147 treeCanvas.setShowBootstrap(newtree.HasBootstrap());
\r
148 treeCanvas.setShowDistances(newtree.HasDistances());
\r
152 treeCanvas.repaint();
\r
154 av.setCurrentTree(tree);
\r
159 public void actionPerformed(ActionEvent evt)
\r
161 if(evt.getSource()==newickOutput)
\r
162 newickOutput_actionPerformed();
\r
163 else if(evt.getSource()==fontSize)
\r
164 fontSize_actionPerformed();
\r
167 public void itemStateChanged(ItemEvent evt)
\r
169 if(evt.getSource()==fitToWindow)
\r
170 treeCanvas.fitToWindow = fitToWindow.getState();
\r
172 else if(evt.getSource()==distanceMenu)
\r
173 treeCanvas.setShowDistances(distanceMenu.getState());
\r
175 else if(evt.getSource()==bootstrapMenu)
\r
176 treeCanvas.setShowBootstrap(bootstrapMenu.getState());
\r
178 else if(evt.getSource()==placeholdersMenu)
\r
179 treeCanvas.setMarkPlaceholders(placeholdersMenu.getState());
\r
181 treeCanvas.repaint();
\r
185 public void newickOutput_actionPerformed()
\r
187 jalview.io.NewickFile fout = new jalview.io.NewickFile(tree.getTopNode());
\r
188 String output = fout.print(false, true);
\r
189 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
\r
190 cap.setText(output);
\r
191 java.awt.Frame frame = new java.awt.Frame();
\r
193 jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100);
\r
196 public java.awt.Font getTreeFont()
\r
198 return treeCanvas.font;
\r
201 public void setTreeFont(java.awt.Font font)
\r
203 treeCanvas.font = font;
\r
204 treeCanvas.repaint();
\r
207 protected void fontSize_actionPerformed()
\r
209 if( treeCanvas==null )
\r
212 new FontChooser(this);
\r
216 BorderLayout borderLayout1 = new BorderLayout();
\r
217 protected ScrollPane scrollPane = new ScrollPane();
\r
218 MenuBar jMenuBar1 = new MenuBar();
\r
219 Menu jMenu2 = new Menu();
\r
220 protected MenuItem fontSize = new MenuItem();
\r
221 protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem();
\r
222 protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem();
\r
223 protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem();
\r
224 protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem();
\r
225 Menu fileMenu = new Menu();
\r
226 MenuItem newickOutput = new MenuItem();
\r
228 private void jbInit() throws Exception {
\r
229 setLayout(borderLayout1);
\r
230 this.setBackground(Color.white);
\r
231 this.setFont(new java.awt.Font("Verdana", 0, 12));
\r
232 jMenu2.setLabel("View");
\r
233 fontSize.setLabel("Font...");
\r
234 fontSize.addActionListener(this);
\r
235 bootstrapMenu.setLabel("Show Bootstrap Values");
\r
236 bootstrapMenu.addItemListener(this);
\r
237 distanceMenu.setLabel("Show Distances");
\r
238 distanceMenu.addItemListener(this);
\r
239 placeholdersMenu.setLabel("Mark Unassociated Leaves");
\r
240 placeholdersMenu.addItemListener(this);
\r
241 fitToWindow.setState(true);
\r
242 fitToWindow.setLabel("Fit To Window");
\r
243 fitToWindow.addItemListener(this);
\r
244 fileMenu.setLabel("File");
\r
245 newickOutput.setLabel("Newick Format");
\r
246 newickOutput.addActionListener(this);
\r
248 add(scrollPane, BorderLayout.CENTER);
\r
249 jMenuBar1.add(fileMenu);
\r
250 jMenuBar1.add(jMenu2);
\r
251 jMenu2.add(fitToWindow);
\r
252 jMenu2.add(fontSize);
\r
253 jMenu2.add(distanceMenu);
\r
254 jMenu2.add(bootstrapMenu);
\r
255 jMenu2.add(placeholdersMenu);
\r
256 fileMenu.add(newickOutput);
\r