Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20220713221322
20220914134307
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.3.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20220713221322
20220914134307
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions sources/net.sf.j2s.java.core/src/javajs/util/DF.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static String formatDecimal(double value, int decimalDigits) {
value = -value;
int n;
if (decimalDigits < 0) {
decimalDigits = -1-decimalDigits;
decimalDigits = -decimalDigits;
if (decimalDigits > formattingStrings.length)
decimalDigits = formattingStrings.length;
if (value == 0)
Expand All @@ -103,7 +103,7 @@ public static String formatDecimal(double value, int decimalDigits) {
String s = ("" + d).toUpperCase();
int i1 = s.indexOf("E");
String sf;
if (i1 < 0) {
if (i1 < 0) {
sf = "" + value;
} else {
n = PT.parseInt(s.substring(i1 + (s.indexOf("E+") == i1 ? 2 : 1))) + n;
Expand Down
59 changes: 59 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/DialogsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package test;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import javajs.async.SwingJSUtils;

public class DialogsTest extends JFrame {

private class PCLPane extends JDesktopPane implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
System.out.println(name);
if (name.equals("value")) {
handlePropEvent(evt.getNewValue());
}
}
}

DialogsTest() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(0, 0, 800, 600);
setVisible(true);
// For JavaScript, we need a property change listener.
setContentPane(new PCLPane());

JOptionPane pane = new JOptionPane("I'm a banana");
JDialog dialog = pane.createDialog(getContentPane(), "Hello!");
dialog.setVisible(true);
if (/** @j2sNative false && */
true)
report("done");
// JavaScript continues....
}

public void handlePropEvent(Object newValue) {
System.out.println("value was " + newValue);
report("done");
}

private void report(String string) {
System.out.println(string);
JOptionPane.showMessageDialog(this, "I'm a Banana");
System.out.println("ok");

}

public static void main(String[] args) {
SwingUtilities.invokeLater(DialogsTest::new);
}

}
25 changes: 25 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Double.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ public static void main(String[] args) {
System.out.println((PT.toDouble(-0.999999f)) + " " + (1d-0.999999d)
+ " " + 0.000001d
+ " " + (double) -0.999999f);
System.out.println(DF.formatDecimal(123456f, -4));
System.out.println(DF.formatDecimal(999999f, -4));

System.out.println(PT.sprintf("%4.0e", "d", new Object[]{1.2345678e-4}));
System.out.println(DF.formatDecimal(0.123456f, -1));
System.out.println(DF.formatDecimal(0.999999f, -4));
System.out.println(String.format("%4.0e",0.12345));
System.out.println(String.format("%4.3e",0.12345));
System.out.println(String.format("%4.3f",0.12345));
System.out.println(DF.formatDecimal(0.12345, -4));
System.out.println(DF.formatDecimal(0.12345, 4));


assert(DF.formatDecimal(123456f, -4).equals("1.235E+5"));
assert(DF.formatDecimal(999999f, -4).equals("1.000E+6"));

assert(PT.sprintf("%4.0e", "d", new Object[]{1.2345678e-4}).equals("1E-4"));
assert(DF.formatDecimal(0.123456f, -1).equals("1E-1"));
assert(DF.formatDecimal(0.999999f, -4).equals("1.000E+0"));
assert(String.format("%4.0e",0.12345).equals("1e-01"));
assert(String.format("%4.3e",0.12345).equals("1.235e-01"));
assert(String.format("%4.3f",0.12345).equals("0.123"));
assert(DF.formatDecimal(0.12345, -4).equals("1.235E-1"));
assert(DF.formatDecimal(0.12345, 4).equals("0.1235"));

assert(DF.formatDecimal(-0.999999f, -4).equals("-1.000E+0"));
assert(DF.formatDecimal(9.999999f, -4).equals("1.000E+1"));
assert(DF.formatDecimal(9.999999f, 4).equals("10.0000"));
Expand Down
27 changes: 27 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Error.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package test;

public class Test_Error extends Test_{

public static void main(String[] args) {

new Test_Error().testError();

try {
//throw new NullPointerException("testing NPE");
/**
* @j2sNative asdlj()
*/
} catch (Throwable e) {
e.printStackTrace();
}
System.out.println("Test_Error OK");
}

private void testError() {
Error x;
x = new LinkageError("test");
x.printStackTrace();
x = new Error("test");
x.printStackTrace();
}
}
29 changes: 25 additions & 4 deletions sources/net.sf.j2s.java.core/src/test/Test_Inner.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public String getString() {
return "Test_Inner";
}

class Test_Abstract_a extends Test_ {
public class Test_Abstract_a extends Test_ {

void testing() {
public void testing() {
System.out.println("this is " + a);
assert (a == "a string");
System.out.println(showt2());
Expand Down Expand Up @@ -73,17 +73,38 @@ public String showt2() {
}


public void testDollar(Test_Abstract_a abs) {

}

public static void main(String[] args) {
Test_Inner inner = new Test_Inner(6) {};
try {
System.out.println(inner.getClass().getMethod("testDollar", new Class<?>[] {Test_Abstract_a.class}).getName());
} catch (NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
inner.showt2();
new Test_Inner(3) {}.showt2();
System.out.println(inner.t_test);
System.out.println("new Test_Inner(){}.t_test=" + new Test_Inner(7) {}.t_test);
Test_Abstract_a abs = inner.new Test_Abstract_a();
System.out.println(new Test_Abstract_a[] {abs}.getClass().getName());
abs.testing();
String s = abs.getClass().getName();
String s1 = new Test_Abstract_a[] {abs}.getClass().getName();
System.out.print("checking inner$");
assert(s.equals("test.Test_Inner$Test_Abstract_a"));
assert(s1.equals("[Ltest.Test_Inner$Test_Abstract_a;"));
System.out.println(" ok");
new Test_Inner(8) {}.new Test_Abstract_a().testing();

try {
System.out.println(abs.getClass().getMethod("testing", new Class<?>[] {}).getName());
} catch (NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


System.out.println("Test_Inner OK");
}
Expand Down
23 changes: 13 additions & 10 deletions sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// j2sApplet.js BH = Bob Hanson hansonr@stolaf.edu

// BH 2022.08.27 fix frame resizing for browsers reporting noninteger pageX, pageY
// BH 2022.06.23 implements J2S._lastAppletID
// BH 2022.01.12 adds pointer option
// BH 2021.09.22 default file save as application/octet-stream, not text/plain
Expand Down Expand Up @@ -2166,8 +2167,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
oe.targetTouches && (oe = oe.targetTouches[0]);
ev.pageX || (ev.pageX = oe ? oe.pageX : J2S._mousePageX);
ev.pageY || (ev.pageY = oe ? oe.pageY : J2S._mousePageY);
x = J2S._mousePageX = ev.pageX;
y = J2S._mousePageY = ev.pageY;
x = J2S._mousePageX = Math.round(ev.pageX);
y = J2S._mousePageY = Math.round(ev.pageY);
return [ Math.round(x - offsets.left), Math.round(y - offsets.top), mods];
}

Expand Down Expand Up @@ -2842,6 +2843,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
__nextExecution();
};

proto.__startAppletJS.j2sname = "__START_APPLET__";

if (!proto._restoreState)
proto._restoreState = function(clazzName, state) {
// applet-dependent
Expand Down Expand Up @@ -3117,8 +3120,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
J2S._dmouseDrag = drag;

tag.isDragging = true; // used by J2S mouse event business
pageX = ev.pageX;
pageY = ev.pageY;
pageX = Math.round(ev.pageX);
pageY = Math.round(ev.pageY);
var xy = {
x : 0,
y : 0,
Expand All @@ -3132,8 +3135,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
var o = $(target(501)).position();
if (!o) return false;
xy = {
x : o.left,
y : o.top
x : Math.round(o.left),
y : Math.round(o.top)
};
}
pageX0 = xy.x;
Expand All @@ -3147,8 +3150,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
tag.isDragging = false;
var mode = (tag.isDragging ? 506 : 503);
if (!J2S._dmouseOwner || tag.isDragging && J2S._dmouseOwner == tag) {
x = pageX0 + (dx = ev.pageX - pageX);
y = pageY0 + (dy = ev.pageY - pageY);
x = pageX0 + (dx = Math.round(ev.pageX) - pageX);
y = pageY0 + (dy = Math.round(ev.pageY) - pageY);
if (isNaN(x))return;
if (fDrag) {
fDrag({
Expand Down Expand Up @@ -3186,8 +3189,8 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {

var fixTouch = function(ev) {
if (ev.originalEvent.targetTouches) {
ev.pageX = ev.originalEvent.targetTouches[0].pageX;
ev.pageY = ev.originalEvent.targetTouches[0].pageY;
ev.pageX = Math.round(ev.originalEvent.targetTouches[0].pageX);
ev.pageY = Math.round(ev.originalEvent.targetTouches[0].pageY);
}
return ev;
}
Expand Down
Loading