JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / appletgui / AnnotationPanel.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "jalview.renderer.AwtRenderPanelI", "java.awt.event.ActionListener", "$.AdjustmentListener", "$.MouseListener", "$.MouseMotionListener", "java.awt.Color"], "jalview.appletgui.AnnotationPanel", ["awt2swing.MenuItem", "$.PopupMenu", "jalview.appletgui.EditNameDialog", "$.UserDefinedColours", "jalview.datamodel.Annotation", "jalview.renderer.AnnotationRenderer", "jalview.util.MessageManager", "$.Platform", "java.awt.Dimension", "java.lang.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.av = null;
5 this.ap = null;
6 this.activeRow = -1;
7 this.HELIX = "Helix";
8 this.SHEET = "Sheet";
9 this.STEM = "RNA Helix";
10 this.LABEL = "Label";
11 this.REMOVE = "Remove Annotation";
12 this.COLOUR = "Colour";
13 this.HELIX_COLOUR = null;
14 this.SHEET_COLOUR = null;
15 this.image = null;
16 this.gg = null;
17 this.fm = null;
18 this.imgWidth = 0;
19 this.$fastPaint = false;
20 this.graphStretch = -1;
21 this.graphStretchY = -1;
22 this.mouseDragging = false;
23 this.MAC = false;
24 this.renderer = null;
25 this.needValidating = false;
26 this.scrollOffset = 0;
27 this.$bounds = null;
28 Clazz.instantialize (this, arguments);
29 }, jalview.appletgui, "AnnotationPanel", awt2swing.Panel, [jalview.renderer.AwtRenderPanelI, java.awt.event.AdjustmentListener, java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener]);
30 Clazz.prepareFields (c$, function () {
31 this.HELIX_COLOUR = java.awt.Color.red.darker ();
32 this.SHEET_COLOUR = java.awt.Color.green.darker ().darker ();
33 this.$bounds =  Clazz.newIntArray (2, 0);
34 });
35 Clazz.makeConstructor (c$, 
36 function (ap) {
37 Clazz.superConstructor (this, jalview.appletgui.AnnotationPanel, []);
38 this.MAC = jalview.util.Platform.isAMac ();
39 this.ap = ap;
40 this.av = ap.av;
41 this.setLayout (null);
42 var height = this.adjustPanelHeight ();
43 ap.apvscroll.setValues (0, this.getSize ().height, 0, height);
44 this.addMouseMotionListener (this);
45 this.addMouseListener (this);
46 this.renderer =  new jalview.renderer.AnnotationRenderer ();
47 }, "jalview.appletgui.AlignmentPanel");
48 Clazz.makeConstructor (c$, 
49 function (av) {
50 Clazz.superConstructor (this, jalview.appletgui.AnnotationPanel, []);
51 this.av = av;
52 this.renderer =  new jalview.renderer.AnnotationRenderer ();
53 }, "jalview.appletgui.AlignViewport");
54 Clazz.overrideMethod (c$, "adjustmentValueChanged", 
55 function (evt) {
56 }, "java.awt.event.AdjustmentEvent");
57 Clazz.overrideMethod (c$, "actionPerformed", 
58 function (evt) {
59 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
60 if (aa == null) {
61 return;
62 }var anot = aa[this.activeRow].annotations;
63 if (anot.length < this.av.getColumnSelection ().getMax ()) {
64 var temp =  new Array (this.av.getColumnSelection ().getMax () + 2);
65 System.arraycopy (anot, 0, temp, 0, anot.length);
66 anot = temp;
67 aa[this.activeRow].annotations = anot;
68 }var label = "";
69 if (this.av.getColumnSelection () != null && this.av.getColumnSelection ().size () > 0 && anot[this.av.getColumnSelection ().getMin ()] != null) {
70 label = anot[this.av.getColumnSelection ().getMin ()].displayCharacter;
71 }if (evt.getActionCommand ().equals ("Remove Annotation")) {
72 for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
73 anot[this.av.getColumnSelection ().columnAt (i)] = null;
74 }
75 } else if (evt.getActionCommand ().equals ("Label")) {
76 label = this.enterLabel (label, "Enter Label");
77 if (label == null) {
78 return;
79 }if ((label.length > 0) && !aa[this.activeRow].hasText) {
80 aa[this.activeRow].hasText = true;
81 }for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
82 var index = this.av.getColumnSelection ().columnAt (i);
83 if (!this.av.getColumnSelection ().isVisible (index)) {
84 continue;
85 }if (anot[index] == null) {
86 anot[index] =  new jalview.datamodel.Annotation (label, "", ' ', 0);
87 }anot[index].displayCharacter = label;
88 }
89 } else if (evt.getActionCommand ().equals ("Colour")) {
90 var udc =  new jalview.appletgui.UserDefinedColours (this, java.awt.Color.black, this.ap.alignFrame);
91 var col = udc.getColor ();
92 for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
93 var index = this.av.getColumnSelection ().columnAt (i);
94 if (!this.av.getColumnSelection ().isVisible (index)) {
95 continue;
96 }if (anot[index] == null) {
97 anot[index] =  new jalview.datamodel.Annotation ("", "", ' ', 0);
98 }anot[index].colour = col;
99 }
100 } else {
101 var type = String.fromCharCode (0);
102 var symbol = "\u03B1";
103 if (evt.getActionCommand ().equals ("Helix")) {
104 type = 'H';
105 } else if (evt.getActionCommand ().equals ("Sheet")) {
106 type = 'E';
107 symbol = "\u03B2";
108 } else if (evt.getActionCommand ().equals ("RNA Helix")) {
109 type = 'S';
110 symbol = "\u03C3";
111 }if (!aa[this.activeRow].hasIcons) {
112 aa[this.activeRow].hasIcons = true;
113 }label = this.enterLabel (symbol, "Enter Label");
114 if (label == null) {
115 return;
116 }if ((label.length > 0) && !aa[this.activeRow].hasText) {
117 aa[this.activeRow].hasText = true;
118 if (evt.getActionCommand ().equals ("RNA Helix")) {
119 aa[this.activeRow].showAllColLabels = true;
120 }}for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
121 var index = this.av.getColumnSelection ().columnAt (i);
122 if (!this.av.getColumnSelection ().isVisible (index)) {
123 continue;
124 }if (anot[index] == null) {
125 anot[index] =  new jalview.datamodel.Annotation (label, "", type, 0);
126 }anot[index].secondaryStructure = type != 'S' ? type : label.length == 0 ? ' ' : label.charAt (0);
127 anot[index].displayCharacter = label;
128 }
129 }this.av.getAlignment ().validateAnnotation (aa[this.activeRow]);
130 this.ap.alignmentChanged ();
131 this.adjustPanelHeight ();
132 this.repaint ();
133 return;
134 }, "java.awt.event.ActionEvent");
135 Clazz.defineMethod (c$, "enterLabel", 
136 function (text, label) {
137 var dialog =  new jalview.appletgui.EditNameDialog (text, null, label, null, this.ap.alignFrame, "Enter Label", 400, 200, true);
138 if (dialog.accept) {
139 return dialog.getName ();
140 } else {
141 return null;
142 }}, "~S,~S");
143 Clazz.overrideMethod (c$, "mousePressed", 
144 function (evt) {
145 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
146 if (aa == null) {
147 return;
148 }var height = -this.scrollOffset;
149 this.activeRow = -1;
150 for (var i = 0; i < aa.length; i++) {
151 if (aa[i].visible) {
152 height += aa[i].height;
153 }if (evt.getY () < height) {
154 if (aa[i].editable) {
155 this.activeRow = i;
156 } else if (aa[i].graph > 0) {
157 this.graphStretch = i;
158 this.graphStretchY = evt.getY ();
159 }break;
160 }}
161 if ((evt.getModifiers () & 4) == 4 && this.activeRow != -1) {
162 if (this.av.getColumnSelection () == null) {
163 return;
164 }var pop =  new awt2swing.PopupMenu (jalview.util.MessageManager.getString ("label.structure_type"));
165 var item;
166 if (this.av.getAlignment ().isNucleotide () == true) {
167 item =  new awt2swing.MenuItem ("RNA Helix");
168 item.addActionListener (this);
169 pop.add (item);
170 } else {
171 item =  new awt2swing.MenuItem ("Helix");
172 item.addActionListener (this);
173 pop.add (item);
174 item =  new awt2swing.MenuItem ("Sheet");
175 item.addActionListener (this);
176 pop.add (item);
177 }item =  new awt2swing.MenuItem ("Label");
178 item.addActionListener (this);
179 pop.add (item);
180 item =  new awt2swing.MenuItem ("Colour");
181 item.addActionListener (this);
182 pop.add (item);
183 item =  new awt2swing.MenuItem ("Remove Annotation");
184 item.addActionListener (this);
185 pop.add (item);
186 this.ap.alignFrame.add (pop);
187 pop.show (this, evt.getX (), evt.getY ());
188 return;
189 }this.ap.scalePanel.mousePressed (evt);
190 }, "java.awt.event.MouseEvent");
191 Clazz.overrideMethod (c$, "mouseReleased", 
192 function (evt) {
193 this.graphStretch = -1;
194 this.graphStretchY = -1;
195 this.mouseDragging = false;
196 if (this.needValidating) {
197 this.ap.validate ();
198 this.needValidating = false;
199 }this.ap.scalePanel.mouseReleased (evt);
200 }, "java.awt.event.MouseEvent");
201 Clazz.overrideMethod (c$, "mouseClicked", 
202 function (evt) {
203 }, "java.awt.event.MouseEvent");
204 Clazz.overrideMethod (c$, "mouseDragged", 
205 function (evt) {
206 if (this.graphStretch > -1) {
207 this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight += this.graphStretchY - evt.getY ();
208 if (this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight < 0) {
209 this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight = 0;
210 }this.graphStretchY = evt.getY ();
211 this.av.calcPanelHeight ();
212 this.needValidating = true;
213 this.ap.paintAlignment (true);
214 } else {
215 this.ap.scalePanel.mouseDragged (evt);
216 }}, "java.awt.event.MouseEvent");
217 Clazz.overrideMethod (c$, "mouseMoved", 
218 function (evt) {
219 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
220 if (aa == null) {
221 return;
222 }var row = -1;
223 var height = -this.scrollOffset;
224 for (var i = 0; i < aa.length; i++) {
225 if (aa[i].visible) {
226 height += aa[i].height;
227 }if (evt.getY () < height) {
228 row = i;
229 break;
230 }}
231 var res = Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ()) + this.av.getStartRes ();
232 if (this.av.hasHiddenColumns ()) {
233 res = this.av.getColumnSelection ().adjustForHiddenColumns (res);
234 }if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null) {
235 var text =  new StringBuffer ("Sequence position " + (res + 1));
236 if (aa[row].annotations[res].description != null) {
237 text.append ("  " + aa[row].annotations[res].description);
238 }this.ap.alignFrame.setStatus (text.toString ());
239 }}, "java.awt.event.MouseEvent");
240 Clazz.overrideMethod (c$, "mouseEntered", 
241 function (evt) {
242 this.ap.scalePanel.mouseEntered (evt);
243 }, "java.awt.event.MouseEvent");
244 Clazz.overrideMethod (c$, "mouseExited", 
245 function (evt) {
246 this.ap.scalePanel.mouseExited (evt);
247 }, "java.awt.event.MouseEvent");
248 Clazz.defineMethod (c$, "adjustPanelHeight", 
249 function () {
250 return this.adjustPanelHeight (true);
251 });
252 Clazz.defineMethod (c$, "adjustPanelHeight", 
253 function (repaint) {
254 var height = this.av.calcPanelHeight ();
255 this.setSize ( new java.awt.Dimension (this.getSize ().width, height));
256 if (repaint) {
257 this.repaint ();
258 }return height;
259 }, "~B");
260 Clazz.defineMethod (c$, "addEditableColumn", 
261 function (i) {
262 if (this.activeRow == -1) {
263 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
264 if (aa == null) {
265 return;
266 }for (var j = 0; j < aa.length; j++) {
267 if (aa[j].editable) {
268 this.activeRow = j;
269 break;
270 }}
271 }}, "~N");
272 Clazz.overrideMethod (c$, "paintComponent", 
273 function (g) {
274 if (this.av.getWrapAlignment () || !this.av.isShowAnnotation ()) return;
275 var d = this.getSize ();
276 this.imgWidth = d.width;
277 if (this.imgWidth < 1 || d.height < 1) {
278 return;
279 }if (this.image == null || this.imgWidth != this.image.getWidth (this) || d.height != this.image.getHeight (this)) {
280 this.image = this.createImage (this.imgWidth, d.height);
281 this.gg = this.image.getGraphics ();
282 this.gg.setFont (this.av.getFont ());
283 this.fm = this.gg.getFontMetrics ();
284 this.$fastPaint = false;
285 }if (this.$fastPaint) {
286 g.drawImage (this.image, 0, 0, this);
287 this.$fastPaint = false;
288 return;
289 }this.gg.setColor (java.awt.Color.white);
290 this.gg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
291 this.drawComponent (this.gg, this.av.startRes, this.av.endRes + 1);
292 g.drawImage (this.image, 0, 0, this);
293 }, "java.awt.Graphics");
294 Clazz.defineMethod (c$, "fastPaint", 
295 function (horizontal) {
296 if (horizontal == 0 || this.av.getAlignment ().getAlignmentAnnotation () == null || this.av.getAlignment ().getAlignmentAnnotation ().length < 1) {
297 this.repaint ();
298 return;
299 }this.gg.copyArea (0, 0, this.imgWidth, this.getSize ().height, -horizontal * this.av.getCharWidth (), 0);
300 var sr = this.av.startRes;
301 var er = this.av.endRes + 1;
302 var transX = 0;
303 if (horizontal > 0) {
304 transX = (er - sr - horizontal) * this.av.getCharWidth ();
305 sr = er - horizontal;
306 } else if (horizontal < 0) {
307 er = sr - horizontal;
308 }this.gg.translate (transX, 0);
309 this.drawComponent (this.gg, sr, er);
310 this.gg.translate (-transX, 0);
311 this.$fastPaint = true;
312 this.repaint ();
313 }, "~N");
314 Clazz.defineMethod (c$, "drawComponent", 
315 function (g, startRes, endRes) {
316 var ofont = this.av.getFont ();
317 g.setFont (ofont);
318 g.setColor (java.awt.Color.white);
319 g.fillRect (0, 0, (endRes - startRes) * this.av.getCharWidth (), this.getSize ().height);
320 if (this.fm == null) {
321 this.fm = g.getFontMetrics ();
322 }if ((this.av.getAlignment ().getAlignmentAnnotation () == null) || (this.av.getAlignment ().getAlignmentAnnotation ().length < 1)) {
323 g.setColor (java.awt.Color.white);
324 g.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
325 g.setColor (java.awt.Color.black);
326 if (this.av.validCharWidth) {
327 g.drawString (jalview.util.MessageManager.getString ("label.alignment_has_no_annotations"), 20, 15);
328 }return;
329 }g.translate (0, -this.scrollOffset);
330 this.renderer.drawComponent (this, this.av, g, this.activeRow, startRes, endRes);
331 g.translate (0, +this.scrollOffset);
332 }, "java.awt.Graphics,~N,~N");
333 Clazz.defineMethod (c$, "setScrollOffset", 
334 function (value, repaint) {
335 this.scrollOffset = value;
336 if (repaint) {
337 this.repaint ();
338 }}, "~N,~B");
339 Clazz.defineMethod (c$, "getFontMetrics", 
340 function () {
341 return this.fm;
342 });
343 Clazz.overrideMethod (c$, "getFadedImage", 
344 function () {
345 return this.image;
346 });
347 Clazz.overrideMethod (c$, "getFadedImageWidth", 
348 function () {
349 return this.imgWidth;
350 });
351 Clazz.overrideMethod (c$, "getVisibleVRange", 
352 function () {
353 if (this.ap != null && this.ap.alabels != null) {
354 var sOffset = -this.ap.alabels.scrollOffset;
355 var visHeight = sOffset + this.ap.annotationPanelHolder.getHeight ();
356 this.$bounds[0] = sOffset;
357 this.$bounds[1] = visHeight;
358 return this.$bounds;
359 } else {
360 return null;
361 }});
362 Clazz.defineStatics (c$,
363 "GRAPH_HEIGHT", 40);
364 });