X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Fappletgui%2FTreeCanvas.js;h=69da9f2fc087f4f04ea326941993e4a39fdc8879;hp=da76a3e560e72d4cf09305020eb67ad0853dec84;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/appletgui/TreeCanvas.js b/site/j2s/jalview/appletgui/TreeCanvas.js index da76a3e..69da9f2 100644 --- a/site/j2s/jalview/appletgui/TreeCanvas.js +++ b/site/j2s/jalview/appletgui/TreeCanvas.js @@ -1,375 +1,375 @@ -Clazz.declarePackage ("jalview.appletgui"); -Clazz.load (["awt2swing.Panel", "java.awt.event.MouseListener", "$.MouseMotionListener", "java.util.Hashtable"], "jalview.appletgui.TreeCanvas", ["jalview.analysis.Conservation", "jalview.appletgui.PaintRefresher", "jalview.datamodel.SequenceGroup", "$.SequenceI", "$.SequenceNode", "jalview.schemes.ColourSchemeProperty", "$.ResidueProperties", "$.UserColourScheme", "jalview.util.Format", "$.MappingUtils", "java.awt.Color", "$.Dimension", "$.Point", "$.Rectangle", "java.util.Vector"], function () { -c$ = Clazz.decorateAsClass (function () { -this.tree = null; -this.scrollPane = null; -this.av = null; -this.$font = null; -this.fitToWindow = true; -this.showDistances = false; -this.showBootstrap = false; -this.markPlaceholders = false; -this.offx = 20; -this.offy = 0; -this.threshold = 0; -this.longestName = null; -this.labelLength = -1; -this.nameHash = null; -this.nodeHash = null; -this.highlightNode = null; -this.ap = null; -Clazz.instantialize (this, arguments); -}, jalview.appletgui, "TreeCanvas", awt2swing.Panel, [java.awt.event.MouseListener, java.awt.event.MouseMotionListener]); -Clazz.prepareFields (c$, function () { -this.nameHash = new java.util.Hashtable (); -this.nodeHash = new java.util.Hashtable (); -}); -Clazz.makeConstructor (c$, -function (ap, scroller) { -Clazz.superConstructor (this, jalview.appletgui.TreeCanvas, []); -this.ap = ap; -this.av = ap.av; -this.$font = this.av.getFont (); -this.scrollPane = scroller; -this.addMouseListener (this); -this.addMouseMotionListener (this); -this.setLayout (null); -jalview.appletgui.PaintRefresher.Register (this, this.av.getSequenceSetId ()); -}, "jalview.appletgui.AlignmentPanel,awt2swing.ScrollPane"); -Clazz.defineMethod (c$, "treeSelectionChanged", -function (sequence) { -var selected = this.av.getSelectionGroup (); -if (selected == null) { -selected = new jalview.datamodel.SequenceGroup (); -this.av.setSelectionGroup (selected); -}selected.setEndRes (this.av.getAlignment ().getWidth () - 1); -selected.addOrRemove (sequence, true); -}, "jalview.datamodel.SequenceI"); -Clazz.defineMethod (c$, "setTree", -function (tree) { -this.tree = tree; -tree.findHeight (tree.getTopNode ()); -var leaves = tree.findLeaves (tree.getTopNode (), new java.util.Vector ()); -var has_placeholders = false; -this.longestName = ""; -for (var i = 0; i < leaves.size (); i++) { -var lf = leaves.elementAt (i); -if (lf.isPlaceholder ()) { -has_placeholders = true; -}if (this.longestName.length < (lf.element ()).getName ().length) { -this.longestName = " * " + (lf.element ()).getName (); -}} -this.setMarkPlaceholders (has_placeholders); -}, "jalview.analysis.NJTree"); -Clazz.defineMethod (c$, "drawNode", -function (g, node, chunk, scale, width, offx, offy) { -if (node == null) { -return; -}if (node.left () == null && node.right () == null) { -var height = node.height; -var dist = node.dist; -var xstart = Clazz.floatToInt ((height - dist) * scale) + offx; -var xend = Clazz.floatToInt (height * scale) + offx; -var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; -if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { -var seq = node.element (); -if (this.av.getSequenceColour (seq) === java.awt.Color.white) { -g.setColor (java.awt.Color.black); -} else { -g.setColor (this.av.getSequenceColour (seq).darker ()); -}} else { -g.setColor (java.awt.Color.black); -}g.drawLine (xstart, ypos, xend, ypos); -var nodeLabel = ""; -if (this.showDistances && node.dist > 0) { -nodeLabel = new jalview.util.Format ("%-.2f").formDouble (node.dist); -}if (this.showBootstrap) { -var btstrap = node.getBootstrap (); -if (btstrap > -1) { -if (this.showDistances) { -nodeLabel = nodeLabel + " : "; -}nodeLabel = nodeLabel + String.valueOf (node.getBootstrap ()); -}}if (!nodeLabel.equals ("")) { -g.drawString (nodeLabel, xstart + 2, ypos - 2); -}var name = (this.markPlaceholders && node.isPlaceholder ()) ? (" * " + node.getName ()) : node.getName (); -var fm = g.getFontMetrics (this.$font); -var charWidth = fm.stringWidth (name) + 3; -var charHeight = fm.getHeight (); -var rect = new java.awt.Rectangle (xend + 10, ypos - charHeight, charWidth, charHeight); -this.nameHash.put (node.element (), rect); -var selected = this.av.getSelectionGroup (); -if (selected != null && selected.getSequences (null).contains (node.element ())) { -g.setColor (java.awt.Color.gray); -g.fillRect (xend + 10, ypos - charHeight + 3, charWidth, charHeight); -g.setColor (java.awt.Color.white); -}g.drawString (name, xend + 10, ypos); -g.setColor (java.awt.Color.black); -} else { -this.drawNode (g, node.left (), chunk, scale, width, offx, offy); -this.drawNode (g, node.right (), chunk, scale, width, offx, offy); -var height = node.height; -var dist = node.dist; -var xstart = Clazz.floatToInt ((height - dist) * scale) + offx; -var xend = Clazz.floatToInt (height * scale) + offx; -var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; -g.setColor (node.color.darker ()); -g.drawLine (xstart, ypos, xend, ypos); -if (node === this.highlightNode) { -g.fillRect (xend - 3, ypos - 3, 6, 6); -} else { -g.fillRect (xend - 2, ypos - 2, 4, 4); -}var ystart = Clazz.floatToInt ((node.left ()).ycount * chunk) + offy; -var yend = Clazz.floatToInt ((node.right ()).ycount * chunk) + offy; -var pos = new java.awt.Rectangle (xend - 2, ypos - 2, 5, 5); -this.nodeHash.put (node, pos); -g.drawLine (Clazz.floatToInt (height * scale) + offx, ystart, Clazz.floatToInt (height * scale) + offx, yend); -var nodeLabel = ""; -if (this.showDistances && (node.dist > 0)) { -nodeLabel = new jalview.util.Format ("%-.2f").formDouble (node.dist); -}if (this.showBootstrap) { -var btstrap = node.getBootstrap (); -if (btstrap > -1) { -if (this.showDistances) { -nodeLabel = nodeLabel + " : "; -}nodeLabel = nodeLabel + String.valueOf (node.getBootstrap ()); -}}if (!nodeLabel.equals ("")) { -g.drawString (nodeLabel, xstart + 2, ypos - 2); -}}}, "java.awt.Graphics,jalview.datamodel.SequenceNode,~N,~N,~N,~N,~N"); -Clazz.defineMethod (c$, "findElement", -function (x, y) { -var keys = this.nameHash.keys (); -while (keys.hasMoreElements ()) { -var ob = keys.nextElement (); -var rect = this.nameHash.get (ob); -if (x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)) { -return ob; -}} -keys = this.nodeHash.keys (); -while (keys.hasMoreElements ()) { -var ob = keys.nextElement (); -var rect = this.nodeHash.get (ob); -if (x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)) { -return ob; -}} -return null; -}, "~N,~N"); -Clazz.defineMethod (c$, "pickNodes", -function (pickBox) { -var width = this.getSize ().width; -var height = this.getSize ().height; -var top = this.tree.getTopNode (); -var wscale = (width * .8 - this.offx * 2) / this.tree.getMaxHeight (); -if (top.count == 0) { -top.count = (top.left ()).count + (top.right ()).count; -}var chunk = (height - this.offy) / top.count; -this.pickNode (pickBox, top, chunk, wscale, width, this.offx, this.offy); -}, "java.awt.Rectangle"); -Clazz.defineMethod (c$, "pickNode", -function (pickBox, node, chunk, scale, width, offx, offy) { -if (node == null) { -return; -}if (node.left () == null && node.right () == null) { -var height = node.height; -var xend = Clazz.floatToInt (height * scale) + offx; -var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; -if (pickBox.contains ( new java.awt.Point (xend, ypos))) { -if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { -var seq = node.element (); -var sg = this.av.getSelectionGroup (); -if (sg != null) { -sg.addOrRemove (seq, true); -}}}} else { -this.pickNode (pickBox, node.left (), chunk, scale, width, offx, offy); -this.pickNode (pickBox, node.right (), chunk, scale, width, offx, offy); -}}, "java.awt.Rectangle,jalview.datamodel.SequenceNode,~N,~N,~N,~N,~N"); -Clazz.defineMethod (c$, "setColor", -function (node, c) { -if (node == null) { -return; -}if (node.left () == null && node.right () == null) { -node.color = c; -if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { -this.av.setSequenceColour (node.element (), c); -}} else { -node.color = c; -this.setColor (node.left (), c); -this.setColor (node.right (), c); -}}, "jalview.datamodel.SequenceNode,java.awt.Color"); -Clazz.overrideMethod (c$, "update", -function (g) { -this.paint (g); -}, "java.awt.Graphics"); -Clazz.overrideMethod (c$, "paintComponent", -function (g) { -if (this.tree == null) { -return; -}if (this.nameHash.size () == 0) { -this.repaint (); -}var width = this.scrollPane.getSize ().width; -var height = this.scrollPane.getSize ().height; -if (!this.fitToWindow) { -height = g.getFontMetrics (this.$font).getHeight () * this.nameHash.size (); -}if (this.getSize ().width > width) { -this.setSize ( new java.awt.Dimension (width, height)); -this.scrollPane.validate (); -return; -}this.setSize ( new java.awt.Dimension (width, height)); -g.setFont (this.$font); -this.draw (g, width, height); -this.validate (); -}, "java.awt.Graphics"); -Clazz.defineMethod (c$, "draw", -function (g, width, height) { -this.offy = this.$font.getSize () + 10; -g.setColor (java.awt.Color.white); -g.fillRect (0, 0, width, height); -this.labelLength = g.getFontMetrics (this.$font).stringWidth (this.longestName) + 20; -var wscale = (width - this.labelLength - this.offx * 2) / this.tree.getMaxHeight (); -var top = this.tree.getTopNode (); -if (top.count == 0) { -top.count = (top.left ()).count + (top.right ()).count; -}var chunk = (height - this.offy) / top.count; -this.drawNode (g, this.tree.getTopNode (), chunk, wscale, width, this.offx, this.offy); -if (this.threshold != 0) { -if (this.av.getCurrentTree () === this.tree) { -g.setColor (java.awt.Color.red); -} else { -g.setColor (java.awt.Color.gray); -}var x = Clazz.floatToInt (this.threshold * (this.getSize ().width - this.labelLength - 2 * this.offx) + this.offx); -g.drawLine (x, 0, x, this.getSize ().height); -}}, "java.awt.Graphics,~N,~N"); -Clazz.overrideMethod (c$, "mouseReleased", -function (e) { -}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mouseEntered", -function (e) { -}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mouseExited", -function (e) { -}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mouseClicked", -function (evt) { -if (this.highlightNode != null) { -if (evt.getClickCount () > 1) { -this.tree.swapNodes (this.highlightNode); -this.tree.reCount (this.tree.getTopNode ()); -this.tree.findHeight (this.tree.getTopNode ()); -} else { -var leaves = new java.util.Vector (); -this.tree.findLeaves (this.highlightNode, leaves); -for (var i = 0; i < leaves.size (); i++) { -var seq = (leaves.elementAt (i)).element (); -this.treeSelectionChanged (seq); -} -}jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); -this.repaint (); -this.av.sendSelection (); -}}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mouseDragged", -function (ect) { -}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mouseMoved", -function (evt) { -this.av.setCurrentTree (this.tree); -var ob = this.findElement (evt.getX (), evt.getY ()); -if (Clazz.instanceOf (ob, jalview.datamodel.SequenceNode)) { -this.highlightNode = ob; -this.repaint (); -} else { -if (this.highlightNode != null) { -this.highlightNode = null; -this.repaint (); -}}}, "java.awt.event.MouseEvent"); -Clazz.overrideMethod (c$, "mousePressed", -function (e) { -this.av.setCurrentTree (this.tree); -var x = e.getX (); -var y = e.getY (); -var ob = this.findElement (x, y); -if (Clazz.instanceOf (ob, jalview.datamodel.SequenceI)) { -this.treeSelectionChanged (ob); -jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); -this.repaint (); -this.av.sendSelection (); -return; -} else if (!(Clazz.instanceOf (ob, jalview.datamodel.SequenceNode))) { -if (this.tree.getMaxHeight () != 0) { -this.threshold = (x - this.offx) / (this.getSize ().width - this.labelLength - 2 * this.offx); -this.tree.getGroups ().removeAllElements (); -this.tree.groupNodes (this.tree.getTopNode (), this.threshold); -this.setColor (this.tree.getTopNode (), java.awt.Color.black); -this.av.setSelectionGroup (null); -this.av.getAlignment ().deleteAllGroups (); -this.av.clearSequenceColours (); -var codingComplement = this.av.getCodingComplement (); -if (codingComplement != null) { -codingComplement.setSelectionGroup (null); -codingComplement.getAlignment ().deleteAllGroups (); -codingComplement.clearSequenceColours (); -}this.colourGroups (); -}}jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); -this.repaint (); -}, "java.awt.event.MouseEvent"); -Clazz.defineMethod (c$, "colourGroups", -function () { -for (var i = 0; i < this.tree.getGroups ().size (); i++) { -var col = new java.awt.Color (Clazz.doubleToInt (Math.random () * 255), Clazz.doubleToInt (Math.random () * 255), Clazz.doubleToInt (Math.random () * 255)); -this.setColor (this.tree.getGroups ().elementAt (i), col.brighter ()); -var l = this.tree.findLeaves (this.tree.getGroups ().elementAt (i), new java.util.Vector ()); -var sequences = new java.util.Vector (); -for (var j = 0; j < l.size (); j++) { -var s1 = (l.elementAt (j)).element (); -if (!sequences.contains (s1)) { -sequences.addElement (s1); -}} -var cs = null; -var sg = new jalview.datamodel.SequenceGroup (sequences, "", cs, true, true, false, 0, this.av.getAlignment ().getWidth () - 1); -if (this.av.getGlobalColourScheme () != null) { -if (Clazz.instanceOf (this.av.getGlobalColourScheme (), jalview.schemes.UserColourScheme)) { -cs = new jalview.schemes.UserColourScheme ((this.av.getGlobalColourScheme ()).getColours ()); -} else { -cs = jalview.schemes.ColourSchemeProperty.getColour (sg, jalview.schemes.ColourSchemeProperty.getColourName (this.av.getGlobalColourScheme ())); -}if (cs != null) { -cs.setThreshold (this.av.getGlobalColourScheme ().getThreshold (), this.av.isIgnoreGapsConsensus ()); -}}sg.cs = cs; -sg.setName ("JTreeGroup:" + sg.hashCode ()); -sg.setIdColour (col); -if (this.av.getGlobalColourScheme () != null && this.av.getGlobalColourScheme ().conservationApplied ()) { -var c = new jalview.analysis.Conservation ("Group", jalview.schemes.ResidueProperties.propHash, 3, sg.getSequences (null), sg.getStartRes (), sg.getEndRes ()); -c.calculate (); -c.verdict (false, this.av.getConsPercGaps ()); -cs.setConservation (c); -sg.cs = cs; -}this.av.getAlignment ().addGroup (sg); -this.av.getAlignment ().addGroup (sg); -var codingComplement = this.av.getCodingComplement (); -if (codingComplement != null) { -var mappedGroup = jalview.util.MappingUtils.mapSequenceGroup (sg, this.av, codingComplement); -if (mappedGroup.getSequences ().size () > 0) { -codingComplement.getAlignment ().addGroup (mappedGroup); -for (var seq, $seq = mappedGroup.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { -codingComplement.setSequenceColour (seq, col); -} -}}} -this.ap.updateAnnotation (); -if (this.av.getCodingComplement () != null) { -(this.av.getCodingComplement ()).firePropertyChange ("alignment", null, this.ap.av.getAlignment ().getSequences ()); -}}); -Clazz.defineMethod (c$, "setShowDistances", -function (state) { -this.showDistances = state; -this.repaint (); -}, "~B"); -Clazz.defineMethod (c$, "setShowBootstrap", -function (state) { -this.showBootstrap = state; -this.repaint (); -}, "~B"); -Clazz.defineMethod (c$, "setMarkPlaceholders", -function (state) { -this.markPlaceholders = state; -this.repaint (); -}, "~B"); -Clazz.defineStatics (c$, -"PLACEHOLDER", " * "); -}); +Clazz.declarePackage ("jalview.appletgui"); +Clazz.load (["awt2swing.Panel", "java.awt.event.MouseListener", "$.MouseMotionListener", "java.util.Hashtable"], "jalview.appletgui.TreeCanvas", ["jalview.analysis.Conservation", "jalview.appletgui.PaintRefresher", "jalview.datamodel.SequenceGroup", "$.SequenceI", "$.SequenceNode", "jalview.schemes.ColourSchemeProperty", "$.ResidueProperties", "$.UserColourScheme", "jalview.util.Format", "$.MappingUtils", "java.awt.Color", "$.Dimension", "$.Point", "$.Rectangle", "java.util.Vector"], function () { +c$ = Clazz.decorateAsClass (function () { +this.tree = null; +this.scrollPane = null; +this.av = null; +this.$font = null; +this.fitToWindow = true; +this.showDistances = false; +this.showBootstrap = false; +this.markPlaceholders = false; +this.offx = 20; +this.offy = 0; +this.threshold = 0; +this.longestName = null; +this.labelLength = -1; +this.nameHash = null; +this.nodeHash = null; +this.highlightNode = null; +this.ap = null; +Clazz.instantialize (this, arguments); +}, jalview.appletgui, "TreeCanvas", awt2swing.Panel, [java.awt.event.MouseListener, java.awt.event.MouseMotionListener]); +Clazz.prepareFields (c$, function () { +this.nameHash = new java.util.Hashtable (); +this.nodeHash = new java.util.Hashtable (); +}); +Clazz.makeConstructor (c$, +function (ap, scroller) { +Clazz.superConstructor (this, jalview.appletgui.TreeCanvas, []); +this.ap = ap; +this.av = ap.av; +this.$font = this.av.getFont (); +this.scrollPane = scroller; +this.addMouseListener (this); +this.addMouseMotionListener (this); +this.setLayout (null); +jalview.appletgui.PaintRefresher.Register (this, this.av.getSequenceSetId ()); +}, "jalview.appletgui.AlignmentPanel,awt2swing.ScrollPane"); +Clazz.defineMethod (c$, "treeSelectionChanged", +function (sequence) { +var selected = this.av.getSelectionGroup (); +if (selected == null) { +selected = new jalview.datamodel.SequenceGroup (); +this.av.setSelectionGroup (selected); +}selected.setEndRes (this.av.getAlignment ().getWidth () - 1); +selected.addOrRemove (sequence, true); +}, "jalview.datamodel.SequenceI"); +Clazz.defineMethod (c$, "setTree", +function (tree) { +this.tree = tree; +tree.findHeight (tree.getTopNode ()); +var leaves = tree.findLeaves (tree.getTopNode (), new java.util.Vector ()); +var has_placeholders = false; +this.longestName = ""; +for (var i = 0; i < leaves.size (); i++) { +var lf = leaves.elementAt (i); +if (lf.isPlaceholder ()) { +has_placeholders = true; +}if (this.longestName.length < (lf.element ()).getName ().length) { +this.longestName = " * " + (lf.element ()).getName (); +}} +this.setMarkPlaceholders (has_placeholders); +}, "jalview.analysis.NJTree"); +Clazz.defineMethod (c$, "drawNode", +function (g, node, chunk, scale, width, offx, offy) { +if (node == null) { +return; +}if (node.left () == null && node.right () == null) { +var height = node.height; +var dist = node.dist; +var xstart = Clazz.floatToInt ((height - dist) * scale) + offx; +var xend = Clazz.floatToInt (height * scale) + offx; +var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; +if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { +var seq = node.element (); +if (this.av.getSequenceColour (seq) === java.awt.Color.white) { +g.setColor (java.awt.Color.black); +} else { +g.setColor (this.av.getSequenceColour (seq).darker ()); +}} else { +g.setColor (java.awt.Color.black); +}g.drawLine (xstart, ypos, xend, ypos); +var nodeLabel = ""; +if (this.showDistances && node.dist > 0) { +nodeLabel = new jalview.util.Format ("%-.2f").formDouble (node.dist); +}if (this.showBootstrap) { +var btstrap = node.getBootstrap (); +if (btstrap > -1) { +if (this.showDistances) { +nodeLabel = nodeLabel + " : "; +}nodeLabel = nodeLabel + String.valueOf (node.getBootstrap ()); +}}if (!nodeLabel.equals ("")) { +g.drawString (nodeLabel, xstart + 2, ypos - 2); +}var name = (this.markPlaceholders && node.isPlaceholder ()) ? (" * " + node.getName ()) : node.getName (); +var fm = g.getFontMetrics (this.$font); +var charWidth = fm.stringWidth (name) + 3; +var charHeight = fm.getHeight (); +var rect = new java.awt.Rectangle (xend + 10, ypos - charHeight, charWidth, charHeight); +this.nameHash.put (node.element (), rect); +var selected = this.av.getSelectionGroup (); +if (selected != null && selected.getSequences (null).contains (node.element ())) { +g.setColor (java.awt.Color.gray); +g.fillRect (xend + 10, ypos - charHeight + 3, charWidth, charHeight); +g.setColor (java.awt.Color.white); +}g.drawString (name, xend + 10, ypos); +g.setColor (java.awt.Color.black); +} else { +this.drawNode (g, node.left (), chunk, scale, width, offx, offy); +this.drawNode (g, node.right (), chunk, scale, width, offx, offy); +var height = node.height; +var dist = node.dist; +var xstart = Clazz.floatToInt ((height - dist) * scale) + offx; +var xend = Clazz.floatToInt (height * scale) + offx; +var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; +g.setColor (node.color.darker ()); +g.drawLine (xstart, ypos, xend, ypos); +if (node === this.highlightNode) { +g.fillRect (xend - 3, ypos - 3, 6, 6); +} else { +g.fillRect (xend - 2, ypos - 2, 4, 4); +}var ystart = Clazz.floatToInt ((node.left ()).ycount * chunk) + offy; +var yend = Clazz.floatToInt ((node.right ()).ycount * chunk) + offy; +var pos = new java.awt.Rectangle (xend - 2, ypos - 2, 5, 5); +this.nodeHash.put (node, pos); +g.drawLine (Clazz.floatToInt (height * scale) + offx, ystart, Clazz.floatToInt (height * scale) + offx, yend); +var nodeLabel = ""; +if (this.showDistances && (node.dist > 0)) { +nodeLabel = new jalview.util.Format ("%-.2f").formDouble (node.dist); +}if (this.showBootstrap) { +var btstrap = node.getBootstrap (); +if (btstrap > -1) { +if (this.showDistances) { +nodeLabel = nodeLabel + " : "; +}nodeLabel = nodeLabel + String.valueOf (node.getBootstrap ()); +}}if (!nodeLabel.equals ("")) { +g.drawString (nodeLabel, xstart + 2, ypos - 2); +}}}, "java.awt.Graphics,jalview.datamodel.SequenceNode,~N,~N,~N,~N,~N"); +Clazz.defineMethod (c$, "findElement", +function (x, y) { +var keys = this.nameHash.keys (); +while (keys.hasMoreElements ()) { +var ob = keys.nextElement (); +var rect = this.nameHash.get (ob); +if (x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)) { +return ob; +}} +keys = this.nodeHash.keys (); +while (keys.hasMoreElements ()) { +var ob = keys.nextElement (); +var rect = this.nodeHash.get (ob); +if (x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)) { +return ob; +}} +return null; +}, "~N,~N"); +Clazz.defineMethod (c$, "pickNodes", +function (pickBox) { +var width = this.getSize ().width; +var height = this.getSize ().height; +var top = this.tree.getTopNode (); +var wscale = (width * .8 - this.offx * 2) / this.tree.getMaxHeight (); +if (top.count == 0) { +top.count = (top.left ()).count + (top.right ()).count; +}var chunk = (height - this.offy) / top.count; +this.pickNode (pickBox, top, chunk, wscale, width, this.offx, this.offy); +}, "java.awt.Rectangle"); +Clazz.defineMethod (c$, "pickNode", +function (pickBox, node, chunk, scale, width, offx, offy) { +if (node == null) { +return; +}if (node.left () == null && node.right () == null) { +var height = node.height; +var xend = Clazz.floatToInt (height * scale) + offx; +var ypos = Clazz.floatToInt (node.ycount * chunk) + offy; +if (pickBox.contains ( new java.awt.Point (xend, ypos))) { +if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { +var seq = node.element (); +var sg = this.av.getSelectionGroup (); +if (sg != null) { +sg.addOrRemove (seq, true); +}}}} else { +this.pickNode (pickBox, node.left (), chunk, scale, width, offx, offy); +this.pickNode (pickBox, node.right (), chunk, scale, width, offx, offy); +}}, "java.awt.Rectangle,jalview.datamodel.SequenceNode,~N,~N,~N,~N,~N"); +Clazz.defineMethod (c$, "setColor", +function (node, c) { +if (node == null) { +return; +}if (node.left () == null && node.right () == null) { +node.color = c; +if (Clazz.instanceOf (node.element (), jalview.datamodel.SequenceI)) { +this.av.setSequenceColour (node.element (), c); +}} else { +node.color = c; +this.setColor (node.left (), c); +this.setColor (node.right (), c); +}}, "jalview.datamodel.SequenceNode,java.awt.Color"); +Clazz.overrideMethod (c$, "update", +function (g) { +this.paint (g); +}, "java.awt.Graphics"); +Clazz.overrideMethod (c$, "paintComponent", +function (g) { +if (this.tree == null) { +return; +}if (this.nameHash.size () == 0) { +this.repaint (); +}var width = this.scrollPane.getSize ().width; +var height = this.scrollPane.getSize ().height; +if (!this.fitToWindow) { +height = g.getFontMetrics (this.$font).getHeight () * this.nameHash.size (); +}if (this.getSize ().width > width) { +this.setSize ( new java.awt.Dimension (width, height)); +this.scrollPane.validate (); +return; +}this.setSize ( new java.awt.Dimension (width, height)); +g.setFont (this.$font); +this.draw (g, width, height); +this.validate (); +}, "java.awt.Graphics"); +Clazz.defineMethod (c$, "draw", +function (g, width, height) { +this.offy = this.$font.getSize () + 10; +g.setColor (java.awt.Color.white); +g.fillRect (0, 0, width, height); +this.labelLength = g.getFontMetrics (this.$font).stringWidth (this.longestName) + 20; +var wscale = (width - this.labelLength - this.offx * 2) / this.tree.getMaxHeight (); +var top = this.tree.getTopNode (); +if (top.count == 0) { +top.count = (top.left ()).count + (top.right ()).count; +}var chunk = (height - this.offy) / top.count; +this.drawNode (g, this.tree.getTopNode (), chunk, wscale, width, this.offx, this.offy); +if (this.threshold != 0) { +if (this.av.getCurrentTree () === this.tree) { +g.setColor (java.awt.Color.red); +} else { +g.setColor (java.awt.Color.gray); +}var x = Clazz.floatToInt (this.threshold * (this.getSize ().width - this.labelLength - 2 * this.offx) + this.offx); +g.drawLine (x, 0, x, this.getSize ().height); +}}, "java.awt.Graphics,~N,~N"); +Clazz.overrideMethod (c$, "mouseReleased", +function (e) { +}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mouseEntered", +function (e) { +}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mouseExited", +function (e) { +}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mouseClicked", +function (evt) { +if (this.highlightNode != null) { +if (evt.getClickCount () > 1) { +this.tree.swapNodes (this.highlightNode); +this.tree.reCount (this.tree.getTopNode ()); +this.tree.findHeight (this.tree.getTopNode ()); +} else { +var leaves = new java.util.Vector (); +this.tree.findLeaves (this.highlightNode, leaves); +for (var i = 0; i < leaves.size (); i++) { +var seq = (leaves.elementAt (i)).element (); +this.treeSelectionChanged (seq); +} +}jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); +this.repaint (); +this.av.sendSelection (); +}}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mouseDragged", +function (ect) { +}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mouseMoved", +function (evt) { +this.av.setCurrentTree (this.tree); +var ob = this.findElement (evt.getX (), evt.getY ()); +if (Clazz.instanceOf (ob, jalview.datamodel.SequenceNode)) { +this.highlightNode = ob; +this.repaint (); +} else { +if (this.highlightNode != null) { +this.highlightNode = null; +this.repaint (); +}}}, "java.awt.event.MouseEvent"); +Clazz.overrideMethod (c$, "mousePressed", +function (e) { +this.av.setCurrentTree (this.tree); +var x = e.getX (); +var y = e.getY (); +var ob = this.findElement (x, y); +if (Clazz.instanceOf (ob, jalview.datamodel.SequenceI)) { +this.treeSelectionChanged (ob); +jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); +this.repaint (); +this.av.sendSelection (); +return; +} else if (!(Clazz.instanceOf (ob, jalview.datamodel.SequenceNode))) { +if (this.tree.getMaxHeight () != 0) { +this.threshold = (x - this.offx) / (this.getSize ().width - this.labelLength - 2 * this.offx); +this.tree.getGroups ().removeAllElements (); +this.tree.groupNodes (this.tree.getTopNode (), this.threshold); +this.setColor (this.tree.getTopNode (), java.awt.Color.black); +this.av.setSelectionGroup (null); +this.av.getAlignment ().deleteAllGroups (); +this.av.clearSequenceColours (); +var codingComplement = this.av.getCodingComplement (); +if (codingComplement != null) { +codingComplement.setSelectionGroup (null); +codingComplement.getAlignment ().deleteAllGroups (); +codingComplement.clearSequenceColours (); +}this.colourGroups (); +}}jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ()); +this.repaint (); +}, "java.awt.event.MouseEvent"); +Clazz.defineMethod (c$, "colourGroups", +function () { +for (var i = 0; i < this.tree.getGroups ().size (); i++) { +var col = new java.awt.Color (Clazz.doubleToInt (Math.random () * 255), Clazz.doubleToInt (Math.random () * 255), Clazz.doubleToInt (Math.random () * 255)); +this.setColor (this.tree.getGroups ().elementAt (i), col.brighter ()); +var l = this.tree.findLeaves (this.tree.getGroups ().elementAt (i), new java.util.Vector ()); +var sequences = new java.util.Vector (); +for (var j = 0; j < l.size (); j++) { +var s1 = (l.elementAt (j)).element (); +if (!sequences.contains (s1)) { +sequences.addElement (s1); +}} +var cs = null; +var sg = new jalview.datamodel.SequenceGroup (sequences, "", cs, true, true, false, 0, this.av.getAlignment ().getWidth () - 1); +if (this.av.getGlobalColourScheme () != null) { +if (Clazz.instanceOf (this.av.getGlobalColourScheme (), jalview.schemes.UserColourScheme)) { +cs = new jalview.schemes.UserColourScheme ((this.av.getGlobalColourScheme ()).getColours ()); +} else { +cs = jalview.schemes.ColourSchemeProperty.getColour (sg, jalview.schemes.ColourSchemeProperty.getColourName (this.av.getGlobalColourScheme ())); +}if (cs != null) { +cs.setThreshold (this.av.getGlobalColourScheme ().getThreshold (), this.av.isIgnoreGapsConsensus ()); +}}sg.cs = cs; +sg.setName ("JTreeGroup:" + sg.hashCode ()); +sg.setIdColour (col); +if (this.av.getGlobalColourScheme () != null && this.av.getGlobalColourScheme ().conservationApplied ()) { +var c = new jalview.analysis.Conservation ("Group", jalview.schemes.ResidueProperties.propHash, 3, sg.getSequences (null), sg.getStartRes (), sg.getEndRes ()); +c.calculate (); +c.verdict (false, this.av.getConsPercGaps ()); +cs.setConservation (c); +sg.cs = cs; +}this.av.getAlignment ().addGroup (sg); +this.av.getAlignment ().addGroup (sg); +var codingComplement = this.av.getCodingComplement (); +if (codingComplement != null) { +var mappedGroup = jalview.util.MappingUtils.mapSequenceGroup (sg, this.av, codingComplement); +if (mappedGroup.getSequences ().size () > 0) { +codingComplement.getAlignment ().addGroup (mappedGroup); +for (var seq, $seq = mappedGroup.getSequences ().iterator (); $seq.hasNext () && ((seq = $seq.next ()) || true);) { +codingComplement.setSequenceColour (seq, col); +} +}}} +this.ap.updateAnnotation (); +if (this.av.getCodingComplement () != null) { +(this.av.getCodingComplement ()).firePropertyChange ("alignment", null, this.ap.av.getAlignment ().getSequences ()); +}}); +Clazz.defineMethod (c$, "setShowDistances", +function (state) { +this.showDistances = state; +this.repaint (); +}, "~B"); +Clazz.defineMethod (c$, "setShowBootstrap", +function (state) { +this.showBootstrap = state; +this.repaint (); +}, "~B"); +Clazz.defineMethod (c$, "setMarkPlaceholders", +function (state) { +this.markPlaceholders = state; +this.repaint (); +}, "~B"); +Clazz.defineStatics (c$, +"PLACEHOLDER", " * "); +});