1 Clazz.declarePackage ("jalview.appletgui");
\r
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 () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
7 this.HELIX = "Helix";
\r
8 this.SHEET = "Sheet";
\r
9 this.STEM = "RNA Helix";
\r
10 this.LABEL = "Label";
\r
11 this.REMOVE = "Remove Annotation";
\r
12 this.COLOUR = "Colour";
\r
13 this.HELIX_COLOUR = null;
\r
14 this.SHEET_COLOUR = null;
\r
19 this.$fastPaint = false;
\r
20 this.graphStretch = -1;
\r
21 this.graphStretchY = -1;
\r
22 this.mouseDragging = false;
\r
24 this.renderer = null;
\r
25 this.needValidating = false;
\r
26 this.scrollOffset = 0;
\r
27 this.$bounds = null;
\r
28 Clazz.instantialize (this, arguments);
\r
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]);
\r
30 Clazz.prepareFields (c$, function () {
\r
31 this.HELIX_COLOUR = java.awt.Color.red.darker ();
\r
32 this.SHEET_COLOUR = java.awt.Color.green.darker ().darker ();
\r
33 this.$bounds = Clazz.newIntArray (2, 0);
\r
35 Clazz.makeConstructor (c$,
\r
37 Clazz.superConstructor (this, jalview.appletgui.AnnotationPanel, []);
\r
38 this.MAC = jalview.util.Platform.isAMac ();
\r
41 this.setLayout (null);
\r
42 var height = this.adjustPanelHeight ();
\r
43 ap.apvscroll.setValues (0, this.getSize ().height, 0, height);
\r
44 this.addMouseMotionListener (this);
\r
45 this.addMouseListener (this);
\r
46 this.renderer = new jalview.renderer.AnnotationRenderer ();
\r
47 }, "jalview.appletgui.AlignmentPanel");
\r
48 Clazz.makeConstructor (c$,
\r
50 Clazz.superConstructor (this, jalview.appletgui.AnnotationPanel, []);
\r
52 this.renderer = new jalview.renderer.AnnotationRenderer ();
\r
53 }, "jalview.appletgui.AlignViewport");
\r
54 Clazz.overrideMethod (c$, "adjustmentValueChanged",
\r
56 }, "java.awt.event.AdjustmentEvent");
\r
57 Clazz.overrideMethod (c$, "actionPerformed",
\r
59 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
\r
62 }var anot = aa[this.activeRow].annotations;
\r
63 if (anot.length < this.av.getColumnSelection ().getMax ()) {
\r
64 var temp = new Array (this.av.getColumnSelection ().getMax () + 2);
\r
65 System.arraycopy (anot, 0, temp, 0, anot.length);
\r
67 aa[this.activeRow].annotations = anot;
\r
69 if (this.av.getColumnSelection () != null && this.av.getColumnSelection ().size () > 0 && anot[this.av.getColumnSelection ().getMin ()] != null) {
\r
70 label = anot[this.av.getColumnSelection ().getMin ()].displayCharacter;
\r
71 }if (evt.getActionCommand ().equals ("Remove Annotation")) {
\r
72 for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
\r
73 anot[this.av.getColumnSelection ().columnAt (i)] = null;
\r
75 } else if (evt.getActionCommand ().equals ("Label")) {
\r
76 label = this.enterLabel (label, "Enter Label");
\r
77 if (label == null) {
\r
79 }if ((label.length > 0) && !aa[this.activeRow].hasText) {
\r
80 aa[this.activeRow].hasText = true;
\r
81 }for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
\r
82 var index = this.av.getColumnSelection ().columnAt (i);
\r
83 if (!this.av.getColumnSelection ().isVisible (index)) {
\r
85 }if (anot[index] == null) {
\r
86 anot[index] = new jalview.datamodel.Annotation (label, "", ' ', 0);
\r
87 }anot[index].displayCharacter = label;
\r
89 } else if (evt.getActionCommand ().equals ("Colour")) {
\r
90 var udc = new jalview.appletgui.UserDefinedColours (this, java.awt.Color.black, this.ap.alignFrame);
\r
91 var col = udc.getColor ();
\r
92 for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
\r
93 var index = this.av.getColumnSelection ().columnAt (i);
\r
94 if (!this.av.getColumnSelection ().isVisible (index)) {
\r
96 }if (anot[index] == null) {
\r
97 anot[index] = new jalview.datamodel.Annotation ("", "", ' ', 0);
\r
98 }anot[index].colour = col;
\r
101 var type = String.fromCharCode (0);
\r
102 var symbol = "\u03B1";
\r
103 if (evt.getActionCommand ().equals ("Helix")) {
\r
105 } else if (evt.getActionCommand ().equals ("Sheet")) {
\r
108 } else if (evt.getActionCommand ().equals ("RNA Helix")) {
\r
111 }if (!aa[this.activeRow].hasIcons) {
\r
112 aa[this.activeRow].hasIcons = true;
\r
113 }label = this.enterLabel (symbol, "Enter Label");
\r
114 if (label == null) {
\r
116 }if ((label.length > 0) && !aa[this.activeRow].hasText) {
\r
117 aa[this.activeRow].hasText = true;
\r
118 if (evt.getActionCommand ().equals ("RNA Helix")) {
\r
119 aa[this.activeRow].showAllColLabels = true;
\r
120 }}for (var i = 0; i < this.av.getColumnSelection ().size (); i++) {
\r
121 var index = this.av.getColumnSelection ().columnAt (i);
\r
122 if (!this.av.getColumnSelection ().isVisible (index)) {
\r
124 }if (anot[index] == null) {
\r
125 anot[index] = new jalview.datamodel.Annotation (label, "", type, 0);
\r
126 }anot[index].secondaryStructure = type != 'S' ? type : label.length == 0 ? ' ' : label.charAt (0);
\r
127 anot[index].displayCharacter = label;
\r
129 }this.av.getAlignment ().validateAnnotation (aa[this.activeRow]);
\r
130 this.ap.alignmentChanged ();
\r
131 this.adjustPanelHeight ();
\r
134 }, "java.awt.event.ActionEvent");
\r
135 Clazz.defineMethod (c$, "enterLabel",
\r
136 function (text, label) {
\r
137 var dialog = new jalview.appletgui.EditNameDialog (text, null, label, null, this.ap.alignFrame, "Enter Label", 400, 200, true);
\r
138 if (dialog.accept) {
\r
139 return dialog.getName ();
\r
143 Clazz.overrideMethod (c$, "mousePressed",
\r
145 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
\r
148 }var height = -this.scrollOffset;
\r
149 this.activeRow = -1;
\r
150 for (var i = 0; i < aa.length; i++) {
\r
151 if (aa[i].visible) {
\r
152 height += aa[i].height;
\r
153 }if (evt.getY () < height) {
\r
154 if (aa[i].editable) {
\r
155 this.activeRow = i;
\r
156 } else if (aa[i].graph > 0) {
\r
157 this.graphStretch = i;
\r
158 this.graphStretchY = evt.getY ();
\r
161 if ((evt.getModifiers () & 4) == 4 && this.activeRow != -1) {
\r
162 if (this.av.getColumnSelection () == null) {
\r
164 }var pop = new awt2swing.PopupMenu (jalview.util.MessageManager.getString ("label.structure_type"));
\r
166 if (this.av.getAlignment ().isNucleotide () == true) {
\r
167 item = new awt2swing.MenuItem ("RNA Helix");
\r
168 item.addActionListener (this);
\r
171 item = new awt2swing.MenuItem ("Helix");
\r
172 item.addActionListener (this);
\r
174 item = new awt2swing.MenuItem ("Sheet");
\r
175 item.addActionListener (this);
\r
177 }item = new awt2swing.MenuItem ("Label");
\r
178 item.addActionListener (this);
\r
180 item = new awt2swing.MenuItem ("Colour");
\r
181 item.addActionListener (this);
\r
183 item = new awt2swing.MenuItem ("Remove Annotation");
\r
184 item.addActionListener (this);
\r
186 this.ap.alignFrame.add (pop);
\r
187 pop.show (this, evt.getX (), evt.getY ());
\r
189 }this.ap.scalePanel.mousePressed (evt);
\r
190 }, "java.awt.event.MouseEvent");
\r
191 Clazz.overrideMethod (c$, "mouseReleased",
\r
193 this.graphStretch = -1;
\r
194 this.graphStretchY = -1;
\r
195 this.mouseDragging = false;
\r
196 if (this.needValidating) {
\r
197 this.ap.validate ();
\r
198 this.needValidating = false;
\r
199 }this.ap.scalePanel.mouseReleased (evt);
\r
200 }, "java.awt.event.MouseEvent");
\r
201 Clazz.overrideMethod (c$, "mouseClicked",
\r
203 }, "java.awt.event.MouseEvent");
\r
204 Clazz.overrideMethod (c$, "mouseDragged",
\r
206 if (this.graphStretch > -1) {
\r
207 this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight += this.graphStretchY - evt.getY ();
\r
208 if (this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight < 0) {
\r
209 this.av.getAlignment ().getAlignmentAnnotation ()[this.graphStretch].graphHeight = 0;
\r
210 }this.graphStretchY = evt.getY ();
\r
211 this.av.calcPanelHeight ();
\r
212 this.needValidating = true;
\r
213 this.ap.paintAlignment (true);
\r
215 this.ap.scalePanel.mouseDragged (evt);
\r
216 }}, "java.awt.event.MouseEvent");
\r
217 Clazz.overrideMethod (c$, "mouseMoved",
\r
219 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
\r
223 var height = -this.scrollOffset;
\r
224 for (var i = 0; i < aa.length; i++) {
\r
225 if (aa[i].visible) {
\r
226 height += aa[i].height;
\r
227 }if (evt.getY () < height) {
\r
231 var res = Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ()) + this.av.getStartRes ();
\r
232 if (this.av.hasHiddenColumns ()) {
\r
233 res = this.av.getColumnSelection ().adjustForHiddenColumns (res);
\r
234 }if (row > -1 && res < aa[row].annotations.length && aa[row].annotations[res] != null) {
\r
235 var text = new StringBuffer ("Sequence position " + (res + 1));
\r
236 if (aa[row].annotations[res].description != null) {
\r
237 text.append (" " + aa[row].annotations[res].description);
\r
238 }this.ap.alignFrame.setStatus (text.toString ());
\r
239 }}, "java.awt.event.MouseEvent");
\r
240 Clazz.overrideMethod (c$, "mouseEntered",
\r
242 this.ap.scalePanel.mouseEntered (evt);
\r
243 }, "java.awt.event.MouseEvent");
\r
244 Clazz.overrideMethod (c$, "mouseExited",
\r
246 this.ap.scalePanel.mouseExited (evt);
\r
247 }, "java.awt.event.MouseEvent");
\r
248 Clazz.defineMethod (c$, "adjustPanelHeight",
\r
250 return this.adjustPanelHeight (true);
\r
252 Clazz.defineMethod (c$, "adjustPanelHeight",
\r
253 function (repaint) {
\r
254 var height = this.av.calcPanelHeight ();
\r
255 this.setSize ( new java.awt.Dimension (this.getSize ().width, height));
\r
260 Clazz.defineMethod (c$, "addEditableColumn",
\r
262 if (this.activeRow == -1) {
\r
263 var aa = this.av.getAlignment ().getAlignmentAnnotation ();
\r
266 }for (var j = 0; j < aa.length; j++) {
\r
267 if (aa[j].editable) {
\r
268 this.activeRow = j;
\r
272 Clazz.overrideMethod (c$, "paintComponent",
\r
274 if (this.av.getWrapAlignment () || !this.av.isShowAnnotation ()) return;
\r
275 var d = this.getSize ();
\r
276 this.imgWidth = d.width;
\r
277 if (this.imgWidth < 1 || d.height < 1) {
\r
279 }if (this.image == null || this.imgWidth != this.image.getWidth (this) || d.height != this.image.getHeight (this)) {
\r
280 this.image = this.createImage (this.imgWidth, d.height);
\r
281 this.gg = this.image.getGraphics ();
\r
282 this.gg.setFont (this.av.getFont ());
\r
283 this.fm = this.gg.getFontMetrics ();
\r
284 this.$fastPaint = false;
\r
285 }if (this.$fastPaint) {
\r
286 g.drawImage (this.image, 0, 0, this);
\r
287 this.$fastPaint = false;
\r
289 }this.gg.setColor (java.awt.Color.white);
\r
290 this.gg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
\r
291 this.drawComponent (this.gg, this.av.startRes, this.av.endRes + 1);
\r
292 g.drawImage (this.image, 0, 0, this);
\r
293 }, "java.awt.Graphics");
\r
294 Clazz.defineMethod (c$, "fastPaint",
\r
295 function (horizontal) {
\r
296 if (horizontal == 0 || this.av.getAlignment ().getAlignmentAnnotation () == null || this.av.getAlignment ().getAlignmentAnnotation ().length < 1) {
\r
299 }this.gg.copyArea (0, 0, this.imgWidth, this.getSize ().height, -horizontal * this.av.getCharWidth (), 0);
\r
300 var sr = this.av.startRes;
\r
301 var er = this.av.endRes + 1;
\r
303 if (horizontal > 0) {
\r
304 transX = (er - sr - horizontal) * this.av.getCharWidth ();
\r
305 sr = er - horizontal;
\r
306 } else if (horizontal < 0) {
\r
307 er = sr - horizontal;
\r
308 }this.gg.translate (transX, 0);
\r
309 this.drawComponent (this.gg, sr, er);
\r
310 this.gg.translate (-transX, 0);
\r
311 this.$fastPaint = true;
\r
314 Clazz.defineMethod (c$, "drawComponent",
\r
315 function (g, startRes, endRes) {
\r
316 var ofont = this.av.getFont ();
\r
318 g.setColor (java.awt.Color.white);
\r
319 g.fillRect (0, 0, (endRes - startRes) * this.av.getCharWidth (), this.getSize ().height);
\r
320 if (this.fm == null) {
\r
321 this.fm = g.getFontMetrics ();
\r
322 }if ((this.av.getAlignment ().getAlignmentAnnotation () == null) || (this.av.getAlignment ().getAlignmentAnnotation ().length < 1)) {
\r
323 g.setColor (java.awt.Color.white);
\r
324 g.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
\r
325 g.setColor (java.awt.Color.black);
\r
326 if (this.av.validCharWidth) {
\r
327 g.drawString (jalview.util.MessageManager.getString ("label.alignment_has_no_annotations"), 20, 15);
\r
329 }g.translate (0, -this.scrollOffset);
\r
330 this.renderer.drawComponent (this, this.av, g, this.activeRow, startRes, endRes);
\r
331 g.translate (0, +this.scrollOffset);
\r
332 }, "java.awt.Graphics,~N,~N");
\r
333 Clazz.defineMethod (c$, "setScrollOffset",
\r
334 function (value, repaint) {
\r
335 this.scrollOffset = value;
\r
339 Clazz.defineMethod (c$, "getFontMetrics",
\r
343 Clazz.overrideMethod (c$, "getFadedImage",
\r
347 Clazz.overrideMethod (c$, "getFadedImageWidth",
\r
349 return this.imgWidth;
\r
351 Clazz.overrideMethod (c$, "getVisibleVRange",
\r
353 if (this.ap != null && this.ap.alabels != null) {
\r
354 var sOffset = -this.ap.alabels.scrollOffset;
\r
355 var visHeight = sOffset + this.ap.annotationPanelHolder.getHeight ();
\r
356 this.$bounds[0] = sOffset;
\r
357 this.$bounds[1] = visHeight;
\r
358 return this.$bounds;
\r
362 Clazz.defineStatics (c$,
\r
363 "GRAPH_HEIGHT", 40);
\r