Author: jukka Date: Mon Sep 22 16:09:44 2008 New Revision: 698032 URL: http://svn.apache.org/viewvc?rev=698032&view=rev Log: TIKA-163: GUI does not support drag and drop in Gnome or KDE
Applied patch by Dave Meikle. Modified: incubator/tika/trunk/CHANGES.txt incubator/tika/trunk/src/main/java/org/apache/tika/gui/ParsingTransferHandler.java Modified: incubator/tika/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/incubator/tika/trunk/CHANGES.txt?rev=698032&r1=698031&r2=698032&view=diff ============================================================================== --- incubator/tika/trunk/CHANGES.txt (original) +++ incubator/tika/trunk/CHANGES.txt Mon Sep 22 16:09:44 2008 @@ -90,6 +90,7 @@ 37. TIKA-140 - HTML parser unable to extract text (Julien Nioche & Jukka Zitting) +38. TIKA-163 - GUI does not support drag and drop in Gnome or KDE (Dave Meikle) Release 0.1-incubating - 12/27/2007 Modified: incubator/tika/trunk/src/main/java/org/apache/tika/gui/ParsingTransferHandler.java URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/gui/ParsingTransferHandler.java?rev=698032&r1=698031&r2=698032&view=diff ============================================================================== --- incubator/tika/trunk/src/main/java/org/apache/tika/gui/ParsingTransferHandler.java (original) +++ incubator/tika/trunk/src/main/java/org/apache/tika/gui/ParsingTransferHandler.java Mon Sep 22 16:09:44 2008 @@ -22,6 +22,9 @@ import java.awt.event.InputEvent; import java.io.File; import java.util.List; +import java.util.StringTokenizer; +import java.util.ArrayList; +import java.net.URI; import javax.swing.Icon; import javax.swing.JComponent; @@ -36,6 +39,14 @@ private final TikaGUI tika; + private static DataFlavor uriListFlavor; + static { + try { + uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String"); + } catch (ClassNotFoundException e) { + } + } + public ParsingTransferHandler(TransferHandler delegate, TikaGUI tika) { this.delegate = delegate; this.tika = tika; @@ -43,7 +54,7 @@ public boolean canImport(JComponent component, DataFlavor[] flavors) { for (DataFlavor flavor : flavors) { - if (flavor.equals(DataFlavor.javaFileListFlavor)) { + if (flavor.equals(DataFlavor.javaFileListFlavor) || flavor.equals(uriListFlavor)) { return true; } } @@ -53,8 +64,14 @@ public boolean importData( JComponent component, Transferable transferable) { try { - List<?> files = (List<?>) - transferable.getTransferData(DataFlavor.javaFileListFlavor); + List<?> files = null; + if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + files = (List<?>) + transferable.getTransferData(DataFlavor.javaFileListFlavor); + } else if (transferable.isDataFlavorSupported(uriListFlavor)) { + files = uriToFileList((String) transferable.getTransferData(uriListFlavor)); + } + for (Object file : files) { tika.importFile((File) file); } @@ -81,4 +98,20 @@ return delegate.getVisualRepresentation(arg0); } -} \ No newline at end of file + private static List<File> uriToFileList(String data) { + List<File> list = new ArrayList<File>(); + StringTokenizer st = new StringTokenizer(data, "\r\n"); + while (st.hasMoreTokens()) + { + String s = st.nextToken(); + if (s.startsWith("#")) { + continue; + } + try { + list.add(new File(new URI(s))); + } catch (Exception e) { + } + } + return list; + } +}