Skip to content

Commit 18ef44b

Browse files
committed
fixes for j2sApplet and J2sClazz
adds J2S._getKeyModifiers missing Character.isISOControl fixes JSTextUI not handling key events
1 parent c82acb2 commit 18ef44b

File tree

7 files changed

+148
-39
lines changed

7 files changed

+148
-39
lines changed

sources/net.sf.j2s.java.core/src/swingjs/api/js/J2SInterface.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void _readyCallback(String appId, String fullId, boolean isReady,
5656
* @return
5757
*/
5858
String _getDefaultLanguage(boolean isAll);
59-
59+
60+
int _getKeyModifiers(Object jQueryEvent);
6061
}
6162

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSTextUI.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import java.awt.Insets;
3434
import java.awt.LayoutManager;
3535
import java.awt.event.ActionEvent;
36+
import java.awt.event.KeyEvent;
37+
import java.awt.event.KeyListener;
38+
3639
import javax.swing.AbstractAction;
3740
import javax.swing.Action;
3841
import javax.swing.ActionMap;
@@ -51,6 +54,7 @@
5154
import javax.swing.text.JTextComponent;
5255
import javax.swing.text.TextAction;
5356
import swingjs.JSToolkit;
57+
import swingjs.JSUtil;
5458
import swingjs.api.js.DOMNode;
5559

5660
/**
@@ -206,13 +210,57 @@ private void installDefaults2() {
206210
/**
207211
* called by JSComponentUI.bindJSEvents
208212
*
209-
* @return handled
213+
* @return handled
214+
*
215+
*
210216
*/
211217
@Override
212218
public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
213-
//System.out.println("Handling for " + id + " " + eventType + " " + jQueryEvent);
219+
// System.out.println("Handling for " + id + " " + eventType + " " +
220+
// jQueryEvent);
214221
JTextComponent t = (JTextComponent) jc;
215-
return (t.isEditable() ? textListener.handleJSTextEvent(this, eventType, jQueryEvent) : false);
222+
if (!t.isEditable())
223+
return false;
224+
switch (eventType) {
225+
case KeyEvent.KEY_PRESSED:
226+
// note that events are bundled here into one eventType
227+
int keyCode = 0;
228+
int modifiers = JSUtil.J2S._getKeyModifiers(jQueryEvent);
229+
char keyChar = '\0';
230+
String type = null;
231+
/**
232+
* @j2sNative
233+
*
234+
* keyCode = jQueryEvent.keyCode;
235+
* keyChar = jQueryEvent.key;
236+
* type = jQueryEvent.type;
237+
*
238+
*/
239+
switch (type) {
240+
case "keydown":
241+
eventType = KeyEvent.KEY_PRESSED;
242+
break;
243+
case "keypress":
244+
eventType = KeyEvent.KEY_TYPED;
245+
break;
246+
case "keyup":
247+
eventType = KeyEvent.KEY_RELEASED;
248+
break;
249+
}
250+
KeyEvent keyEvent = new KeyEvent(jc, eventType, System.currentTimeMillis(), modifiers, keyCode, keyChar);
251+
jc.dispatchEvent(keyEvent);
252+
if (keyEvent.isConsumed()) {
253+
/**
254+
* @j2sNative
255+
*
256+
* jQueryEvent.preventDefault();
257+
* jQueryEvent.stopPropagation();
258+
*/
259+
return true;
260+
}
261+
break;
262+
}
263+
return textListener.handleJSTextEvent(this, eventType, jQueryEvent);
216264
}
217265

218266
/**
@@ -2762,5 +2810,4 @@ protected Color getInactiveTextColor(Color fg) {
27622810
return (!editor.isEnabled() ? editor.getDisabledTextColor() : !editor.isEditable() ? inactiveForeground : fg);
27632811
}
27642812

2765-
27662813
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
})();
3+
4+
Clazz._coreLoaded = true;
5+
6+
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
;(function() {
2+
3+
if (Jmol._debugCode)return;
4+

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// j2sCore.js (based on JmolCore.js)
22

3+
// BH 2/20/2018 12:08:08 AM adds J2S._getKeyModifiers
34
// BH 1/8/2018 10:27:46 PM SwingJS2
45
// BH 12/22/2017 1:18:42 PM adds j2sargs for setting arguments
56
// BH 11/19/2017 3:55:04 AM adding support for swingjs2.js; adds static j2sHeadless=true;
@@ -1481,6 +1482,11 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
14811482
modifiers = (1<<2)|(1<<12);//InputEvent.BUTTON3 + InputEvent.BUTTON3_DOWN_MASK;
14821483
break;
14831484
}
1485+
return modifiers | J2S._getKeyModifiers(ev);
1486+
}
1487+
1488+
J2S._getKeyModifiers = function(ev) {
1489+
var modifiers = 0;
14841490
if (ev.shiftKey)
14851491
modifiers |= (1<<0)|(1<<6); //InputEvent.SHIFT_MASK + InputEvent.SHIFT_DOWN_MASK;
14861492
if (ev.ctrlKey)

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

1010

11+
// BH 2/20/2018 12:59:28 AM adds Character.isISOControl
1112
// BH 2/13/2018 6:24:44 AM adds String.copyValueOf (two forms)
1213
// BH 2/7/2018 7:47:07 PM adds System.out.flush and System.err.flush
1314
// BH 2/1/2018 12:14:20 AM fix for new int[128][] not nulls
@@ -3975,39 +3976,57 @@ function(c){
39753976
c = c.charCodeAt(0);
39763977
return (48 <= c && c <= 57);
39773978
}, 1);
3978-
m$(C$,"isUpperCase",
3979-
function(c){
3980-
c = c.charCodeAt(0);
3981-
return (65 <= c && c <= 90);
3982-
}, 1);
3983-
m$(C$,"isLowerCase",
3984-
function(c){
3985-
c = c.charCodeAt(0);
3986-
return (97 <= c && c <= 122);
3987-
}, 1);
3988-
m$(C$,"isWhitespace",
3979+
3980+
m$(C$,"isISOControl",
39893981
function(c){
3990-
c = (c).charCodeAt(0);
3991-
return (c >= 0x1c && c <= 0x20 || c >= 0x9 && c <= 0xd || c == 0x1680
3992-
|| c >= 0x2000 && c != 0x2007 && (c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000));
3982+
if (typeof c == "string")
3983+
c = c.charCodeAt(0);
3984+
return (c < 0x1F || 0x7F <= c && c <= 0x9F);
39933985
}, 1);
3986+
39943987
m$(C$,"isLetter",
39953988
function(c){
3996-
c = c.charCodeAt(0);
3989+
if (typeof c == "string")
3990+
c = c.charCodeAt(0);
39973991
return (65 <= c && c <= 90 || 97 <= c && c <= 122);
39983992
}, 1);
39993993
m$(C$,"isLetterOrDigit",
40003994
function(c){
4001-
c = c.charCodeAt(0);
3995+
if (typeof c == "string")
3996+
c = c.charCodeAt(0);
40023997
return (65 <= c && c <= 90 || 97 <= c && c <= 122 || 48 <= c && c <= 57);
40033998
}, 1);
4004-
m$(C$,"isSpaceChar",
3999+
m$(C$,"isLowerCase",
4000+
function(c){
4001+
if (typeof c == "string")
4002+
c = c.charCodeAt(0);
4003+
return (97 <= c && c <= 122);
4004+
}, 1);
4005+
m$(C$,"isSpace",
40054006
function(c){
40064007
var i = c.charCodeAt(0);
4008+
return (i==0x20||i==0x9||i==0xA||i==0xC||i==0xD);
4009+
}, 1);
4010+
m$(C$,"isSpaceChar",
4011+
function(c){
4012+
var i = (typeof c == "string" ? c.charCodeAt(0) : c);
40074013
if(i==0x20||i==0xa0||i==0x1680)return true;
40084014
if(i<0x2000)return false;
40094015
return i<=0x200b||i==0x2028||i==0x2029||i==0x202f||i==0x3000;
40104016
}, 1);
4017+
m$(C$,"isUpperCase",
4018+
function(c){
4019+
if (typeof c == "string")
4020+
c = c.charCodeAt(0);
4021+
return (65 <= c && c <= 90);
4022+
}, 1);
4023+
m$(C$,"isWhitespace",
4024+
function(c){
4025+
if (typeof c == "string")
4026+
c = c.charCodeAt(0);
4027+
return (c >= 0x1c && c <= 0x20 || c >= 0x9 && c <= 0xd || c == 0x1680
4028+
|| c >= 0x2000 && c != 0x2007 && (c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000));
4029+
}, 1);
40114030
m$(C$,"digit",
40124031
function(c,radix){
40134032
var i = c.charCodeAt(0);

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10654,6 +10654,7 @@ return jQuery;
1065410654
})(jQuery,document,"click mousemove mouseup touchmove touchend", "outjsmol");
1065510655
// j2sCore.js (based on JmolCore.js)
1065610656

10657+
// BH 2/20/2018 12:08:08 AM adds J2S._getKeyModifiers
1065710658
// BH 1/8/2018 10:27:46 PM SwingJS2
1065810659
// BH 12/22/2017 1:18:42 PM adds j2sargs for setting arguments
1065910660
// BH 11/19/2017 3:55:04 AM adding support for swingjs2.js; adds static j2sHeadless=true;
@@ -12135,6 +12136,11 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
1213512136
modifiers = (1<<2)|(1<<12);//InputEvent.BUTTON3 + InputEvent.BUTTON3_DOWN_MASK;
1213612137
break;
1213712138
}
12139+
return modifiers | J2S._getKeyModifiers(ev);
12140+
}
12141+
12142+
J2S._getKeyModifiers = function(ev) {
12143+
var modifiers = 0;
1213812144
if (ev.shiftKey)
1213912145
modifiers |= (1<<0)|(1<<6); //InputEvent.SHIFT_MASK + InputEvent.SHIFT_DOWN_MASK;
1214012146
if (ev.ctrlKey)
@@ -13072,6 +13078,7 @@ J2S._getResourcePath = function(path, isJavaPath) {
1307213078
// Google closure compiler cannot handle Clazz.new or Clazz.super
1307313079

1307413080

13081+
// BH 2/20/2018 12:59:28 AM adds Character.isISOControl
1307513082
// BH 2/13/2018 6:24:44 AM adds String.copyValueOf (two forms)
1307613083
// BH 2/7/2018 7:47:07 PM adds System.out.flush and System.err.flush
1307713084
// BH 2/1/2018 12:14:20 AM fix for new int[128][] not nulls
@@ -17039,39 +17046,57 @@ function(c){
1703917046
c = c.charCodeAt(0);
1704017047
return (48 <= c && c <= 57);
1704117048
}, 1);
17042-
m$(C$,"isUpperCase",
17043-
function(c){
17044-
c = c.charCodeAt(0);
17045-
return (65 <= c && c <= 90);
17046-
}, 1);
17047-
m$(C$,"isLowerCase",
17048-
function(c){
17049-
c = c.charCodeAt(0);
17050-
return (97 <= c && c <= 122);
17051-
}, 1);
17052-
m$(C$,"isWhitespace",
17049+
17050+
m$(C$,"isISOControl",
1705317051
function(c){
17054-
c = (c).charCodeAt(0);
17055-
return (c >= 0x1c && c <= 0x20 || c >= 0x9 && c <= 0xd || c == 0x1680
17056-
|| c >= 0x2000 && c != 0x2007 && (c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000));
17052+
if (typeof c == "string")
17053+
c = c.charCodeAt(0);
17054+
return (c < 0x1F || 0x7F <= c && c <= 0x9F);
1705717055
}, 1);
17056+
1705817057
m$(C$,"isLetter",
1705917058
function(c){
17060-
c = c.charCodeAt(0);
17059+
if (typeof c == "string")
17060+
c = c.charCodeAt(0);
1706117061
return (65 <= c && c <= 90 || 97 <= c && c <= 122);
1706217062
}, 1);
1706317063
m$(C$,"isLetterOrDigit",
1706417064
function(c){
17065-
c = c.charCodeAt(0);
17065+
if (typeof c == "string")
17066+
c = c.charCodeAt(0);
1706617067
return (65 <= c && c <= 90 || 97 <= c && c <= 122 || 48 <= c && c <= 57);
1706717068
}, 1);
17068-
m$(C$,"isSpaceChar",
17069+
m$(C$,"isLowerCase",
17070+
function(c){
17071+
if (typeof c == "string")
17072+
c = c.charCodeAt(0);
17073+
return (97 <= c && c <= 122);
17074+
}, 1);
17075+
m$(C$,"isSpace",
1706917076
function(c){
1707017077
var i = c.charCodeAt(0);
17078+
return (i==0x20||i==0x9||i==0xA||i==0xC||i==0xD);
17079+
}, 1);
17080+
m$(C$,"isSpaceChar",
17081+
function(c){
17082+
var i = (typeof c == "string" ? c.charCodeAt(0) : c);
1707117083
if(i==0x20||i==0xa0||i==0x1680)return true;
1707217084
if(i<0x2000)return false;
1707317085
return i<=0x200b||i==0x2028||i==0x2029||i==0x202f||i==0x3000;
1707417086
}, 1);
17087+
m$(C$,"isUpperCase",
17088+
function(c){
17089+
if (typeof c == "string")
17090+
c = c.charCodeAt(0);
17091+
return (65 <= c && c <= 90);
17092+
}, 1);
17093+
m$(C$,"isWhitespace",
17094+
function(c){
17095+
if (typeof c == "string")
17096+
c = c.charCodeAt(0);
17097+
return (c >= 0x1c && c <= 0x20 || c >= 0x9 && c <= 0xd || c == 0x1680
17098+
|| c >= 0x2000 && c != 0x2007 && (c <= 0x200b || c == 0x2028 || c == 0x2029 || c == 0x3000));
17099+
}, 1);
1707517100
m$(C$,"digit",
1707617101
function(c,radix){
1707717102
var i = c.charCodeAt(0);

0 commit comments

Comments
 (0)