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