JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / appletgui / IdCanvas.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel"], "jalview.appletgui.IdCanvas", ["jalview.appletgui.AnnotationLabels", "$.AnnotationPanel", "$.PaintRefresher", "java.awt.Color", "$.Font"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.av = null;
5 this.showScores = true;
6 this.maxIdLength = -1;
7 this.maxIdStr = null;
8 this.image = null;
9 this.gg = null;
10 this.imgHeight = 0;
11 this.$fastPaint = false;
12 this.searchResults = null;
13 this.avcharHeight = 0;
14 Clazz.instantialize (this, arguments);
15 }, jalview.appletgui, "IdCanvas", awt2swing.Panel);
16 Clazz.makeConstructor (c$, 
17 function (av) {
18 Clazz.superConstructor (this, jalview.appletgui.IdCanvas, []);
19 this.setLayout (null);
20 this.av = av;
21 jalview.appletgui.PaintRefresher.Register (this, av.getSequenceSetId ());
22 }, "jalview.appletgui.AlignViewport");
23 Clazz.defineMethod (c$, "drawIdString", 
24 function (gg, hiddenRows, s, i, starty, ypos) {
25 var charHeight = this.av.getCharHeight ();
26 if (this.searchResults != null && this.searchResults.contains (s)) {
27 gg.setColor (java.awt.Color.black);
28 gg.fillRect (0, ((i - starty) * charHeight) + ypos, this.getSize ().width, charHeight);
29 gg.setColor (java.awt.Color.white);
30 } else if (this.av.getSelectionGroup () != null && this.av.getSelectionGroup ().getSequences (null).contains (s)) {
31 gg.setColor (java.awt.Color.lightGray);
32 gg.fillRect (0, ((i - starty) * charHeight) + ypos, this.getSize ().width, charHeight);
33 gg.setColor (java.awt.Color.white);
34 } else {
35 gg.setColor (this.av.getSequenceColour (s));
36 gg.fillRect (0, ((i - starty) * charHeight) + ypos, this.getSize ().width, charHeight);
37 gg.setColor (java.awt.Color.black);
38 }gg.drawString (s.getDisplayId (this.av.getShowJVSuffix ()), 0, ((i - starty) * charHeight) + ypos + charHeight - (Clazz.doubleToInt (charHeight / 5)));
39 if (hiddenRows) {
40 this.drawMarker (i, starty, ypos);
41 }}, "java.awt.Graphics,~B,jalview.datamodel.SequenceI,~N,~N,~N");
42 Clazz.defineMethod (c$, "fastPaint", 
43 function (vertical) {
44 if (this.gg == null) {
45 this.repaint ();
46 return;
47 }this.gg.copyArea (0, 0, this.getSize ().width, this.imgHeight, 0, -vertical * this.av.getCharHeight ());
48 var ss = this.av.startSeq;
49 var es = this.av.endSeq;
50 var transY = 0;
51 if (vertical > 0) {
52 ss = es - vertical;
53 if (ss < this.av.startSeq) {
54 ss = this.av.startSeq;
55 } else {
56 transY = this.imgHeight - vertical * this.av.getCharHeight ();
57 }} else if (vertical < 0) {
58 es = ss - vertical;
59 if (es > this.av.endSeq) {
60 es = this.av.endSeq;
61 }}this.gg.translate (0, transY);
62 this.drawIds (ss, es);
63 this.gg.translate (0, -transY);
64 this.$fastPaint = true;
65 this.repaint ();
66 }, "~N");
67 Clazz.overrideMethod (c$, "paintComponent", 
68 function (g) {
69 if (this.getSize ().height < 0 || this.getSize ().width < 0) {
70 return;
71 }if (this.$fastPaint) {
72 this.$fastPaint = false;
73 g.drawImage (this.image, 0, 0, this);
74 return;
75 }this.imgHeight = this.getSize ().height;
76 this.imgHeight -= this.imgHeight % this.av.getCharHeight ();
77 if (this.imgHeight < 1) {
78 return;
79 }if (this.image == null || this.imgHeight != this.image.getHeight (this)) {
80 this.image = this.createImage (this.getSize ().width, this.imgHeight);
81 this.gg = this.image.getGraphics ();
82 this.gg.setFont (this.av.getFont ());
83 }this.gg.setColor (java.awt.Color.white);
84 var italic =  new java.awt.Font (this.av.getFont ().getName (), 2, this.av.getFont ().getSize ());
85 this.gg.setFont (italic);
86 this.gg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
87 this.drawIds (this.av.startSeq, this.av.endSeq);
88 g.drawImage (this.image, 0, 0, this);
89 }, "java.awt.Graphics");
90 Clazz.defineMethod (c$, "drawIds", 
91 function (starty, endy) {
92 var italic =  new java.awt.Font (this.av.getFont ().getName (), 2, this.av.getFont ().getSize ());
93 this.avcharHeight = this.av.getCharHeight ();
94 this.gg.setFont (italic);
95 var currentColor = java.awt.Color.white;
96 var currentTextColor = java.awt.Color.black;
97 var doHiddenCheck = this.av.isDisplayReferenceSeq () || this.av.hasHiddenRows ();
98 var hiddenRows = this.av.hasHiddenRows () && this.av.getShowHiddenMarkers ();
99 if (this.av.getWrapAlignment ()) {
100 var maxwidth = this.av.getAlignment ().getWidth ();
101 var alheight = this.av.getAlignment ().getHeight ();
102 if (this.av.hasHiddenColumns ()) {
103 maxwidth = this.av.getColumnSelection ().findColumnPosition (maxwidth) - 1;
104 }var annotationHeight = 0;
105 var labels = null;
106 if (this.av.isShowAnnotation ()) {
107 var ap =  new jalview.appletgui.AnnotationPanel (this.av);
108 annotationHeight = ap.adjustPanelHeight ();
109 labels =  new jalview.appletgui.AnnotationLabels (this.av);
110 }var hgap = this.avcharHeight;
111 if (this.av.getScaleAboveWrapped ()) {
112 hgap += this.avcharHeight;
113 }var cHeight = alheight * this.avcharHeight + hgap + annotationHeight;
114 var rowSize = this.av.getEndRes () - this.av.getStartRes ();
115 for (var ypos = hgap, row = this.av.startRes; (ypos <= this.getSize ().height) && (row < maxwidth); ypos += cHeight, row += rowSize) {
116 for (var i = starty; i < alheight; i++) {
117 var s = this.av.getAlignment ().getSequenceAt (i);
118 this.gg.setFont (italic);
119 if (doHiddenCheck) {
120 this.setHiddenFont (s);
121 }this.drawIdString (this.gg, hiddenRows, s, i, 0, ypos);
122 }
123 if (labels != null) {
124 this.gg.translate (0, ypos + (alheight * this.avcharHeight));
125 labels.drawComponent (this.gg, this.getSize ().width);
126 this.gg.translate (0, -ypos - (alheight * this.avcharHeight));
127 }}
128 } else {
129 var seq;
130 for (var i = starty; i < endy; i++) {
131 seq = this.av.getAlignment ().getSequenceAt (i);
132 if (seq == null) {
133 continue;
134 }this.gg.setFont (italic);
135 if (doHiddenCheck) {
136 this.setHiddenFont (seq);
137 }if ((this.searchResults != null) && this.searchResults.contains (seq)) {
138 currentColor = java.awt.Color.black;
139 currentTextColor = java.awt.Color.white;
140 } else if ((this.av.getSelectionGroup () != null) && this.av.getSelectionGroup ().getSequences (null).contains (seq)) {
141 currentColor = java.awt.Color.lightGray;
142 currentTextColor = java.awt.Color.black;
143 } else {
144 currentColor = this.av.getSequenceColour (seq);
145 currentTextColor = java.awt.Color.black;
146 }this.gg.setColor (currentColor);
147 this.gg.fillRect (0, (i - starty) * this.avcharHeight, this.getSize ().width, this.avcharHeight);
148 this.gg.setColor (currentTextColor);
149 this.gg.drawString (seq.getDisplayId (this.av.getShowJVSuffix ()), 0, (((i - starty) * this.avcharHeight) + this.avcharHeight) - (Clazz.doubleToInt (this.avcharHeight / 5)));
150 if (hiddenRows) {
151 this.drawMarker (i, starty, 0);
152 }}
153 }}, "~N,~N");
154 Clazz.defineMethod (c$, "setHighlighted", 
155 function (list) {
156 this.searchResults = list;
157 this.repaint ();
158 }, "java.util.List");
159 Clazz.defineMethod (c$, "drawMarker", 
160 function (i, starty, yoffset) {
161 var hseqs = this.av.getAlignment ().getHiddenSequences ().hiddenSequences;
162 var hSize = hseqs.length;
163 var hiddenIndex = i;
164 var lastIndex = i - 1;
165 var nextIndex = i + 1;
166 for (var j = 0; j < hSize; j++) {
167 if (hseqs[j] != null) {
168 if (j - 1 < hiddenIndex) {
169 hiddenIndex++;
170 }if (j - 1 < lastIndex) {
171 lastIndex++;
172 }if (j - 1 < nextIndex) {
173 nextIndex++;
174 }}}
175 var below = (hiddenIndex > lastIndex + 1);
176 var above = (nextIndex > hiddenIndex + 1);
177 this.gg.setColor (java.awt.Color.blue);
178 if (below) {
179 this.gg.fillPolygon ( Clazz.newIntArray (-1, [this.getSize ().width - this.avcharHeight, this.getSize ().width - this.avcharHeight, this.getSize ().width]),  Clazz.newIntArray (-1, [(i - starty) * this.avcharHeight + yoffset, (i - starty) * this.avcharHeight + yoffset + Clazz.doubleToInt (this.avcharHeight / 4), (i - starty) * this.avcharHeight + yoffset]), 3);
180 }if (above) {
181 this.gg.fillPolygon ( Clazz.newIntArray (-1, [this.getSize ().width - this.avcharHeight, this.getSize ().width - this.avcharHeight, this.getSize ().width]),  Clazz.newIntArray (-1, [(i - starty + 1) * this.avcharHeight + yoffset, (i - starty + 1) * this.avcharHeight + yoffset - Clazz.doubleToInt (this.avcharHeight / 4), (i - starty + 1) * this.avcharHeight + yoffset]), 3);
182 }}, "~N,~N,~N");
183 Clazz.defineMethod (c$, "setHiddenFont", 
184 function (seq) {
185 var bold =  new java.awt.Font (this.av.getFont ().getName (), 1, this.av.getFont ().getSize ());
186 if (this.av.isHiddenRepSequence (seq)) {
187 this.gg.setFont (bold);
188 return true;
189 }return false;
190 }, "jalview.datamodel.SequenceI");
191 });