Skip to content

Commit 1bfe0a8

Browse files
author
zhourenjian
committed
Add support for new functions in net.sf.j2s.ui.
1 parent 6188845 commit 1bfe0a8

File tree

4 files changed

+86
-21
lines changed

4 files changed

+86
-21
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Java2Script Release
2+
#Sun Mar 04 22:38:19 CST 2007
3+
alias=1.0.0-m5
4+
version=20070304

sources/net.sf.j2s.java.core/src/java/lang/ClassLoader.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ ClazzLoader.getJ2SLibBase = function () {
20602060
if (idx != -1) {
20612061
return src.substring (0, idx);
20622062
}
2063-
idx = src.indexOf ("j2slib.core.js"); // consider it as key string!
2063+
idx = src.indexOf ("j2slibcore.z.js"); // consider it as key string!
20642064
if (idx != -1) {
20652065
return src.substring (0, idx);
20662066
}
@@ -2124,12 +2124,9 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
21242124
if (name.indexOf (swtPkg) == 0 || name.indexOf ("$wt") == 0) {
21252125
ClazzLoader.assurePackageClasspath (swtPkg);
21262126
}
2127-
/*
2128-
* "junit" is not considered as inner supported library.
2129-
*/
2130-
//if (name.indexOf ("junit") == 0) {
2131-
// ClazzLoader.assurePackageClasspath ("junit");
2132-
//}
2127+
if (name.indexOf ("junit") == 0) {
2128+
ClazzLoader.assurePackageClasspath ("junit");
2129+
}
21332130

21342131
/*
21352132
* Any ClazzLoader#loadClass calls will be queued until java.* core classes
@@ -2189,11 +2186,14 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
21892186
}
21902187
}
21912188
} else if (optionalsLoaded != null && ClazzLoader.isClassDefined (name)) {
2192-
if (async) {
2193-
window.setTimeout (optionalsLoaded, 25);
2194-
} else {
2195-
optionalsLoaded ();
2196-
}
2189+
var nn = ClazzLoader.findClass (name);
2190+
if (nn == null || nn.status >= ClazzNode.STATUS_OPTIONALS_LOADED) {
2191+
if (async) {
2192+
window.setTimeout (optionalsLoaded, 25);
2193+
} else {
2194+
optionalsLoaded ();
2195+
}
2196+
} // else ... should be called later
21972197
}
21982198

21992199
};
@@ -2202,7 +2202,7 @@ ClazzLoader.loadClass = function (name, optionalsLoaded, forced, async) {
22022202
* Load the application by the given class name and run its static main method.
22032203
*/
22042204
/* public */
2205-
$w$ = ClazzLoader.loadAppMain = function (clazz, args) {
2205+
$w$ = ClazzLoader.loadJ2SApp = function (clazz, args, loaded) {
22062206
if (clazz == null) {
22072207
return;
22082208
}
@@ -2219,12 +2219,31 @@ $w$ = ClazzLoader.loadAppMain = function (clazz, args) {
22192219
if (agmts == null || !(agmts instanceof Array)) {
22202220
agmts = [];
22212221
}
2222-
var afterLoaded = (function (clazzName, argv) {
2222+
var afterLoaded = loaded;
2223+
if (afterLoaded == null) {
2224+
afterLoaded = (function (clazzName, argv) {
2225+
return function () {
2226+
Clazz.evalType (clazzName).main (argv);
2227+
};
2228+
}) (clazzStr, agmts);
2229+
} else {
2230+
afterLoaded = loaded(clazzStr, agmts);
2231+
}
2232+
ClazzLoader.loadClass (clazzStr, afterLoaded);
2233+
};
2234+
/**
2235+
* Load JUnit tests by the given class name.
2236+
*/
2237+
/* public */
2238+
$u$ = ClazzLoader.loadJUnit = function (clazz, args) {
2239+
var afterLoaded = function (clazzName, argv) {
22232240
return function () {
2224-
Clazz.evalType (clazzName).main (argv);
2241+
ClazzLoader.loadClass ("junit.textui.TestRunner", function () {
2242+
junit.textui.TestRunner.run (Clazz.evalType (clazzName));
2243+
});
22252244
};
2226-
}) (clazzStr, agmts);
2227-
ClazzLoader.loadClass (clazzStr, afterLoaded);
2245+
};
2246+
ClazzLoader.loadJ2SApp (clazz, args, afterLoaded);
22282247
};
22292248

22302249
/* private */
@@ -2368,14 +2387,14 @@ ClazzLoader.destroyClassNode = function (node) {
23682387
};
23692388

23702389
/*
2371-
* Remove j2slib.z.js, j2slib.core.js or Class/Ext/Loader/.js.
2390+
* Remove j2slib.z.js, j2slibcore.z.js or Class/Ext/Loader/.js.
23722391
*/
23732392
window.setTimeout (function () {
23742393
var ss = document.getElementsByTagName ("SCRIPT");
23752394
for (var i = 0; i < ss.length; i++) {
23762395
var src = ss[i].src;
2377-
if ((src.indexOf ("j2slib.z.js") != -1)
2378-
|| (src.indexOf ("j2slib.core.js") != -1)) {
2396+
if (src.indexOf ("chrome:") != 0 && (src.indexOf ("j2slib.z.js") != -1
2397+
|| src.indexOf ("j2slibcore.z.js") != -1)) {
23792398
ClazzLoader.getJ2SLibBase (); // cached ...
23802399
ClazzLoader.removeScriptNode (ss[i]);
23812400
break;

sources/net.sf.j2s.java.core/src/java/lang/ClassLoaderProgressMonitor.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*******/
1818

1919
/*
20+
* Update: March 5, 2007
21+
* ClassLoaderProgressMonitor were already in default j2slib.z.js.
22+
*
2023
* ClassLoaderProgressMonitor is optional. It's used to display class loading
2124
* progress so that user know that background loading is still processing.
2225
*
@@ -46,7 +49,7 @@ clpm.fadeAlpha = 0;
4649
clpm.monitorEl = null;
4750
clpm.lastScrollTop = 0;
4851
clpm.bindingParent = null;
49-
clpm.DEFAULT_OPACITY = 75;
52+
clpm.DEFAULT_OPACITY = 55;
5053
/* private static */ clpm.clearChildren = function (el) {
5154
if (el == null) return;
5255
for (var i = el.childNodes.length - 1; i >= 0; i--) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// mozilla.addon.js
2+
// Following script will make J2SLib compatiable with Java2Script addon
3+
function loadJ2SLibZJS (path, cb) {
4+
var sxr = document.createElement ("SCRIPT");
5+
sxr.src = path;
6+
sxr.type = "text/javascript";
7+
if (cb) {
8+
var t = "onreadystatechange";
9+
var xhrCallback = function () {
10+
var s = this.readyState;
11+
if (s == null || s == "loaded" || s == "complete") {
12+
window["j2s.lib"].onload ();
13+
}
14+
};
15+
if (typeof sxr[t] == "undefined") {
16+
sxr.onload = xhrCallback;
17+
} else {
18+
sxr[t] = xhrCallback;
19+
}
20+
}
21+
document.getElementsByTagName ("HEAD")[0].appendChild (sxr);
22+
};
23+
if (navigator.userAgent.toLowerCase ().indexOf ("gecko") != -1) {
24+
loadJ2SLibZJS("chrome://java2script/content/j2slib.js");
25+
window.setTimeout (function () {
26+
if (window["j2s.addon.loaded"]) return; // Loaded by Firefox addon!
27+
var o = window["j2s.lib"];
28+
if (o.base == null) {
29+
o.base = "http://archive.java2script.org/";
30+
}
31+
loadJ2SLibZJS(o.base + (o.alias ? o.alias : o.version) + "/j2slib.z.js", o.onload);
32+
}, 300); // with 0.3 second lag! 0.3 is enough for chrome://*.js to be loaded.
33+
} else {
34+
var o = window["j2s.lib"];
35+
if (o.base == null) {
36+
o.base = "http://archive.java2script.org/";
37+
}
38+
loadJ2SLibZJS(o.base + (o.alias ? o.alias : o.version) + "/j2slib.z.js", o.onload);
39+
}

0 commit comments

Comments
 (0)