X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FTreePanel.java;h=58da0748dcf176ace9c2f484eb36084f6dd3cf55;hb=fbec1b33d0fc169d72be059a5d2cf12b248270e1;hp=c33975b28f60003f6a3ec461c3e8f4e3e2e3327e;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index c33975b..58da074 100755 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -1,34 +1,35 @@ /* -* Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -*/ + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.appletgui; -import jalview.datamodel.*; -import jalview.io.NewickFile; -import jalview.analysis.*; -import jalview.jbappletgui.GTreePanel; -import java.awt.event.*; import java.util.*; -import jalview.io.NewickFile; +import java.awt.event.*; + +import jalview.analysis.*; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbappletgui.*; -public class TreePanel extends GTreePanel +public class TreePanel + extends GTreePanel { SequenceI[] seq; String type; @@ -44,7 +45,8 @@ public class TreePanel extends GTreePanel return tree; } - public TreePanel(AlignViewport av, Vector seqVector, String type, String pwtype, int s, int e) + public TreePanel(AlignViewport av, Vector seqVector, String type, + String pwtype, int s, int e) { super(); @@ -55,12 +57,14 @@ public class TreePanel extends GTreePanel end = e; String longestName = ""; - seq = new Sequence [seqVector.size()]; - for (int i=0;i < seqVector.size();i++) + seq = new Sequence[seqVector.size()]; + for (int i = 0; i < seqVector.size(); i++) { seq[i] = (Sequence) seqVector.elementAt(i); - if(seq[i].getName().length()>longestName.length()) + if (seq[i].getName().length() > longestName.length()) + { longestName = seq[i].getName(); + } } tree = new NJTree(seq, type, pwtype, start, end); @@ -72,49 +76,61 @@ public class TreePanel extends GTreePanel scrollPane.add(treeCanvas); } + public TreePanel(AlignViewport av, Vector seqVector, NewickFile newtree, String type, String pwtype) - { - super(); - // These are probably only arbitrary strings reflecting source of tree - this.type = type; - this.pwtype = pwtype; + { + super(); + // These are probably only arbitrary strings reflecting source of tree + this.type = type; + this.pwtype = pwtype; - start = 0; - end = seqVector.size(); + start = 0; + end = seqVector.size(); + + String longestName = ""; + seq = new Sequence[seqVector.size()]; + for (int i = 0; i < seqVector.size(); i++) + { + seq[i] = (Sequence) seqVector.elementAt(i); + } + // This constructor matches sequence names to treenodes and sets up the tree layouts. + tree = new NJTree(seq, newtree); + // Now have to calculate longest name based on the leaves + Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector()); - String longestName = ""; - seq = new Sequence [seqVector.size()]; - for (int i=0;i < seqVector.size();i++) + for (int i = 0; i < leaves.size(); i++) + { + if (longestName.length() < + ( (Sequence) ( (SequenceNode) leaves.elementAt(i)).element()).getName(). + length()) { - seq[i] = (Sequence) seqVector.elementAt(i); + longestName = TreeCanvas.PLACEHOLDER + + ( (Sequence) ( (SequenceNode) leaves.elementAt(i)).element()). + getName(); } - // This constructor matches sequence names to treenodes and sets up the tree layouts. - tree = new NJTree(seq, newtree); - // Now have to calculate longest name based on the leaves - Vector leaves = tree.findLeaves(tree.getTopNode(),new Vector()); - - for (int i=0;i < leaves.size();i++) - if (longestName.length()<((Sequence) ((SequenceNode) leaves.elementAt(i)).element()).getName().length()) - longestName = TreeCanvas.PLACEHOLDER+((Sequence) ((SequenceNode) leaves.elementAt(i)).element()).getName(); - - tree.reCount(tree.getTopNode()); - tree.findHeight(tree.getTopNode()); - - treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName); - treeCanvas.setShowBootstrap(newtree.HasBootstrap()); - treeCanvas.setShowDistances(newtree.HasDistances()); - distanceMenu.setState(newtree.HasDistances()); - bootstrapMenu.setState(newtree.HasBootstrap()); - if (true) // JBPNote TODO: preference for always marking placeholders in new associated tree - placeholdersMenu.setState(treeCanvas.markPlaceholders); - scrollPane.add(treeCanvas); + } + + tree.reCount(tree.getTopNode()); + tree.findHeight(tree.getTopNode()); + treeCanvas = new TreeCanvas(av, tree, scrollPane, longestName); + treeCanvas.setShowBootstrap(newtree.HasBootstrap()); + treeCanvas.setShowDistances(newtree.HasDistances()); + distanceMenu.setState(newtree.HasDistances()); + bootstrapMenu.setState(newtree.HasBootstrap()); + if (true) // JBPNote TODO: preference for always marking placeholders in new associated tree + { + placeholdersMenu.setState(treeCanvas.markPlaceholders); } + scrollPane.add(treeCanvas); -public String getText(String format) { - return null; -} + } + + public String getText(String format) + { + return null; + } protected void fitToWindow_actionPerformed(ActionEvent e) { @@ -130,33 +146,31 @@ public String getText(String format) { cap.setText(output); java.awt.Frame frame = new java.awt.Frame(); frame.add(cap); - jalview.bin.JalviewLite.addFrame(frame, type+" "+pwtype, 500,100); + jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100); } - - protected void fontSize_actionPerformed(ActionEvent e) { - /* if( treeCanvas==null ) - return; - - String size = fontSize.getLabel().substring( fontSize.getLabel().indexOf("-")+1); - - Object selection = JOptionPane.showInternalInputDialog(Desktop.desktop, - "Select font size", - "Font size", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"} - ,"Font Size - "+size); - if(selection!=null) - { - fontSize.setText("Font Size - " + selection); - - int i = Integer.parseInt(selection.toString()); - treeCanvas.setFontSize(i); - } - scrollPane.setViewportView(treeCanvas); -*/ + /* if( treeCanvas==null ) + return; + + String size = fontSize.getLabel().substring( fontSize.getLabel().indexOf("-")+1); + + Object selection = JOptionPane.showInternalInputDialog(Desktop.desktop, + "Select font size", + "Font size", + JOptionPane.QUESTION_MESSAGE, + null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"} + ,"Font Size - "+size); + if(selection!=null) + { + fontSize.setText("Font Size - " + selection); + + int i = Integer.parseInt(selection.toString()); + treeCanvas.setFontSize(i); + } + scrollPane.setViewportView(treeCanvas); + */ } protected void distanceMenu_actionPerformed(ActionEvent e) @@ -171,7 +185,7 @@ public String getText(String format) { protected void placeholdersMenu_actionPerformed(ActionEvent e) { - treeCanvas.setMarkPlaceholders(placeholdersMenu.getState()); + treeCanvas.setMarkPlaceholders(placeholdersMenu.getState()); } }