Jalview-JS/JAL-3253-applet also comments relating to JAL-3268
[jalview.git] / src / jalview / util / Platform.java
index 9b57a5a..a1412f2 100644 (file)
@@ -41,6 +41,8 @@ import javax.swing.SwingUtilities;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
+import com.stevesoft.pat.Regex;
+
 /**
  * System platform information used by Applet and Application
  * 
@@ -657,4 +659,42 @@ public class Platform
     return null;
   }
 
+  /**
+   * load a resource -- probably a core file -- if and only if a particular
+   * class has not been instantialized. We use a String here because if we used
+   * a .class object, that reference itself would simply load the class, and we
+   * want the core package to include that as well.
+   * 
+   * @param resourcePath
+   * @param className
+   */
+  public static void loadStaticResource(Object resourcePath,
+          String className)
+  {
+    /**
+     * 
+     * @j2sNative if (!swingjs.JSUtil.isClassLoaded$S(className))
+     *            swingjs.JSUtil.loadStaticResource$S(resourcePath);
+     */
+  }
+
+  public static void ensureRegex()
+  {
+    loadStaticResource("core/core_stevesoft.z.js",
+            "com.stevesoft.pat.Regex");
+  }
+
+  public static Regex newRegex(String searchString, String replaceString)
+  {
+    ensureRegex();
+    return (replaceString == null ? new Regex(searchString)
+            : new Regex(searchString, replaceString));
+  }
+
+  public static Regex newRegexPerl(String code)
+  {
+    ensureRegex();
+    return Regex.perlCode(code);
+  }
+
 }