JAL-3438 spotless for 2.11.2.0
[jalview.git] / src / swingjs / api / JSUtilI.java
1 package swingjs.api;
2
3 import java.awt.Component;
4 import java.io.File;
5 import java.io.InputStream;
6 import java.net.URL;
7 import java.util.HashMap;
8 import java.util.Properties;
9
10 import swingjs.api.js.HTML5Applet;
11
12 public interface JSUtilI
13 {
14
15   /**
16    * Indicate to SwingJS that the given file type is binary.
17    * 
18    * @param ext
19    */
20   void addBinaryFileType(String ext);
21
22   /**
23    * Indicate to SwingJS that we can load files using AJAX from the given
24    * domain, such as "www.stolaf.edu", because we know that CORS access has been
25    * provided.
26    * 
27    * @param domain
28    */
29   void addDirectDatabaseCall(String domain);
30
31   /**
32    * Cache or uncache data under the given path name.
33    * 
34    * @param path
35    * @param data
36    *          null to remove from the cache
37    */
38   void cachePathData(String path, Object data);
39
40   /**
41    * Get the HTML5 object corresponding to the specified Component, or the
42    * current thread if null.
43    * 
44    * @param c
45    *          the associated component, or null for the current thread
46    * @return HTML5 applet object
47    */
48   HTML5Applet getAppletForComponent(Component c);
49
50   /**
51    * Get an attribute applet.foo for the applet found using getApplet(null).
52    * 
53    * @param key
54    * @return
55    */
56   Object getAppletAttribute(String key);
57
58   /**
59    * Get the code base (swingjs/j2s, probably) for the applet found using
60    * getApplet(null).
61    * 
62    * @return
63    */
64   URL getCodeBase();
65
66   /**
67    * Get the document base (wherever the page is) for the applet found using
68    * getApplet(null).
69    * 
70    * @return
71    */
72
73   URL getDocumentBase();
74
75   /**
76    * Get an attribute from the div on the page that is associated with this
77    * frame, i.e. with id frame.getName() + "-div".
78    * 
79    * @param frame
80    * @param type
81    *          "node" or "dim"
82    * @return
83    */
84   Object getEmbeddedAttribute(Component frame, String type);
85
86   /**
87    * Get a file synchronously.
88    * 
89    * @param path
90    * @param asString
91    *          true for String; false for byte[]
92    * @return byte[] or String
93    */
94   Object getFile(String path, boolean asString);
95
96   /**
97    * Get the 秘bytes field associated with a file, but only if the File object
98    * itself has them attached, not downloading them.
99    * 
100    * @param f
101    * @return
102    */
103   byte[] getBytes(File f);
104
105   /**
106    * Retrieve a HashMap consisting of whatever the application wants, but
107    * guaranteed to be unique to this app context, that is, for the applet found
108    * using getApplet(null).
109    * 
110    * @param contextKey
111    * @return
112    */
113   HashMap<?, ?> getJSContext(Object contextKey);
114
115   /**
116    * Load a resource -- probably a core file -- if and only if a particular
117    * class has not been instantialized. We use a String here because if we used
118    * a .class object, that reference itself would simply load the class, and we
119    * want the core package to include that as well.
120    * 
121    * @param resourcePath
122    * @param className
123    */
124   void loadResourceIfClassUnknown(String resource, String className);
125
126   /**
127    * Read all applet.__Info properties for the applet found using
128    * getApplet(null) that start with the given prefix, such as "jalview_". A
129    * null prefix retrieves all properties. Note that non-string properties will
130    * be stringified.
131    * 
132    * @param prefix
133    *          an application prefix, or null for all properties
134    * @param p
135    *          properties to be appended to
136    */
137   void readInfoProperties(String prefix, Properties p);
138
139   /**
140    * Set an attribute for the applet found using getApplet(null). That is,
141    * applet[key] = val.
142    * 
143    * @param key
144    * @param val
145    */
146   void setAppletAttribute(String key, Object val);
147
148   /**
149    * Set an attribute of applet's Info map for the applet found using
150    * getApplet(null). That is, applet.__Info[key] = val.
151    * 
152    * @param infoKey
153    * @param val
154    */
155   void setAppletInfo(String infoKey, Object val);
156
157   /**
158    * Set the given File object's 秘bytes field from an InputStream or a byte[]
159    * array. If the file is a JSTempFile, then also cache those bytes.
160    * 
161    * @param f
162    * @param isOrBytes
163    *          BufferedInputStream, ByteArrayInputStream, FileInputStream, or
164    *          byte[]
165    * @return
166    */
167   boolean setFileBytes(File f, Object isOrBytes);
168
169   /**
170    * Same as setFileBytes, but also caches the data if it is a JSTempFile.
171    * 
172    * @param is
173    * @param outFile
174    * @return
175    */
176   boolean streamToFile(InputStream is, File outFile);
177
178   /**
179    * Switch the flag in SwingJS to use or not use the JavaScript Map object in
180    * Hashtable, HashMap, and HashSet. Default is enabled.
181    * 
182    */
183
184   void setJavaScriptMapObjectEnabled(boolean enabled);
185
186 }