X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=70aeb60ea3a49bf40e68fb71d51b632c6189ca14;hb=d7d3a412210d013e401a3825eaf425fa55ce8106;hp=e89f4417cd4232ea2673a82c2628208e94f1e412;hpb=fdcfb775a9b255c4c09c9509bf35e7352b5d1f3a;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index e89f441..70aeb60 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 @@ -42,7 +42,7 @@ import javax.swing.*; * @version $Revision$ */ public class TreeCanvas extends JPanel implements MouseListener, Runnable, - Printable + Printable, MouseMotionListener { /** DOCUMENT ME!! */ public static final String PLACEHOLDER = " * "; @@ -61,10 +61,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, String longestName; int labelLength = -1; - //RubberbandRectangle rubberband; - Vector listeners; Hashtable nameHash = new Hashtable(); Hashtable nodeHash = new Hashtable(); + SequenceNode highlightNode; /** * Creates a new TreeCanvas object. @@ -80,6 +79,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, font = av.getFont(); scrollPane = scroller; addMouseListener(this); + addMouseMotionListener(this); PaintRefresher.Register(this, av.alignment); } @@ -89,7 +89,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * * @param sequence DOCUMENT ME! */ - public void TreeSelectionChanged(Sequence sequence) + public void treeSelectionChanged(SequenceI sequence) { SequenceGroup selected = av.getSelectionGroup(); @@ -101,9 +101,6 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, selected.setEndRes(av.alignment.getWidth()-1); selected.addOrRemove(sequence, true); - - PaintRefresher.Refresh(this, av.alignment); - repaint(); } /** @@ -195,7 +192,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (showDistances && (node.dist > 0)) { - nodeLabel = new Format("%5.2f").form(node.dist); + nodeLabel = new Format("%-.2f").form(node.dist); } if (showBootstrap) @@ -210,14 +207,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node.getName()) : node.getName(); int charWidth = fm.stringWidth(name) + 3; - int charHeight = fm.getHeight(); + int charHeight = font.getSize(); Rectangle rect = new Rectangle(xend+10, ypos-charHeight/2, charWidth, charHeight); @@ -228,7 +225,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, SequenceGroup selected = av.getSelectionGroup(); if ((selected != null) && - selected.sequences.contains((SequenceI) node.element())) + selected.getSequences(false).contains((SequenceI) node.element())) { g.setColor(Color.gray); @@ -258,7 +255,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, // Draw horizontal line g.drawLine(xstart, ypos, xend, ypos); - g.fillRect(xend - 2, ypos - 2, 4, 4); + if (node == highlightNode) + g.fillRect(xend - 3, ypos - 3, 6, 6); + else + g.fillRect(xend - 2, ypos - 2, 4, 4); int ystart = (int) (((SequenceNode) node.left()).ycount * chunk) + offy; @@ -273,8 +273,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (showDistances && (node.dist > 0)) { - g.drawString(new Format("%5.2f").form(node.dist), xstart, - ypos - 5); + g.drawString(new Format("%-.2f").form(node.dist).trim(), xstart+2, + ypos - 2); } } } @@ -587,7 +587,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g2.setFont(font); - offy = font.getSize()*2; + offy = font.getSize()+10; fm = g2.getFontMetrics(font); @@ -657,10 +657,60 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, * * @param e DOCUMENT ME! */ - public void mouseClicked(MouseEvent e) + public void mouseClicked(MouseEvent evt) { + if(highlightNode!=null) + { + if(evt.getClickCount()>1) + { + tree.swapNodes(highlightNode); + tree.reCount(tree.getTopNode()); + tree.findHeight(tree.getTopNode()); + } + else + { + Vector leaves = new Vector(); + tree.findLeaves(highlightNode, leaves); + + for (int i = 0; i < leaves.size(); i++) + { + SequenceI seq = + (SequenceI) ( (SequenceNode) leaves.elementAt(i)).element(); + treeSelectionChanged(seq); + } + } + + PaintRefresher.Refresh(this, av.alignment); + repaint(); + } } + + + public void mouseMoved(MouseEvent evt) + { + av.setCurrentTree(tree); + + Object ob = findElement(evt.getX(), evt.getY()); + + if (ob instanceof SequenceNode) + { + highlightNode = (SequenceNode) ob; + repaint(); + } + else + { + if (highlightNode != null) + { + highlightNode = null; + repaint(); + } + } + } + + public void mouseDragged(MouseEvent ect) + {} + /** * DOCUMENT ME! * @@ -677,19 +727,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (ob instanceof SequenceI) { - TreeSelectionChanged((Sequence) ob); - repaint(); - - return; + treeSelectionChanged( (Sequence) ob); + PaintRefresher.Refresh(this, av.alignment); + repaint(); + return; } - else if (ob instanceof SequenceNode) - { - SequenceNode tmpnode = (SequenceNode) ob; - tree.swapNodes(tmpnode); - tree.reCount(tree.getTopNode()); - tree.findHeight(tree.getTopNode()); - } - else + else if( !(ob instanceof SequenceNode) ) { // Find threshold if (tree.getMaxHeight() != 0) @@ -704,75 +747,84 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, av.setSelectionGroup(null); av.alignment.deleteAllGroups(); - 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)); - setColor((SequenceNode) tree.getGroups().elementAt(i), - col.brighter()); + colourGroups(); + } - Vector l = tree.findLeaves((SequenceNode) tree.getGroups() - .elementAt(i), - new Vector()); + PaintRefresher.Refresh(this, av.alignment); + repaint(); + } - Vector sequences = new Vector(); - for (int j = 0; j < l.size(); j++) - { - SequenceI s1 = (SequenceI) ((SequenceNode) l.elementAt(j)).element(); + } - if (!sequences.contains(s1)) - { - sequences.addElement(s1); - } - } + void colourGroups() + { + 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)); + setColor( (SequenceNode) tree.getGroups().elementAt(i), + col.brighter()); - ColourSchemeI cs = null; + Vector l = tree.findLeaves( (SequenceNode) tree.getGroups() + .elementAt(i), + new Vector()); - if (av.getGlobalColourScheme() != null) - { - if (av.getGlobalColourScheme() instanceof UserColourScheme) - { - cs = new UserColourScheme( - ( (UserColourScheme) av.getGlobalColourScheme()).getColours()); - - } - else - cs = ColourSchemeProperty.getColour(sequences, - av.alignment.getWidth(), - ColourSchemeProperty.getColourName( - av.getGlobalColourScheme())); - - cs.setThreshold(av.getGlobalColourScheme().getThreshold(), - av.getIgnoreGapsConsensus()); - } + Vector sequences = new Vector(); + for (int j = 0; j < l.size(); j++) + { + SequenceI s1 = (SequenceI) ( (SequenceNode) l.elementAt(j)).element(); + + if (!sequences.contains(s1)) + { + sequences.addElement(s1); + } + } - SequenceGroup sg = new SequenceGroup(sequences, - "TreeGroup", cs, true, true, false, 0, - av.alignment.getWidth()); + ColourSchemeI cs = null; + if (av.getGlobalColourScheme() != null) + { + if (av.getGlobalColourScheme() instanceof UserColourScheme) + { + cs = new UserColourScheme( + ( (UserColourScheme) av.getGlobalColourScheme()).getColours()); - if ( av.getGlobalColourScheme()!=null - && av.getGlobalColourScheme().conservationApplied()) - { - Conservation c = new Conservation("Group", - ResidueProperties.propHash, 3, sg.sequences, - sg.getStartRes(), sg.getEndRes()); + } + else + cs = ColourSchemeProperty.getColour(sequences, + av.alignment.getWidth(), + ColourSchemeProperty. + getColourName( + av.getGlobalColourScheme())); + + cs.setThreshold(av.getGlobalColourScheme().getThreshold(), + av.getIgnoreGapsConsensus()); + } - c.calculate(); - c.verdict(false, av.ConsPercGaps); - sg.cs.setConservation(c); - } + SequenceGroup sg = new SequenceGroup(sequences, + "TreeGroup", cs, true, true, false, + 0, + av.alignment.getWidth() - 1); - av.alignment.addGroup(sg); - } - } + if (av.getGlobalColourScheme() != null + && av.getGlobalColourScheme().conservationApplied()) + { + Conservation c = new Conservation("Group", + ResidueProperties.propHash, 3, + sg.getSequences(false), + sg.getStartRes(), sg.getEndRes()); + + c.calculate(); + c.verdict(false, av.ConsPercGaps); + sg.cs.setConservation(c); } - PaintRefresher.Refresh(this, av.alignment); - repaint(); + av.alignment.addGroup(sg); + } + } /**