JAL-1460 new data flavor for URLs added belt-and-braces URL drop code found in Marina...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 24 May 2018 10:54:26 +0000 (11:54 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 24 May 2018 10:54:26 +0000 (11:54 +0100)
src/jalview/gui/Desktop.java

index 9a696e9..9598f60 100644 (file)
@@ -3300,7 +3300,46 @@ public class Desktop extends jalview.jbgui.GDesktop
   {
 
     DataFlavor uriListFlavor = new DataFlavor(
-            "text/uri-list;class=java.lang.String");
+            "text/uri-list;class=java.lang.String"), urlFlavour = null;
+    try
+    {
+      urlFlavour = new DataFlavor(
+              "application/x-java-url; class=java.net.URL");
+    } catch (ClassNotFoundException cfe)
+    {
+      Cache.log.debug("Couldn't instantiate the URL dataflavor.", cfe);
+    }
+
+    if (urlFlavour != null && t.isDataFlavorSupported(urlFlavour))
+    {
+
+      try
+      {
+      java.net.URL url = (URL) t.getTransferData(urlFlavour);
+        // nb: java 8 osx bug https://bugs.openjdk.java.net/browse/JDK-8156099
+        // means url may be null.
+      if (url != null)
+      {
+        protocols.add(DataSourceType.URL);
+        files.add(url.toString());
+        Cache.log.debug("Drop handled as URL dataflavor "
+                + files.get(files.size() - 1));
+          return;
+        }
+        else
+        {
+          if (Platform.isAMac())
+          {
+            System.err.println(
+                    "Please ignore plist error - occurs due to problem with java 8 on OSX");
+          }
+          ;
+      }
+      } catch (Throwable ex)
+      {
+        Cache.log.debug("URL drop handler failed.", ex);
+      }
+    }
     if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
     {
       // Works on Windows and MacOSX
@@ -3332,7 +3371,7 @@ public class Desktop extends jalview.jbgui.GDesktop
                 new DataFlavor("text/plain;class=java.lang.String"));
         if (Cache.log.isDebugEnabled())
         {
-          Cache.log.debug("fallback returned " + data);
+          Cache.log.debug("Plain text drop content returned " + data);
         }
       }
       while (protocols.size() < files.size())