X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fappletgui%2FTreeCanvas.java;h=e3f6c3cd0911a241b955545d8d6d968df4ac1e28;hb=c23f28e21e50f93f6e695bdc86247f2700c35869;hp=434ad60c49393a23382c03f936a9108bf1328242;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 434ad60..e3f6c3c 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -37,15 +37,13 @@ public class TreeCanvas AlignViewport av; public static final String PLACEHOLDER = " * "; Font font; - int fontSize = 12; - boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; boolean markPlaceholders = false; int offx = 20; - int offy = 20; + int offy; float threshold; @@ -59,18 +57,15 @@ public class TreeCanvas Hashtable nameHash = new Hashtable(); Hashtable nodeHash = new Hashtable(); - public TreeCanvas(AlignViewport av, NJTree tree, ScrollPane scroller, - String label) + public TreeCanvas(AlignViewport av, ScrollPane scroller) { this.av = av; - this.tree = tree; + font = av.getFont(); scrollPane = scroller; addMouseListener(this); - tree.findHeight(tree.getTopNode()); - longestName = label; setLayout(null); - PaintRefresher.Register(this); + PaintRefresher.Register(this, av.alignment); } public void TreeSelectionChanged(Sequence sequence) @@ -82,10 +77,10 @@ public class TreeCanvas av.setSelectionGroup(selected); } - selected.setEndRes(av.alignment.getWidth()); - selected.addOrRemove(sequence); + selected.setEndRes(av.alignment.getWidth()-1); + selected.addOrRemove(sequence, true); - PaintRefresher.Refresh(this); + PaintRefresher.Refresh(this, av.alignment); repaint(); } @@ -93,6 +88,30 @@ public class TreeCanvas { this.tree = tree; tree.findHeight(tree.getTopNode()); + + // Now have to calculate longest name based on the leaves + Vector leaves = tree.findLeaves(tree.getTopNode(), new Vector()); + boolean has_placeholders = false; + longestName = ""; + + for (int i = 0; i < leaves.size(); i++) + { + SequenceNode lf = (SequenceNode) leaves.elementAt(i); + + if (lf.isPlaceholder()) + { + has_placeholders = true; + } + + if (longestName.length() < ( (Sequence) lf.element()).getName() + .length()) + { + longestName = TreeCanvas.PLACEHOLDER + + ( (Sequence) lf.element()).getName(); + } + } + + setMarkPlaceholders(has_placeholders); } public void drawNode(Graphics g, SequenceNode node, float chunk, float scale, @@ -140,7 +159,7 @@ public class TreeCanvas String nodeLabel = ""; if (showDistances && node.dist > 0) { - nodeLabel = new Format("%5.2f").form(node.dist); + nodeLabel = new Format("%-.2f").form(node.dist); } if (showBootstrap) { @@ -152,7 +171,7 @@ public class TreeCanvas } if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? @@ -161,7 +180,7 @@ public class TreeCanvas int charWidth = fm.stringWidth(name) + 3; int charHeight = fm.getHeight(); - Rectangle rect = new Rectangle(xend + 20, ypos - charHeight, + Rectangle rect = new Rectangle(xend + 10, ypos - charHeight, charWidth, charHeight); nameHash.put( (SequenceI) node.element(), rect); @@ -208,7 +227,7 @@ public class TreeCanvas 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), xstart+2, ypos - 2); } } @@ -260,7 +279,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; pickNode(pickBox, top, chunk, wscale, width, offx, offy); } @@ -276,9 +295,9 @@ public class TreeCanvas if (node.left() == null && node.right() == null) { float height = node.height; - float dist = node.dist; + //float dist = node.dist; - int xstart = (int) ( (height - dist) * scale) + offx; + //int xstart = (int) ( (height - dist) * scale) + offx; int xend = (int) (height * scale) + offx; int ypos = (int) (node.ycount * chunk) + offy; @@ -291,7 +310,7 @@ public class TreeCanvas SequenceGroup sg = av.getSelectionGroup(); if (sg != null) { - sg.addOrRemove(seq); + sg.addOrRemove(seq, true); } } } @@ -332,9 +351,12 @@ public class TreeCanvas public void paint(Graphics g) { - font = new Font("Verdana", Font.PLAIN, fontSize); + if(tree==null) + return; + g.setFont(font); + FontMetrics fm = g.getFontMetrics(font); if (nameHash.size() == 0) @@ -358,19 +380,10 @@ public class TreeCanvas scrollPane.validate(); } - public int getFontSize() - { - return fontSize; - } - - public void setFontSize(int fontSize) - { - this.fontSize = fontSize; - repaint(); - } public void draw(Graphics g, int width, int height) { + offy = font.getSize()+10; g.setColor(Color.white); g.fillRect(0, 0, width, height); @@ -386,7 +399,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy); @@ -424,7 +437,6 @@ public class TreeCanvas public void mousePressed(MouseEvent e) { - av.setCurrentTree(tree); int x = e.getX(); @@ -472,23 +484,43 @@ public class TreeCanvas Vector l = tree.findLeaves( (SequenceNode) tree.getGroups().elementAt( i), new Vector()); - SequenceGroup sg = null; + + Vector sequences = new Vector(); for (int j = 0; j < l.size(); j++) { - SequenceNode sn = (SequenceNode) l.elementAt(j); - if (sg == null) + SequenceI s1 = (SequenceI) ( (SequenceNode) l.elementAt(j)).element(); + if(!sequences.contains(s1)) + sequences.addElement(s1); + } + + ColourSchemeI cs = null; + + if (av.getGlobalColourScheme() != null) + { + if (av.getGlobalColourScheme() instanceof UserColourScheme) { - sg = new SequenceGroup("TreeGroup", av.getGlobalColourScheme(), true, true, false, - 0, av.alignment.getWidth()); - } + cs = new UserColourScheme( + ( (UserColourScheme) av.getGlobalColourScheme()).getColours()); - sg.addSequence( (Sequence) sn.element()); + } + else + cs = ColourSchemeProperty.getColour(sequences, + av.alignment.getWidth(), + ColourSchemeProperty.getColourName( + av.getGlobalColourScheme())); + + cs.setThreshold(av.getGlobalColourScheme().getThreshold(), + av.getIgnoreGapsConsensus()); } - if (av.getGlobalColourScheme() instanceof ConservationColourScheme) - { - ConservationColourScheme ccs = (ConservationColourScheme) av. - getGlobalColourScheme(); + SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup", + cs, true, true, + false, 0, av.alignment.getWidth()-1); + + + if ( av.getGlobalColourScheme()!=null + && av.getGlobalColourScheme().conservationApplied()) + { Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, sg.sequences, sg.getStartRes(), @@ -496,9 +528,9 @@ public class TreeCanvas c.calculate(); c.verdict(false, av.ConsPercGaps); - ccs = new ConservationColourScheme(c, ccs.cs); + cs.setConservation(c); - sg.cs = ccs; + sg.cs = cs; } @@ -508,7 +540,7 @@ public class TreeCanvas } } - PaintRefresher.Refresh(this); + PaintRefresher.Refresh(this, av.alignment); repaint(); }