JAL-1807 test
[jalviewjs.git] / bin / jalview / renderer / seqfeatures / FeatureRenderer.js
1 Clazz.declarePackage ("jalview.renderer.seqfeatures");
2 Clazz.load (["jalview.viewmodel.seqfeatures.FeatureRendererModel"], "jalview.renderer.seqfeatures.FeatureRenderer", ["jalview.util.Comparison", "java.awt.AlphaComposite", "$.Color", "java.awt.image.BufferedImage", "java.lang.Float"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.fm = null;
5 this.charOffset = 0;
6 this.offscreenRender = false;
7 this.lastSeq = null;
8 this.s = '\0';
9 this.i = 0;
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;
16 this.sfSize = 0;
17 this.sfindex = 0;
18 this.spos = 0;
19 this.epos = 0;
20 this.transparencyAvailable = true;
21 Clazz.instantialize (this, arguments);
22 }, jalview.renderer.seqfeatures, "FeatureRenderer", jalview.viewmodel.seqfeatures.FeatureRendererModel);
23 Clazz.defineMethod (c$, "updateAvConfig", 
24 function () {
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 ();
29 });
30 Clazz.defineMethod (c$, "renderFeature", 
31 function (g, seq, fstart, fend, featureColour, start, end, y1) {
32 this.updateAvConfig ();
33 if (((fstart <= end) && (fend >= start))) {
34 if (fstart < start) {
35 fstart = start;
36 }if (fend >= end) {
37 fend = end;
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)) {
42 continue;
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) {
46 continue;
47 }g.setColor (java.awt.Color.white);
48 this.charOffset = Clazz.doubleToInt ((this.av_charWidth - this.fm.charWidth (this.s)) / 2);
49 g.drawString (String.valueOf (this.s), this.charOffset + (this.av_charWidth * (this.i - start)), pady);
50 }
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))) {
56 if (fstart < start) {
57 fstart = start;
58 }if (fend >= end) {
59 fend = end;
60 }var pady = (y1 + this.av_charHeight) - Clazz.doubleToInt (this.av_charHeight / 5);
61 var ystrt = 0;
62 var yend = this.av_charHeight;
63 if (bs[0] != 0) {
64 if (bs[1] < 128) {
65 yend = Clazz.doubleToInt (this.av_charHeight * (128 - bs[1]) / 512);
66 ystrt = this.av_charHeight - Clazz.doubleToInt (yend / 2);
67 } else {
68 ystrt = Clazz.doubleToInt (this.av_charHeight / 2);
69 yend = Clazz.doubleToInt (this.av_charHeight * (bs[1] - 128) / 512);
70 }} else {
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)) {
76 continue;
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) {
82 continue;
83 }g.setColor (java.awt.Color.black);
84 this.charOffset = Clazz.doubleToInt ((this.av_charWidth - this.fm.charWidth (this.s)) / 2);
85 g.drawString (String.valueOf (this.s), this.charOffset + (this.av_charWidth * (this.i - start)), pady);
86 }
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 ()) {
95 return initialCol;
96 }var sequenceFeatures = seq.getSequenceFeatures ();
97 if (seq !== this.lastSeq) {
98 this.lastSeq = seq;
99 this.lastSequenceFeatures = sequenceFeatures;
100 if (this.lastSequenceFeatures != null) {
101 this.sfSize = this.lastSequenceFeatures.length;
102 }} else {
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) {
108 return initialCol;
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);
119 } else {
120 this.drawSequence (null, this.lastSeq, this.lastSeq.findPosition (column), -1, -1);
121 if (this.currentColour == null) {
122 return initialCol;
123 } else {
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) {
130 return;
131 }if (g != null) {
132 this.fm = g.getFontMetrics ();
133 }this.updateFeatures ();
134 if (this.lastSeq == null || seq !== this.lastSeq || sequenceFeatures !== this.lastSequenceFeatures) {
135 this.lastSeq = seq;
136 this.lastSequenceFeatures = sequenceFeatures;
137 }if (this.transparency != 1 && g != null) {
138 var g2 = g;
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;
144 var type;
145 for (var renderIndex = 0; renderIndex < this.renderOrder.length; renderIndex++) {
146 type = this.renderOrder[renderIndex];
147 if (type == null || !this.showFeatureOfType (type)) {
148 continue;
149 }for (this.sfindex = 0; this.sfindex < this.sfSize; this.sfindex++) {
150 var sequenceFeature = this.lastSequenceFeatures[this.sfindex];
151 if (!sequenceFeature.type.equals (type)) {
152 continue;
153 }if (this.featureGroups != null && sequenceFeature.featureGroup != null && sequenceFeature.featureGroup.length != 0 && this.featureGroups.containsKey (sequenceFeature.featureGroup) && !this.featureGroups.get (sequenceFeature.featureGroup).booleanValue ()) {
154 continue;
155 }if (!this.offscreenRender && (sequenceFeature.getBegin () > this.epos || sequenceFeature.getEnd () < this.spos)) {
156 continue;
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));
166 } else {
167 this.renderFeature (g, seq, seq.findIndex (sequenceFeature.begin) - 1, seq.findIndex (sequenceFeature.end) - 1, this.getColour (sequenceFeature), start, end, y1);
168 }}}
169 }
170 if (this.transparency != 1.0 && g != null && this.transparencyAvailable) {
171 var g2 = g;
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;
177 }, "~B");
178 Clazz.overrideMethod (c$, "isTransparencyAvailable", 
179 function () {
180 return this.transparencyAvailable;
181 });
182 Clazz.overrideMethod (c$, "featuresAdded", 
183 function () {
184 this.lastSeq = null;
185 this.findAllFeatures ();
186 });
187 });