From 9c60565679988fbf1139adb6805c28f8719f8af3 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 24 May 2018 11:54:26 +0100 Subject: [PATCH] =?utf8?q?JAL-1460=20new=20data=20flavor=20for=20URLs=20adde?= =?utf8?q?d=20belt-and-braces=20URL=20drop=20code=20found=20in=20Marinacci=20?= =?utf8?q?and=20Adamson=E2=80=99s=20=E2=80=99Swing=20Hacks=E2=80=99=20(https?= =?utf8?q?://books.google.co.uk/books=3Fid=3DoNbFfcyAtv4C&lpg=3DPA336&ots=3D?= =?utf8?q?hflsI561Dv&dq=3Djava%20drag%20and%20drop%20url&pg=3DPA337#v=3Donep?= =?utf8?q?age&q=3Djava%20drag%20and%20drop%20url&f=3Dfalse=20)=20plus=20OS=20?= =?utf8?q?X=20bug=20workaround.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/gui/Desktop.java | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) 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()) -- 1.7.10.2