JAL-1807 update
[jalviewjs.git] / site / j2s / java / awt / AWTKeyStroke.js
1 Clazz.declarePackage ("java.awt");
2 Clazz.load (null, ["java.awt.AWTKeyStroke", "$.VKCollection"], ["java.io.ObjectStreamException", "java.lang.IllegalArgumentException", "$.StringBuilder", "java.util.Collections", "$.HashMap", "$.StringTokenizer", "java.awt.event.KeyEvent", "jssun.awt.AppContext"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.keyChar = '\uffff';
5 this.keyCode = 0;
6 this.modifiers = 0;
7 this.onKeyRelease = false;
8 Clazz.instantialize (this, arguments);
9 }, java.awt, "AWTKeyStroke");
10 c$.getAWTKeyStrokeClass = Clazz.defineMethod (c$, "getAWTKeyStrokeClass", 
11  function () {
12 var clazz = jssun.awt.AppContext.getAppContext ().get (java.awt.AWTKeyStroke);
13 if (clazz == null) {
14 clazz = java.awt.AWTKeyStroke;
15 jssun.awt.AppContext.getAppContext ().put (java.awt.AWTKeyStroke, java.awt.AWTKeyStroke);
16 }return clazz;
17 });
18 Clazz.makeConstructor (c$, 
19 function () {
20 });
21 Clazz.makeConstructor (c$, 
22 function (keyChar, keyCode, modifiers, onKeyRelease) {
23 this.keyChar = keyChar;
24 this.keyCode = keyCode;
25 this.modifiers = modifiers;
26 this.onKeyRelease = onKeyRelease;
27 }, "~S,~N,~N,~B");
28 c$.registerSubclass = Clazz.defineMethod (c$, "registerSubclass", 
29 function (subclass) {
30 }, "Class");
31 c$.getCachedStroke = Clazz.defineMethod (c$, "getCachedStroke", 
32  function (keyChar, keyCode, modifiers, onKeyRelease) {
33 return null;
34 }, "~S,~N,~N,~B");
35 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke", 
36 function (keyChar) {
37 return java.awt.AWTKeyStroke.getCachedStroke (keyChar, 0, 0, false);
38 }, "~S");
39 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke", 
40 function (keyChar, modifiers) {
41 if (keyChar == null) {
42 throw  new IllegalArgumentException ("keyChar cannot be null");
43 }return java.awt.AWTKeyStroke.getCachedStroke (keyChar.charValue (), 0, modifiers, false);
44 }, "Character,~N");
45 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke", 
46 function (keyCode, modifiers, onKeyRelease) {
47 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', keyCode, modifiers, onKeyRelease);
48 }, "~N,~N,~B");
49 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke", 
50 function (keyCode, modifiers) {
51 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', keyCode, modifiers, false);
52 }, "~N,~N");
53 c$.getAWTKeyStrokeForEvent = Clazz.defineMethod (c$, "getAWTKeyStrokeForEvent", 
54 function (anEvent) {
55 var id = anEvent.getID ();
56 switch (id) {
57 case 401:
58 case 402:
59 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', anEvent.getKeyCode (), anEvent.getModifiers (), (id == 402));
60 case 400:
61 return java.awt.AWTKeyStroke.getCachedStroke (anEvent.getKeyChar (), 0, anEvent.getModifiers (), false);
62 default:
63 return null;
64 }
65 }, "java.awt.event.KeyEvent");
66 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke", 
67 function (s) {
68 if (s == null) {
69 throw  new IllegalArgumentException ("String cannot be null");
70 }var errmsg = "String formatted incorrectly";
71 var st =  new java.util.StringTokenizer (s, " ");
72 var mask = 0;
73 var released = false;
74 var typed = false;
75 var pressed = false;
76 {
77 if (java.awt.AWTKeyStroke.modifierKeywords == null) {
78 var uninitializedMap =  new java.util.HashMap (8, 1.0);
79 uninitializedMap.put ("shift", Integer.$valueOf (65));
80 uninitializedMap.put ("control", Integer.$valueOf (130));
81 uninitializedMap.put ("ctrl", Integer.$valueOf (130));
82 uninitializedMap.put ("meta", Integer.$valueOf (260));
83 uninitializedMap.put ("alt", Integer.$valueOf (520));
84 uninitializedMap.put ("altGraph", Integer.$valueOf (8224));
85 uninitializedMap.put ("button1", Integer.$valueOf (1024));
86 uninitializedMap.put ("button2", Integer.$valueOf (2048));
87 uninitializedMap.put ("button3", Integer.$valueOf (4096));
88 java.awt.AWTKeyStroke.modifierKeywords = java.util.Collections.synchronizedMap (uninitializedMap);
89 }}var count = st.countTokens ();
90 for (var i = 1; i <= count; i++) {
91 var token = st.nextToken ();
92 if (typed) {
93 if (token.length != 1 || i != count) {
94 throw  new IllegalArgumentException ("String formatted incorrectly");
95 }return java.awt.AWTKeyStroke.getCachedStroke (token.charAt (0), 0, mask, false);
96 }if (pressed || released || i == count) {
97 if (i != count) {
98 throw  new IllegalArgumentException ("String formatted incorrectly");
99 }var keyCodeName = "VK_" + token;
100 var keyCode = java.awt.AWTKeyStroke.getVKValue (keyCodeName);
101 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', keyCode, mask, released);
102 }if (token.equals ("released")) {
103 released = true;
104 continue;
105 }if (token.equals ("pressed")) {
106 pressed = true;
107 continue;
108 }if (token.equals ("typed")) {
109 typed = true;
110 continue;
111 }var tokenMask = java.awt.AWTKeyStroke.modifierKeywords.get (token);
112 if (tokenMask != null) {
113 mask |= tokenMask.intValue ();
114 } else {
115 throw  new IllegalArgumentException ("String formatted incorrectly");
116 }}
117 throw  new IllegalArgumentException ("String formatted incorrectly");
118 }, "~S");
119 c$.getVKCollection = Clazz.defineMethod (c$, "getVKCollection", 
120  function () {
121 if (java.awt.AWTKeyStroke.vks == null) {
122 java.awt.AWTKeyStroke.vks =  new java.awt.VKCollection ();
123 }return java.awt.AWTKeyStroke.vks;
124 });
125 c$.getVKValue = Clazz.defineMethod (c$, "getVKValue", 
126  function (key) {
127 var vkCollect = java.awt.AWTKeyStroke.getVKCollection ();
128 var value = vkCollect.findCode (key);
129 if (value == null) {
130 var keyCode = 0;
131 var errmsg = "String formatted incorrectly";
132 try {
133 keyCode = java.awt.event.KeyEvent.getField (key).getInt (java.awt.event.KeyEvent);
134 } catch (e$$) {
135 if (Clazz.exceptionOf (e$$, NoSuchFieldException)) {
136 var nsfe = e$$;
137 {
138 throw  new IllegalArgumentException ("String formatted incorrectly");
139 }
140 } else if (Clazz.exceptionOf (e$$, IllegalAccessException)) {
141 var iae = e$$;
142 {
143 throw  new IllegalArgumentException ("String formatted incorrectly");
144 }
145 } else {
146 throw e$$;
147 }
148 }
149 value = Integer.$valueOf (keyCode);
150 vkCollect.put (key, value);
151 }return value.intValue ();
152 }, "~S");
153 Clazz.defineMethod (c$, "getKeyChar", 
154 function () {
155 return this.keyChar;
156 });
157 Clazz.defineMethod (c$, "getKeyCode", 
158 function () {
159 return this.keyCode;
160 });
161 Clazz.defineMethod (c$, "getModifiers", 
162 function () {
163 return this.modifiers;
164 });
165 Clazz.defineMethod (c$, "isOnKeyRelease", 
166 function () {
167 return this.onKeyRelease;
168 });
169 Clazz.defineMethod (c$, "getKeyEventType", 
170 function () {
171 if (this.keyCode == 0) {
172 return 400;
173 } else {
174 return (this.onKeyRelease) ? 402 : 401;
175 }});
176 Clazz.overrideMethod (c$, "hashCode", 
177 function () {
178 return (((this.keyChar).charCodeAt (0)) + 1) * (2 * (this.keyCode + 1)) * (this.modifiers + 1) + (this.onKeyRelease ? 1 : 2);
179 });
180 Clazz.defineMethod (c$, "equals", 
181 function (anObject) {
182 if (Clazz.instanceOf (anObject, java.awt.AWTKeyStroke)) {
183 var ks = anObject;
184 return (ks.keyChar == this.keyChar && ks.keyCode == this.keyCode && ks.onKeyRelease == this.onKeyRelease && ks.modifiers == this.modifiers);
185 }return false;
186 }, "~O");
187 Clazz.overrideMethod (c$, "toString", 
188 function () {
189 if (this.keyCode == 0) {
190 return java.awt.AWTKeyStroke.getModifiersText (this.modifiers) + "typed " + this.keyChar;
191 } else {
192 return java.awt.AWTKeyStroke.getModifiersText (this.modifiers) + (this.onKeyRelease ? "released" : "pressed") + " " + java.awt.AWTKeyStroke.getVKText (this.keyCode);
193 }});
194 c$.getModifiersText = Clazz.defineMethod (c$, "getModifiersText", 
195 function (modifiers) {
196 var buf =  new StringBuilder ();
197 if ((modifiers & 64) != 0) {
198 buf.append ("shift ");
199 }if ((modifiers & 128) != 0) {
200 buf.append ("ctrl ");
201 }if ((modifiers & 256) != 0) {
202 buf.append ("meta ");
203 }if ((modifiers & 512) != 0) {
204 buf.append ("alt ");
205 }if ((modifiers & 8192) != 0) {
206 buf.append ("altGraph ");
207 }if ((modifiers & 1024) != 0) {
208 buf.append ("button1 ");
209 }if ((modifiers & 2048) != 0) {
210 buf.append ("button2 ");
211 }if ((modifiers & 4096) != 0) {
212 buf.append ("button3 ");
213 }return buf.toString ();
214 }, "~N");
215 c$.getVKText = Clazz.defineMethod (c$, "getVKText", 
216 function (keyCode) {
217 return "UNKNOWN";
218 }, "~N");
219 Clazz.defineMethod (c$, "readResolve", 
220 function () {
221 {
222 var newClass = this.getClass ();
223 var awtKeyStrokeClass = java.awt.AWTKeyStroke.getAWTKeyStrokeClass ();
224 if (!newClass.equals (awtKeyStrokeClass)) {
225 java.awt.AWTKeyStroke.registerSubclass (newClass);
226 }return java.awt.AWTKeyStroke.getCachedStroke (this.keyChar, this.keyCode, this.modifiers, this.onKeyRelease);
227 }});
228 Clazz.defineStatics (c$,
229 "modifierKeywords", null,
230 "vks", null);
231 c$ = Clazz.decorateAsClass (function () {
232 this.code2name = null;
233 this.name2code = null;
234 Clazz.instantialize (this, arguments);
235 }, java.awt, "VKCollection");
236 Clazz.makeConstructor (c$, 
237 function () {
238 this.code2name =  new java.util.HashMap ();
239 this.name2code =  new java.util.HashMap ();
240 });
241 Clazz.defineMethod (c$, "put", 
242 function (name, code) {
243 this.code2name.put (code, name);
244 this.name2code.put (name, code);
245 }, "~S,Integer");
246 Clazz.defineMethod (c$, "findCode", 
247 function (name) {
248 return this.name2code.get (name);
249 }, "~S");
250 Clazz.defineMethod (c$, "findName", 
251 function (code) {
252 return this.code2name.get (code);
253 }, "Integer");
254 });