X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=c5650f5a973013c65c436c11991d76b7bd60a390;hb=9493ac8f3b6a02d3cf9747ed6c0d6cf407d284e8;hp=29626fe21538af77d3e715f8412e6f93192e461e;hpb=e3bd0a071f26eed0ab8448c326fa7574c5da0572;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 29626fe..c5650f5 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -1,20 +1,22 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) + * Copyright (C) 2014 The Jalview Authors * - * 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 file is part of Jalview. * - * 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. + * 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.gui; @@ -86,13 +88,13 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * Creates a new TreeCanvas object. * * @param av - * DOCUMENT ME! + * DOCUMENT ME! * @param tree - * DOCUMENT ME! + * DOCUMENT ME! * @param scroller - * DOCUMENT ME! + * DOCUMENT ME! * @param label - * DOCUMENT ME! + * DOCUMENT ME! */ public TreeCanvas(TreePanel tp, AlignmentPanel ap, JScrollPane scroller) { @@ -110,7 +112,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param sequence - * DOCUMENT ME! + * DOCUMENT ME! */ public void treeSelectionChanged(SequenceI sequence) { @@ -126,7 +128,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, aps[a].av.setSelectionGroup(selected); } - selected.setEndRes(aps[a].av.alignment.getWidth() - 1); + selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1); selected.addOrRemove(sequence, true); } } @@ -135,7 +137,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param tree - * DOCUMENT ME! + * DOCUMENT ME! */ public void setTree(NJTree tree) { @@ -171,19 +173,19 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param g - * DOCUMENT ME! + * DOCUMENT ME! * @param node - * DOCUMENT ME! + * DOCUMENT ME! * @param chunk - * DOCUMENT ME! + * DOCUMENT ME! * @param scale - * DOCUMENT ME! + * DOCUMENT ME! * @param width - * DOCUMENT ME! + * DOCUMENT ME! * @param offx - * DOCUMENT ME! + * DOCUMENT ME! * @param offy - * DOCUMENT ME! + * DOCUMENT ME! */ public void drawNode(Graphics g, SequenceNode node, float chunk, float scale, int width, int offx, int offy) @@ -248,8 +250,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node - .getName()) - : node.getName(); + .getName()) : node.getName(); int charWidth = fm.stringWidth(name) + 3; int charHeight = font.getSize(); @@ -341,9 +342,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param x - * DOCUMENT ME! + * DOCUMENT ME! * @param y - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! */ @@ -384,7 +385,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param pickBox - * DOCUMENT ME! + * DOCUMENT ME! */ public void pickNodes(Rectangle pickBox) { @@ -411,19 +412,19 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param pickBox - * DOCUMENT ME! + * DOCUMENT ME! * @param node - * DOCUMENT ME! + * DOCUMENT ME! * @param chunk - * DOCUMENT ME! + * DOCUMENT ME! * @param scale - * DOCUMENT ME! + * DOCUMENT ME! * @param width - * DOCUMENT ME! + * DOCUMENT ME! * @param offx - * DOCUMENT ME! + * DOCUMENT ME! * @param offy - * DOCUMENT ME! + * DOCUMENT ME! */ public void pickNode(Rectangle pickBox, SequenceNode node, float chunk, float scale, int width, int offx, int offy) @@ -470,9 +471,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param node - * DOCUMENT ME! + * DOCUMENT ME! * @param c - * DOCUMENT ME! + * DOCUMENT ME! */ public void setColor(SequenceNode node, Color c) { @@ -488,9 +489,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (node.element() instanceof SequenceI) { AlignmentPanel[] aps = getAssociatedPanels(); - for (int a = 0; a < aps.length; a++) + if (aps != null) { - aps[a].av.setSequenceColour((SequenceI) node.element(), c); + for (int a = 0; a < aps.length; a++) + { + aps[a].av.setSequenceColour((SequenceI) node.element(), c); + } } } } @@ -535,16 +539,16 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param pg - * DOCUMENT ME! + * DOCUMENT ME! * @param pf - * DOCUMENT ME! + * DOCUMENT ME! * @param pi - * DOCUMENT ME! + * DOCUMENT ME! * * @return DOCUMENT ME! * * @throws PrinterException - * DOCUMENT ME! + * DOCUMENT ME! */ public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException @@ -598,7 +602,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param g - * DOCUMENT ME! + * DOCUMENT ME! */ public void paintComponent(Graphics g) { @@ -607,7 +611,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (tree == null) { - g.drawString("Calculating tree....", 20, getHeight() / 2); + g.drawString(MessageManager.getString("label.calculating_tree") + + "....", 20, getHeight() / 2); } else { @@ -627,9 +632,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - setPreferredSize(new Dimension(scrollPane.getWidth(), fm - .getHeight() - * nameHash.size())); + setPreferredSize(new Dimension(scrollPane.getWidth(), + fm.getHeight() * nameHash.size())); draw(g, scrollPane.getWidth(), fm.getHeight() * nameHash.size()); } @@ -641,7 +645,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param fontSize - * DOCUMENT ME! + * DOCUMENT ME! */ public void setFont(Font font) { @@ -653,11 +657,11 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param g1 - * DOCUMENT ME! + * DOCUMENT ME! * @param width - * DOCUMENT ME! + * DOCUMENT ME! * @param height - * DOCUMENT ME! + * DOCUMENT ME! */ public void draw(Graphics g1, int width, int height) { @@ -666,9 +670,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.white); g2.fillRect(0, 0, width, height); - g2.setFont(font); + if (longestName == null || tree == null) + { + g2.drawString("Calculating tree.", 20, 20); + } offy = font.getSize() + 10; fm = g2.getFontMetrics(font); @@ -711,7 +718,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void mouseReleased(MouseEvent e) { @@ -721,7 +728,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void mouseEntered(MouseEvent e) { @@ -731,7 +738,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void mouseExited(MouseEvent e) { @@ -741,7 +748,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void mouseClicked(MouseEvent evt) { @@ -750,7 +757,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (SwingUtilities.isRightMouseButton(evt)) { Color col = JColorChooser.showDialog(this, - "Select Sub-Tree Colour", highlightNode.color); + MessageManager.getString("label.select_subtree_colour"), highlightNode.color); if (col != null) { setColor(highlightNode, col); @@ -790,9 +797,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (ob instanceof SequenceNode) { highlightNode = (SequenceNode) ob; - this.setToolTipText("Left click to select leaves" - + "
Double-click to invert leaves" - + "
Right click to change colour"); + this.setToolTipText("" + + MessageManager.getString("label.highlightnode")); repaint(); } @@ -815,7 +821,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void mousePressed(MouseEvent e) { @@ -851,8 +857,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, for (int a = 0; a < aps.length; a++) { aps[a].av.setSelectionGroup(null); - aps[a].av.alignment.deleteAllGroups(); - aps[a].av.sequenceColours = null; + aps[a].av.getAlignment().deleteAllGroups(); + aps[a].av.clearSequenceColours(); } colourGroups(); } @@ -865,14 +871,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, void colourGroups() { + AlignmentPanel[] aps = getAssociatedPanels(); for (int i = 0; i < tree.getGroups().size(); i++) { - Color col = new Color((int) (Math.random() * 255), (int) (Math - .random() * 255), (int) (Math.random() * 255)); + Color col = new Color((int) (Math.random() * 255), + (int) (Math.random() * 255), (int) (Math.random() * 255)); setColor((SequenceNode) tree.getGroups().elementAt(i), col.brighter()); - Vector l = tree.findLeaves((SequenceNode) tree.getGroups().elementAt( - i), new Vector()); + Vector l = tree.findLeaves( + (SequenceNode) tree.getGroups().elementAt(i), new Vector()); Vector sequences = new Vector(); @@ -888,49 +895,58 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } ColourSchemeI cs = null; + SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true, + false, 0, av.getAlignment().getWidth() - 1); if (av.getGlobalColourScheme() != null) { if (av.getGlobalColourScheme() instanceof UserColourScheme) { - cs = new UserColourScheme(((UserColourScheme) av - .getGlobalColourScheme()).getColours()); + cs = new UserColourScheme( + ((UserColourScheme) av.getGlobalColourScheme()) + .getColours()); } else { - cs = ColourSchemeProperty.getColour(sequences, av.alignment - .getWidth(), ColourSchemeProperty.getColourName(av - .getGlobalColourScheme())); + cs = ColourSchemeProperty.getColour(sg, ColourSchemeProperty + .getColourName(av.getGlobalColourScheme())); + } + // cs is null if shading is an annotationColourGradient + if (cs != null) + { + cs.setThreshold(av.getGlobalColourScheme().getThreshold(), + av.getIgnoreGapsConsensus()); } - - cs.setThreshold(av.getGlobalColourScheme().getThreshold(), av - .getIgnoreGapsConsensus()); } - - SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true, - false, 0, av.alignment.getWidth() - 1); - + sg.cs = cs; + // sg.recalcConservation(); sg.setName("JTreeGroup:" + sg.hashCode()); sg.setIdColour(col); - AlignmentPanel[] aps = getAssociatedPanels(); for (int a = 0; a < aps.length; a++) { if (aps[a].av.getGlobalColourScheme() != null && aps[a].av.getGlobalColourScheme().conservationApplied()) { Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg.getSequences(null), sg - .getStartRes(), sg.getEndRes()); + ResidueProperties.propHash, 3, sg.getSequences(null), + sg.getStartRes(), sg.getEndRes()); c.calculate(); - c.verdict(false, aps[a].av.ConsPercGaps); + c.verdict(false, aps[a].av.getConsPercGaps()); sg.cs.setConservation(c); } - aps[a].av.alignment.addGroup(sg); + aps[a].av.getAlignment().addGroup(new SequenceGroup(sg)); } } + // notify the panel to redo any group specific stuff. + for (int a = 0; a < aps.length; a++) + { + aps[a].updateAnnotation(); + // TODO: JAL-868 - need to ensure view colour change message is broadcast + // to any Jmols listening in + } } @@ -938,7 +954,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param state - * DOCUMENT ME! + * DOCUMENT ME! */ public void setShowDistances(boolean state) { @@ -950,7 +966,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param state - * DOCUMENT ME! + * DOCUMENT ME! */ public void setShowBootstrap(boolean state) { @@ -962,7 +978,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * DOCUMENT ME! * * @param state - * DOCUMENT ME! + * DOCUMENT ME! */ public void setMarkPlaceholders(boolean state) {