From: Jim Procter Date: Thu, 24 May 2018 10:54:26 +0000 (+0100) Subject: JAL-1460 new data flavor for URLs added belt-and-braces URL drop code found in Marina... X-Git-Tag: Release_2_10_5~67^2~5 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9c60565679988fbf1139adb6805c28f8719f8af3;p=jalview.git JAL-1460 new data flavor for URLs added belt-and-braces URL drop code found in Marinacci and Adamson’s ’Swing Hacks’ (https://books.google.co.uk/books?id=oNbFfcyAtv4C&lpg=PA336&ots=hflsI561Dv&dq=java%20drag%20and%20drop%20url&pg=PA337#v=onepage&q=java%20drag%20and%20drop%20url&f=false ) plus OS X bug workaround. --- diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 9a696e9..9598f60 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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())