1 package org.jmol.applet;
2 /* $RCSfile$
3  * $Author: hansonr $
4  * $Date: 2018-01-28 23:38:16 -0600 (Sun, 28 Jan 2018) $
5  * $Revision: 21814 $
6  *
7  * Copyright (C) 2004-2005  The Jmol Development Team
8  *
9  * Contact: jmol-developers@lists.sf.net
10  *
11  *  This library is free software; you can redistribute it and/or
12  *  modify it under the terms of the GNU Lesser General Public
13  *  License as published by the Free Software Foundation; either
14  *  version 2.1 of the License, or (at your option) any later version.
15  *
16  *  This library is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  *  Lesser General Public License for more details.
20  *
21  *  You should have received a copy of the GNU Lesser General Public
22  *  License along with this library; if not, write to the Free Software
23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 /**
27  * This class only exists so that people can declare
28  * JmolApplet in applet tags without having to give a full package
29  * specification
30  *
31  * see org.jmol.applet.Jmol
32  *
33  */
34 
35 
36 import java.util.Map;
37 
38 import javajs.util.SB;
39 
40 import org.jmol.api.JmolAppletInterface;
41 import org.jmol.api.JmolSyncInterface;
42 import org.jmol.applet.AppletWrapper;
43 import org.jmol.util.GenericApplet;
44 
45 public class JmolApplet extends AppletWrapper implements
46     JmolAppletInterface {
47 
48   //protected void finalize() throws Throwable {
49   //  System.out.println("JmolApplet finalize " + this);
50   //  super.finalize();
51   //}
52 
JmolApplet()53   public JmolApplet() {
54     super("jmol75x29x8.gif", 3, preloadClasses);
55     //System.out.println("JmolApplet constructor " + this);
56     //BH focus test: this.setFocusable(false);
57   }
58 
59   private final static String[] preloadClasses = {
60 //    "org.jmol.viewer.JC",                           // 1b
61 //    "org.jmol.g3d.Graphics3D",                      // 1c
62 //    "org.jmol.modelset.Atom",                       // 1d
63 //    "org.jmol.util.Escape",                         // 1e
64 //    "org.jmol.adapter.smarter.SmarterJmolAdapter",  // 1f
65     //"org.jmol.popup.JmolPopup",
66     };
67 
68   @Override
getPropertyAsString(String infoType)69   public String getPropertyAsString(String infoType) {
70     return (wrappedApplet == null ? null : ""
71         + ((GenericApplet) wrappedApplet).getPropertyAsString("" + infoType));
72   }
73 
74   @Override
getPropertyAsString(String infoType, String paramInfo)75   public String getPropertyAsString(String infoType, String paramInfo) {
76     return (wrappedApplet == null ? null : ""
77         + ((GenericApplet) wrappedApplet).getPropertyAsString("" + infoType, "" + paramInfo));
78   }
79 
80   @Override
getPropertyAsJSON(String infoType)81   public String getPropertyAsJSON(String infoType) {
82     return (wrappedApplet == null ? null : ""
83         + ((GenericApplet) wrappedApplet).getPropertyAsJSON("" + infoType));
84   }
85 
86   @Override
getPropertyAsJSON(String infoType, String paramInfo)87   public String getPropertyAsJSON(String infoType, String paramInfo) {
88     return (wrappedApplet == null ? null : ""
89         + ((GenericApplet) wrappedApplet).getPropertyAsJSON("" + infoType, "" + paramInfo));
90   }
91 
92   @Override
getJSpecViewProperty(String infoType)93   public Map<String, Object> getJSpecViewProperty(String infoType) {
94     return null;
95   }
96 
97   @Override
getProperty(String infoType, String paramInfo)98   public Object getProperty(String infoType, String paramInfo) {
99     return (wrappedApplet == null ? null : ((GenericApplet) wrappedApplet).getProperty(""
100         + infoType, "" + paramInfo));
101   }
102 
103   @Override
getProperty(String infoType)104   public Object getProperty(String infoType) {
105     return (wrappedApplet == null ? null : ((GenericApplet) wrappedApplet).getProperty(""
106         + infoType));
107   }
108 
109   @Override
loadInlineArray(String[] strModels, String script, boolean isAppend)110   public String loadInlineArray(String[] strModels, String script, boolean isAppend) {
111     if (wrappedApplet == null || strModels == null || strModels.length == 0)
112         return null;
113       String s = "" + strModels[0];
114       if (s.indexOf('\n') >= 0 || s.indexOf('\r') >= 0) {
115         String[] converted = new String[strModels.length];
116         for (int i = 0; i < strModels.length; ++i)
117           converted[i] = "" + strModels[i];
118         return ((GenericApplet) wrappedApplet).loadInlineArray(converted, "" + script, isAppend);
119       }
120       SB sb = new SB();
121       for (int i = 0; i < strModels.length; ++i)
122         sb.append(strModels[i]).appendC('\n');
123       return ((GenericApplet) wrappedApplet).loadInlineString(sb.toString(), "" + script, isAppend);
124   }
125 
126   @Override
loadInlineString(String strModel, String script, boolean isAppend)127   public String loadInlineString(String strModel, String script, boolean isAppend) {
128     return (wrappedApplet == null ? null :
129       ((GenericApplet) wrappedApplet).loadInlineString("" + strModel, "" + script, isAppend));
130   }
131 
132   // bizarre Mac OS X / Java bug:
133   // Mac cannot differentiate between signatures String and String[]
134   // so, instead, we deprecate these and go for the above two methods only.
135 
136   /**
137    * @deprecated
138    * @param strModel
139    * @return         error or null
140    */
141   @Override
142   @Deprecated
loadInline(String strModel)143   public String loadInline(String strModel) {
144     return (wrappedApplet == null ? null :
145       ((GenericApplet) wrappedApplet).loadInline("" + strModel));
146   }
147 
148   /**
149    * @deprecated
150    * @param strModel
151    * @param script
152    * @return         error or null
153    */
154   @Override
155   @Deprecated
loadInline(String strModel, String script)156   public String loadInline(String strModel, String script) {
157     return (wrappedApplet == null ? null :
158       ((GenericApplet) wrappedApplet).loadInline("" + strModel, "" + script));
159   }
160 
161   /**
162    * @deprecated
163    * @param strModels
164    * @return         error or null
165    */
166   @Override
167   @Deprecated
loadInline(String[] strModels)168   public String loadInline(String[] strModels) {
169     return (wrappedApplet == null ? null :
170       ((GenericApplet) wrappedApplet).loadInline(strModels));
171   }
172 
173   /**
174    * @deprecated
175    * @param strModels
176    * @param script
177    * @return         error or null
178    */
179   @Override
180   @Deprecated
loadInline(String[] strModels, String script)181   public String loadInline(String[] strModels, String script) {
182     return (wrappedApplet == null ? null :
183       ((GenericApplet) wrappedApplet).loadInline(strModels, script));
184   }
185 
186   @Override
loadDOMNode(Object DOMNode)187   public String loadDOMNode(Object DOMNode) {
188     return (wrappedApplet == null ? null : ((GenericApplet) wrappedApplet).loadDOMNode(DOMNode));
189   }
190 
191   @Override
script(String script)192   public void script(String script) {
193     //System.out.println("JmolApplet script test " + script + " " + wrappedApplet);
194     if (wrappedApplet != null)
195       ((GenericApplet) wrappedApplet).script("" + script);
196   }
197 
198   @Override
syncScript(String script)199   public void syncScript(String script) {
200     if (wrappedApplet != null)
201       ((GenericApplet) wrappedApplet).syncScript("" + script);
202   }
203 
204   @Override
setStereoGraphics(boolean isStereo)205   public Object setStereoGraphics(boolean isStereo) {
206     return (wrappedApplet == null ? null :
207         ((GenericApplet) wrappedApplet).setStereoGraphics(isStereo));
208   }
209 
210   @Override
scriptNoWait(String script)211   public String scriptNoWait(String script) {
212     if (wrappedApplet != null)
213       return "" + (((GenericApplet) wrappedApplet).scriptNoWait("" + script));
214     return null;
215   }
216 
217   @Override
scriptCheck(String script)218   public String scriptCheck(String script) {
219     if (wrappedApplet != null)
220       return "" + (((GenericApplet) wrappedApplet).scriptCheck("" + script));
221     return null;
222   }
223 
224   @Override
scriptWait(String script)225   public String scriptWait(String script) {
226     if (wrappedApplet != null)
227       return "" + (((GenericApplet) wrappedApplet).scriptWait("" + script));
228     return null;
229   }
230 
231   @Override
scriptWait(String script, String statusParams)232   public String scriptWait(String script, String statusParams) {
233     if (statusParams == null)
234       statusParams = "";
235     if (wrappedApplet != null)
236       return "" + (((GenericApplet) wrappedApplet).scriptWait("" + script, statusParams));
237     return null;
238   }
239 
240   @Override
scriptWaitOutput(String script)241   public String scriptWaitOutput(String script) {
242     if (wrappedApplet != null)
243       return "" + (((GenericApplet) wrappedApplet).scriptWaitOutput("" + script));
244     return null;
245   }
246 
registerApplet(String id, String fullName)247   public void registerApplet(String id, String fullName) {
248     // does not work looking for JSVApplet!
249     JmolSyncInterface applet = (JmolSyncInterface) getAppletContext().getApplet(id);
250     if (applet == null)
251       System.out.println("could not find " + id);
252     register(fullName, applet);
253   }
254 
255   @Override
register(String id, JmolSyncInterface jsi)256   public void register(String id, JmolSyncInterface jsi) {
257     if (wrappedApplet != null)
258       ((GenericApplet) wrappedApplet).register(id, jsi);
259   }
260 
261   @Override
getModelIndexFromId(String id)262   public int getModelIndexFromId(String id) {
263     return (wrappedApplet == null ? Integer.MIN_VALUE :
264       ((GenericApplet) wrappedApplet).getModelIndexFromId(id));
265   }
266 
267   @Override
notifyAudioEnded(Object htParams)268   public void notifyAudioEnded(Object htParams) {
269     if (wrappedApplet != null)
270       ((GenericApplet) wrappedApplet).notifyAudioEnded(htParams);
271   }
272 
273 }
274