1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel"], "jalview.appletgui.SeqCanvas", ["jalview.appletgui.AnnotationPanel", "$.FeatureRenderer", "$.PaintRefresher", "$.SequenceRenderer", "jalview.util.Comparison", "java.awt.Color"], function () {
3 c$ = Clazz.decorateAsClass (function () {
11 this.searchResults = null;
12 this.$fastPaint = false;
15 this.avcharHeight = 0;
20 this.annotations = null;
21 Clazz.instantialize (this, arguments);
22 }, jalview.appletgui, "SeqCanvas", awt2swing.Panel);
23 Clazz.makeConstructor (c$,
25 Clazz.superConstructor (this, jalview.appletgui.SeqCanvas, []);
27 this.fr = new jalview.appletgui.FeatureRenderer (av);
28 this.sr = new jalview.appletgui.SequenceRenderer (av);
29 jalview.appletgui.PaintRefresher.Register (this, av.getSequenceSetId ());
30 this.updateViewport ();
31 }, "jalview.appletgui.AlignViewport");
32 Clazz.defineMethod (c$, "updateViewport",
34 this.avcharHeight = this.av.getCharHeight ();
35 this.avcharWidth = this.av.getCharWidth ();
36 }, $fz.isPrivate = true, $fz));
37 Clazz.defineMethod (c$, "getViewport",
41 Clazz.defineMethod (c$, "getFeatureRenderer",
45 Clazz.defineMethod (c$, "getSequenceRenderer",
49 Clazz.defineMethod (c$, "drawNorthScale",
50 ($fz = function (g, startx, endx, ypos) {
51 var scalestartx = startx - startx % 10 + 10;
52 g.setColor (java.awt.Color.black);
53 for (var i = scalestartx; i < endx; i += 10) {
55 if (this.av.hasHiddenColumns ()) {
56 value = this.av.getColumnSelection ().adjustForHiddenColumns (value);
57 }g.drawString (String.valueOf (value), (i - startx - 1) * this.avcharWidth, ypos - (Clazz.doubleToInt (this.avcharHeight / 2)));
58 g.drawLine (((i - startx - 1) * this.avcharWidth) + (Clazz.doubleToInt (this.avcharWidth / 2)), (ypos + 2) - (Clazz.doubleToInt (this.avcharHeight / 2)), ((i - startx - 1) * this.avcharWidth) + (Clazz.doubleToInt (this.avcharWidth / 2)), ypos - 2);
60 }, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N");
61 Clazz.defineMethod (c$, "drawWestScale",
62 ($fz = function (g, startx, endx, ypos) {
63 var fm = this.getFontMetrics (this.av.getFont ());
64 ypos += this.avcharHeight;
65 if (this.av.hasHiddenColumns ()) {
66 startx = this.av.getColumnSelection ().adjustForHiddenColumns (startx);
67 endx = this.av.getColumnSelection ().adjustForHiddenColumns (endx);
68 }var maxwidth = this.av.getAlignment ().getWidth ();
69 if (this.av.hasHiddenColumns ()) {
70 maxwidth = this.av.getColumnSelection ().findColumnPosition (maxwidth) - 1;
71 }for (var i = 0; i < this.av.getAlignment ().getHeight (); i++) {
72 var seq = this.av.getAlignment ().getSequenceAt (i);
75 while (index < endx) {
76 if (jalview.util.Comparison.isGap (seq.getCharAt (index))) {
79 }value = this.av.getAlignment ().getSequenceAt (i).findPosition (index);
83 var x = this.LABEL_WEST - fm.stringWidth (String.valueOf (value)) - Clazz.doubleToInt (this.avcharWidth / 2);
84 g.drawString (value + "", x, (ypos + (i * this.avcharHeight)) - (Clazz.doubleToInt (this.avcharHeight / 5)));
86 }, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N");
87 Clazz.defineMethod (c$, "drawEastScale",
88 ($fz = function (g, startx, endx, ypos) {
89 ypos += this.avcharHeight;
90 if (this.av.hasHiddenColumns ()) {
91 endx = this.av.getColumnSelection ().adjustForHiddenColumns (endx);
93 for (var i = 0; i < this.av.getAlignment ().getHeight (); i++) {
94 seq = this.av.getAlignment ().getSequenceAt (i);
97 while (index > startx) {
98 if (jalview.util.Comparison.isGap (seq.getCharAt (index))) {
101 }value = seq.findPosition (index);
105 g.drawString (String.valueOf (value), 0, (ypos + (i * this.avcharHeight)) - (Clazz.doubleToInt (this.avcharHeight / 5)));
107 }, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N");
108 Clazz.defineMethod (c$, "fastPaint",
109 function (horizontal, vertical) {
110 if (this.$fastPaint || this.gg == null) {
112 }this.updateViewport ();
113 if (this.lastsr + horizontal != this.av.startRes) {
114 horizontal = this.av.startRes - this.lastsr;
115 }this.lastsr = this.av.startRes;
116 this.$fastPaint = true;
117 this.gg.copyArea (horizontal * this.avcharWidth, vertical * this.avcharHeight, this.imgWidth - horizontal * this.avcharWidth, this.imgHeight - vertical * this.avcharHeight, -horizontal * this.avcharWidth, -vertical * this.avcharHeight);
118 var sr = this.av.startRes;
119 var er = this.av.endRes;
120 var ss = this.av.startSeq;
121 var es = this.av.endSeq;
124 if (horizontal > 0) {
125 transX = (er - sr - horizontal) * this.avcharWidth;
126 sr = er - horizontal;
127 } else if (horizontal < 0) {
128 er = sr - horizontal;
129 } else if (vertical > 0) {
131 if (ss < this.av.startSeq) {
132 ss = this.av.startSeq;
134 transY = this.imgHeight - vertical * this.avcharHeight;
135 }} else if (vertical < 0) {
137 if (es > this.av.endSeq) {
139 }}this.gg.translate (transX, transY);
140 this.drawPanel (this.gg, sr, er, ss, es, 0);
141 this.gg.translate (-transX, -transY);
144 Clazz.overrideMethod (c$, "paintComponent",
146 if (this.img != null && (this.$fastPaint || (this.getSize ().width != g.getClipBounds ().width) || (this.getSize ().height != g.getClipBounds ().height))) {
147 g.drawImage (this.img, 0, 0, this);
148 this.$fastPaint = false;
150 }if (this.$fastPaint) {
151 g.drawImage (this.img, 0, 0, this);
152 this.$fastPaint = false;
154 }this.updateViewport ();
155 this.imgWidth = this.getSize ().width;
156 this.imgHeight = this.getSize ().height;
157 this.imgWidth -= this.imgWidth % this.avcharWidth;
158 this.imgHeight -= this.imgHeight % this.avcharHeight;
159 if (this.imgWidth < 1 || this.imgHeight < 1) {
161 }if (this.img == null || this.imgWidth != this.img.getWidth (this) || this.imgHeight != this.img.getHeight (this)) {
162 this.img = this.createImage (this.imgWidth, this.imgHeight);
163 this.gg = this.img.getGraphics ();
164 this.gg.setFont (this.av.getFont ());
165 }this.gg.setColor (java.awt.Color.white);
166 this.gg.fillRect (0, 0, this.imgWidth, this.imgHeight);
167 if (this.av.getWrapAlignment ()) {
168 this.drawWrappedPanel (this.gg, this.imgWidth, this.imgHeight, this.av.startRes);
170 this.drawPanel (this.gg, this.av.startRes, this.av.endRes, this.av.startSeq, this.av.endSeq, 0);
171 }g.drawImage (this.img, 0, 0, this);
172 }, "java.awt.Graphics");
173 Clazz.defineMethod (c$, "getWrappedCanvasWidth",
175 cwidth -= cwidth % this.av.getCharWidth ();
176 var fm = this.getFontMetrics (this.av.getFont ());
179 if (this.av.getScaleRightWrapped ()) {
180 this.LABEL_EAST = fm.stringWidth (this.getMask ());
181 }if (this.av.getScaleLeftWrapped ()) {
182 this.LABEL_WEST = fm.stringWidth (this.getMask ());
183 }return Clazz.doubleToInt ((cwidth - this.LABEL_EAST - this.LABEL_WEST) / this.av.getCharWidth ());
185 Clazz.defineMethod (c$, "getMask",
190 var alignment = this.av.getAlignment ();
191 for (var i = 0; i < alignment.getHeight (); i++) {
192 tmp = alignment.getSequenceAt (i).getEnd ();
193 if (tmp > maxWidth) {
196 for (var i = maxWidth; i > 0; i /= 10) {
201 Clazz.defineMethod (c$, "drawWrappedPanel",
202 ($fz = function (g, canvasWidth, canvasHeight, startRes) {
203 var al = this.av.getAlignment ();
204 var fm = this.getFontMetrics (this.av.getFont ());
205 if (this.av.getScaleRightWrapped ()) {
206 this.LABEL_EAST = fm.stringWidth (this.getMask ());
207 }if (this.av.getScaleLeftWrapped ()) {
208 this.LABEL_WEST = fm.stringWidth (this.getMask ());
209 }var hgap = this.avcharHeight;
210 if (this.av.getScaleAboveWrapped ()) {
211 hgap += this.avcharHeight;
212 }var cWidth = Clazz.doubleToInt ((canvasWidth - this.LABEL_EAST - this.LABEL_WEST) / this.avcharWidth);
213 var cHeight = this.av.getAlignment ().getHeight () * this.avcharHeight;
214 this.av.setWrappedWidth (cWidth);
215 this.av.endRes = this.av.startRes + cWidth;
218 var maxwidth = this.av.getAlignment ().getWidth () - 1;
219 if (this.av.hasHiddenColumns ()) {
220 maxwidth = this.av.getColumnSelection ().findColumnPosition (maxwidth) - 1;
221 }while ((ypos <= canvasHeight) && (startRes < maxwidth)) {
222 endx = startRes + cWidth - 1;
223 if (endx > maxwidth) {
225 }g.setColor (java.awt.Color.black);
226 if (this.av.getScaleLeftWrapped ()) {
227 this.drawWestScale (g, startRes, endx, ypos);
228 }if (this.av.getScaleRightWrapped ()) {
229 g.translate (canvasWidth - this.LABEL_EAST, 0);
230 this.drawEastScale (g, startRes, endx, ypos);
231 g.translate (-(canvasWidth - this.LABEL_EAST), 0);
232 }g.translate (this.LABEL_WEST, 0);
233 if (this.av.getScaleAboveWrapped ()) {
234 this.drawNorthScale (g, startRes, endx, ypos);
235 }if (this.av.hasHiddenColumns () && this.av.getShowHiddenMarkers ()) {
236 g.setColor (java.awt.Color.blue);
238 for (var i = 0; i < this.av.getColumnSelection ().getHiddenColumns ().size (); i++) {
239 res = this.av.getColumnSelection ().findHiddenRegionPosition (i) - startRes;
240 if (res < 0 || res > endx - startRes) {
242 }this.gg.fillPolygon ( Clazz.newIntArray (-1, [res * this.avcharWidth - Clazz.doubleToInt (this.avcharHeight / 4), res * this.avcharWidth + Clazz.doubleToInt (this.avcharHeight / 4), res * this.avcharWidth]), Clazz.newIntArray (-1, [ypos - (Clazz.doubleToInt (this.avcharHeight / 2)), ypos - (Clazz.doubleToInt (this.avcharHeight / 2)), ypos - (Clazz.doubleToInt (this.avcharHeight / 2)) + 8]), 3);
244 }if (g.getClip () == null) {
245 g.setClip (0, 0, cWidth * this.avcharWidth, canvasHeight);
246 }this.drawPanel (g, startRes, endx, 0, al.getHeight (), ypos);
248 if (this.av.isShowAnnotation ()) {
249 g.translate (0, cHeight + ypos + 4);
250 if (this.annotations == null) {
251 this.annotations = new jalview.appletgui.AnnotationPanel (this.av);
252 }this.annotations.drawComponent (g, startRes, endx + 1);
253 g.translate (0, -cHeight - ypos - 4);
254 }g.translate (-this.LABEL_WEST, 0);
255 ypos += cHeight + this.getAnnotationHeight () + hgap;
258 }, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N");
259 Clazz.defineMethod (c$, "getAnnotationHeight",
261 if (!this.av.isShowAnnotation ()) {
263 }if (this.annotations == null) {
264 this.annotations = new jalview.appletgui.AnnotationPanel (this.av);
265 }return this.annotations.adjustPanelHeight ();
267 Clazz.defineMethod (c$, "drawPanel",
268 ($fz = function (g1, startRes, endRes, startSeq, endSeq, offset) {
269 if (!this.av.hasHiddenColumns ()) {
270 this.draw (g1, startRes, endRes, startSeq, endSeq, offset);
273 var blockStart = startRes;
274 var blockEnd = endRes;
275 if (this.av.hasHiddenColumns ()) {
276 for (var region, $region = this.av.getColumnSelection ().getHiddenColumns ().iterator (); $region.hasNext () && ((region = $region.next ()) || true);) {
277 var hideStart = region[0];
278 var hideEnd = region[1];
279 if (hideStart <= blockStart) {
280 blockStart += (hideEnd - hideStart) + 1;
282 }blockEnd = hideStart - 1;
283 g1.translate (screenY * this.avcharWidth, 0);
284 this.draw (g1, blockStart, blockEnd, startSeq, endSeq, offset);
285 if (this.av.getShowHiddenMarkers ()) {
286 g1.setColor (java.awt.Color.blue);
287 g1.drawLine ((blockEnd - blockStart + 1) * this.avcharWidth - 1, 0 + offset, (blockEnd - blockStart + 1) * this.avcharWidth - 1, (endSeq - startSeq) * this.avcharHeight + offset);
288 }g1.translate (-screenY * this.avcharWidth, 0);
289 screenY += blockEnd - blockStart + 1;
290 blockStart = hideEnd + 1;
292 }if (screenY <= (endRes - startRes)) {
293 blockEnd = blockStart + (endRes - startRes) - screenY;
294 g1.translate (screenY * this.avcharWidth, 0);
295 this.draw (g1, blockStart, blockEnd, startSeq, endSeq, offset);
296 g1.translate (-screenY * this.avcharWidth, 0);
297 }}}, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N,~N,~N");
298 Clazz.defineMethod (c$, "draw",
299 function (g, startRes, endRes, startSeq, endSeq, offset) {
300 g.setFont (this.av.getFont ());
301 this.sr.prepare (g, this.av.isRenderGaps ());
302 this.updateViewport ();
304 for (var i = startSeq; i < endSeq; i++) {
305 nextSeq = this.av.getAlignment ().getSequenceAt (i);
306 if (nextSeq == null) {
308 }this.sr.drawSequence (nextSeq, this.av.getAlignment ().findAllGroups (nextSeq), startRes, endRes, offset + ((i - startSeq) * this.avcharHeight));
309 if (this.av.isShowSequenceFeatures ()) {
310 this.fr.drawSequence (g, nextSeq, startRes, endRes, offset + ((i - startSeq) * this.avcharHeight));
311 }if (this.searchResults != null) {
312 var visibleResults = this.searchResults.getResults (nextSeq, startRes, endRes);
313 if (visibleResults != null) {
314 for (var r = 0; r < visibleResults.length; r += 2) {
315 this.sr.drawHighlightedText (nextSeq, visibleResults[r], visibleResults[r + 1], (visibleResults[r] - startRes) * this.avcharWidth, offset + ((i - startSeq) * this.avcharHeight));
317 }}if (this.av.cursorMode && this.cursorY == i && this.cursorX >= startRes && this.cursorX <= endRes) {
318 this.sr.drawCursor (nextSeq, this.cursorX, (this.cursorX - startRes) * this.avcharWidth, offset + ((i - startSeq) * this.avcharHeight));
320 if (this.av.getSelectionGroup () != null || this.av.getAlignment ().getGroups ().size () > 0) {
321 this.drawGroupsBoundaries (g, startRes, endRes, startSeq, endSeq, offset);
322 }}, "java.awt.Graphics,~N,~N,~N,~N,~N");
323 Clazz.defineMethod (c$, "drawGroupsBoundaries",
324 ($fz = function (g, startRes, endRes, startSeq, endSeq, offset) {
325 var group = this.av.getSelectionGroup ();
330 if ((group == null) && (this.av.getAlignment ().getGroups ().size () > 0)) {
331 group = this.av.getAlignment ().getGroups ().get (0);
333 }if (group != null) {
340 var alHeight = this.av.getAlignment ().getHeight () - 1;
341 for (i = startSeq; i < endSeq; i++) {
342 sx = (group.getStartRes () - startRes) * this.avcharWidth;
343 sy = offset + ((i - startSeq) * this.avcharHeight);
344 ex = (((group.getEndRes () + 1) - group.getStartRes ()) * this.avcharWidth) - 1;
345 if (sx + ex < 0 || sx > this.imgWidth) {
347 }if ((sx <= (endRes - startRes) * this.avcharWidth) && group.getSequences (null).contains (this.av.getAlignment ().getSequenceAt (i))) {
348 if ((bottom == -1) && (i >= alHeight || !group.getSequences (null).contains (this.av.getAlignment ().getSequenceAt (i + 1)))) {
349 bottom = sy + this.avcharHeight;
351 if (((top == -1) && (i == 0)) || !group.getSequences (null).contains (this.av.getAlignment ().getSequenceAt (i - 1))) {
355 if (group === this.av.getSelectionGroup ()) {
356 g.setColor (java.awt.Color.red);
358 g.setColor (group.getOutlineColour ());
361 if (sx >= 0 && sx < this.imgWidth) {
362 g.drawLine (sx, oldY, sx, sy);
363 }if (sx + ex < this.imgWidth) {
364 g.drawLine (sx + ex, oldY, sx + ex, sy);
368 }if (sx + ex > this.imgWidth) {
370 } else if (sx + ex >= (endRes - startRes + 1) * this.avcharWidth) {
371 ex = (endRes - startRes + 1) * this.avcharWidth;
373 g.drawLine (sx, top, sx + ex, top);
376 g.drawLine (sx, bottom, sx + ex, bottom);
381 sy = offset + ((i - startSeq) * this.avcharHeight);
382 if (sx >= 0 && sx < this.imgWidth) {
383 g.drawLine (sx, oldY, sx, sy);
384 }if (sx + ex < this.imgWidth) {
385 g.drawLine (sx + ex, oldY, sx + ex, sy);
389 }if (sx + ex > this.imgWidth) {
391 } else if (sx + ex >= (endRes - startRes + 1) * this.avcharWidth) {
392 ex = (endRes - startRes + 1) * this.avcharWidth;
394 g.drawLine (sx, top, sx + ex, top);
397 g.drawLine (sx, bottom - 1, sx + ex, bottom - 1);
401 if (groupIndex >= this.av.getAlignment ().getGroups ().size ()) {
403 }group = this.av.getAlignment ().getGroups ().get (groupIndex);
404 } while (groupIndex < this.av.getAlignment ().getGroups ().size ());
405 }}, $fz.isPrivate = true, $fz), "java.awt.Graphics,~N,~N,~N,~N,~N");
406 Clazz.defineMethod (c$, "highlightSearchResults",
408 this.searchResults = results;
410 }, "jalview.datamodel.SearchResults");