X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FTreeCanvas.java;h=af1d752897a78d10b230306775b536db3ce67e06;hb=559b96a91b710f3f2e116790c9cf7e3aa6c76766;hp=15c4bfa9f62af1f7b952c2c92c6a03c15150d269;hpb=085727a32930d9a05becd66686ed001f50331bc6;p=jalview.git diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 15c4bfa..af1d752 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,15 +57,12 @@ 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, av.alignment); @@ -82,10 +77,9 @@ public class TreeCanvas av.setSelectionGroup(selected); } - selected.setEndRes(av.alignment.getWidth()); + selected.setEndRes(av.alignment.getWidth()-1); selected.addOrRemove(sequence, true); -System.out.println("called here"); PaintRefresher.Refresh(this, av.alignment); repaint(); } @@ -94,6 +88,30 @@ System.out.println("called here"); { 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, @@ -141,7 +159,7 @@ System.out.println("called here"); String nodeLabel = ""; if (showDistances && node.dist > 0) { - nodeLabel = new Format("%5.2f").form(node.dist); + nodeLabel = new Format("%-.2f").form(node.dist); } if (showBootstrap) { @@ -153,7 +171,7 @@ System.out.println("called here"); } if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? @@ -162,7 +180,7 @@ System.out.println("called here"); 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); @@ -170,7 +188,7 @@ System.out.println("called here"); // Colour selected leaves differently SequenceGroup selected = av.getSelectionGroup(); if (selected != null && - selected.sequences.contains( (SequenceI) node.element())) + selected.getSequences(false).contains( (SequenceI) node.element())) { g.setColor(Color.gray); @@ -209,7 +227,7 @@ System.out.println("called here"); 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); } } @@ -261,7 +279,7 @@ System.out.println("called here"); 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); } @@ -277,9 +295,9 @@ System.out.println("called here"); 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; @@ -333,9 +351,12 @@ System.out.println("called here"); 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) @@ -359,19 +380,10 @@ System.out.println("called here"); 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); @@ -387,7 +399,7 @@ System.out.println("called here"); 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); @@ -481,29 +493,45 @@ System.out.println("called here"); sequences.addElement(s1); } - ColourSchemeI cs = ColourSchemeProperty.getColour(sequences, av.alignment.getWidth(), - ColourSchemeProperty.getColourName(av.getGlobalColourScheme())); + ColourSchemeI cs = null; + 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()); + } SequenceGroup sg = new SequenceGroup(sequences, "TreeGroup", cs, true, true, - false, 0, av.alignment.getWidth()); + false, 0, av.alignment.getWidth()-1); - if (av.getGlobalColourScheme() instanceof ConservationColourScheme) - { - ConservationColourScheme ccs = (ConservationColourScheme) av. - getGlobalColourScheme(); + if ( av.getGlobalColourScheme()!=null + && av.getGlobalColourScheme().conservationApplied()) + { Conservation c = new Conservation("Group", ResidueProperties.propHash, 3, - sg.sequences, sg.getStartRes(), + sg.getSequences(false), + sg.getStartRes(), sg.getEndRes()); c.calculate(); c.verdict(false, av.ConsPercGaps); - ccs = new ConservationColourScheme(c, ccs.cs); + cs.setConservation(c); - sg.cs = ccs; + sg.cs = cs; }