private void acceptDrop(DropTargetDropEvent dtde) { int dragaction = dtde.getDropAction(); if (dragaction != 0) { dtde.acceptDrop(dragaction); } else { dtde.acceptDrop(ALL_ACTIONS); } }
public void drop(DropTargetDropEvent dtde) { if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { dtde.rejectDrop(); return; } dtde.acceptDrop(DnDConstants.ACTION_COPY); Vector<RowContainer> oldvec = this.filevector; Transferable transferable = dtde.getTransferable(); try { java.util.List<File> filelist = (java.util.List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); for (File f : filelist) { filevector.add(new RowContainer(f)); model.fireTableDataChanged(); System.out.println(f.toString()); } } catch (IOException ex) { ex.printStackTrace(); } catch (UnsupportedFlavorException ex) { ex.printStackTrace(); } dtde.dropComplete(true); File[] filar = new File[filevector.size()]; for (int i = 0; i < filevector.size(); i++) { filar[i] = filevector.get(i).getFile(); } super.firePropertyChange("filevector", null, filar); }
private void processDrop(DropData dropData, DropTargetDropEvent dropTargetDropEvent) { putEntryAtPoint(dropData.whatToDrop, dropData.whereInTable); _widget.addEntry(dropData.whatToDrop); _underlyingTable.setRowSelectionInterval(dropData.whereInTable.x, dropData.whereInTable.x); _underlyingTable.setColumnSelectionInterval(dropData.whereInTable.y, dropData.whereInTable.y); dropTargetDropEvent.acceptDrop(dropTargetDropEvent.getDropAction()); dropTargetDropEvent.dropComplete(true); }
public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); DataFlavor[] flavors = null; try { Transferable t = dtde.getTransferable(); iterator = null; flavors = t.getTransferDataFlavors(); if (IJ.debugMode) IJ.log("DragAndDrop.drop: " + flavors.length + " flavors"); for (int i = 0; i < flavors.length; i++) { if (IJ.debugMode) IJ.log(" flavor[" + i + "]: " + flavors[i].getMimeType()); if (flavors[i].isFlavorJavaFileListType()) { Object data = t.getTransferData(DataFlavor.javaFileListFlavor); iterator = ((List) data).iterator(); break; } else if (flavors[i].isFlavorTextType()) { Object ob = t.getTransferData(flavors[i]); if (!(ob instanceof String)) continue; String s = ob.toString().trim(); if (IJ.isLinux() && s.length() > 1 && (int) s.charAt(1) == 0) s = fixLinuxString(s); ArrayList list = new ArrayList(); if (s.indexOf("href=\"") != -1 || s.indexOf("src=\"") != -1) { s = parseHTML(s); if (IJ.debugMode) IJ.log(" url: " + s); list.add(s); this.iterator = list.iterator(); break; } BufferedReader br = new BufferedReader(new StringReader(s)); String tmp; while (null != (tmp = br.readLine())) { tmp = java.net.URLDecoder.decode(tmp.replaceAll("\\+", "%2b"), "UTF-8"); if (tmp.startsWith("file://")) tmp = tmp.substring(7); if (IJ.debugMode) IJ.log(" content: " + tmp); if (tmp.startsWith("http://")) list.add(s); else list.add(new File(tmp)); } this.iterator = list.iterator(); break; } } if (iterator != null) { Thread thread = new Thread(this, "DrawAndDrop"); thread.setPriority(Math.max(thread.getPriority() - 1, Thread.MIN_PRIORITY)); thread.start(); } } catch (Exception e) { dtde.dropComplete(false); return; } dtde.dropComplete(true); if (flavors == null || flavors.length == 0) { if (IJ.isMacOSX()) IJ.error( "First drag and drop ignored. Please try again. You can avoid this\n" + "problem by dragging to the toolbar instead of the status bar."); else IJ.error("Drag and drop failed"); } }
public void drop(DropTargetDropEvent evt) { try { Transferable t = evt.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String s = (String) t.getTransferData(DataFlavor.stringFlavor); evt.getDropTargetContext().dropComplete(true); process(s); } else { evt.rejectDrop(); } } catch (IOException e) { evt.rejectDrop(); } catch (UnsupportedFlavorException e) { evt.rejectDrop(); } }
@Override public void drop(DropTargetDropEvent dtde) { try { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); Transferable t = dtde.getTransferable(); List list = (List) t.getTransferData(DataFlavor.javaFileListFlavor); for (Object o : list) { if (o instanceof File) { File f = (File) o; System.out.println(f.getAbsolutePath()); } } dtde.dropComplete(true); return; } } catch (UnsupportedFlavorException | IOException ex) { ex.printStackTrace(); } dtde.rejectDrop(); }