X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjalview%2Fappletgui%2FSequenceRenderer.js;h=103924e80e2f0fef45dbf8f32ec0f7d51b2b00be;hp=bbe8dc920f0f0fc9e0f09fd0149bbc7077c97277;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=8ffd05b3abe52c0b6b79b011c0966361f82d5fe6 diff --git a/site/j2s/jalview/appletgui/SequenceRenderer.js b/site/j2s/jalview/appletgui/SequenceRenderer.js index bbe8dc9..103924e 100644 --- a/site/j2s/jalview/appletgui/SequenceRenderer.js +++ b/site/j2s/jalview/appletgui/SequenceRenderer.js @@ -1,196 +1,196 @@ -Clazz.declarePackage ("jalview.appletgui"); -Clazz.load (["jalview.api.SequenceRenderer"], "jalview.appletgui.SequenceRenderer", ["jalview.util.Comparison", "java.awt.Color", "$.Font"], function () { -c$ = Clazz.decorateAsClass (function () { -this.av = null; -this.fm = null; -this.renderGaps = true; -this.currentSequenceGroup = null; -this.allGroups = null; -this.resBoxColour = null; -this.graphics = null; -this.forOverview = false; -Clazz.instantialize (this, arguments); -}, jalview.appletgui, "SequenceRenderer", null, jalview.api.SequenceRenderer); -Clazz.makeConstructor (c$, -function (av) { -this.av = av; -}, "jalview.appletgui.AlignViewport"); -Clazz.defineMethod (c$, "prepare", -function (g, renderGaps) { -this.graphics = g; -this.fm = g.getFontMetrics (); -this.renderGaps = renderGaps; -}, "java.awt.Graphics,~B"); -Clazz.overrideMethod (c$, "getResidueBoxColour", -function (seq, i) { -this.allGroups = this.av.getAlignment ().findAllGroups (seq); -if (this.inCurrentSequenceGroup (i)) { -if (this.currentSequenceGroup.getDisplayBoxes ()) { -this.getBoxColour (this.currentSequenceGroup.cs, seq, i); -}} else if (this.av.getShowBoxes ()) { -this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); -}return this.resBoxColour; -}, "jalview.datamodel.SequenceI,~N"); -Clazz.overrideMethod (c$, "getResidueColour", -function (seq, position, fr) { -var col = this.getResidueBoxColour (seq, position); -if (fr != null) { -col = fr.findFeatureColour (col, seq, position); -}return col; -}, "jalview.datamodel.SequenceI,~N,jalview.api.FeatureRenderer"); -Clazz.defineMethod (c$, "getBoxColour", -function (cs, seq, i) { -if (cs != null) { -this.resBoxColour = cs.findColour (seq.getCharAt (i), i, seq); -} else if (this.forOverview && !jalview.util.Comparison.isGap (seq.getCharAt (i))) { -this.resBoxColour = java.awt.Color.lightGray; -} else { -this.resBoxColour = java.awt.Color.white; -}}, "jalview.schemes.ColourSchemeI,jalview.datamodel.SequenceI,~N"); -Clazz.defineMethod (c$, "findSequenceColour", -function (seq, i) { -this.allGroups = this.av.getAlignment ().findAllGroups (seq); -this.drawBoxes (seq, i, i, 0); -return this.resBoxColour; -}, "jalview.datamodel.SequenceI,~N"); -Clazz.defineMethod (c$, "drawSequence", -function (seq, sg, start, end, y1) { -if (seq == null) { -return; -}this.allGroups = sg; -this.drawBoxes (seq, start, end, y1); -if (this.av.validCharWidth) { -this.drawText (seq, start, end, y1); -}}, "jalview.datamodel.SequenceI,~A,~N,~N,~N"); -Clazz.defineMethod (c$, "drawBoxes", -function (seq, start, end, y1) { -var i = start; -var length = seq.getLength (); -var curStart = -1; -var curWidth = this.av.getCharWidth (); -var avCharWidth = this.av.getCharWidth (); -var avCharHeight = this.av.getCharHeight (); -var tempColour = null; -while (i <= end) { -this.resBoxColour = java.awt.Color.white; -if (i < length) { -if (this.inCurrentSequenceGroup (i)) { -if (this.currentSequenceGroup.getDisplayBoxes ()) { -this.getBoxColour (this.currentSequenceGroup.cs, seq, i); -}} else if (this.av.getShowBoxes ()) { -this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); -}}if (this.resBoxColour !== tempColour) { -if (tempColour != null) { -this.graphics.fillRect (avCharWidth * (curStart - start), y1, curWidth, avCharHeight); -}this.graphics.setColor (this.resBoxColour); -curStart = i; -curWidth = avCharWidth; -tempColour = this.resBoxColour; -} else { -curWidth += avCharWidth; -}i++; -} -this.graphics.fillRect (avCharWidth * (curStart - start), y1, curWidth, avCharHeight); -}, "jalview.datamodel.SequenceI,~N,~N,~N"); -Clazz.defineMethod (c$, "drawText", -function (seq, start, end, y1) { -var avCharWidth = this.av.getCharWidth (); -var avCharHeight = this.av.getCharHeight (); -var boldFont = null; -var bold = false; -if (this.av.isUpperCasebold ()) { -boldFont = new java.awt.Font (this.av.getFont ().getName (), 1, avCharHeight); -this.graphics.setFont (this.av.getFont ()); -}y1 += avCharHeight - Clazz.doubleToInt (avCharHeight / 5); -var charOffset = 0; -if (end + 1 >= seq.getLength ()) { -end = seq.getLength () - 1; -}var s = ' '; -var srep = this.av.isDisplayReferenceSeq (); -for (var i = start; i <= end; i++) { -this.graphics.setColor (java.awt.Color.black); -s = seq.getCharAt (i); -if (!this.renderGaps && jalview.util.Comparison.isGap (s)) { -continue; -}if (this.inCurrentSequenceGroup (i)) { -if (!this.currentSequenceGroup.getDisplayText ()) { -continue; -}if (this.currentSequenceGroup.getColourText ()) { -this.getBoxColour (this.currentSequenceGroup.cs, seq, i); -this.graphics.setColor (this.resBoxColour.darker ()); -}if (this.currentSequenceGroup.getShowNonconserved ()) { -s = this.getDisplayChar (srep, i, s, '.'); -}} else { -if (!this.av.getShowText ()) { -continue; -}if (this.av.getColourText ()) { -this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); -if (this.av.getShowBoxes ()) { -this.graphics.setColor (this.resBoxColour.darker ()); -} else { -this.graphics.setColor (this.resBoxColour); -}}if (this.av.getShowUnconserved ()) { -s = this.getDisplayChar (srep, i, s, '.'); -}}if (this.av.isUpperCasebold ()) { -this.fm = this.graphics.getFontMetrics (); -if ('A' <= s && s <= 'Z') { -if (!bold) { -this.graphics.setFont (boldFont); -}bold = true; -} else if (bold) { -this.graphics.setFont (this.av.font); -bold = false; -}}charOffset = Clazz.doubleToInt ((avCharWidth - this.fm.charWidth (s)) / 2); -this.graphics.drawString (String.valueOf (s), charOffset + avCharWidth * (i - start), y1); -} -}, "jalview.datamodel.SequenceI,~N,~N,~N"); -Clazz.defineMethod (c$, "getDisplayChar", - function (usesrep, position, s, c) { -var conschar = (usesrep) ? this.av.getAlignment ().getSeqrep ().getCharAt (position) : this.av.getAlignmentConsensusAnnotation ().annotations[position].displayCharacter.charAt (0); -if (conschar != '-' && s == conschar) { -s = c; -}return s; -}, "~B,~N,~S,~S"); -Clazz.defineMethod (c$, "inCurrentSequenceGroup", -function (res) { -if (this.allGroups == null) { -return false; -}for (var i = 0; i < this.allGroups.length; i++) { -if (this.allGroups[i].getStartRes () <= res && this.allGroups[i].getEndRes () >= res) { -this.currentSequenceGroup = this.allGroups[i]; -return true; -}} -return false; -}, "~N"); -Clazz.defineMethod (c$, "drawHighlightedText", -function (seq, start, end, x1, y1) { -var avCharWidth = this.av.getCharWidth (); -var avCharHeight = this.av.getCharHeight (); -var pady = Clazz.doubleToInt (avCharHeight / 5); -var charOffset = 0; -this.graphics.setColor (java.awt.Color.black); -this.graphics.fillRect (x1, y1, avCharWidth * (end - start + 1), avCharHeight); -this.graphics.setColor (java.awt.Color.white); -var s = '~'; -if (this.av.validCharWidth) { -for (var i = start; i <= end; i++) { -if (i < seq.getLength ()) { -s = seq.getCharAt (i); -}charOffset = Clazz.doubleToInt ((avCharWidth - this.fm.charWidth (s)) / 2); -this.graphics.drawString (String.valueOf (s), charOffset + x1 + avCharWidth * (i - start), y1 + avCharHeight - pady); -} -}}, "jalview.datamodel.SequenceI,~N,~N,~N,~N"); -Clazz.defineMethod (c$, "drawCursor", -function (seq, res, x1, y1) { -var pady = Clazz.doubleToInt (this.av.getCharHeight () / 5); -var charOffset = 0; -this.graphics.setColor (java.awt.Color.black); -this.graphics.fillRect (x1, y1, this.av.getCharWidth (), this.av.getCharHeight ()); -this.graphics.setColor (java.awt.Color.white); -this.graphics.setColor (java.awt.Color.white); -var s = seq.getCharAt (res); -if (this.av.validCharWidth) { -charOffset = Clazz.doubleToInt ((this.av.getCharWidth () - this.fm.charWidth (s)) / 2); -this.graphics.drawString (String.valueOf (s), charOffset + x1, (y1 + this.av.getCharHeight ()) - pady); -}}, "jalview.datamodel.SequenceI,~N,~N,~N"); -}); +Clazz.declarePackage ("jalview.appletgui"); +Clazz.load (["jalview.api.SequenceRenderer"], "jalview.appletgui.SequenceRenderer", ["jalview.util.Comparison", "java.awt.Color", "$.Font"], function () { +c$ = Clazz.decorateAsClass (function () { +this.av = null; +this.fm = null; +this.renderGaps = true; +this.currentSequenceGroup = null; +this.allGroups = null; +this.resBoxColour = null; +this.graphics = null; +this.forOverview = false; +Clazz.instantialize (this, arguments); +}, jalview.appletgui, "SequenceRenderer", null, jalview.api.SequenceRenderer); +Clazz.makeConstructor (c$, +function (av) { +this.av = av; +}, "jalview.appletgui.AlignViewport"); +Clazz.defineMethod (c$, "prepare", +function (g, renderGaps) { +this.graphics = g; +this.fm = g.getFontMetrics (); +this.renderGaps = renderGaps; +}, "java.awt.Graphics,~B"); +Clazz.overrideMethod (c$, "getResidueBoxColour", +function (seq, i) { +this.allGroups = this.av.getAlignment ().findAllGroups (seq); +if (this.inCurrentSequenceGroup (i)) { +if (this.currentSequenceGroup.getDisplayBoxes ()) { +this.getBoxColour (this.currentSequenceGroup.cs, seq, i); +}} else if (this.av.getShowBoxes ()) { +this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); +}return this.resBoxColour; +}, "jalview.datamodel.SequenceI,~N"); +Clazz.overrideMethod (c$, "getResidueColour", +function (seq, position, fr) { +var col = this.getResidueBoxColour (seq, position); +if (fr != null) { +col = fr.findFeatureColour (col, seq, position); +}return col; +}, "jalview.datamodel.SequenceI,~N,jalview.api.FeatureRenderer"); +Clazz.defineMethod (c$, "getBoxColour", +function (cs, seq, i) { +if (cs != null) { +this.resBoxColour = cs.findColour (seq.getCharAt (i), i, seq); +} else if (this.forOverview && !jalview.util.Comparison.isGap (seq.getCharAt (i))) { +this.resBoxColour = java.awt.Color.lightGray; +} else { +this.resBoxColour = java.awt.Color.white; +}}, "jalview.schemes.ColourSchemeI,jalview.datamodel.SequenceI,~N"); +Clazz.defineMethod (c$, "findSequenceColour", +function (seq, i) { +this.allGroups = this.av.getAlignment ().findAllGroups (seq); +this.drawBoxes (seq, i, i, 0); +return this.resBoxColour; +}, "jalview.datamodel.SequenceI,~N"); +Clazz.defineMethod (c$, "drawSequence", +function (seq, sg, start, end, y1) { +if (seq == null) { +return; +}this.allGroups = sg; +this.drawBoxes (seq, start, end, y1); +if (this.av.validCharWidth) { +this.drawText (seq, start, end, y1); +}}, "jalview.datamodel.SequenceI,~A,~N,~N,~N"); +Clazz.defineMethod (c$, "drawBoxes", +function (seq, start, end, y1) { +var i = start; +var length = seq.getLength (); +var curStart = -1; +var curWidth = this.av.getCharWidth (); +var avCharWidth = this.av.getCharWidth (); +var avCharHeight = this.av.getCharHeight (); +var tempColour = null; +while (i <= end) { +this.resBoxColour = java.awt.Color.white; +if (i < length) { +if (this.inCurrentSequenceGroup (i)) { +if (this.currentSequenceGroup.getDisplayBoxes ()) { +this.getBoxColour (this.currentSequenceGroup.cs, seq, i); +}} else if (this.av.getShowBoxes ()) { +this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); +}}if (this.resBoxColour !== tempColour) { +if (tempColour != null) { +this.graphics.fillRect (avCharWidth * (curStart - start), y1, curWidth, avCharHeight); +}this.graphics.setColor (this.resBoxColour); +curStart = i; +curWidth = avCharWidth; +tempColour = this.resBoxColour; +} else { +curWidth += avCharWidth; +}i++; +} +this.graphics.fillRect (avCharWidth * (curStart - start), y1, curWidth, avCharHeight); +}, "jalview.datamodel.SequenceI,~N,~N,~N"); +Clazz.defineMethod (c$, "drawText", +function (seq, start, end, y1) { +var avCharWidth = this.av.getCharWidth (); +var avCharHeight = this.av.getCharHeight (); +var boldFont = null; +var bold = false; +if (this.av.isUpperCasebold ()) { +boldFont = new java.awt.Font (this.av.getFont ().getName (), 1, avCharHeight); +this.graphics.setFont (this.av.getFont ()); +}y1 += avCharHeight - Clazz.doubleToInt (avCharHeight / 5); +var charOffset = 0; +if (end + 1 >= seq.getLength ()) { +end = seq.getLength () - 1; +}var s = ' '; +var srep = this.av.isDisplayReferenceSeq (); +for (var i = start; i <= end; i++) { +this.graphics.setColor (java.awt.Color.black); +s = seq.getCharAt (i); +if (!this.renderGaps && jalview.util.Comparison.isGap (s)) { +continue; +}if (this.inCurrentSequenceGroup (i)) { +if (!this.currentSequenceGroup.getDisplayText ()) { +continue; +}if (this.currentSequenceGroup.getColourText ()) { +this.getBoxColour (this.currentSequenceGroup.cs, seq, i); +this.graphics.setColor (this.resBoxColour.darker ()); +}if (this.currentSequenceGroup.getShowNonconserved ()) { +s = this.getDisplayChar (srep, i, s, '.'); +}} else { +if (!this.av.getShowText ()) { +continue; +}if (this.av.getColourText ()) { +this.getBoxColour (this.av.getGlobalColourScheme (), seq, i); +if (this.av.getShowBoxes ()) { +this.graphics.setColor (this.resBoxColour.darker ()); +} else { +this.graphics.setColor (this.resBoxColour); +}}if (this.av.getShowUnconserved ()) { +s = this.getDisplayChar (srep, i, s, '.'); +}}if (this.av.isUpperCasebold ()) { +this.fm = this.graphics.getFontMetrics (); +if ('A' <= s && s <= 'Z') { +if (!bold) { +this.graphics.setFont (boldFont); +}bold = true; +} else if (bold) { +this.graphics.setFont (this.av.font); +bold = false; +}}charOffset = Clazz.doubleToInt ((avCharWidth - this.fm.charWidth (s)) / 2); +this.graphics.drawString (String.valueOf (s), charOffset + avCharWidth * (i - start), y1); +} +}, "jalview.datamodel.SequenceI,~N,~N,~N"); +Clazz.defineMethod (c$, "getDisplayChar", + function (usesrep, position, s, c) { +var conschar = (usesrep) ? this.av.getAlignment ().getSeqrep ().getCharAt (position) : this.av.getAlignmentConsensusAnnotation ().annotations[position].displayCharacter.charAt (0); +if (conschar != '-' && s == conschar) { +s = c; +}return s; +}, "~B,~N,~S,~S"); +Clazz.defineMethod (c$, "inCurrentSequenceGroup", +function (res) { +if (this.allGroups == null) { +return false; +}for (var i = 0; i < this.allGroups.length; i++) { +if (this.allGroups[i].getStartRes () <= res && this.allGroups[i].getEndRes () >= res) { +this.currentSequenceGroup = this.allGroups[i]; +return true; +}} +return false; +}, "~N"); +Clazz.defineMethod (c$, "drawHighlightedText", +function (seq, start, end, x1, y1) { +var avCharWidth = this.av.getCharWidth (); +var avCharHeight = this.av.getCharHeight (); +var pady = Clazz.doubleToInt (avCharHeight / 5); +var charOffset = 0; +this.graphics.setColor (java.awt.Color.black); +this.graphics.fillRect (x1, y1, avCharWidth * (end - start + 1), avCharHeight); +this.graphics.setColor (java.awt.Color.white); +var s = '~'; +if (this.av.validCharWidth) { +for (var i = start; i <= end; i++) { +if (i < seq.getLength ()) { +s = seq.getCharAt (i); +}charOffset = Clazz.doubleToInt ((avCharWidth - this.fm.charWidth (s)) / 2); +this.graphics.drawString (String.valueOf (s), charOffset + x1 + avCharWidth * (i - start), y1 + avCharHeight - pady); +} +}}, "jalview.datamodel.SequenceI,~N,~N,~N,~N"); +Clazz.defineMethod (c$, "drawCursor", +function (seq, res, x1, y1) { +var pady = Clazz.doubleToInt (this.av.getCharHeight () / 5); +var charOffset = 0; +this.graphics.setColor (java.awt.Color.black); +this.graphics.fillRect (x1, y1, this.av.getCharWidth (), this.av.getCharHeight ()); +this.graphics.setColor (java.awt.Color.white); +this.graphics.setColor (java.awt.Color.white); +var s = seq.getCharAt (res); +if (this.av.validCharWidth) { +charOffset = Clazz.doubleToInt ((this.av.getCharWidth () - this.fm.charWidth (s)) / 2); +this.graphics.drawString (String.valueOf (s), charOffset + x1, (y1 + this.av.getCharHeight ()) - pady); +}}, "jalview.datamodel.SequenceI,~N,~N,~N"); +});