1 Clazz.declarePackage ("swingjs");
2 Clazz.load (["java.applet.AppletContext", "$.AppletStub", "java.awt.Panel", "swingjs.api.JSInterface", "java.awt.Dimension"], "swingjs.JSAppletPanel", ["java.lang.InstantiationException", "java.net.URL", "java.awt.BorderLayout", "$.Font", "$.Toolkit", "javax.swing.JApplet", "jssun.applet.AppletEvent", "$.AppletEventMulticaster", "swingjs.JSAppletThread", "$.JSGraphics2D", "$.JSMouse", "$.JSThreadGroup", "$.JSToolkit", "$.JSUtil", "swingjs.api.Interface"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.html5Applet = null;
7 this.appletCodeBase = null;
8 this.appletIdiomaBase = null;
9 this.appletDocumentBase = null;
10 this.maximumSize = 2147483647;
11 this.appletName = null;
13 this.testAsync = false;
15 this.strJavaVersion = null;
16 this.strJavaVendor = null;
19 this.jsgraphics = null;
21 this.defaultAppletSize = null;
22 this.currentAppletSize = null;
25 this.listeners = null;
27 Clazz.instantialize (this, arguments);
28 }, swingjs, "JSAppletPanel", java.awt.Panel, [java.applet.AppletStub, java.applet.AppletContext, swingjs.api.JSInterface]);
29 Clazz.prepareFields (c$, function () {
30 this.defaultAppletSize = new java.awt.Dimension (10, 10);
31 this.currentAppletSize = new java.awt.Dimension (10, 10);
33 Clazz.makeConstructor (c$,
35 Clazz.superConstructor (this, swingjs.JSAppletPanel, []);
38 }, "java.util.Hashtable");
39 Clazz.defineMethod (c$, "set",
41 System.out.println ("JSAppletPanel initializing");
43 this.htmlName = swingjs.JSUtil.split ("" + this.getParameter ("name"), "_object")[0];
44 this.appletName = swingjs.JSUtil.split (this.htmlName + "_", "_")[0];
45 this.syncId = this.getParameter ("syncId");
46 this.fullName = this.htmlName + "__" + this.syncId + "__";
47 params.put ("fullName", this.fullName);
48 var o = params.get ("codePath");
49 if (o == null) o = "../java/";
50 this.appletCodeBase = o.toString ();
51 this.appletIdiomaBase = this.appletCodeBase.substring (0, this.appletCodeBase.lastIndexOf ("/", this.appletCodeBase.length - 2) + 1) + "idioma";
52 o = params.get ("documentBase");
53 this.appletDocumentBase = (o == null ? "" : o.toString ());
54 if (params.containsKey ("maximumSize")) Math.max ((params.get ("maximumSize")).intValue (), 100);
55 this.async = (this.testAsync || params.containsKey ("async"));
59 if(self.Jmol) { applet =
60 Jmol._applets[this.htmlName.split("_object")[0]]; javaver =
62 }this.html5Applet = applet;
63 this.strJavaVersion = javaver;
64 this.strJavaVendor = "Java2Script/Java 1.6 (HTML5)";
65 this.display = params.get ("display");
66 this.threadGroup = new swingjs.JSThreadGroup (this.appletName);
67 this.myThread = new swingjs.JSAppletThread (this, this.threadGroup, this.appletName);
68 (this.threadGroup).setHtmlApplet (this.html5Applet);
70 Jmol._applets[this.appletName + "_thread"] =
71 java.lang.Thread.thisThread = this.myThread;
72 }this.appContext = swingjs.JSToolkit.createNewAppContext ();
73 java.awt.Toolkit.getDefaultToolkit ();
75 java.net.URL.setURLStreamHandlerFactory (swingjs.api.Interface.getInstance ("JU.AjaxURLStreamHandlerFactory", false));
78 System.out.println ("JSAppletPanel initialized");
79 }, "java.util.Hashtable");
80 Clazz.defineMethod (c$, "start",
82 if (this.status == 0) this.myThread.start ();
83 else this.showStatus ("already started");
85 Clazz.defineMethod (c$, "addAppletListener",
87 this.listeners = jssun.applet.AppletEventMulticaster.add (this.listeners, l);
88 }, "jssun.applet.AppletListener");
89 Clazz.defineMethod (c$, "removeAppletListener",
91 this.listeners = jssun.applet.AppletEventMulticaster.remove (this.listeners, l);
92 }, "jssun.applet.AppletListener");
93 Clazz.defineMethod (c$, "dispatchAppletEvent",
94 function (id, argument) {
95 if (this.listeners != null) {
96 var evt = new jssun.applet.AppletEvent (this, id, argument);
97 this.listeners.appletStateChanged (evt);
99 Clazz.defineMethod (c$, "getCode",
101 return this.getParameter ("code");
103 Clazz.defineMethod (c$, "getCanvas",
105 return (this.canvas == null ? (this.canvas = this.html5Applet._getHtml5Canvas ()) : this.canvas);
107 Clazz.overrideMethod (c$, "isActive",
111 Clazz.overrideMethod (c$, "appletResize",
112 function (width, height) {
113 var currentSize = new java.awt.Dimension (this.currentAppletSize.width, this.currentAppletSize.height);
114 this.currentAppletSize.width = width;
115 this.currentAppletSize.height = height;
116 this.applet.setBounds (0, 0, this.getWidth (), this.getHeight ());
117 this.applet.getRootPane ().setBounds (0, 0, this.getWidth (), this.getHeight ());
118 this.applet.getContentPane ().setBounds (0, 0, this.getWidth (), this.getHeight ());
119 (this.applet.getContentPane ()).revalidate ();
120 this.dispatchAppletEvent (51234, currentSize);
122 Clazz.overrideMethod (c$, "getDocumentBase",
125 return new java.net.URL (this.params.get ("documentBase"));
127 if (Clazz.exceptionOf (e, java.net.MalformedURLException)) {
134 Clazz.overrideMethod (c$, "getCodeBase",
137 return new java.net.URL (this.params.get ("codePath"));
139 if (Clazz.exceptionOf (e, java.net.MalformedURLException)) {
146 Clazz.overrideMethod (c$, "getParameter",
148 var s = this.params.get (name);
149 System.out.println ("get parameter: " + name + " = " + s);
150 return (s == null ? null : "" + s);
152 Clazz.overrideMethod (c$, "getAppletContext",
156 Clazz.defineMethod (c$, "getHeight",
158 return this.html5Applet._getHeight ();
160 Clazz.defineMethod (c$, "getWidth",
162 return this.html5Applet._getWidth ();
164 Clazz.defineMethod (c$, "setBounds",
165 function (x, y, width, height) {
166 this.reshape (x, y, width, height);
167 this.currentAppletSize.width = width;
168 this.currentAppletSize.height = height;
170 Clazz.overrideMethod (c$, "getImage",
174 Clazz.overrideMethod (c$, "getApplet",
178 applet = Jmol._applets[name]; applet && (applet =
182 Clazz.overrideMethod (c$, "getApplets",
186 Clazz.defineMethod (c$, "showDocument",
189 window.open(url.toString());
191 Clazz.defineMethod (c$, "showDocument",
192 function (url, target) {
194 window.open(url.toString(), target);
195 }}, "java.net.URL,~S");
196 Clazz.defineMethod (c$, "showStatus",
198 swingjs.JSToolkit.log (status);
200 Clazz._LoaderProgressMonitor.showStatus(status, true);
202 Clazz.overrideMethod (c$, "cacheFileByName",
203 function (fileName, isAdd) {
206 Clazz.overrideMethod (c$, "cachePut",
207 function (key, data) {
209 Clazz.overrideMethod (c$, "destroy",
212 Clazz.overrideMethod (c$, "getFullName",
214 return this.fullName;
216 Clazz.overrideMethod (c$, "openFileAsyncSpecial",
217 function (fileName, flags) {
219 Clazz.defineMethod (c$, "processMouseEvent",
220 function (id, x, y, modifiers, time) {
221 this.getMouse ().processEvent (id, x, y, modifiers, time);
223 }, "~N,~N,~N,~N,~N");
224 Clazz.defineMethod (c$, "getMouse",
226 return (this.mouse == null ? this.mouse = new swingjs.JSMouse (this) : this.mouse);
228 Clazz.overrideMethod (c$, "processTwoPointGesture",
230 this.getMouse ().processTwoPointGesture (touches);
232 Clazz.overrideMethod (c$, "setDisplay",
234 this.canvas = canvas;
235 }, "swingjs.api.HTML5Canvas");
236 Clazz.overrideMethod (c$, "setScreenDimension",
237 function (width, height) {
238 this.setGraphics (this.jsgraphics = null);
239 if (this.applet != null) this.applet.resize (width, height);
241 Clazz.overrideMethod (c$, "setStatusDragDropped",
242 function (mode, x, y, fileName) {
245 Clazz.overrideMethod (c$, "startHoverWatcher",
248 Clazz.overrideMethod (c$, "paint",
250 this.applet.paint (this.setGraphics (g));
251 }, "java.awt.Graphics");
252 Clazz.defineMethod (c$, "setGraphics",
254 return (g == null ? this.getGraphics () : g);
255 }, "java.awt.Graphics");
256 Clazz.overrideMethod (c$, "getGraphics",
258 if (this.jsgraphics == null) {
259 this.jsgraphics = new swingjs.JSGraphics2D (this.getCanvas ());
260 this.jsgraphics.setWindowParameters (this.getWidth (), this.getHeight ());
261 }return this.jsgraphics;
263 Clazz.defineMethod (c$, "showAppletStatus",
265 this.getAppletContext ().showStatus (this.htmlName + " " + status);
267 Clazz.defineMethod (c$, "showAppletException",
270 this.showAppletStatus("error " + (t.getMessage ?
271 t.getMessage() : t)); t.printStackTrace &&
275 Clazz.defineMethod (c$, "run1",
280 this.currentAppletSize.width = this.defaultAppletSize.width = this.getWidth ();
281 this.currentAppletSize.height = this.defaultAppletSize.height = this.getHeight ();
282 this.setLayout ( new java.awt.BorderLayout ());
287 switch (this.nextStatus) {
289 if (this.status != 0) {
290 this.showAppletStatus ("notdisposed");
293 }System.out.println ("JSAppletPanel runloader");
299 if (this.status != 1 && this.status != 5) {
300 this.showAppletStatus ("notloaded");
302 }System.out.println ("JSAppletPanel init");
303 this.setFont ( new java.awt.Font ("Dialog", 0, 12));
304 this.applet.resize (this.defaultAppletSize);
308 this.showAppletStatus ("initialized");
313 if (this.status != 2 && this.status != 4) {
314 this.showAppletStatus ("notstarted");
317 }this.applet.getRootPane ().addNotify ();
318 System.out.println ("JSAppletPanel start" + this.currentAppletSize);
319 this.applet.resize (this.currentAppletSize);
320 this.applet.start ();
322 this.showAppletStatus ("started");
323 this.nextStatus = 35;
327 swingjs.JSToolkit.readyCallback (this.appletName, this.fullName, this.applet, this);
330 if (this.status == 3) {
332 this.applet.setVisible (false);
334 this.showAppletStatus ("stopped");
336 this.showAppletStatus ("notstopped");
340 if (this.status == 4 || this.status == 2) {
342 this.applet.destroy ();
343 this.showAppletStatus ("destroyed");
345 this.showAppletStatus ("notdestroyed");
349 if (this.status == 5 || this.status == 1) {
350 this.showAppletStatus ("notdisposed");
354 this.removeChild (this.applet);
356 this.showAppletStatus ("disposed");
361 System.out.println ("unrecognized JSAppletPanel status: " + this.nextStatus);
366 System.out.println ("unrecognized JSAppletThread mode: " + mode);
371 Clazz.defineMethod (c$, "runLoader",
373 this.dispatchAppletEvent (51235, null);
375 var code = this.getCode ();
378 System.err.println ("runloader.err-- \"code\" must be specified.");
379 throw new InstantiationException ("\"code\" must be specified.");
380 }this.applet = swingjs.JSToolkit.getInstance (code);
381 if (this.applet == null) {
382 System.out.println (code + " could not be launched");
384 } else if (!(Clazz.instanceOf (this.applet, javax.swing.JApplet))) {
385 System.out.println (code + " is not a JApplet!?");
388 if (Clazz.exceptionOf (e$$, InstantiationException)) {
392 this.showAppletException (e);
395 } else if (Clazz.exceptionOf (e$$, Exception)) {
399 this.showAppletException (e);
402 } else if (Clazz.exceptionOf (e$$, ThreadDeath)) {
406 this.showAppletStatus ("death");
409 } else if (Clazz.exceptionOf (e$$, Error)) {
413 this.showAppletException (e);
420 this.dispatchAppletEvent (51236, null);
422 if (this.applet != null) {
423 this.applet.setStub (this);
424 this.applet.setVisible (false);
425 this.add ("Center", this.applet);
426 this.applet.setDispatcher ();
427 this.applet.addNotify ();
428 this.showAppletStatus ("loaded");
431 Clazz.defineMethod (c$, "getUI",
435 Clazz.overrideMethod (c$, "repaintImpl",
436 function (tm, x, y, width, height) {
437 if (this.applet.isVisible () && this.applet.getWidth () > 0 && this.applet.getHeight () > 0) {
438 this.applet.getContentPane ().repaint (tm, x, y, width, height);
439 }}, "~N,~N,~N,~N,~N");
440 Clazz.defineStatics (c$,
441 "APPLET_UNINITIALIZED", 0,
450 "APPLET_DISPOSE", 75,
451 "APPLET_RESIZE", 51234,
452 "APPLET_LOADING", 51235,
453 "APPLET_LOADING_COMPLETED", 51236);