X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=57e652c03c3e899c4544fabce68d6024502c250e;hb=7cf75b5b379dd71b3480726419c7dc55d8e01f0e;hp=95245445ab65c83699fe41bb45dff109ab3966e8;hpb=a6cd54c46366acd8bc3350a79374b18f9eb0b240;p=jalview.git
diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java
index 9524544..57e652c 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,13 +42,14 @@ import javax.swing.*;
* @version $Revision$
*/
public class TreeCanvas extends JPanel implements MouseListener, Runnable,
- Printable
+ Printable, MouseMotionListener
{
/** DOCUMENT ME!! */
public static final String PLACEHOLDER = " * ";
NJTree tree;
JScrollPane scrollPane;
AlignViewport av;
+ AlignmentPanel ap;
Font font;
FontMetrics fm;
boolean fitToWindow = true;
@@ -61,10 +62,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.
@@ -74,13 +74,16 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
* @param scroller DOCUMENT ME!
* @param label DOCUMENT ME!
*/
- public TreeCanvas(AlignViewport av, JScrollPane scroller)
+ public TreeCanvas(AlignmentPanel ap, JScrollPane scroller)
{
- this.av = av;
+ this.av = ap.av;
+ this.ap = ap;
font = av.getFont();
scrollPane = scroller;
addMouseListener(this);
- PaintRefresher.Register(this, av.alignment);
+ addMouseMotionListener(this);
+ PaintRefresher.Register(this, ap.av.getSequenceSetId());
+ ToolTipManager.sharedInstance().registerComponent(this);
}
@@ -89,7 +92,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 +104,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();
}
/**
@@ -173,14 +173,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
if (node.element() instanceof SequenceI)
{
- if (((SequenceI) ((SequenceNode) node).element()).getColor() == Color.white)
+ SequenceI seq = (SequenceI)((SequenceNode) node).element();
+
+ if (av.getSequenceColour(seq) == Color.white)
{
g.setColor(Color.black);
}
else
{
- g.setColor(((SequenceI) ((SequenceNode) node).element()).getColor()
- .darker());
+ g.setColor(av.getSequenceColour(seq).darker());
}
}
else
@@ -195,7 +196,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
if (showDistances && (node.dist > 0))
{
- nodeLabel = new Format("%5.2f").form(node.dist).trim();
+ nodeLabel = new Format("%-.2f").form(node.dist);
}
if (showBootstrap)
@@ -228,7 +229,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 +259,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,7 +277,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
if (showDistances && (node.dist > 0))
{
- g.drawString(new Format("%5.2f").form(node.dist).trim(), xstart+2,
+ g.drawString(new Format("%-.2f").form(node.dist).trim(), xstart+2,
ypos - 2);
}
}
@@ -416,7 +420,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
if (node.element() instanceof SequenceI)
{
- ((SequenceI) node.element()).setColor(c);
+ av.setSequenceColour((SequenceI) node.element(), c);
}
}
else
@@ -657,10 +661,74 @@ 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 (SwingUtilities.isRightMouseButton(evt))
+ {
+ Color col = JColorChooser.showDialog(this, "Select Background Colour",
+ highlightNode.color);
+
+ setColor(highlightNode, col);
+ }
+ else
+ 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.getSequenceSetId());
+ repaint();
+ }
}
+
+
+ public void mouseMoved(MouseEvent evt)
+ {
+ av.setCurrentTree(tree);
+
+ Object ob = findElement(evt.getX(), evt.getY());
+
+ if (ob instanceof SequenceNode)
+ {
+ highlightNode = (SequenceNode) ob;
+ this.setToolTipText(
+ "Left click to select leaves"
+ + "
Double-click to invert leaves"
+ + "
Right click to change colour");
+ repaint();
+
+ }
+ else
+ {
+ if (highlightNode != null)
+ {
+ highlightNode = null;
+ setToolTipText(null);
+ repaint();
+ }
+ }
+ }
+
+ public void mouseDragged(MouseEvent ect)
+ {}
+
/**
* DOCUMENT ME!
*
@@ -677,19 +745,12 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
if (ob instanceof SequenceI)
{
- TreeSelectionChanged((Sequence) ob);
- repaint();
-
- return;
- }
- else if (ob instanceof SequenceNode)
- {
- SequenceNode tmpnode = (SequenceNode) ob;
- tree.swapNodes(tmpnode);
- tree.reCount(tree.getTopNode());
- tree.findHeight(tree.getTopNode());
+ treeSelectionChanged( (Sequence) ob);
+ PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
+ repaint();
+ return;
}
- else
+ else if( !(ob instanceof SequenceNode) )
{
// Find threshold
if (tree.getMaxHeight() != 0)
@@ -703,76 +764,86 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
av.setSelectionGroup(null);
av.alignment.deleteAllGroups();
+ av.sequenceColours.clear();
- 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, ap.av.getSequenceSetId());
+ 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);
+ }
+
}
/**