Skip to content

Commit 5e386e9

Browse files
committed
Key Event work -- unfinished; JSThread fix Clazz.new_; init() size fix
1 parent 5e8bb2a commit 5e386e9

File tree

8 files changed

+72
-14
lines changed

8 files changed

+72
-14
lines changed
1.7 MB
Binary file not shown.

sources/net.sf.j2s.java.core/src/a2s/Applet.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.swing.JApplet;
99
import javax.swing.JPanel;
1010

11-
@SuppressWarnings("serial")
1211
public class Applet extends JApplet implements A2SContainer {
1312

1413

@@ -23,18 +22,14 @@ public void paintComponent(Graphics g) {
2322
super.paintComponent(g);
2423
// System.out.println("init " + this.getSize());
2524
try {
25+
// The content pane's paintComponent method has not been overridden.
26+
// There may be no problem, but it also could mean that the applet
27+
// is not painting properly.
2628
if (this.getWidth() > 0)
27-
paintMe(g);
29+
paintComponent_(g);
2830
} catch (Throwable e) {
29-
System.out.println(e);
31+
System.out.println("There was a problem in Applet.paintComponent(g) " + e);
3032
e.printStackTrace();
31-
/**
32-
* @j2sNative
33-
*
34-
* debugger;
35-
*/
36-
{
37-
}
3833
}
3934
}
4035
});
@@ -57,9 +52,9 @@ public A2SListener getA2SListener() {
5752

5853
private boolean paintMeNotified;
5954

60-
protected void paintMe(Graphics g) {
55+
protected void paintComponent_(Graphics g) {
6156
if (!paintMeNotified) {
62-
System.out.println("paintMe has not been implemented for " + this);
57+
System.out.println("JComponent.paintComponent(g) has not been overridden (including a super.paintComponent(g)) \nfor the " + this.getClass().getName() + " AWT applet.\nThis many be no problem, or it may mean the applet is not displaying properly.\n See https://docs.oracle.com/javase/tutorial/uiswing/painting/refining.html\n and https://docs.oracle.com/javase/tutorial/uiswing/painting/closer.html");
6358
paintMeNotified = true;
6459
}
6560
}

sources/net.sf.j2s.java.core/src/java/awt/AWTKeyStroke.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ private static VKCollection getVKCollection() {
591591
if (vks == null) {
592592
vks = new VKCollection();
593593
VKCollection vk = vks;
594+
// TODO: THIS IS NOT GOING TO WORK ANYMORE -- WE DO NOT CREATE THE VK_ names
594595
/**
595596
* @j2sNative
596597
* var c = Clazz.load("java.awt.event.KeyEvent");

sources/net.sf.j2s.java.core/src/javajs/util/JSThread.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ public void run() {
200200
* @j2sNative
201201
*
202202
* setTimeout(
203-
* function() {java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent$java_awt_AWTEvent(Clazz.new(java.awt.event.InvocationEvent.c$$O$Runnable,[me, r]))},
203+
* function() {
204+
* java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent$java_awt_AWTEvent(
205+
* Clazz.new_(java.awt.event.InvocationEvent.c$$O$Runnable,[me, r]))},
204206
* delay);
205207
*
206208
*/

sources/net.sf.j2s.java.core/src/swingjs/JSAppletViewer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public int run1(int mode) {
410410
}
411411
System.out.println("JSAppletViewer init");
412412
japplet.setFont(new Font(Font.DIALOG, Font.PLAIN, 12));
413-
japplet.resizeHTML(defaultAppletSize.width, defaultAppletSize.height);
413+
japplet.resizeOriginal(defaultAppletSize.width, defaultAppletSize.height);
414414
japplet.init();
415415
// Need the default(fallback) font to be created in this
416416
// AppContext

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,11 @@ private void setTextAlignment() {
16251625
default:
16261626
return;
16271627
}
1628+
// edu_northwestern_physics_groups_atomic_applet_Mirror_applet.html
1629+
// seems to work OK here because the absolute is being removed
1630+
// there was a problem with Applet.init() not having the right width/height initialization
1631+
// but now it seems OK. This issue is most certainly the issue that in applet start up
1632+
// an initial paint shows checkboxes lower than they should be.
16281633
DOMNode.setStyles(centeringNode, "position", "absolute", "left", left + "px");
16291634
}
16301635
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@
88
@SuppressWarnings({"serial", "unused"})
99
public class JSKeyEvent extends KeyEvent {
1010

11+
12+
//Alphanumeric keys
13+
// VK_0, VK_1, ..., VK_9, VK_A, VK_B, ..., VK_Z
14+
//Java: pressed/typed/released (typed has charCode 0; pressed has UCASE keyCode but true-case keyChar
15+
//JavaScript: down/pressed/up
16+
17+
//Control keys
18+
// VK_ENTER, VK_BACKSPACE, VK_TAB, VK_ESCAPE
19+
//Java: pressed/typed/released (typed has charCode 0; pressed has UCASE keyCode but true-case keyChar
20+
//JavaScript: down/pressed/up
21+
22+
//Function keys
23+
// VK_F1, VK_F2, VK_F3, VK_F4 VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
24+
// VK_SCROLL_LOCK, VK_PRINTSCREEN, VK_PAUSE,
25+
// VK_DELETE, VK_INSERT,
26+
// VK_PAGE_UP, VK_PAGE_DOWN, VK_HOME, VK_END
27+
//Java: pressed/released only, with keyChar 0xFFFF
28+
// DEL: adds 0 127 typed
29+
// INS: code is 155
30+
//JavaScript: down/pressed/up; only up for printScreen
31+
// DEL: code is 46
32+
// INS: code is 45
33+
34+
//Arrow keys
35+
// VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN
36+
//Java: pressed/released 38/0xFFFF
37+
//JavaScript: down/pressed/up 38/"ArrowUp"
38+
1139
Object jqEvent;
1240

1341
public JSKeyEvent(JComponent source, Object jQueryEvent) {

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,34 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
241241
eventType = KeyEvent.KEY_PRESSED;
242242
break;
243243
case "keypress":
244+
// igonred by Java for
245+
246+
247+
// Control keys
248+
// VK_ENTER, VK_BACKSPACE, VK_TAB, VK_ESCAPE
249+
// Function keys
250+
// VK_F1, VK_F2, VK_F3, VK_F4 VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12,
251+
// VK_SCROLL_LOCK, VK_PRINTSCREEN, VK_PAUSE,
252+
// VK_DELETE, VK_INSERT,
253+
// VK_PAGE_UP, VK_PAGE_DOWN, VK_HOME, VK_END
254+
// Java: pressed/released only, with keyChar 0xFFFF
255+
// DEL: adds 0 127 typed
256+
// INS: code is 155
257+
// JavaScript: down/pressed/up; but only up for printScreen
258+
// PRINTSCREEN code is 44
259+
// INS: code is 45
260+
// DEL: code is 46
261+
//
262+
// Arrow keys
263+
// VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN
264+
// Java: pressed/released 38/0xFFFF
265+
//
266+
//
267+
268+
// TODO: generate this for BACKSPACE and what other keys?
244269
eventType = KeyEvent.KEY_TYPED;
270+
keyChar = (char) keyCode;
271+
keyCode = KeyEvent.VK_UNDEFINED;
245272
break;
246273
case "keyup":
247274
eventType = KeyEvent.KEY_RELEASED;

0 commit comments

Comments
 (0)