Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / event / MouseEvent.js
1 Clazz.declarePackage ("java.awt.event");
2 Clazz.load (["java.awt.event.InputEvent"], "java.awt.event.MouseEvent", ["java.lang.IllegalArgumentException", "$.StringBuilder", "java.awt.Point", "$.Toolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.x = 0;
5 this.y = 0;
6 this.xAbs = 0;
7 this.yAbs = 0;
8 this.clickCount = 0;
9 this.button = 0;
10 this.popupTrigger = false;
11 Clazz.instantialize (this, arguments);
12 }, java.awt.event, "MouseEvent", java.awt.event.InputEvent);
13 Clazz.defineMethod (c$, "getLocationOnScreen", 
14 function () {
15 return  new java.awt.Point (this.xAbs, this.yAbs);
16 });
17 Clazz.defineMethod (c$, "getXOnScreen", 
18 function () {
19 return this.xAbs;
20 });
21 Clazz.defineMethod (c$, "getYOnScreen", 
22 function () {
23 return this.yAbs;
24 });
25 Clazz.makeConstructor (c$, 
26 function (source, id, when, modifiers, x, y, clickCount, popupTrigger, button) {
27 this.construct (source, id, when, modifiers, x, y, 0, 0, clickCount, popupTrigger, button);
28 var eventLocationOnScreen =  new java.awt.Point (0, 0);
29 try {
30 eventLocationOnScreen = source.getLocationOnScreen ();
31 this.xAbs = eventLocationOnScreen.x + x;
32 this.yAbs = eventLocationOnScreen.y + y;
33 } catch (e) {
34 if (Clazz.exceptionOf (e, java.awt.IllegalComponentStateException)) {
35 this.xAbs = 0;
36 this.yAbs = 0;
37 } else {
38 throw e;
39 }
40 }
41 }, "java.awt.Component,~N,~N,~N,~N,~N,~N,~B,~N");
42 Clazz.makeConstructor (c$, 
43 function (source, id, when, modifiers, x, y, clickCount, popupTrigger) {
44 this.construct (source, id, when, modifiers, x, y, clickCount, popupTrigger, 0);
45 }, "java.awt.Component,~N,~N,~N,~N,~N,~N,~B");
46 Clazz.makeConstructor (c$, 
47 function (source, id, when, modifiers, x, y, xAbs, yAbs, clickCount, popupTrigger, button) {
48 Clazz.superConstructor (this, java.awt.event.MouseEvent, [source, id, when, modifiers]);
49 this.x = x;
50 this.y = y;
51 this.xAbs = xAbs;
52 this.yAbs = yAbs;
53 this.clickCount = clickCount;
54 this.popupTrigger = popupTrigger;
55 if (button < 0 || button > 3) {
56 throw  new IllegalArgumentException ("Invalid button value");
57 }this.button = button;
58 if ((this.getModifiers () != 0) && (this.getModifiersEx () == 0)) {
59 this.setNewModifiers ();
60 } else if ((this.getModifiers () == 0) && (this.getModifiersEx () != 0 || button != 0)) {
61 this.setOldModifiers ();
62 }}, "java.awt.Component,~N,~N,~N,~N,~N,~N,~N,~N,~B,~N");
63 Clazz.defineMethod (c$, "getX", 
64 function () {
65 return this.x;
66 });
67 Clazz.defineMethod (c$, "getY", 
68 function () {
69 return this.y;
70 });
71 Clazz.defineMethod (c$, "getPoint", 
72 function () {
73 var x;
74 var y;
75 {
76 x = this.x;
77 y = this.y;
78 }return  new java.awt.Point (x, y);
79 });
80 Clazz.defineMethod (c$, "translatePoint", 
81 function (x, y) {
82 this.x += x;
83 this.y += y;
84 }, "~N,~N");
85 Clazz.defineMethod (c$, "getClickCount", 
86 function () {
87 return this.clickCount;
88 });
89 Clazz.defineMethod (c$, "getButton", 
90 function () {
91 return this.button;
92 });
93 Clazz.defineMethod (c$, "isPopupTrigger", 
94 function () {
95 return this.popupTrigger;
96 });
97 c$.getMouseModifiersText = Clazz.defineMethod (c$, "getMouseModifiersText", 
98 function (modifiers) {
99 var buf =  new StringBuilder ();
100 if ((modifiers & 8) != 0) {
101 buf.append (java.awt.Toolkit.getProperty ("AWT.alt", "Alt"));
102 buf.append ("+");
103 }if ((modifiers & 4) != 0) {
104 buf.append (java.awt.Toolkit.getProperty ("AWT.meta", "Meta"));
105 buf.append ("+");
106 }if ((modifiers & 2) != 0) {
107 buf.append (java.awt.Toolkit.getProperty ("AWT.control", "Ctrl"));
108 buf.append ("+");
109 }if ((modifiers & 1) != 0) {
110 buf.append (java.awt.Toolkit.getProperty ("AWT.shift", "Shift"));
111 buf.append ("+");
112 }if ((modifiers & 32) != 0) {
113 buf.append (java.awt.Toolkit.getProperty ("AWT.altGraph", "Alt Graph"));
114 buf.append ("+");
115 }if ((modifiers & 16) != 0) {
116 buf.append (java.awt.Toolkit.getProperty ("AWT.button1", "Button1"));
117 buf.append ("+");
118 }if ((modifiers & 8) != 0) {
119 buf.append (java.awt.Toolkit.getProperty ("AWT.button2", "Button2"));
120 buf.append ("+");
121 }if ((modifiers & 4) != 0) {
122 buf.append (java.awt.Toolkit.getProperty ("AWT.button3", "Button3"));
123 buf.append ("+");
124 }if (buf.length () > 0) {
125 buf.setLength (buf.length () - 1);
126 }return buf.toString ();
127 }, "~N");
128 Clazz.overrideMethod (c$, "paramString", 
129 function () {
130 var str =  new StringBuilder (80);
131 str.append (java.awt.event.MouseEvent.getIdString (this.id));
132 str.append (",(" + this.x).append ("," + this.y).append ("," + this.when).append (")");
133 str.append (",absolute(").append ("" + this.xAbs).append (",").append ("" + this.yAbs).append (")");
134 str.append (",button=").append ("" + this.getButton ());
135 if (this.getModifiers () != 0) {
136 str.append (",modifiers=").append (java.awt.event.MouseEvent.getMouseModifiersText (this.modifiers));
137 }if (this.getModifiersEx () != 0) {
138 str.append (",extModifiers=").append (java.awt.event.InputEvent.getModifiersExText (this.modifiers));
139 }str.append (",clickCount=").append ("" + this.clickCount);
140 return str.toString ();
141 });
142 c$.getIdString = Clazz.defineMethod (c$, "getIdString", 
143 function (id) {
144 switch (id) {
145 case 501:
146 return "MOUSE_PRESSED";
147 case 502:
148 return "MOUSE_RELEASED";
149 case 500:
150 return "MOUSE_CLICKED";
151 case 504:
152 return "MOUSE_ENTERED";
153 case 505:
154 return "MOUSE_EXITED";
155 case 503:
156 return "MOUSE_MOVED";
157 case 506:
158 return "MOUSE_DRAGGED";
159 case 507:
160 return "MOUSE_WHEEL";
161 default:
162 return "unknown type";
163 }
164 }, "~N");
165 Clazz.defineMethod (c$, "setNewModifiers", 
166  function () {
167 if ((this.modifiers & 16) != 0) {
168 this.modifiers |= 1024;
169 }if ((this.modifiers & 8) != 0) {
170 this.modifiers |= 2048;
171 }if ((this.modifiers & 4) != 0) {
172 this.modifiers |= 4096;
173 }if (this.id == 501 || this.id == 502 || this.id == 500) {
174 if ((this.modifiers & 16) != 0) {
175 this.button = 1;
176 this.modifiers &= -13;
177 if (this.id != 501) {
178 this.modifiers &= -1025;
179 }} else if ((this.modifiers & 8) != 0) {
180 this.button = 2;
181 this.modifiers &= -21;
182 if (this.id != 501) {
183 this.modifiers &= -2049;
184 }} else if ((this.modifiers & 4) != 0) {
185 this.button = 3;
186 this.modifiers &= -25;
187 if (this.id != 501) {
188 this.modifiers &= -4097;
189 }}}if ((this.modifiers & 8) != 0) {
190 this.modifiers |= 512;
191 }if ((this.modifiers & 4) != 0) {
192 this.modifiers |= 256;
193 }if ((this.modifiers & 1) != 0) {
194 this.modifiers |= 64;
195 }if ((this.modifiers & 2) != 0) {
196 this.modifiers |= 128;
197 }if ((this.modifiers & 32) != 0) {
198 this.modifiers |= 8192;
199 }});
200 Clazz.defineMethod (c$, "setOldModifiers", 
201  function () {
202 if (this.id == 501 || this.id == 502 || this.id == 500) {
203 switch (this.button) {
204 case 1:
205 this.modifiers |= 16;
206 break;
207 case 2:
208 this.modifiers |= 8;
209 break;
210 case 3:
211 this.modifiers |= 4;
212 break;
213 }
214 } else {
215 if ((this.modifiers & 1024) != 0) {
216 this.modifiers |= 16;
217 }if ((this.modifiers & 2048) != 0) {
218 this.modifiers |= 8;
219 }if ((this.modifiers & 4096) != 0) {
220 this.modifiers |= 4;
221 }}if ((this.modifiers & 512) != 0) {
222 this.modifiers |= 8;
223 }if ((this.modifiers & 256) != 0) {
224 this.modifiers |= 4;
225 }if ((this.modifiers & 64) != 0) {
226 this.modifiers |= 1;
227 }if ((this.modifiers & 128) != 0) {
228 this.modifiers |= 2;
229 }if ((this.modifiers & 8192) != 0) {
230 this.modifiers |= 32;
231 }});
232 Clazz.defineStatics (c$,
233 "MOUSE_FIRST", 500,
234 "MOUSE_LAST", 507,
235 "MOUSE_CLICKED", 500,
236 "MOUSE_PRESSED", 501,
237 "MOUSE_RELEASED", 502,
238 "MOUSE_MOVED", 503,
239 "MOUSE_ENTERED", 504,
240 "MOUSE_EXITED", 505,
241 "MOUSE_DRAGGED", 506,
242 "MOUSE_WHEEL", 507,
243 "NOBUTTON", 0,
244 "BUTTON1", 1,
245 "BUTTON2", 2,
246 "BUTTON3", 3);
247 });