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