JAL-1807 Bob
[jalviewjs.git] / site / j2s / swingjs / JSMouse.js
1 Clazz.declarePackage ("swingjs");
2 Clazz.load (null, "swingjs.JSMouse", ["JU.V3", "java.awt.Toolkit", "java.awt.event.MouseEvent"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.ap = null;
5 this.isMouseDown = false;
6 this.wheeling = false;
7 this.xWhenPressed = 0;
8 this.yWhenPressed = 0;
9 this.modifiersWhenPressed10 = 0;
10 Clazz.instantialize (this, arguments);
11 }, swingjs, "JSMouse");
12 Clazz.makeConstructor (c$, 
13 function (ap) {
14 this.ap = ap;
15 }, "swingjs.JSAppletPanel");
16 Clazz.defineMethod (c$, "processEvent", 
17 function (id, x, y, modifiers, time) {
18 if (id != -1) modifiers = swingjs.JSMouse.applyLeftMouse (modifiers);
19 switch (id) {
20 case -1:
21 this.wheeled (time, x, modifiers);
22 break;
23 case 501:
24 this.xWhenPressed = x;
25 this.yWhenPressed = y;
26 this.modifiersWhenPressed10 = modifiers;
27 this.pressed (time, x, y, modifiers, false);
28 break;
29 case 506:
30 this.dragged (time, x, y, modifiers);
31 break;
32 case 504:
33 this.entry (time, x, y, false);
34 break;
35 case 505:
36 this.entry (time, x, y, true);
37 break;
38 case 503:
39 this.moved (time, x, y, modifiers);
40 break;
41 case 502:
42 this.released (time, x, y, modifiers);
43 if (x == this.xWhenPressed && y == this.yWhenPressed && modifiers == this.modifiersWhenPressed10) {
44 this.clicked (time, x, y, modifiers, 1);
45 }break;
46 default:
47 return false;
48 }
49 return true;
50 }, "~N,~N,~N,~N,~N");
51 Clazz.defineMethod (c$, "processTwoPointGesture", 
52 function (touches) {
53 if (touches[0].length < 2) return;
54 var t1 = touches[0];
55 var t2 = touches[1];
56 var t1first = t1[0];
57 var t1last = t1[t2.length - 1];
58 var x1first = t1first[0];
59 var x1last = t1last[0];
60 var dx1 = x1last - x1first;
61 var y1first = t1first[1];
62 var y1last = t1last[1];
63 var dy1 = y1last - y1first;
64 var v1 = JU.V3.new3 (dx1, dy1, 0);
65 var d1 = v1.length ();
66 var t2first = t2[0];
67 var t2last = t2[t2.length - 1];
68 var x2first = t2first[0];
69 var x2last = t2last[0];
70 var dx2 = x2last - x2first;
71 var y2first = t2first[1];
72 var y2last = t2last[1];
73 var dy2 = y2last - y2first;
74 var v2 = JU.V3.new3 (dx2, dy2, 0);
75 var d2 = v2.length ();
76 if (d1 < 1 || d2 < 1) return;
77 v1.normalize ();
78 v2.normalize ();
79 var cos12 = (v1.dot (v2));
80 if (cos12 > 0.8) {
81 var deltaX = Clazz.floatToInt (x1last - t1[t1.length - 2][0]);
82 var deltaY = Clazz.floatToInt (y1last - t1[t1.length - 2][1]);
83 this.translateXYBy (deltaX, deltaY);
84 } else if (cos12 < -0.8) {
85 v1 = JU.V3.new3 (x2first - x1first, y2first - y1first, 0);
86 v2 = JU.V3.new3 (x2last - x1last, y2last - y1last, 0);
87 var dx = v2.length () - v1.length ();
88 this.wheeled (System.currentTimeMillis (), dx < 0 ? -1 : 1, 32);
89 }}, "~A");
90 Clazz.defineMethod (c$, "translateXYBy", 
91  function (deltaX, deltaY) {
92 }, "~N,~N");
93 Clazz.defineMethod (c$, "mouseClicked", 
94 function (e) {
95 this.clicked (e.getWhen (), e.getX (), e.getY (), e.getModifiers (), e.getClickCount ());
96 }, "java.awt.event.MouseEvent");
97 Clazz.defineMethod (c$, "mouseEntered", 
98 function (e) {
99 this.entry (e.getWhen (), e.getX (), e.getY (), false);
100 }, "java.awt.event.MouseEvent");
101 Clazz.defineMethod (c$, "mouseExited", 
102 function (e) {
103 this.entry (e.getWhen (), e.getX (), e.getY (), true);
104 }, "java.awt.event.MouseEvent");
105 Clazz.defineMethod (c$, "mousePressed", 
106 function (e) {
107 this.pressed (e.getWhen (), e.getX (), e.getY (), e.getModifiers (), e.isPopupTrigger ());
108 }, "java.awt.event.MouseEvent");
109 Clazz.defineMethod (c$, "mouseReleased", 
110 function (e) {
111 this.released (e.getWhen (), e.getX (), e.getY (), e.getModifiers ());
112 }, "java.awt.event.MouseEvent");
113 Clazz.defineMethod (c$, "mouseDragged", 
114 function (e) {
115 var modifiers = e.getModifiers ();
116 if ((modifiers & 28) == 0) modifiers |= 16;
117 this.dragged (e.getWhen (), e.getX (), e.getY (), modifiers);
118 }, "java.awt.event.MouseEvent");
119 Clazz.defineMethod (c$, "mouseMoved", 
120 function (e) {
121 this.moved (e.getWhen (), e.getX (), e.getY (), e.getModifiers ());
122 }, "java.awt.event.MouseEvent");
123 Clazz.defineMethod (c$, "mouseWheelMoved", 
124 function (e) {
125 e.consume ();
126 this.wheeled (e.getWhen (), e.getWheelRotation (), e.getModifiers ());
127 }, "java.awt.event.MouseWheelEvent");
128 Clazz.defineMethod (c$, "entry", 
129  function (time, x, y, isExit) {
130 this.wheeling = false;
131 this.mouseEnterExit (time, x, y, isExit);
132 }, "~N,~N,~N,~B");
133 Clazz.defineMethod (c$, "clicked", 
134  function (time, x, y, modifiers, clickCount) {
135 this.mouseAction (500, time, x, y, 1, modifiers);
136 }, "~N,~N,~N,~N,~N");
137 Clazz.defineMethod (c$, "moved", 
138  function (time, x, y, modifiers) {
139 if (this.isMouseDown) this.mouseAction (506, time, x, y, 0, swingjs.JSMouse.applyLeftMouse (modifiers));
140  else this.mouseAction (503, time, x, y, 0, modifiers);
141 }, "~N,~N,~N,~N");
142 Clazz.defineMethod (c$, "wheeled", 
143  function (time, rotation, modifiers) {
144 this.wheeling = true;
145 this.mouseAction (507, time, 0, rotation, 0, modifiers & -29 | 32);
146 }, "~N,~N,~N");
147 Clazz.defineMethod (c$, "pressed", 
148  function (time, x, y, modifiers, isPopupTrigger) {
149 this.isMouseDown = true;
150 this.wheeling = false;
151 this.mouseAction (501, time, x, y, 0, modifiers);
152 }, "~N,~N,~N,~N,~B");
153 Clazz.defineMethod (c$, "released", 
154  function (time, x, y, modifiers) {
155 this.isMouseDown = false;
156 this.wheeling = false;
157 this.mouseAction (502, time, x, y, 0, modifiers);
158 }, "~N,~N,~N,~N");
159 Clazz.defineMethod (c$, "dragged", 
160  function (time, x, y, modifiers) {
161 if (this.wheeling) return;
162 if ((modifiers & 20) == 20) modifiers = modifiers & -5 | 2;
163 this.mouseAction (506, time, x, y, 0, modifiers);
164 }, "~N,~N,~N,~N");
165 c$.applyLeftMouse = Clazz.defineMethod (c$, "applyLeftMouse", 
166  function (modifiers) {
167 return ((modifiers & 28) == 0) ? (modifiers | 16) : modifiers;
168 }, "~N");
169 Clazz.defineMethod (c$, "getButton", 
170  function (modifiers) {
171 switch (modifiers & 28) {
172 case 16:
173 return 1;
174 case 8:
175 return 2;
176 case 4:
177 return 3;
178 default:
179 return 0;
180 }
181 }, "~N");
182 Clazz.defineMethod (c$, "mouseEnterExit", 
183  function (time, x, y, isExit) {
184 }, "~N,~N,~N,~B");
185 Clazz.defineMethod (c$, "mouseAction", 
186  function (id, time, x, y, count, modifiers) {
187 var popupTrigger = false;
188 var button = this.getButton (modifiers);
189 var source = this.ap.applet;
190 var e =  new java.awt.event.MouseEvent (source, id, time, modifiers, x, y, x, y, count, popupTrigger, button);
191 java.awt.Toolkit.getEventQueue ().postEvent (e);
192 }, "~N,~N,~N,~N,~N,~N");
193 Clazz.defineStatics (c$,
194 "MOUSE_LEFT", 16,
195 "MOUSE_MIDDLE", 8,
196 "MOUSE_RIGHT", 4,
197 "MOUSE_WHEEL", 32,
198 "MAC_COMMAND", 20,
199 "BUTTON_MASK", 28);
200 });