Skip to content

Commit c2d681d

Browse files
committed
AsyncSwingWorker.executeSychronously(); fix for
JSUtil.getAppletInfo(String)
1 parent 20b6561 commit c2d681d

File tree

11 files changed

+155
-65
lines changed

11 files changed

+155
-65
lines changed
1.39 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200504090455
1+
20200506131724
1.39 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200504090455
1+
20200506131724
Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
1+
j2sApplet exec testApplet start applet null
2+
transpiler was unknown now 3.2.9-v1 for java.lang.Class
3+
swingjs.api.Interface creating instance of javajs.util.AjaxURLStreamHandlerFactory
4+
JSApp get parameter: language = null
5+
swingjs.JSUtil initialized;debug=false
6+
JSApp get parameter: name = testApplet
7+
JSApp get parameter: syncId = 022516724642611
8+
JSApp initialized
9+
JSAppletViewer initializing2
10+
JSToolkit initialized
11+
JSGraphicsConfiguration initialized
12+
swingjs.api.Interface creating instance of swingjs.JSGraphicsEnvironment
13+
JSGraphicsEnvironment initialized
14+
swingjs.api.Interface creating instance of swingjs.JSScreenDevice
15+
JSScreenDevice initialized
16+
JSAppletViewer thread run1 mode=0 status=0
17+
JSAppletViewer thread run1 mode=1 status=1
18+
JSAppletViewer runloader
19+
JSApp get parameter: main = test.Derivative
20+
swingjs.api.Interface creating instance of swingjs.JSDummyApplet
21+
swingjs.api.Interface creating instance of swingjs.plaf.HTML5LookAndFeel
22+
testApplet loaded
23+
JSAppletViewer thread run1 mode=1 status=76
24+
testApplet running test.Derivative
25+
Running main(args) in class test.Derivative
126
1.8 Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
2-
Direct: ...........-8069730.430666382........148
3-
Direct: ...........-8069730.430666382........149
4-
Direct: ...........-8069730.430666382........151
5-
Unwrapped: ........-7908873.121916154................ 155
6-
Unwrapped: ........-7908873.121916154................ 170
7-
Unwrapped: ........-7908873.121916154................ 195
8-
Wrapped: ..........-8069730.430666382........................166
9-
Wrapped: ..........-8069730.430666382........................148
10-
Wrapped: ..........-8069730.430666382........................141
11-
Direct: ...........-8069730.430666382........139
12-
Unwrapped: ........-7908873.121916154................ 138
13-
Wrapped: ..........-8069730.430666382........................140
14-
Direct: ...........-8069730.430666382........165
15-
Unwrapped: ........-7908873.121916154................ 200
16-
Wrapped: ..........-8069730.430666382........................142
17-
Direct: ...........-8069730.430666382........141
18-
Unwrapped: ........-7908873.121916154................ 140
19-
Wrapped: ..........-8069730.430666382........................147
20-
Wrapped: ..........-8069730.430666382........................143
21-
Wrapped: ..........-8069730.430666382........................140
27+
Direct: ...........-8069730.430666382........131
28+
Direct: ...........-8069730.430666382........128
29+
Direct: ...........-8069730.430666382........123
30+
Unwrapped: ........-8069730.430666382................ 128
31+
Unwrapped: ........-8069730.430666382................ 127
32+
Unwrapped: ........-8069730.430666382................ 124
33+
Wrapped: ..........-8069730.430666382........................132
2234
Wrapped: ..........-8069730.430666382........................134
23-
Unwrapped: ........-7908873.121916154................ 124
24-
Unwrapped: ........-7908873.121916154................ 121
25-
Unwrapped: ........-7908873.121916154................ 124
26-
Direct: ...........-8069730.430666382........122
35+
Wrapped: ..........-8069730.430666382........................130
36+
Direct: ...........-8069730.430666382........121
37+
Unwrapped: ........-8069730.430666382................ 125
38+
Wrapped: ..........-8069730.430666382........................130
39+
Direct: ...........-8069730.430666382........120
40+
Unwrapped: ........-8069730.430666382................ 125
41+
Wrapped: ..........-8069730.430666382........................129
42+
Direct: ...........-8069730.430666382........120
43+
Unwrapped: ........-8069730.430666382................ 124
44+
Wrapped: ..........-8069730.430666382........................132
45+
Wrapped: ..........-8069730.430666382........................131
46+
Wrapped: ..........-8069730.430666382........................130
47+
Wrapped: ..........-8069730.430666382........................130
48+
Unwrapped: ........-8069730.430666382................ 122
49+
Unwrapped: ........-8069730.430666382................ 124
50+
Unwrapped: ........-8069730.430666382................ 124
2751
Direct: ...........-8069730.430666382........121
28-
Direct: ...........-8069730.430666382........124
52+
Direct: ...........-8069730.430666382........122
53+
Direct: ...........-8069730.430666382........121
1.39 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/util/regex/Matcher.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@
44
//BH fix for String not having .length() or .subSequence()
55
//BH fix for not reinitializing correctly
66
//BH note that start(groupIndex) is not implemented for groupIndex > 0
7-
(function(){Clazz.newPackage("java.util.regex");
7+
8+
(function(){var P$=Clazz.newPackage("java.util.regex");
89

910
var C$=Clazz.newClass(java.util.regex,"Matcher",function(){
1011
Clazz.newInstance(this,arguments);
1112
},null,"java.util.regex.MatchResult");
1213

14+
C$.$clinit$=2;
15+
16+
Clazz.newMeth(C$, '$init$', function () {
17+
},1);
1318

14-
C$.$clinit$ = function() {
15-
delete C$.$clinit$;
16-
Clazz.load(C$, 1);
17-
};
19+
Clazz.newMeth(C$);
1820

19-
(function(){
21+
;
22+
(function(){/*c*/var C$=Clazz.newClass(P$.Matcher, "Matcher1", function(){
23+
Clazz.newInstance(this, arguments[0],true,C$);
24+
});
2025

21-
var C$=Clazz.newClass(java.util.regex,"Matcher$1",function(){
22-
Clazz.newInstance(this, arguments[0], true);
23-
});
24-
25-
C$.$clinit$ = function() {delete C$.$clinit$;Clazz.load(C$, 1);}
26+
C$.$clinit$=2;
2627

27-
Clazz.newMeth(C$, "$init$", function() {
28-
this.grN=0;
29-
}, 1);
30-
Clazz.newMeth(C$,"toString", function(){
31-
return this.b$["java.util.regex.Matcher"].group$I(this.grN);
32-
});
33-
})();
28+
Clazz.newMeth(C$, '$init$', function () {
29+
this.grN=0;
30+
},1);
31+
32+
C$.$fields$=[['I',['grN']]]
33+
34+
Clazz.newMeth(C$, 'toString', function () {
35+
return this.b$['java.util.regex.Matcher'].group$I.apply(this.b$['java.util.regex.Matcher'], [this.grN]);
36+
});
37+
38+
Clazz.newMeth(C$);
39+
})()
3440

3541
Clazz.newMeth(C$, 'c$$java_util_regex_Pattern$CharSequence', function(pat,cs){
3642
this.pat=pat;
@@ -120,16 +126,16 @@ Clazz.newMeth(C$,"processReplacement$S",function(replacement){
120126
if(this.replacementParts==null){
121127
return this.processedRepl;
122128
}else{
123-
var sb=new StringBuffer();
129+
var sb=Clazz.new_("java.lang.StringBuffer");
124130
for(var i=0;i<this.replacementParts.length;i++){
125131
sb.append$S(this.replacementParts[i]);
126132
}
127133
return sb.toString();
128134
}
129135
}else{
130136
this.replacement=replacement;
131-
var repl=replacement.toCharArray();
132-
var res=new StringBuffer();
137+
var repl=replacement.toCharArray$();
138+
var res=Clazz.new_("java.lang.StringBuffer");
133139
this.replacementParts=null;
134140
var index=0;
135141
var replacementPos=0;
@@ -145,15 +151,15 @@ Clazz.newMeth(C$,"processReplacement$S",function(replacement){
145151
}else{
146152
if((repl[index]).charCodeAt(0)==('$').charCodeAt(0)){
147153
if(this.replacementParts==null){
148-
this.replacementParts=Clazz.array(String, 0);
154+
this.replacementParts=[];
149155
}
150156
try{
151157
var gr=Integer.parseInt$S(String.instantialize(repl,++index,1));
152158
if(replacementPos!=res.length$()){
153159
this.replacementParts[this.replacementParts.length]=res.subSequence$I$I(replacementPos,res.length$());
154160
replacementPos=res.length$();
155161
}
156-
this.replacementParts[this.replacementParts.length]= Clazz.new_(Clazz.load("java.util.regex.Matcher$1").c$,[this]);
162+
this.replacementParts[this.replacementParts.length]= Clazz.new_(P$.Matcher.Matcher1.c$,[this]);
157163
var group=this.group$I(gr);
158164
replacementPos+=group.length;
159165
res.append$S(group);
@@ -205,15 +211,15 @@ Clazz.newMeth(C$,"appendTail$StringBuffer",function(sb){
205211
Clazz.newMeth(C$,"replaceFirst$S",function(replacement){
206212
this.reset$();
207213
if(this.find$()){
208-
var sb=new StringBuffer();
214+
var sb=Clazz.new_("java.lang.StringBuffer");
209215
this.appendReplacement$StringBuffer$S(sb,replacement);
210216
return this.appendTail$StringBuffer(sb).toString();
211217
}
212218
return this.charSeq.toString();
213219
});
214220

215221
Clazz.newMeth(C$,"replaceAll$S", function(replacement){
216-
var sb=new StringBuffer();
222+
var sb=Clazz.new_("java.lang.StringBuffer");
217223
this.reset$();
218224
while(this.find$()){
219225
this.appendReplacement$StringBuffer$S(sb,replacement);
@@ -327,3 +333,4 @@ Clazz.newMeth(C$,"usePattern$java.util_regex_Pattern",function(pat){
327333
});
328334

329335
})();
336+
// BH 2020.05.04

sources/net.sf.j2s.java.core/src/java/util/regex/Pattern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ var C$=Clazz.newClass(java.util.regex,"Pattern",function(){
66
Clazz.newInstance(this,arguments);
77
});
88

9-
C$.$clinit$ = function() {delete C$.$clinit$;Clazz.load(C$, 1);}
9+
C$.$clinit$ = 2;
1010

1111
Clazz.newMeth(C$,"$init$", function(){
1212
this.$flags=0;
1313
this.regexp=null;
1414
}, 1);
1515

16-
Clazz.newMeth(C$,"$c", function(){
16+
Clazz.newMeth(C$,"c$", function(){
1717
C$.$init$.apply(this);
1818
}, 1);
1919

sources/net.sf.j2s.java.core/src/javajs/async/AsyncSwingWorker.java

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import javajs.async.SwingJSUtils.StateMachine;
1111

1212
/**
13-
* Executes asynchronous tasks using a SwingWorker in Java or JavaScript,
13+
* Executes synchronous or asynchronous tasks using a SwingWorker in Java or JavaScript,
1414
* equivalently.
1515
*
1616
* Unlike a standard SwingWorker, AsyncSwingWorker may itself be asynchronous.
@@ -38,6 +38,9 @@
3838
* the subclass to update the progress field in both the SwingWorker and the
3939
* ProgressMonitor.
4040
*
41+
* If it is desired to run the AsyncSwingWorker synchonously, call the
42+
* executeSynchronously() method rather than execute(). Never call SwingWorker.run().
43+
*
4144
*
4245
* @author hansonr
4346
*
@@ -78,6 +81,9 @@ public abstract class AsyncSwingWorker extends SwingWorker<Void, Void> implement
7881
protected int max;
7982
protected int progressPercent;
8083

84+
protected boolean isAsync;
85+
private Exception exception;
86+
8187
/**
8288
* Construct an asynchronous SwingWorker task that optionally will display a
8389
* ProgressMonitor. Progress also can be monitored by adding a PropertyChangeListener
@@ -96,15 +102,37 @@ public abstract class AsyncSwingWorker extends SwingWorker<Void, Void> implement
96102
*
97103
*/
98104
public AsyncSwingWorker(Component owner, String title, int delayMillis, int min, int max) {
99-
if (title != null) {
105+
if (title != null && delayMillis > 0) {
100106
progressMonitor = new ProgressMonitor(owner, title, "", Math.min(min, max), Math.max(min, max));
101107
progressMonitor.setProgress(Math.min(min, max)); // displays monitor
102108
}
103-
this.delayMillis = Math.max(1, delayMillis);
109+
this.delayMillis = Math.max(0, delayMillis);
110+
this.isAsync = (delayMillis > 0);
111+
104112
this.min = min;
105113
this.max = max;
106114
}
107115

116+
public void executeAsync() {
117+
super.execute();
118+
}
119+
120+
public void executeSynchronously() {
121+
isAsync = false;
122+
delayMillis = 0;
123+
try {
124+
doInBackground();
125+
} catch (Exception e) {
126+
exception = e;
127+
e.printStackTrace();
128+
cancelAsync();
129+
}
130+
}
131+
132+
public Exception getException() {
133+
return exception;
134+
}
135+
108136
public int getMinimum() {
109137
return min;
110138
}
@@ -270,20 +298,28 @@ public boolean stateLoop() {
270298
progressMonitor.close();
271299
// Put the doneAsync() method on the AWTEventQueue
272300
// just as for SwingWorker.done().
273-
SwingUtilities.invokeLater(new Runnable() {
274-
275-
@Override
276-
public void run() {
277-
doneAsync();
278-
firePropertyChange("state", null, DONE_ASYNC);
279-
}
301+
if (isAsync)
302+
{
303+
SwingUtilities.invokeLater(doneRunnable);
304+
} else {
305+
doneRunnable.run();
306+
}
280307

281-
});
282308
return false;
283309
}
284310
}
285311
return false;
286312
}
313+
314+
private Runnable doneRunnable = new Runnable() {
315+
@Override
316+
public void run() {
317+
doneAsync();
318+
firePropertyChange("state", null, DONE_ASYNC);
319+
}
320+
321+
};
322+
287323

288324
private boolean checkCanceled() {
289325
if (isMonitorCanceled() || isCancelled()) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,19 @@ public Object getFile(String path, boolean asString) {
947947
return (asString ? getFileAsString(path) : getFileAsBytes(path));
948948
}
949949

950+
@Override
951+
public Object getAppletInfo(String infoKey) {
952+
@SuppressWarnings("unused")
953+
HTML5Applet applet = getApplet();
954+
/** @j2sNative
955+
*
956+
* var val = applet.__Info[infoKey];
957+
* return (val == null ? null : val);
958+
*/ {
959+
return null;
960+
}
961+
}
962+
950963
@Override
951964
public void setAppletInfo(String infoKey, Object val) {
952965
HTML5Applet applet = getApplet();

0 commit comments

Comments
 (0)