Adding SwingJS interface and utility classes
[jalview.git] / src / jalview / util / Platform.java
index 121ac1b..4d2a09e 100644 (file)
@@ -22,7 +22,6 @@ package jalview.util;
 
 import jalview.javascript.json.JSON;
 
-import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Toolkit;
 import java.awt.event.MouseEvent;
@@ -49,6 +48,8 @@ import org.json.simple.parser.ParseException;
 
 import com.stevesoft.pat.Regex;
 
+import swingjs.api.JSUtilI;
+
 /**
  * System platform information used by Applet and Application
  * 
@@ -63,6 +64,20 @@ public class Platform
   private static Boolean isNoJSMac = null, isNoJSWin = null, isMac = null,
           isWin = null;
 
+  private static swingjs.api.JSUtilI jsutil;
+
+  static {
+          if (isJS) {
+      try
+      {
+        jsutil = ((JSUtilI) Class.forName("swingjs.JSUtil").newInstance());
+      } catch (InstantiationException | IllegalAccessException
+              | ClassNotFoundException e)
+      {
+        e.printStackTrace();
+      }
+          }
+  }
   // private static Boolean isHeadless = null;
 
   /**
@@ -336,12 +351,7 @@ public class Platform
     {
       return;
     }
-    /**
-     * @j2sNative
-     * 
-     *            swingjs.JSUtil.cacheFileData$S$O(path, data);
-     * 
-     */
+    jsutil.cachePathData(path, data);
   }
 
   public static void cacheFileData(File file)
@@ -356,19 +366,13 @@ public class Platform
 
   public static byte[] getFileBytes(File f)
   {
-    // TODO temporary doubling of 秘bytes and _bytes;
-    // just remove _bytes when new transpiler has been installed
-    return /** @j2sNative f && (f.秘bytes || f._bytes) || */
-    null;
+    // JavaScript only
+    return jsutil.getBytes(f);
   }
 
   public static byte[] getFileAsBytes(String fileStr)
   {
-    byte[] bytes = null;
-    // BH 2018 hack for no support for access-origin
-    /**
-     * @j2sNative bytes = swingjs.JSUtil.getFileAsBytes$O(fileStr)
-     */
+    byte[] bytes = (byte[]) jsutil.getFile(fileStr, false);
     cacheFileData(fileStr, bytes);
     return bytes;
   }
@@ -376,14 +380,7 @@ public class Platform
   @SuppressWarnings("unused")
   public static String getFileAsString(String url)
   {
-    String ret = null;
-    /**
-     * @j2sNative
-     * 
-     *            ret = swingjs.JSUtil.getFileAsString$S(url);
-     * 
-     * 
-     */
+    String ret = (String) jsutil.getFile(url, true);
     cacheFileData(url, ret);
     return ret;
   }
@@ -396,16 +393,13 @@ public class Platform
     }
     @SuppressWarnings("unused")
     byte[] bytes = getFileAsBytes(urlstring);
-    // TODO temporary doubling of 秘bytes and _bytes;
-    // just remove _bytes when new transpiler has been installed
-    /**
-     * @j2sNative f.秘bytes = f._bytes = bytes;
-     */
+    jsutil.setFileBytes(f, bytes);
     return true;
   }
 
   public static void addJ2SBinaryType(String ext)
   {
+
     /**
      * @j2sNative
      *