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 () {
5 this.isMouseDown = false;
9 this.modifiersWhenPressed10 = 0;
10 Clazz.instantialize (this, arguments);
11 }, swingjs, "JSMouse");
12 Clazz.makeConstructor (c$,
15 }, "swingjs.JSAppletPanel");
16 Clazz.defineMethod (c$, "processEvent",
17 function (id, x, y, modifiers, time) {
18 if (id != -1) modifiers = swingjs.JSMouse.applyLeftMouse (modifiers);
21 this.wheeled (time, x, modifiers);
24 this.xWhenPressed = x;
25 this.yWhenPressed = y;
26 this.modifiersWhenPressed10 = modifiers;
27 this.pressed (time, x, y, modifiers, false);
30 this.dragged (time, x, y, modifiers);
33 this.entry (time, x, y, false);
36 this.entry (time, x, y, true);
39 this.moved (time, x, y, modifiers);
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);
51 Clazz.defineMethod (c$, "processTwoPointGesture",
53 if (touches[0].length < 2) return;
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 ();
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;
79 var cos12 = (v1.dot (v2));
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);
90 Clazz.defineMethod (c$, "translateXYBy",
91 function (deltaX, deltaY) {
93 Clazz.defineMethod (c$, "mouseClicked",
95 this.clicked (e.getWhen (), e.getX (), e.getY (), e.getModifiers (), e.getClickCount ());
96 }, "java.awt.event.MouseEvent");
97 Clazz.defineMethod (c$, "mouseEntered",
99 this.entry (e.getWhen (), e.getX (), e.getY (), false);
100 }, "java.awt.event.MouseEvent");
101 Clazz.defineMethod (c$, "mouseExited",
103 this.entry (e.getWhen (), e.getX (), e.getY (), true);
104 }, "java.awt.event.MouseEvent");
105 Clazz.defineMethod (c$, "mousePressed",
107 this.pressed (e.getWhen (), e.getX (), e.getY (), e.getModifiers (), e.isPopupTrigger ());
108 }, "java.awt.event.MouseEvent");
109 Clazz.defineMethod (c$, "mouseReleased",
111 this.released (e.getWhen (), e.getX (), e.getY (), e.getModifiers ());
112 }, "java.awt.event.MouseEvent");
113 Clazz.defineMethod (c$, "mouseDragged",
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",
121 this.moved (e.getWhen (), e.getX (), e.getY (), e.getModifiers ());
122 }, "java.awt.event.MouseEvent");
123 Clazz.defineMethod (c$, "mouseWheelMoved",
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);
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);
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);
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);
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);
165 c$.applyLeftMouse = Clazz.defineMethod (c$, "applyLeftMouse",
166 function (modifiers) {
167 return ((modifiers & 28) == 0) ? (modifiers | 16) : modifiers;
169 Clazz.defineMethod (c$, "getButton",
170 function (modifiers) {
171 switch (modifiers & 28) {
182 Clazz.defineMethod (c$, "mouseEnterExit",
183 function (time, x, y, isExit) {
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$,