1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "jalview.api.RotatableCanvasI", "java.awt.event.KeyListener", "$.MouseListener", "$.MouseMotionListener", "jalview.math.RotatableMatrix"], "jalview.appletgui.RotatableCanvas", ["jalview.appletgui.PaintRefresher", "jalview.datamodel.SequenceGroup", "jalview.util.Format", "$.MessageManager", "java.awt.Color", "$.Dimension", "$.Font"], function () {
3 c$ = Clazz.decorateAsClass (function () {
10 this.$drawAxes = true;
38 this.$showLabels = false;
39 Clazz.instantialize (this, arguments);
40 }, jalview.appletgui, "RotatableCanvas", awt2swing.Panel, [java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener, jalview.api.RotatableCanvasI]);
41 Clazz.prepareFields (c$, function () {
42 this.idmat = new jalview.math.RotatableMatrix (3, 3);
43 this.objmat = new jalview.math.RotatableMatrix (3, 3);
44 this.rotmat = new jalview.math.RotatableMatrix (3, 3);
45 this.centre = Clazz.newFloatArray (3, 0);
46 this.$width = Clazz.newFloatArray (3, 0);
47 this.max = Clazz.newFloatArray (3, 0);
48 this.min = Clazz.newFloatArray (3, 0);
50 Clazz.makeConstructor (c$,
52 Clazz.superConstructor (this, jalview.appletgui.RotatableCanvas, []);
54 }, "jalview.viewmodel.AlignmentViewport");
55 Clazz.defineMethod (c$, "showLabels",
60 Clazz.overrideMethod (c$, "setPoints",
61 function (points, npoint) {
64 jalview.appletgui.PaintRefresher.Register (this, this.av.getSequenceSetId ());
65 this.prefsize = this.getPreferredSize ();
66 this.orig = Clazz.newFloatArray (npoint, 3, 0);
67 for (var i = 0; i < npoint; i++) {
68 var sp = points.elementAt (i);
69 for (var j = 0; j < 3; j++) {
70 this.orig[i][j] = sp.coord[j];
73 for (var i = 0; i < 3; i++) {
74 for (var j = 0; j < 3; j++) {
76 this.idmat.addElement (i, j, 0);
77 this.objmat.addElement (i, j, 0);
78 this.rotmat.addElement (i, j, 0);
80 this.idmat.addElement (i, j, 0);
81 this.objmat.addElement (i, j, 0);
82 this.rotmat.addElement (i, j, 0);
85 this.axes = Clazz.newFloatArray (3, 3, 0);
89 this.scale = this.findScale ();
90 this.addMouseListener (this);
91 this.addKeyListener (this);
92 this.addMouseMotionListener (this);
93 }, "java.util.Vector,~N");
94 Clazz.defineMethod (c$, "initAxes",
96 for (var i = 0; i < 3; i++) {
97 for (var j = 0; j < 3; j++) {
105 Clazz.defineMethod (c$, "findWidth",
107 this.max = Clazz.newFloatArray (3, 0);
108 this.min = Clazz.newFloatArray (3, 0);
109 this.max[0] = -1.0E30;
110 this.max[1] = -1.0E30;
111 this.max[2] = -1.0E30;
115 for (var i = 0; i < 3; i++) {
116 for (var j = 0; j < this.npoint; j++) {
117 var sp = this.points.elementAt (j);
118 if (sp.coord[i] >= this.max[i]) {
119 this.max[i] = sp.coord[i];
120 }if (sp.coord[i] <= this.min[i]) {
121 this.min[i] = sp.coord[i];
124 this.$width[0] = Math.abs (this.max[0] - this.min[0]);
125 this.$width[1] = Math.abs (this.max[1] - this.min[1]);
126 this.$width[2] = Math.abs (this.max[2] - this.min[2]);
127 this.maxwidth = this.$width[0];
128 if (this.$width[1] > this.$width[0]) {
129 this.maxwidth = this.$width[1];
130 }if (this.$width[2] > this.$width[1]) {
131 this.maxwidth = this.$width[2];
133 Clazz.defineMethod (c$, "findScale",
138 if (this.getSize ().width != 0) {
139 width = this.getSize ().width;
140 height = this.getSize ().height;
142 width = this.prefsize.width;
143 height = this.prefsize.height;
144 }if (width < height) {
148 }return dim * this.scalefactor / (2 * this.maxwidth);
150 Clazz.defineMethod (c$, "findCentre",
153 this.centre[0] = (this.max[0] + this.min[0]) / 2;
154 this.centre[1] = (this.max[1] + this.min[1]) / 2;
155 this.centre[2] = (this.max[2] + this.min[2]) / 2;
157 Clazz.overrideMethod (c$, "getPreferredSize",
159 if (this.prefsize != null) {
160 return this.prefsize;
162 return new java.awt.Dimension (400, 400);
164 Clazz.overrideMethod (c$, "getMinimumSize",
166 return this.getPreferredSize ();
168 Clazz.overrideMethod (c$, "update",
171 }, "java.awt.Graphics");
172 Clazz.defineMethod (c$, "PaintComponent",
174 if (this.points == null) {
175 g.setFont ( new java.awt.Font ("Verdana", 0, 18));
176 g.drawString (jalview.util.MessageManager.getString ("label.calculating_pca") + "....", 20, Clazz.doubleToInt (this.getSize ().height / 2));
178 if ((this.img == null) || (this.prefsize.width != this.getSize ().width) || (this.prefsize.height != this.getSize ().height)) {
179 this.prefsize.width = this.getSize ().width;
180 this.prefsize.height = this.getSize ().height;
181 this.scale = this.findScale ();
182 this.img = this.createImage (this.getSize ().width, this.getSize ().height);
183 this.ig = this.img.getGraphics ();
184 }this.drawBackground (this.ig, java.awt.Color.black);
185 this.drawScene (this.ig);
186 if (this.$drawAxes == true) {
187 this.drawAxes (this.ig);
188 }if (this.tooltip != null) {
189 this.ig.setColor (java.awt.Color.red);
190 this.ig.drawString (this.tooltip, this.toolx, this.tooly);
191 }g.drawImage (this.img, 0, 0, this);
192 }}, "java.awt.Graphics");
193 Clazz.defineMethod (c$, "drawAxes",
195 g.setColor (java.awt.Color.yellow);
196 for (var i = 0; i < 3; i++) {
197 g.drawLine (Clazz.doubleToInt (this.getSize ().width / 2), Clazz.doubleToInt (this.getSize ().height / 2), Clazz.floatToInt (this.axes[i][0] * this.scale * this.max[0] + Clazz.doubleToInt (this.getSize ().width / 2)), Clazz.floatToInt (this.axes[i][1] * this.scale * this.max[1] + Clazz.doubleToInt (this.getSize ().height / 2)));
199 }, "java.awt.Graphics");
200 Clazz.defineMethod (c$, "drawBackground",
203 g.fillRect (0, 0, this.prefsize.width, this.prefsize.height);
204 }, "java.awt.Graphics,java.awt.Color");
205 Clazz.defineMethod (c$, "drawScene",
207 var halfwidth = Clazz.doubleToInt (this.getSize ().width / 2);
208 var halfheight = Clazz.doubleToInt (this.getSize ().height / 2);
209 for (var i = 0; i < this.npoint; i++) {
210 var sp = this.points.elementAt (i);
211 var x = Clazz.floatToInt ((sp.coord[0] - this.centre[0]) * this.scale) + halfwidth;
212 var y = Clazz.floatToInt ((sp.coord[1] - this.centre[1]) * this.scale) + halfheight;
213 var z = sp.coord[1] - this.centre[2];
214 if (this.av.getSequenceColour (sp.sequence) === java.awt.Color.black) {
215 g.setColor (java.awt.Color.white);
217 g.setColor (this.av.getSequenceColour (sp.sequence));
218 }if (this.av.getSelectionGroup () != null) {
219 if (this.av.getSelectionGroup ().getSequences (null).contains ((this.points.elementAt (i)).sequence)) {
220 g.setColor (java.awt.Color.gray);
222 g.setColor (g.getColor ().darker ());
223 }g.fillRect (x - 3, y - 3, 6, 6);
224 if (this.$showLabels) {
225 g.setColor (java.awt.Color.red);
226 g.drawString ((this.points.elementAt (i)).sequence.getName (), x - 3, y - 4);
228 }, "java.awt.Graphics");
229 Clazz.defineMethod (c$, "minimumsize",
231 return this.prefsize;
233 Clazz.defineMethod (c$, "preferredsize",
235 return this.prefsize;
237 Clazz.overrideMethod (c$, "keyTyped",
239 }, "java.awt.event.KeyEvent");
240 Clazz.overrideMethod (c$, "keyReleased",
242 }, "java.awt.event.KeyEvent");
243 Clazz.overrideMethod (c$, "keyPressed",
245 if (evt.getKeyCode () == 38) {
246 this.scalefactor = (this.scalefactor * 1.1);
247 this.scale = this.findScale ();
248 } else if (evt.getKeyCode () == 40) {
249 this.scalefactor = (this.scalefactor * 0.9);
250 this.scale = this.findScale ();
251 } else if (evt.getKeyChar () == 's') {
252 System.err.println ("DEBUG: Rectangle selection");
253 if (this.rectx2 != -1 && this.recty2 != -1) {
254 this.rectSelect (this.rectx1, this.recty1, this.rectx2, this.recty2);
256 }, "java.awt.event.KeyEvent");
257 Clazz.defineMethod (c$, "printPoints",
259 for (var i = 0; i < this.npoint; i++) {
260 var sp = this.points.elementAt (i);
261 jalview.util.Format.printLong (System.out, "%5d ", i);
262 for (var j = 0; j < 3; j++) {
263 jalview.util.Format.printDouble (System.out, "%13.3f ", sp.coord[j]);
265 System.out.println ();
268 Clazz.overrideMethod (c$, "mouseClicked",
270 }, "java.awt.event.MouseEvent");
271 Clazz.overrideMethod (c$, "mouseEntered",
273 }, "java.awt.event.MouseEvent");
274 Clazz.overrideMethod (c$, "mouseExited",
276 }, "java.awt.event.MouseEvent");
277 Clazz.overrideMethod (c$, "mouseReleased",
279 }, "java.awt.event.MouseEvent");
280 Clazz.overrideMethod (c$, "mousePressed",
294 var found = this.findPoint (x, y);
296 if (this.av.getSelectionGroup () != null) {
297 this.av.getSelectionGroup ().addOrRemove (found, true);
298 this.av.getSelectionGroup ().setEndRes (this.av.getAlignment ().getWidth () - 1);
300 this.av.setSelectionGroup ( new jalview.datamodel.SequenceGroup ());
301 this.av.getSelectionGroup ().addOrRemove (found, true);
302 this.av.getSelectionGroup ().setEndRes (this.av.getAlignment ().getWidth () - 1);
303 }jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ());
304 this.av.sendSelection ();
306 }, "java.awt.event.MouseEvent");
307 Clazz.overrideMethod (c$, "mouseMoved",
309 var found = this.findPoint (evt.getX (), evt.getY ());
313 this.tooltip = found.getName ();
314 this.toolx = evt.getX ();
315 this.tooly = evt.getY ();
317 }, "java.awt.event.MouseEvent");
318 Clazz.overrideMethod (c$, "mouseDragged",
320 this.mx = evt.getX ();
321 this.my = evt.getY ();
322 this.rotmat.setIdentity ();
323 this.rotmat.rotate (this.my - this.omy, 'x');
324 this.rotmat.rotate (this.mx - this.omx, 'y');
325 for (var i = 0; i < this.npoint; i++) {
326 var sp = this.points.elementAt (i);
327 sp.coord[0] -= this.centre[0];
328 sp.coord[1] -= this.centre[1];
329 sp.coord[2] -= this.centre[2];
330 sp.coord = this.rotmat.vectorMultiply (sp.coord);
331 sp.coord[0] += this.centre[0];
332 sp.coord[1] += this.centre[1];
333 sp.coord[2] += this.centre[2];
335 for (var i = 0; i < 3; i++) {
336 this.axes[i] = this.rotmat.vectorMultiply (this.axes[i]);
340 this.paint (this.getGraphics ());
341 }, "java.awt.event.MouseEvent");
342 Clazz.defineMethod (c$, "rectSelect",
343 function (x1, y1, x2, y2) {
344 for (var i = 0; i < this.npoint; i++) {
345 var sp = this.points.elementAt (i);
346 var tmp1 = Clazz.doubleToInt ((sp.coord[0] - this.centre[0]) * this.scale + this.getSize ().width / 2.0);
347 var tmp2 = Clazz.doubleToInt ((sp.coord[1] - this.centre[1]) * this.scale + this.getSize ().height / 2.0);
348 if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2) {
349 if (this.av != null) {
350 if (!this.av.getSelectionGroup ().getSequences (null).contains (sp.sequence)) {
351 this.av.getSelectionGroup ().addSequence (sp.sequence, true);
354 Clazz.defineMethod (c$, "findPoint",
356 var halfwidth = Clazz.doubleToInt (this.getSize ().width / 2);
357 var halfheight = Clazz.doubleToInt (this.getSize ().height / 2);
359 for (var i = 0; i < this.npoint; i++) {
360 var sp = this.points.elementAt (i);
361 var px = Clazz.floatToInt ((sp.coord[0] - this.centre[0]) * this.scale) + halfwidth;
362 var py = Clazz.floatToInt ((sp.coord[1] - this.centre[1]) * this.scale) + halfheight;
363 if (Math.abs (px - x) < 3 && Math.abs (py - y) < 3) {
367 return (this.points.elementAt (found)).sequence;