X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreePanel.java;h=d8253db879df6c4548097bf52eade01af91bee94;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=3bb910807ca54f4ac22f8ff6d43574f0a1b6c3cc;hpb=7b3241c464d774516c4295a5023f4aef7939298e;p=jalview.git diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 3bb9108..d8253db 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -1,613 +1,830 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 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 (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * + * This file is part of Jalview. + * + * Jalview 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 3 of the License, or (at your option) any later version. + * + * Jalview 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 Jalview. If not, see . */ package jalview.gui; -import jalview.analysis.*; - -import jalview.datamodel.*; - -import jalview.io.*; - -import jalview.jbgui.*; - -import org.jibble.epsgraphics.*; +import java.beans.*; +import java.io.*; +import java.util.*; +import javax.imageio.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; - -import java.io.*; - -import java.util.*; - import javax.swing.*; -import javax.imageio.*; - -import java.beans.PropertyChangeEvent; +import org.jibble.epsgraphics.*; +import jalview.analysis.*; +import jalview.commands.CommandI; +import jalview.commands.OrderCommand; +import jalview.datamodel.*; +import jalview.io.*; +import jalview.jbgui.*; /** * DOCUMENT ME! - * + * * @author $author$ * @version $Revision$ */ public class TreePanel extends GTreePanel { - String type; - String pwtype; - TreeCanvas treeCanvas; - NJTree tree; - AlignViewport av; - - /** - * Creates a new TreePanel object. - * - * @param av DOCUMENT ME! - * @param seqVector DOCUMENT ME! - * @param type DOCUMENT ME! - * @param pwtype DOCUMENT ME! - * @param s DOCUMENT ME! - * @param e DOCUMENT ME! - */ - public TreePanel(AlignmentPanel ap, String type, String pwtype) + String type; + + String pwtype; + + TreeCanvas treeCanvas; + + NJTree tree; + + AlignViewport av; + + /** + * Creates a new TreePanel object. + * + * @param av + * DOCUMENT ME! + * @param seqVector + * DOCUMENT ME! + * @param type + * DOCUMENT ME! + * @param pwtype + * DOCUMENT ME! + * @param s + * DOCUMENT ME! + * @param e + * DOCUMENT ME! + */ + public TreePanel(AlignmentPanel ap, String type, String pwtype) + { + super(); + initTreePanel(ap, type, pwtype, null, null); + + // We know this tree has distances. JBPNote TODO: prolly should add this as + // a userdefined default + // showDistances(true); + } + + /** + * Creates a new TreePanel object. + * + * @param av + * DOCUMENT ME! + * @param seqVector + * DOCUMENT ME! + * @param newtree + * DOCUMENT ME! + * @param type + * DOCUMENT ME! + * @param pwtype + * DOCUMENT ME! + */ + public TreePanel(AlignmentPanel ap, String type, String pwtype, + NewickFile newtree) + { + super(); + initTreePanel(ap, type, pwtype, newtree, null); + } + + public TreePanel(AlignmentPanel av, String type, String pwtype, + NewickFile newtree, AlignmentView inputData) + { + super(); + initTreePanel(av, type, pwtype, newtree, inputData); + } + + public AlignmentI getAlignment() + { + return treeCanvas.av.getAlignment(); + } + + public AlignViewport getViewPort() + { + return treeCanvas.av; + } + + void initTreePanel(AlignmentPanel ap, String type, String pwtype, + NewickFile newTree, AlignmentView inputData) + { + + av = ap.av; + this.type = type; + this.pwtype = pwtype; + + treeCanvas = new TreeCanvas(this, ap, scrollPane); + scrollPane.setViewportView(treeCanvas); + + PaintRefresher.Register(this, ap.av.getSequenceSetId()); + + buildAssociatedViewMenu(); + + av.addPropertyChangeListener(new java.beans.PropertyChangeListener() { - super(); - initTreePanel(ap, type, pwtype, null, null); + public void propertyChange(PropertyChangeEvent evt) + { + if (evt.getPropertyName().equals("alignment")) + { + if (tree == null) + { + System.out.println("tree is null"); + // TODO: deal with case when a change event is received whilst a + // tree is still being calculated - should save reference for + // processing message later. + return; + } + if (evt.getNewValue() == null) + { + System.out + .println("new alignment sequences vector value is null"); + } - // We know this tree has distances. JBPNote TODO: prolly should add this as a userdefined default - // showDistances(true); - } + tree.UpdatePlaceHolders((Vector) evt.getNewValue()); + treeCanvas.nameHash.clear(); // reset the mapping between canvas + // rectangles and leafnodes + repaint(); + } + } + }); - /** - * Creates a new TreePanel object. - * - * @param av DOCUMENT ME! - * @param seqVector DOCUMENT ME! - * @param newtree DOCUMENT ME! - * @param type DOCUMENT ME! - * @param pwtype DOCUMENT ME! - */ - public TreePanel(AlignmentPanel ap, - String type, - String pwtype, - NewickFile newtree) + TreeLoader tl = new TreeLoader(newTree); + if (inputData != null) { - super(); - initTreePanel(ap, type, pwtype, newtree, null); + tl.odata = inputData; } + tl.start(); - public TreePanel(AlignmentPanel av, - String type, - String pwtype, - NewickFile newtree, AlignmentView inputData) { - super(); - initTreePanel(av,type,pwtype,newtree,inputData); - } + } - public AlignmentI getAlignment() - { - return treeCanvas.av.getAlignment(); - } - public AlignViewport getViewPort() { - return treeCanvas.av; - } + public void viewMenu_menuSelected() + { + buildAssociatedViewMenu(); + } - void initTreePanel(AlignmentPanel ap, String type, String pwtype, - NewickFile newTree, AlignmentView inputData) + void buildAssociatedViewMenu() + { + AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(av + .getSequenceSetId()); + if (aps.length == 1 && treeCanvas.ap == aps[0]) { + associateLeavesMenu.setVisible(false); + return; + } - av = ap.av; - this.type = type; - this.pwtype = pwtype; + associateLeavesMenu.setVisible(true); - buildAssociatedViewMenu(); + if ((viewMenu.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem)) + { + viewMenu.insertSeparator(viewMenu.getItemCount() - 1); + } - treeCanvas = new TreeCanvas(ap, scrollPane); - scrollPane.setViewportView(treeCanvas); + associateLeavesMenu.removeAll(); - av.addPropertyChangeListener(new java.beans.PropertyChangeListener() + JRadioButtonMenuItem item; + ButtonGroup buttonGroup = new ButtonGroup(); + int i, iSize = aps.length; + final TreePanel thisTreePanel = this; + for (i = 0; i < iSize; i++) + { + final AlignmentPanel ap = aps[i]; + item = new JRadioButtonMenuItem(ap.av.viewName, ap == treeCanvas.ap); + buttonGroup.add(item); + item.addActionListener(new ActionListener() { - public void propertyChange(PropertyChangeEvent evt) + public void actionPerformed(ActionEvent evt) { - if (evt.getPropertyName().equals("alignment")) - { - if(tree==null) - System.out.println("tree is null"); - if(evt.getNewValue()==null) - System.out.println("new alignment sequences vector value is null"); - - tree.UpdatePlaceHolders( (Vector) evt.getNewValue()); - treeCanvas.nameHash.clear(); // reset the mapping between canvas rectangles and leafnodes - repaint(); - } + treeCanvas.applyToAllViews = false; + treeCanvas.ap = ap; + treeCanvas.av = ap.av; + PaintRefresher.Register(thisTreePanel, ap.av.getSequenceSetId()); } }); - TreeLoader tl = new TreeLoader(newTree); - if (inputData!=null) { - tl.odata=inputData; - } - tl.start(); - + associateLeavesMenu.add(item); } - void buildAssociatedViewMenu() + final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem("All Views"); + buttonGroup.add(itemf); + itemf.setSelected(treeCanvas.applyToAllViews); + itemf.addActionListener(new ActionListener() { - AlignmentPanel [] aps = PaintRefresher.getAssociatedPanels(av.getSequenceSetId()); - if(aps.length<2) + public void actionPerformed(ActionEvent evt) { - associateLeavesMenu.setVisible(false); - return; + treeCanvas.applyToAllViews = itemf.isSelected(); } - associateLeavesMenu.addSeparator(); + }); + associateLeavesMenu.add(itemf); - JRadioButtonMenuItem item; - ButtonGroup buttonGroup = new ButtonGroup(); - int i, iSize = aps.length; - for(i=0; i