/** * The file or URL has been dropped. * * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent) */ public void drop(DropTargetDropEvent event) { // important to first try urlFlavor if (event.isDataFlavorSupported(urlFlavor)) { try { event.acceptDrop(DnDConstants.ACTION_COPY); Transferable trans = event.getTransferable(); URL url = (URL) (trans.getTransferData(urlFlavor)); String urlStr = url.toString(); gridIO.openShape(url); reset(); event.dropComplete(true); } catch (Exception e) { event.dropComplete(false); } } else if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try { event.acceptDrop(DnDConstants.ACTION_COPY); Transferable trans = event.getTransferable(); java.util.List list = (java.util.List) (trans.getTransferData(DataFlavor.javaFileListFlavor)); File droppedFile = (File) list.get(0); // More than one file -> get only first file gridIO.openShape(droppedFile.getPath()); reset(); event.dropComplete(true); } catch (Exception e) { event.dropComplete(false); } } }
/** * The drag operation has terminated with a drop on this <code>DropTarget</code>. This method is * responsible for undertaking the transfer of the data associated with the gesture. The <code> * DropTargetDropEvent</code> provides a means to obtain a <code>Transferable</code> object that * represents the data object(s) to be transfered. * * <p>From this method, the <code>DropTargetListener</code> shall accept or reject the drop via * the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent * </code> parameter. * * <p>Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s * getTransferable() method may be invoked, and data transfer may be performed via the returned * <code>Transferable</code>'s getTransferData() method. * * <p>At the completion of a drop, an implementation of this method is required to signal the * success/failure of the drop by passing an appropriate <code>boolean</code> to the <code> * DropTargetDropEvent</code>'s dropComplete(boolean success) method. * * <p>Note: The actual processing of the data transfer is not required to finish before this * method returns. It may be deferred until later. * * <p> * * @param dtde the <code>DropTargetDropEvent</code> */ @Override @SuppressWarnings("unchecked") public void drop(DropTargetDropEvent event) { if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { event.acceptDrop(DnDConstants.ACTION_COPY); try { List<File> files = (List<File>) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); splitMPOFiles(files); } catch (IOException e) { JOptionPane.showConfirmDialog( MPOImageSplitter.this, "Could not access the dropped data.", "MPOImageSplitter: Drop Failed", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } catch (UnsupportedFlavorException e) { JOptionPane.showConfirmDialog( MPOImageSplitter.this, "Unsupported data flavor.", "MPOImageSplitter: Drop Failed", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE); } } else { event.rejectDrop(); } }
public void drop(DropTargetDropEvent dtde) { logger.info("Drop: " + dtde); if (dtde.isDataFlavorSupported(OWLObjectDataFlavor.OWL_OBJECT_DATA_FLAVOR)) { try { List<OWLObject> objects = (List<OWLObject>) dtde.getTransferable().getTransferData(OWLObjectDataFlavor.OWL_OBJECT_DATA_FLAVOR); List<OWLClass> clses = new ArrayList<OWLClass>(); for (OWLObject obj : objects) { if (obj instanceof OWLClass) { clses.add((OWLClass) obj); } } if (!clses.isEmpty()) { getAssertedGraphComponent().getVisualisedObjectManager().showObjects(clses.toArray()); dtde.dropComplete(true); } } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
public void drop(DropTargetDropEvent dtde) { // System.out.println("drop"); // System.out.println(dtde.getDropAction()); // System.out.println(); // Check the drop action if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { // Accept the drop and get the transfer data dtde.acceptDrop(dtde.getDropAction()); Transferable transferable = dtde.getTransferable(); try { boolean result = false; if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { result = dropFile(transferable); } else { result = false; } dtde.dropComplete(result); } catch (Exception e) { System.out.println("Exception while handling drop " + e); dtde.rejectDrop(); } } else { System.out.println("Drop target rejected drop"); dtde.dropComplete(false); } }
@SuppressWarnings("unchecked") public void drop(DropTargetDropEvent event) { try { if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { Transferable tr = event.getTransferable(); int action = event.getDropAction(); event.acceptDrop(action); java.util.List<File> files = (java.util.List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); for (File f : files) { JEXStatics.logManager.log("Copying file " + f, 1, this); String newDest = parent.folder.getPath() + File.separator + f.getName(); FileUtility.copy(f, new File(newDest)); } parent.rebuild(); event.dropComplete(true); JEXStatics.logManager.log("Drop completed...", 1, this); return; } event.rejectDrop(); } catch (Exception e) { e.printStackTrace(); event.rejectDrop(); } }
public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try { content = (java.util.List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); repaint(); } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } dtde.dropComplete(true); boolean listsAreEqual = true; for (int i = 0; i < content.size(); i++) { if (!FileListTransferable.files[i].getName().equals(content.get(i).getName())) { listsAreEqual = false; } } if (listsAreEqual) { System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL); System.exit(0); } } dtde.rejectDrop(); System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED); System.exit(1); }
public boolean isDropAcceptable(final DropTargetDropEvent e) { // Only accept COPY or MOVE gestures (ie LINK is not supported) if ((e.getDropAction() & DnDConstants.ACTION_MOVE) == 0) return false; // Only accept this particular flavor if (!e.isDataFlavorSupported(JDragTree.TREEPATH_FLAVOR)) return false; // Do this if you want to prohibit dropping onto the drag source... final Point pt = e.getLocation(); final TreePath path = getClosestPathForLocation(pt.x, pt.y); if ((path == null) || path.equals(_pathSource)) return false; return true; }
public void drop(DropTargetDropEvent event) { if (!event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { event.rejectDrop(); return; } event.acceptDrop(event.getDropAction()); try { List<File> data = (List<File>) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); Vector<String> pages = this.model.addWikiPages((File[]) data.toArray()); JList pagelist = new JList(pages); this.updateUI(this.ui, pagelist); event.dropComplete(true); } catch (Exception e) { event.dropComplete(false); log.error("Failed to accept drag n drop", e); } highlightUI(false); }
@Override public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(CardFlavor.cardFlavor) && this.canDrop) { Transferable trans = dtde.getTransferable(); try { Object data = trans.getTransferData(CardFlavor.cardFlavor); CardWindow card = (CardWindow) data; DropTargetContext context = dtde.getDropTargetContext(); CardCollection comp = (CardCollection) context.getComponent(); Container parent = comp.getParent(); GameController.getController(false) .makeMove( CardCollection.getMoveFromIndex( comp.getCardMouseLocation(), new OrderedCard(card.card, card.cardLocation))); if (parent != null) parent.remove(card); comp.setCard(card, comp.getCardMouseLocation()); dtde.acceptDrop(DnDConstants.ACTION_MOVE); comp.validate(); comp.repaint(); dtde.dropComplete(true); } catch (Exception e) { dtde.rejectDrop(); dtde.dropComplete(false); JOptionPane.showMessageDialog( MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } else { dtde.rejectDrop(); dtde.dropComplete(false); JOptionPane.showMessageDialog( MainWindow.getMainWindow(), "Invalid move.", "Invalid Move Error", JOptionPane.ERROR_MESSAGE); } }
@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(); }
@Override public void drop(DropTargetDropEvent dtde) { Point pt = dtde.getLocation(); DropTargetContext dtc = dtde.getDropTargetContext(); JTree tree = (JTree) dtc.getComponent(); TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y); Object node = parentpath.getLastPathComponent(); if (dtde.isDataFlavorSupported(TransferableUDO.UDO_CAT_FLAVOR)) { if (!(node instanceof UDOCategory)) { dtde.rejectDrop(); return; } if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) { dtde.acceptDrop(dtde.getDropAction()); Transferable tr = dtde.getTransferable(); try { Object transferNode = tr.getTransferData(TransferableUDO.UDO_CAT_FLAVOR); UDOCategory udoCategory = (UDOCategory) transferNode; UDOCategory parentNode = (UDOCategory) node; UDOLibrary udoLibrary = (UDOLibrary) tree.getModel(); udoLibrary.addCategory(parentNode, udoCategory); dtde.dropComplete(true); } catch (UnsupportedFlavorException | IOException e) { dtde.dropComplete(false); } } else { dtde.rejectDrop(); } } else if (dtde.isDataFlavorSupported(TransferableUDO.UDO_FLAVOR)) { dtde.acceptDrop(dtde.getDropAction()); try { Transferable tr = dtde.getTransferable(); Object transferNode = tr.getTransferData(TransferableUDO.UDO_FLAVOR); UserDefinedOpcode udo = (UserDefinedOpcode) transferNode; UDOLibrary udoLibrary = (UDOLibrary) tree.getModel(); // iLibrary.removeInstrument(instrument); if (node instanceof UDOCategory) { UDOCategory parentNode = (UDOCategory) node; udoLibrary.addUDO(parentNode, udo); } else if (node instanceof UserDefinedOpcode) { UDOCategory parentNode = (UDOCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2); int index = ListUtil.indexOfByRef(parentNode.getUserDefinedOpcodes(), node); int closestRow = tree.getClosestRowForLocation(pt.x, pt.y); Rectangle bounds = tree.getRowBounds(closestRow); if (pt.y > bounds.y + bounds.height) { udoLibrary.addUDO(parentNode, udo); } else { udoLibrary.addUDO(parentNode, index, udo); } } dtde.dropComplete(true); } catch (UnsupportedFlavorException | IOException e) { dtde.dropComplete(false); } } else { dtde.rejectDrop(); } }
/** * The drag operation has terminated with a drop on this DropTarget. Be nice to somehow * incorporate FigureTransferCommand here. */ public void drop(java.awt.dnd.DropTargetDropEvent dtde) { System.out.println("DropTargetDropEvent-drop"); if (dtde.isDataFlavorSupported(DNDFiguresTransferable.DNDFiguresFlavor) == true) { log("DNDFiguresFlavor"); if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { log("copy or move"); if (dtde.isLocalTransfer() == false) { System.err.println("Intra-JVM Transfers not implemented for figures yet."); dtde.rejectDrop(); return; } dtde.acceptDrop(dtde.getDropAction()); try { /* protection from a malicious dropped object */ setTargetUndoActivity(createTargetUndoActivity(view())); DNDFigures ff = (DNDFigures) DNDHelper.processReceivedData( DNDFiguresTransferable.DNDFiguresFlavor, dtde.getTransferable()); getTargetUndoActivity().setAffectedFigures(ff.getFigures()); Point theO = ff.getOrigin(); view().clearSelection(); Point newP = dtde.getLocation(); /** * origin is where the figure thinks it is now newP is where the mouse is now. we move the * figure to where the mouse is with this equation */ int dx = newP.x - theO.x; /* distance the mouse has moved */ int dy = newP.y - theO.y; /* distance the mouse has moved */ log("mouse at " + newP); FigureEnumeration fe = view().insertFigures(getTargetUndoActivity().getAffectedFigures(), dx, dy, false); getTargetUndoActivity().setAffectedFigures(fe); if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) { view().addToSelectionAll(getTargetUndoActivity().getAffectedFigures()); } view().checkDamage(); editor().getUndoManager().pushUndo(getTargetUndoActivity()); editor().getUndoManager().clearRedos(); // update menus editor().figureSelectionChanged(view()); dtde.dropComplete(true); } catch (NullPointerException npe) { npe.printStackTrace(); dtde.dropComplete(false); } } else { dtde.rejectDrop(); } } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { log("String flavor dropped."); dtde.acceptDrop(dtde.getDropAction()); Object o = DNDHelper.processReceivedData(DataFlavor.stringFlavor, dtde.getTransferable()); if (o != null) { log("Received string flavored data."); dtde.getDropTargetContext().dropComplete(true); } else { dtde.getDropTargetContext().dropComplete(false); } } else if (dtde.isDataFlavorSupported(DNDHelper.ASCIIFlavor) == true) { log("ASCII Flavor dropped."); dtde.acceptDrop(DnDConstants.ACTION_COPY); Object o = DNDHelper.processReceivedData(DNDHelper.ASCIIFlavor, dtde.getTransferable()); if (o != null) { log("Received ASCII Flavored data."); dtde.getDropTargetContext().dropComplete(true); // System.out.println(o); } else { dtde.getDropTargetContext().dropComplete(false); } } else if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { log("Java File List Flavor dropped."); dtde.acceptDrop(DnDConstants.ACTION_COPY); File[] fList = (File[]) DNDHelper.processReceivedData(DataFlavor.javaFileListFlavor, dtde.getTransferable()); if (fList != null) { log("Got list of files."); for (int x = 0; x < fList.length; x++) { System.out.println(fList[x].getAbsolutePath()); } dtde.getDropTargetContext().dropComplete(true); } else { dtde.getDropTargetContext().dropComplete(false); } } fLastX = 0; fLastY = 0; }