JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / util / BrowserLauncher.java
index 8119daa..ca2e55e 100755 (executable)
@@ -28,9 +28,14 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
- * BrowserLauncher is a class that provides one static method, openURL, which
- * opens the default web browser for the current user of the system to the given
- * URL. It may support other protocols depending on the system -- mailto, ftp,
+ * BrowserLauncher is a class that provides two static methods:
+ * 
+ * openURL(String url), which opens the default web browser for the current user
+ * of the system to the given URL, and
+ * 
+ * resetBrowser(), which allows switching browsers in Java.
+ * 
+ * openURL may support other protocols depending on the system -- mailto, ftp,
  * etc. -- but that has not been rigorously tested and is not guaranteed to
  * work.
  * <p>
@@ -79,6 +84,14 @@ import java.lang.reflect.Method;
  *         "mailto:ejalbert@cs.stanford.edu">ejalbert@cs.stanford.edu</a>)
  * @version 1.4b1 (Released June 20, 2001)
  */
+/*
+ * 
+ * SwingJS note: Do not use methods in this class directly. Use
+ * 
+ * Platform.openURL(String url) only.
+ * 
+ * JavaScript does not see this class.
+ */
 public class BrowserLauncher
 {
   /**
@@ -101,22 +114,22 @@ public class BrowserLauncher
   private static boolean loadedWithoutErrors;
 
   /** The com.apple.mrj.MRJFileUtils class */
-  private static Class mrjFileUtilsClass;
+  private static Class<?> mrjFileUtilsClass;
 
   /** The com.apple.mrj.MRJOSType class */
-  private static Class mrjOSTypeClass;
+  private static Class<?> mrjOSTypeClass;
 
   /** The com.apple.MacOS.AEDesc class */
-  private static Class aeDescClass;
+  private static Class<?> aeDescClass;
 
   /** The &lt;init&gt;(int) method of com.apple.MacOS.AETarget */
-  private static Constructor aeTargetConstructor;
+  private static Constructor<?> aeTargetConstructor;
 
   /** The &lt;init&gt;(int, int, int) method of com.apple.MacOS.AppleEvent */
-  private static Constructor appleEventConstructor;
+  private static Constructor<?> appleEventConstructor;
 
   /** The &lt;init&gt;(String) method of com.apple.MacOS.AEDesc */
-  private static Constructor aeDescConstructor;
+  private static Constructor<?> aeDescConstructor;
 
   /** The findFolder method of com.apple.mrj.MRJFileUtils */
   private static Method findFolder;
@@ -236,14 +249,6 @@ public class BrowserLauncher
 
     loadedWithoutErrors = true;
 
-    if (!Platform.isJS())
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     * 
-     */
-    {
     String osName = System.getProperty("os.name");
 
     if (osName.startsWith("Mac OS"))
@@ -316,7 +321,6 @@ public class BrowserLauncher
     { // if we haven't hit any errors yet
       loadedWithoutErrors = loadClasses();
     }
-    }
   }
 
   /**
@@ -336,24 +340,17 @@ public class BrowserLauncher
   private static boolean loadClasses()
   {
 
-    if (!Platform.isJS())
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     * 
-     */
-    {
     switch (jvm)
     {
     case MRJ_2_0:
 
       try
       {
-        Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
-        Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
-        Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
-        Class aeClass = Class.forName("com.apple.MacOS.ae");
+        Class<?> aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
+        Class<?> osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
+        Class<?> appleEventClass = Class
+                .forName("com.apple.MacOS.AppleEvent");
+        Class<?> aeClass = Class.forName("com.apple.MacOS.ae");
         aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
 
         aeTargetConstructor = aeTargetClass
@@ -464,8 +461,8 @@ public class BrowserLauncher
 
       try
       {
-        Class linker = Class.forName("com.apple.mrj.jdirect.Linker");
-        Constructor constructor = linker
+        Class<?> linker = Class.forName("com.apple.mrj.jdirect.Linker");
+        Constructor<?> constructor = linker
                 .getConstructor(new Class[]
                 { Class.class });
         linkage = constructor
@@ -526,7 +523,6 @@ public class BrowserLauncher
       break;
     }
 
-    }
     return true;
   }
 
@@ -543,14 +539,6 @@ public class BrowserLauncher
    */
   private static Object locateBrowser()
   {
-    if (!Platform.isJS())
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     * 
-     */
-    {
     if (browser != null)
     {
       return browser;
@@ -716,11 +704,7 @@ public class BrowserLauncher
 
       break;
     }
-
-    }
-
     return browser;
-
   }
 
   /**
@@ -742,20 +726,11 @@ public class BrowserLauncher
    */
   public static void openURL(String url) throws IOException
   {
-
     if (Platform.isJS())
     {
       Platform.openURL(url);
       return;
     }
-    else
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     */
-    {
-
     if (!loadedWithoutErrors)
     {
       throw new IOException(MessageManager
@@ -934,14 +909,11 @@ public class BrowserLauncher
       break;
 
     default:
-
       // This should never occur, but if it does, we'll try the simplest thing
       // possible
       Runtime.getRuntime().exec(new String[] { (String) browser, url });
-
       break;
     }
-    }
   }