1 Clazz.declarePackage ("jalview.renderer.seqfeatures");
2 Clazz.load (["jalview.viewmodel.seqfeatures.FeatureRendererModel"], "jalview.renderer.seqfeatures.FeatureRenderer", ["awt2swing.Util", "jalview.util.Comparison", "java.awt.AlphaComposite", "$.Color", "java.awt.image.BufferedImage", "java.lang.Float"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 this.offscreenRender = false;
10 this.av_charHeight = 0;
11 this.av_charWidth = 0;
12 this.av_validCharWidth = false;
13 this.av_isShowSeqFeatureHeight = false;
14 this.offscreenImage = null;
15 this.lastSequenceFeatures = null;
20 this.transparencyAvailable = true;
21 Clazz.instantialize (this, arguments);
22 }, jalview.renderer.seqfeatures, "FeatureRenderer", jalview.viewmodel.seqfeatures.FeatureRendererModel);
23 Clazz.defineMethod (c$, "updateAvConfig",
25 this.av_charHeight = this.av.getCharHeight ();
26 this.av_charWidth = this.av.getCharWidth ();
27 this.av_validCharWidth = this.av.isValidCharWidth ();
28 this.av_isShowSeqFeatureHeight = this.av.isShowSequenceFeaturesHeight ();
30 Clazz.defineMethod (c$, "renderFeature",
31 function (g, seq, fstart, fend, featureColour, start, end, y1) {
32 this.updateAvConfig ();
33 if (((fstart <= end) && (fend >= start))) {
38 }var pady = (y1 + this.av_charHeight) - Clazz.doubleToInt (this.av_charHeight / 5);
39 for (this.i = fstart; this.i <= fend; this.i++) {
40 this.s = seq.getCharAt (this.i);
41 if (jalview.util.Comparison.isGap (this.s)) {
43 }g.setColor (featureColour);
44 g.fillRect ((this.i - start) * this.av_charWidth, y1, this.av_charWidth, this.av_charHeight);
45 if (this.offscreenRender || !this.av_validCharWidth) {
47 }g.setColor (java.awt.Color.white);
48 this.charOffset = Clazz.doubleToInt ((this.av_charWidth - this.fm.charWidth (this.s)) / 2);
49 awt2swing.Util.drawString (g, String.valueOf (this.s), this.charOffset + (this.av_charWidth * (this.i - start)), pady);
51 }}, "java.awt.Graphics,jalview.datamodel.SequenceI,~N,~N,java.awt.Color,~N,~N,~N");
52 Clazz.defineMethod (c$, "renderScoreFeature",
53 function (g, seq, fstart, fend, featureColour, start, end, y1, bs) {
54 this.updateAvConfig ();
55 if (((fstart <= end) && (fend >= start))) {
60 }var pady = (y1 + this.av_charHeight) - Clazz.doubleToInt (this.av_charHeight / 5);
62 var yend = this.av_charHeight;
65 yend = Clazz.doubleToInt (this.av_charHeight * (128 - bs[1]) / 512);
66 ystrt = this.av_charHeight - Clazz.doubleToInt (yend / 2);
68 ystrt = Clazz.doubleToInt (this.av_charHeight / 2);
69 yend = Clazz.doubleToInt (this.av_charHeight * (bs[1] - 128) / 512);
71 yend = Clazz.doubleToInt (this.av_charHeight * bs[1] / 255);
72 ystrt = this.av_charHeight - yend;
73 }for (this.i = fstart; this.i <= fend; this.i++) {
74 this.s = seq.getCharAt (this.i);
75 if (jalview.util.Comparison.isGap (this.s)) {
77 }g.setColor (featureColour);
78 var x = (this.i - start) * this.av_charWidth;
79 g.drawRect (x, y1, this.av_charWidth, this.av_charHeight);
80 g.fillRect (x, y1 + ystrt, this.av_charWidth, yend);
81 if (this.offscreenRender || !this.av_validCharWidth) {
83 }g.setColor (java.awt.Color.black);
84 this.charOffset = Clazz.doubleToInt ((this.av_charWidth - this.fm.charWidth (this.s)) / 2);
85 awt2swing.Util.drawString (g, String.valueOf (this.s), this.charOffset + (this.av_charWidth * (this.i - start)), pady);
87 }}, "java.awt.Graphics,jalview.datamodel.SequenceI,~N,~N,java.awt.Color,~N,~N,~N,~A");
88 Clazz.defineMethod (c$, "findFeatureColour",
89 function (initialCol, seq, res) {
90 return new java.awt.Color (this.findFeatureColour (initialCol.getRGB (), seq, res));
91 }, "java.awt.Color,jalview.datamodel.SequenceI,~N");
92 Clazz.defineMethod (c$, "findFeatureColour",
93 function (initialCol, seq, column) {
94 if (!this.av.isShowSequenceFeatures ()) {
96 }var sequenceFeatures = seq.getSequenceFeatures ();
97 if (seq !== this.lastSeq) {
99 this.lastSequenceFeatures = sequenceFeatures;
100 if (this.lastSequenceFeatures != null) {
101 this.sfSize = this.lastSequenceFeatures.length;
103 if (this.lastSequenceFeatures !== sequenceFeatures) {
104 this.lastSequenceFeatures = sequenceFeatures;
105 if (this.lastSequenceFeatures != null) {
106 this.sfSize = this.lastSequenceFeatures.length;
107 }}}if (this.lastSequenceFeatures == null || this.sfSize == 0) {
109 }if (jalview.util.Comparison.isGap (this.lastSeq.getCharAt (column))) {
110 return java.awt.Color.white.getRGB ();
111 }if (this.transparency != 1.0 && this.offscreenImage == null) {
112 this.offscreenImage = new java.awt.image.BufferedImage (1, 1, 2);
113 }this.currentColour = null;
114 this.offscreenRender = true;
115 if (this.offscreenImage != null) {
116 this.offscreenImage.setRGB (0, 0, initialCol);
117 this.drawSequence (this.offscreenImage.getGraphics (), this.lastSeq, column, column, 0);
118 return this.offscreenImage.getRGB (0, 0);
120 this.drawSequence (null, this.lastSeq, this.lastSeq.findPosition (column), -1, -1);
121 if (this.currentColour == null) {
124 return (this.currentColour).intValue ();
125 }}}, "~N,jalview.datamodel.SequenceI,~N");
126 Clazz.defineMethod (c$, "drawSequence",
127 function (g, seq, start, end, y1) {
128 var sequenceFeatures = seq.getSequenceFeatures ();
129 if (sequenceFeatures == null || sequenceFeatures.length == 0) {
132 this.fm = g.getFontMetrics ();
133 }this.updateFeatures ();
134 if (this.lastSeq == null || seq !== this.lastSeq || sequenceFeatures !== this.lastSequenceFeatures) {
136 this.lastSequenceFeatures = sequenceFeatures;
137 }if (this.transparency != 1 && g != null) {
139 g2.setComposite (java.awt.AlphaComposite.getInstance (3, this.transparency));
140 }if (!this.offscreenRender) {
141 this.spos = this.lastSeq.findPosition (start);
142 this.epos = this.lastSeq.findPosition (end);
143 }this.sfSize = this.lastSequenceFeatures.length;
145 for (var renderIndex = 0; renderIndex < this.renderOrder.length; renderIndex++) {
146 type = this.renderOrder[renderIndex];
147 if (type == null || !this.showFeatureOfType (type)) {
149 }for (this.sfindex = 0; this.sfindex < this.sfSize; this.sfindex++) {
150 var sequenceFeature = this.lastSequenceFeatures[this.sfindex];
151 if (!sequenceFeature.type.equals (type)) {
153 }if (this.featureGroups != null && sequenceFeature.featureGroup != null && sequenceFeature.featureGroup.length != 0 && this.featureGroups.containsKey (sequenceFeature.featureGroup) && !this.featureGroups.get (sequenceFeature.featureGroup).booleanValue ()) {
155 }if (!this.offscreenRender && (sequenceFeature.getBegin () > this.epos || sequenceFeature.getEnd () < this.spos)) {
157 }if (this.offscreenRender && this.offscreenImage == null) {
158 if (sequenceFeature.begin <= start && sequenceFeature.end >= start) {
159 this.currentColour = new Integer (this.getColour (sequenceFeature).getRGB ());
160 }} else if (sequenceFeature.type.equals ("disulfide bond")) {
161 this.renderFeature (g, seq, seq.findIndex (sequenceFeature.begin) - 1, seq.findIndex (sequenceFeature.begin) - 1, this.getColour (sequenceFeature), start, end, y1);
162 this.renderFeature (g, seq, seq.findIndex (sequenceFeature.end) - 1, seq.findIndex (sequenceFeature.end) - 1, this.getColour (sequenceFeature), start, end, y1);
163 } else if (this.showFeature (sequenceFeature)) {
164 if (this.av_isShowSeqFeatureHeight && !Float.isNaN (sequenceFeature.score)) {
165 this.renderScoreFeature (g, seq, seq.findIndex (sequenceFeature.begin) - 1, seq.findIndex (sequenceFeature.end) - 1, this.getColour (sequenceFeature), start, end, y1, this.normaliseScore (sequenceFeature));
167 this.renderFeature (g, seq, seq.findIndex (sequenceFeature.begin) - 1, seq.findIndex (sequenceFeature.end) - 1, this.getColour (sequenceFeature), start, end, y1);
170 if (this.transparency != 1.0 && g != null && this.transparencyAvailable) {
172 g2.setComposite (java.awt.AlphaComposite.getInstance (3, 1.0));
173 }}, "java.awt.Graphics,jalview.datamodel.SequenceI,~N,~N,~N");
174 Clazz.defineMethod (c$, "setTransparencyAvailable",
175 function (isTransparencyAvailable) {
176 this.transparencyAvailable = isTransparencyAvailable;
178 Clazz.overrideMethod (c$, "isTransparencyAvailable",
180 return this.transparencyAvailable;
182 Clazz.overrideMethod (c$, "featuresAdded",
185 this.findAllFeatures ();