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