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';
7 this.onKeyRelease = false;
8 Clazz.instantialize (this, arguments);
9 }, java.awt, "AWTKeyStroke");
10 c$.getAWTKeyStrokeClass = Clazz.defineMethod (c$, "getAWTKeyStrokeClass",
12 var clazz = jssun.awt.AppContext.getAppContext ().get (java.awt.AWTKeyStroke);
14 clazz = java.awt.AWTKeyStroke;
15 jssun.awt.AppContext.getAppContext ().put (java.awt.AWTKeyStroke, java.awt.AWTKeyStroke);
18 Clazz.makeConstructor (c$,
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;
28 c$.registerSubclass = Clazz.defineMethod (c$, "registerSubclass",
31 c$.getCachedStroke = Clazz.defineMethod (c$, "getCachedStroke",
32 function (keyChar, keyCode, modifiers, onKeyRelease) {
35 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke",
37 return java.awt.AWTKeyStroke.getCachedStroke (keyChar, 0, 0, false);
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);
45 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke",
46 function (keyCode, modifiers, onKeyRelease) {
47 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', keyCode, modifiers, onKeyRelease);
49 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke",
50 function (keyCode, modifiers) {
51 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', keyCode, modifiers, false);
53 c$.getAWTKeyStrokeForEvent = Clazz.defineMethod (c$, "getAWTKeyStrokeForEvent",
55 var id = anEvent.getID ();
59 return java.awt.AWTKeyStroke.getCachedStroke ('\uffff', anEvent.getKeyCode (), anEvent.getModifiers (), (id == 402));
61 return java.awt.AWTKeyStroke.getCachedStroke (anEvent.getKeyChar (), 0, anEvent.getModifiers (), false);
65 }, "java.awt.event.KeyEvent");
66 c$.getAWTKeyStroke = Clazz.defineMethod (c$, "getAWTKeyStroke",
69 throw new IllegalArgumentException ("String cannot be null");
70 }var errmsg = "String formatted incorrectly";
71 var st = new java.util.StringTokenizer (s, " ");
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 ();
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) {
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")) {
105 }if (token.equals ("pressed")) {
108 }if (token.equals ("typed")) {
111 }var tokenMask = java.awt.AWTKeyStroke.modifierKeywords.get (token);
112 if (tokenMask != null) {
113 mask |= tokenMask.intValue ();
115 throw new IllegalArgumentException ("String formatted incorrectly");
117 throw new IllegalArgumentException ("String formatted incorrectly");
119 c$.getVKCollection = Clazz.defineMethod (c$, "getVKCollection",
121 if (java.awt.AWTKeyStroke.vks == null) {
122 java.awt.AWTKeyStroke.vks = new java.awt.VKCollection ();
123 }return java.awt.AWTKeyStroke.vks;
125 c$.getVKValue = Clazz.defineMethod (c$, "getVKValue",
127 var vkCollect = java.awt.AWTKeyStroke.getVKCollection ();
128 var value = vkCollect.findCode (key);
131 var errmsg = "String formatted incorrectly";
133 keyCode = java.awt.event.KeyEvent.getField (key).getInt (java.awt.event.KeyEvent);
135 if (Clazz.exceptionOf (e$$, NoSuchFieldException)) {
138 throw new IllegalArgumentException ("String formatted incorrectly");
140 } else if (Clazz.exceptionOf (e$$, IllegalAccessException)) {
143 throw new IllegalArgumentException ("String formatted incorrectly");
149 value = Integer.$valueOf (keyCode);
150 vkCollect.put (key, value);
151 }return value.intValue ();
153 Clazz.defineMethod (c$, "getKeyChar",
157 Clazz.defineMethod (c$, "getKeyCode",
161 Clazz.defineMethod (c$, "getModifiers",
163 return this.modifiers;
165 Clazz.defineMethod (c$, "isOnKeyRelease",
167 return this.onKeyRelease;
169 Clazz.defineMethod (c$, "getKeyEventType",
171 if (this.keyCode == 0) {
174 return (this.onKeyRelease) ? 402 : 401;
176 Clazz.overrideMethod (c$, "hashCode",
178 return (((this.keyChar).charCodeAt (0)) + 1) * (2 * (this.keyCode + 1)) * (this.modifiers + 1) + (this.onKeyRelease ? 1 : 2);
180 Clazz.defineMethod (c$, "equals",
181 function (anObject) {
182 if (Clazz.instanceOf (anObject, java.awt.AWTKeyStroke)) {
184 return (ks.keyChar == this.keyChar && ks.keyCode == this.keyCode && ks.onKeyRelease == this.onKeyRelease && ks.modifiers == this.modifiers);
187 Clazz.overrideMethod (c$, "toString",
189 if (this.keyCode == 0) {
190 return java.awt.AWTKeyStroke.getModifiersText (this.modifiers) + "typed " + this.keyChar;
192 return java.awt.AWTKeyStroke.getModifiersText (this.modifiers) + (this.onKeyRelease ? "released" : "pressed") + " " + java.awt.AWTKeyStroke.getVKText (this.keyCode);
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) {
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 ();
215 c$.getVKText = Clazz.defineMethod (c$, "getVKText",
219 Clazz.defineMethod (c$, "readResolve",
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);
228 Clazz.defineStatics (c$,
229 "modifierKeywords", 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$,
238 this.code2name = new java.util.HashMap ();
239 this.name2code = new java.util.HashMap ();
241 Clazz.defineMethod (c$, "put",
242 function (name, code) {
243 this.code2name.put (code, name);
244 this.name2code.put (name, code);
246 Clazz.defineMethod (c$, "findCode",
248 return this.name2code.get (name);
250 Clazz.defineMethod (c$, "findName",
252 return this.code2name.get (code);