private static File[] createFileArray(BufferedReader bReader, PrintStream out) { try { List list = new java.util.ArrayList(); String line; while ((line = bReader.readLine()) != null) { try { // kde seems to append a 0 char to the end of the reader if (ZERO_CHAR_STRING.equals(line)) continue; File file = new File(new URI(line)); list.add(file); } catch (Exception ex) { log(out, "Error with " + line + ": " + ex.getMessage()); } } return (java.io.File[]) list.toArray(new File[list.size()]); } catch (IOException ex) { log(out, "FileDrop: IOException"); } return new File[0]; } // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
/** * Determine if the dragged data is a file list. */ private boolean isDragOk(final PrintStream out, final DropTargetDragEvent evt) { boolean ok = false; // Get data flavors being dragged DataFlavor[] flavors = evt.getCurrentDataFlavors(); // See if any of the flavors are a file list int i = 0; while (!ok && i < flavors.length) { // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. // Is the flavor a file list? final DataFlavor curFlavor = flavors[i]; if (curFlavor.equals(DataFlavor.javaFileListFlavor) || curFlavor.isRepresentationClassReader()) ok = true; // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. i++; } // end while: through flavors // If logging is enabled, show data flavors if (out != null) { if (flavors.length == 0) log(out, "FileDrop: no data flavors."); for (i = 0; i < flavors.length; i++) log(out, flavors[i].toString()); } return ok; }
/** * Removes the drag-and-drop hooks from the component and optionally from * the all children. You should call this if you add and remove components * after you've set up the drag-and-drop. * * @param out Optional {@link PrintStream} for logging drag and drop * messages * @param c The component to unregister * @param recursive Recursively unregister components within a container * @return {@code true} if hooks were removed, and {@code false} otherwise * @since 1.0 */ public static boolean remove(PrintStream out, Component c, boolean recursive) { // Make sure we support dnd. if (supportsDnD()) { log(out, "FileDrop: Removing drag-and-drop hooks."); c.setDropTarget(null); if (recursive && (c instanceof java.awt.Container)) { Component[] comps = ((java.awt.Container) c).getComponents(); for (Component comp : comps) remove(out, comp, recursive); return true; } else { return false; } } else { return false; } }
dt.addDropTargetListener(dropListener); } catch (java.util.TooManyListenersException e) { log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
log(out, "FileDrop: Drag and drop is not supported with this JVM");