Skip to content

Commit cf430b8

Browse files
committed
update of test runtime
1 parent c7264fd commit cf430b8

File tree

5 files changed

+99
-118
lines changed

5 files changed

+99
-118
lines changed

sources/net.sf.j2s.core/test/dev/js/SJSApplet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ if (typeof(SwingJS) == "undefined") {
229229
}
230230

231231
proto._addCoreFiles = function() {
232-
J2S._addCoreFile("swingjs", this._j2sPath, this.__Info.preloadCore);
232+
J2S._addCoreFile((this.__Info.core || "swingjs"), this._j2sPath, this.__Info.preloadCore);
233233
if (J2S._debugCode) {
234234
// no min package for that
235235
J2S._addExec([this, null, "swingjs.JSAppletViewer", "load " + this.__Info.code]);

sources/net.sf.j2s.core/test/dev/js/j2sApplet.js

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

3+
// BH 1/8/2018 10:27:46 PM SwingJS2
34
// BH 12/22/2017 1:18:42 PM adds j2sargs for setting arguments
45
// BH 11/19/2017 3:55:04 AM adding support for swingjs2.js; adds static j2sHeadless=true;
56
// BH 10/4/2017 2:25:03 PM adds Clazz.loadClass("javajs.util.Base64")
@@ -84,6 +85,7 @@ J2S = (function(document) {
8485
_z:getZOrders(z),
8586
db: {
8687
_DirectDatabaseCalls:{
88+
"chemapps.stolaf.edu" : null
8789
// these sites are known to implement access-control-allow-origin *
8890
}
8991
},
@@ -640,11 +642,11 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
640642
return true;
641643
}
642644

643-
J2S._binaryTypes = [".gz",".jpg",".jpeg",".gif",".png",".zip",".jmol",".bin",".smol",".spartan",".mrc",".pse", ".map", ".omap",
644-
".dcd",".mp3",".ogg", ".wav"];
645+
J2S._binaryTypes = [".gz<",".jpg<",".jpeg<",".gif<",".png<",".zip<",".jmol<",".bin<",".smol<",".spartan<",".mrc<",".pse<", ".map<", ".omap<",
646+
".dcd<",".mp3<",".ogg<", ".wav<", ".au<"];
645647

646648
J2S._isBinaryUrl = function(url) {
647-
url = url.toLowerCase();
649+
url = url.toLowerCase() + "<";
648650
for (var i = J2S._binaryTypes.length; --i >= 0;)
649651
if (url.indexOf(J2S._binaryTypes[i]) >= 0) return true;
650652
return false;
@@ -834,8 +836,11 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
834836
var map = Clazz.new_(Clazz.load("java.util.Hashtable"));
835837
map.put$TK$TV("fileName", file.name);
836838
map.put$TK$TV("bytes", J2S._toBytes(data));
837-
fDone(map);
838-
return;
839+
return fDone(map);
840+
case "java.io.File":
841+
var f = Clazz.new_(Clazz.load("java.io.File").c$$S, [file.name]);
842+
f._bytes = J2S._toBytes(data);
843+
return fDone(f);
839844
case "ArrayBuffer":
840845
break;
841846
case "string":
@@ -1162,7 +1167,7 @@ J2S._getDefaultLanguage = function(isAll) { return (isAll ? J2S.featureDetection
11621167
try {
11631168
if (applet._appletPanel) applet._appletPanel.destroy();
11641169
applet._applet = null;
1165-
J2S._unsetMouse(applet._mouseInterface)
1170+
J2S._jsUnsetMouse(applet._mouseInterface)
11661171
applet._canvas = null;
11671172
var n = 0;
11681173
for (var i = 0; i < J2S._syncedApplets.length; i++) {
@@ -1604,7 +1609,7 @@ J2S.Cache.get = function(filename) {
16041609
J2S.Cache.put = function(filename, data) {
16051610
J2S.Cache.fileCache[filename] = data;
16061611
}
1607-
1612+
// dnd
16081613
J2S.Cache.setDragDrop = function(me) {
16091614
J2S.$appEvent(me, "appletdiv", "dragover", function(e) {
16101615
e = e.originalEvent;
@@ -1616,6 +1621,12 @@ J2S.Cache.put = function(filename, data) {
16161621
var oe = e.originalEvent;
16171622
oe.stopPropagation();
16181623
oe.preventDefault();
1624+
var target = oe.target;
1625+
var c = target;
1626+
while (c && !c["data-dropComponent"])
1627+
c = c.parentElement;
1628+
if (!c)
1629+
return;
16191630
var file = oe.dataTransfer.files[0];
16201631
if (file == null) {
16211632
// FF and Chrome will drop an image here
@@ -1636,8 +1647,16 @@ J2S.Cache.put = function(filename, data) {
16361647
var reader = new FileReader();
16371648
reader.onloadend = function(evt) {
16381649
if (evt.target.readyState == FileReader.DONE) {
1639-
var cacheName = "cache://DROP_" + file.name;
1650+
var target = oe.target;
16401651
var bytes = J2S._toBytes(evt.target.result);
1652+
// what about a frame?? what about x and y?
1653+
var comp = c["data-dropComponent"];
1654+
var d = comp.getLocationOnScreen();
1655+
var x = oe.pageX - d.x;
1656+
var y = oe.pageY - d.y;
1657+
Clazz.load("swingjs.JSDnD").drop$javax_swing_JComponent$S$BA$I$I(comp, file.name, bytes, x, y);
1658+
/*
1659+
var cacheName = "cache://DROP_" + file.name;
16411660
if (!cacheName.endsWith(".spt"))
16421661
me._appletPanel.cacheFileByName$S$Z("cache://DROP_*",false);
16431662
if (me._viewType == "JSV" || cacheName.endsWith(".jdx")) // shared by Jmol and JSV
@@ -1648,6 +1667,7 @@ J2S.Cache.put = function(filename, data) {
16481667
if(xym && (!me._appletPanel.setStatusDragDropped$I$I$I$S || me._appletPanel.setStatusDragDropped$I$I$I$S(0, xym[0], xym[1], cacheName))) {
16491668
me._appletPanel.openFileAsyncSpecial$S$I(cacheName, 1);
16501669
}
1670+
*/
16511671
}
16521672
};
16531673
reader.readAsArrayBuffer(file);
@@ -1983,6 +2003,9 @@ J2S.Cache.put = function(filename, data) {
19832003
base[base.length - 1] = codePath;
19842004
codePath = base.join("/");
19852005
}
2006+
if (applet.__Info.code)
2007+
codePath += applet.__Info.code.replace(/\./g,"/");
2008+
codePath = codePath.substring(0, codePath.lastIndexOf("/") + 1);
19862009
viewerOptions.put("codePath", codePath);
19872010
viewerOptions.put("appletReadyCallback","J2S._readyCallback");
19882011
viewerOptions.put("applet", true);

sources/net.sf.j2s.core/test/dev/js/j2sSwingJS.js

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 1/9/2018 8:40:52 AM fully running SwingJS2; adds String.isEmpty()
1011
// BH 12/16/2017 5:53:47 PM refactored; removed older unused parts
1112
// BH 11/16/2017 10:52:53 PM adds method name aliasing for generics; adds String.contains$CharSequence(cs)
1213
// BH 10/14/2017 8:17:57 AM removing all node-based dependency class loading; fix String.initialize with four arguments (arr->byte)
@@ -48,11 +49,13 @@ window["j2s.clazzloaded"] = true;
4849
/*Class = */ Clazz = {
4950
_isQuiet: false,
5051
_debugging: false,
52+
_loadcore: true,
5153
_nooutput: 0
5254
};
5355

5456
;(function(Clazz, J2S) {
5557

58+
Clazz.ClassFilesLoaded = [];
5659

5760
Clazz.popup = Clazz.log = Clazz.error = window.alert;
5861

@@ -247,11 +250,12 @@ Clazz.forName = function(name, initialize, loader) {
247250
Clazz.getClass = function(cl, methodList) {
248251
// $Class$ is the java.lang.Class object wrapper
249252
// $clazz$ is the unwrapped JavaScript object
253+
cl = getClazz(cl) || cl;
250254
if (cl.$Class$)
251255
return cl.$Class$;
252256
java.lang.Class || Clazz.load("java.lang.Class");
253257
var Class_ = cl.$Class$ = new java.lang.Class();
254-
Class_.$clazz$ = getClazz(cl) || cl; // for arrays - a bit of a hack
258+
Class_.$clazz$ = cl; // for arrays - a bit of a hack
255259
Class_.$methodList$ = methodList;
256260
return Class_;
257261
}
@@ -365,7 +369,7 @@ Clazz.new_ = function(c, args, cl) {
365369
clInner && clInner.$init$.apply(f);
366370
}
367371

368-
_profileNew && addProfileNew(myclass, window.performance.now() - t0);
372+
_profileNew && addProfileNew(cl, window.performance.now() - t0);
369373

370374
return f;
371375
}
@@ -630,6 +634,7 @@ var arrayClass = function(baseClass, ndim) {
630634

631635
try {
632636
Clazz._debugging = (document.location.href.indexOf("j2sdebug") >= 0);
637+
Clazz._loadcore = (document.location.href.indexOf("j2snocore") < 0);
633638
} catch (e) {
634639
}
635640

@@ -1578,23 +1583,6 @@ Clazz._setDeclared = function(name, func) {
15781583
*/
15791584

15801585

1581-
/**
1582-
* Class dependency tree node
1583-
*/
1584-
/* private */
1585-
var Node = function () {
1586-
this.parents = [];
1587-
this.musts = [];
1588-
this.optionals = [];
1589-
this.declaration = null;
1590-
this.name = null; // id
1591-
this.path = null;
1592-
// this.requires = null;
1593-
// this.requiresMap = null;
1594-
this.onLoaded = null;
1595-
this.status = 0;
1596-
this.random = 0.13412;
1597-
};
15981586

15991587

16001588
/**
@@ -1658,32 +1646,7 @@ _Loader.doTODO = function() {
16581646
f();
16591647
}
16601648
}
1661-
1662-
_Loader.updateNodeForFunctionDecoration = function(qName) {
1663-
1664-
var node = findNode(qName);
1665-
if (node && node.status == Node.STATUS_KNOWN) {
1666-
if (node.musts.length == 0 && node.optionals.length == 0) {
1667-
var f = function() { updateNode(node) };
1668-
_Loader._TODO.push(f);
1669-
} else {
1670-
window.setTimeout(f, 1);
1671-
}
1672-
}
1673-
}
1674-
1675-
Node.prototype.toString = function() {
1676-
return this.name || this.path || "ClazzNode";
1677-
}
1678-
1679-
Node.STATUS_UNKNOWN = 0;
1680-
Node.STATUS_KNOWN = 1;
1681-
Node.STATUS_CONTENT_LOADED = 2;
1682-
Node.STATUS_MUSTS_LOADED = 3;
1683-
Node.STATUS_DECLARED = 4;
1684-
Node.STATUS_LOAD_COMPLETE = 5;
1685-
1686-
1649+
16871650
var loaders = [];
16881651

16891652
/* public */
@@ -1835,7 +1798,7 @@ Clazz.loadClass = function (name, onLoaded, async) {
18351798
*/
18361799
/* public */
18371800
_Loader.loadClass = _Loader.prototype.loadClass = function (name, onLoaded, forced, async, mode) {
1838-
1801+
18391802
mode || (mode = 0); // BH: not implemented
18401803
(async == null) && (async = false);
18411804

@@ -1844,7 +1807,7 @@ _Loader.loadClass = _Loader.prototype.loadClass = function (name, onLoaded, forc
18441807

18451808
//System.out.println("loadClass " + name)
18461809
var path = _Loader.getClasspathFor(name);
1847-
1810+
Clazz.ClassFilesLoaded.push(name.replace(/\./g,"/") + ".js");
18481811
Clazz.loadScript(path);//(n, n.path, n.requiredBy, false, onLoaded ? function(_loadClass){ isLoadingEntryClass = bSave; onLoaded()}: null);
18491812
}
18501813

@@ -2032,7 +1995,7 @@ Clazz._4Name = function(clazzName, applet, state, asClazz, initialize) {
20321995
var cl = evalType(clazzName);
20331996
if (!cl){
20341997
alert(clazzName + " could not be loaded");
2035-
debugger;
1998+
doDebugger();
20361999
}
20372000
Clazz.allClasses[clazzName] = cl;
20382001
if (initialize !== false)
@@ -3641,7 +3604,7 @@ if(cs=="utf-8"||cs=="utf8"){
36413604
s=Encoding.convert2UTF8(this);
36423605
}
36433606
}
3644-
var arrs=Clazz.array(Byte.TYPE, [s.length]);
3607+
var arrs=[];
36453608
for(var i=0, ii=0;i<s.length;i++){
36463609
var c=s.charCodeAt(i);
36473610
if(c>255){
@@ -3654,7 +3617,7 @@ arrs[ii]=c;
36543617
}
36553618
ii++;
36563619
}
3657-
return arrs;
3620+
return Clazz.array(Byte.TYPE, -1, arrs);
36583621
};
36593622

36603623
sp.contains$S = function(a) {return this.indexOf(a) >= 0} // bh added
@@ -3770,6 +3733,9 @@ throw new NullPointerException();
37703733
return this.$concat(s);
37713734
};
37723735

3736+
sp.isEmpty = function() {
3737+
return this.valueOf().length == 0;
3738+
}
37733739
sp.$lastIndexOf=sp.lastIndexOf;
37743740
sp.lastIndexOf=function(s,last){
37753741
if(last!=null&&last+this.length<=0){
@@ -4995,6 +4961,7 @@ return null;
49954961
//Clazz._Loader.loadZJar(Clazz._Loader.getJ2SLibBase() + "core/coreswingjs.z.js", "swingjs.JSUtil");
49964962

49974963
//if (!J2S._isAsync) {
4964+
if (Clazz._loadcore)
49984965
for (var i = 0; i < J2S._coreFiles.length; i++)
49994966
Clazz.loadScript(J2S._coreFiles[i]);
50004967
//ClazzLoader.loadZJar(J2S._coreFiles[i], ClazzLoader.runtimeKeyClass);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
copy /b jquery.js+j2sJQueryExt.js+j2sApplet.js+j2sSwingJS.js+SJSApplet.js ..\swingjs2.js
2+
copy ..\swingjs2.js c:\temp
23

34

45

0 commit comments

Comments
 (0)