JAL-1460 more complete drag'n'drop debugging info and bugfixes
authorJim Procter <jprocter@jalview.org>
Thu, 24 May 2018 12:52:32 +0000 (13:52 +0100)
committerJim Procter <jprocter@jalview.org>
Thu, 24 May 2018 12:52:32 +0000 (13:52 +0100)
src/jalview/gui/Desktop.java

index e14e991..e592abf 100644 (file)
@@ -3370,85 +3370,105 @@ public class Desktop extends jalview.jbgui.GDesktop
         // fallback to text: workaround - on OSX where there's a JVM bug
         Cache.log.debug("standard URIListFlavor failed. Trying text");
         // try text fallback
-        data = (String) t.getTransferData(
-                new DataFlavor("text/plain;class=java.lang.String"));
-        if (Cache.log.isDebugEnabled())
+        DataFlavor textDf = new DataFlavor(
+                "text/plain;class=java.lang.String");
+        if (t.isDataFlavorSupported(textDf))
         {
-          Cache.log.debug("Plain text drop content returned " + data);
+          data = (String) t.getTransferData(textDf);
         }
+
+        Cache.log.debug("Plain text drop content returned "
+                + (data == null ? "Null - failed" : data));
+
       }
-      while (protocols.size() < files.size())
-      {
-        Cache.log.debug("Adding missing FILE protocol for "
-                + files.get(protocols.size()));
-        protocols.add(DataSourceType.FILE);
-      }
-      for (java.util.StringTokenizer st = new java.util.StringTokenizer(
-              data, "\r\n"); st.hasMoreTokens();)
+      if (data != null)
       {
-        added = true;
-        String s = st.nextToken();
-        if (s.startsWith("#"))
+        while (protocols.size() < files.size())
         {
-          // the line is a comment (as per the RFC 2483)
-          continue;
+          Cache.log.debug("Adding missing FILE protocol for "
+                  + files.get(protocols.size()));
+          protocols.add(DataSourceType.FILE);
         }
-        java.net.URI uri = new java.net.URI(s);
-        if (uri.getScheme().toLowerCase().startsWith("http"))
+        for (java.util.StringTokenizer st = new java.util.StringTokenizer(
+                data, "\r\n"); st.hasMoreTokens();)
         {
-          protocols.add(DataSourceType.URL);
-          files.add(uri.toString());
+          added = true;
+          String s = st.nextToken();
+          if (s.startsWith("#"))
+          {
+            // the line is a comment (as per the RFC 2483)
+            continue;
+          }
+          java.net.URI uri = new java.net.URI(s);
+          if (uri.getScheme().toLowerCase().startsWith("http"))
+          {
+            protocols.add(DataSourceType.URL);
+            files.add(uri.toString());
+          }
+          else
+          {
+            // otherwise preserve old behaviour: catch all for file objects
+            java.io.File file = new java.io.File(uri);
+            protocols.add(DataSourceType.FILE);
+            files.add(file.toString());
+          }
         }
-        else
+        if (Platform.isWindows())
         {
-          // otherwise preserve old behaviour: catch all for file objects
-          java.io.File file = new java.io.File(uri);
-          protocols.add(DataSourceType.FILE);
-          files.add(file.toString());
-        }
-      }
-      if (Platform.isWindows())
-      {
-        Cache.log.debug("Scanning dropped content for Windows Link Files");
+          Cache.log
+                  .debug("Scanning dropped content for Windows Link Files");
 
-         // resolve any .lnk files in the file drop
-        for (int f=0;f<files.size();f++)
-        {
-          if (protocols.get(f).equals(DataSourceType.FILE)) {
+          // resolve any .lnk files in the file drop
+          for (int f = 0; f < files.size(); f++)
+          {
+            if (protocols.get(f).equals(DataSourceType.FILE))
+            {
               File lf = new File(files.get(f));
-              if (WindowsShortcut.isPotentialValidLink(lf)) {
+              if (WindowsShortcut.isPotentialValidLink(lf))
+              {
                 // process link file to get a URL
-                Cache.log.debug("Found potential link file: "+lf);
+                Cache.log.debug("Found potential link file: " + lf);
                 WindowsShortcut wscfile = new WindowsShortcut(lf);
                 String fullname = wscfile.getRealFilename();
-                protocols.set(f,FormatAdapter.checkProtocol(fullname));
-                files.set(f,fullname);
-                Cache.log.debug("Parsed real filename "+fullname+" to extract protocol: "+protocols.get(f));
+                protocols.set(f, FormatAdapter.checkProtocol(fullname));
+                files.set(f, fullname);
+                Cache.log.debug("Parsed real filename " + fullname
+                        + " to extract protocol: " + protocols.get(f));
+              }
             }
           }
         }
       }
-        
       if (Cache.log.isDebugEnabled())
       {
         if (data == null || !added)
         {
-          Cache.log.debug(
-                  "Couldn't resolve drop data. Here are the supported flavors:");
-          for (DataFlavor fl : t.getTransferDataFlavors())
+
+          if (t.getTransferDataFlavors() != null
+                  && t.getTransferDataFlavors().length > 0)
           {
             Cache.log.debug(
-                    "Supported transfer dataflavor: " + fl.toString());
-            Object df = t.getTransferData(fl);
-            if (df != null)
+                    "Couldn't resolve drop data. Here are the supported flavors:");
+            for (DataFlavor fl : t.getTransferDataFlavors())
             {
-              Cache.log.debug("Retrieves: " + df);
-            }
-            else
-            {
-              Cache.log.debug("Retrieved nothing");
+              Cache.log.debug(
+                      "Supported transfer dataflavor: " + fl.toString());
+              Object df = t.getTransferData(fl);
+              if (df != null)
+              {
+                Cache.log.debug("Retrieves: " + df);
+              }
+              else
+              {
+                Cache.log.debug("Retrieved nothing");
+              }
             }
           }
+          else
+          {
+            Cache.log.debug("Couldn't resolve dataflavor for drop: "
+                    + t.toString());
+          }
         }
       }
     }