List of usage examples for java.awt.dnd DropTargetDropEvent acceptDrop
public void acceptDrop(int dropAction)
From source file:EditorDropTarget4.java
public void drop(DropTargetDropEvent dtde) { DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction())); // 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 {//w ww .j a v a 2 s . co m boolean result = false; if (draggingFile) { result = dropFile(transferable); } else { result = dropContent(transferable, dtde); } dtde.dropComplete(result); DnDUtils.debugPrintln("Drop completed, success: " + result); } catch (Exception e) { DnDUtils.debugPrintln("Exception while handling drop " + e); dtde.rejectDrop(); } } else { DnDUtils.debugPrintln("Drop target rejected drop"); dtde.dropComplete(false); } }
From source file:com.ftb2om2.view.MultiplePane.java
private void difficultyTableDragAndDrop(DropTargetDropEvent evt) { try {//from ww w .ja v a2 s.c o m DefaultTableModel model = (DefaultTableModel) difficultyTable.getModel(); evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFile = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); droppedFile.forEach(file -> model.addRow( new Object[] { file.getName(), file.getPath(), FilenameUtils.getBaseName(file.getPath()) })); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.INFO, null, ex); } }
From source file:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java
public void drop(DropTargetDropEvent e) { // Check DataFlavor DataFlavor[] dfs = e.getCurrentDataFlavors(); DataFlavor tdf = null;/*from w w w. j ava 2s . c o m*/ for (int i = 0; i < dfs.length; i++) { if (DataFlavor.javaFileListFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } else if (DataFlavor.stringFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } } // Data Flavor available ? if (tdf != null) { // Accept COPY DnD only. if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) { e.acceptDrop(DnDConstants.ACTION_COPY); } else return; try { Transferable t = e.getTransferable(); Object data = t.getTransferData(tdf); processDrop(data); } catch (IOException ioe) { log.info("Drop error", ioe); e.dropComplete(false); return; } catch (UnsupportedFlavorException ufe) { log.info("Drop error", ufe); e.dropComplete(false); return; } catch (Exception ex) { log.info("Drop error", ex); e.dropComplete(false); return; } e.dropComplete(true); } }
From source file:com.mirth.connect.client.ui.EditMessageDialog.java
public void drop(DropTargetDropEvent dtde) { try {// w ww. j av a 2 s. c o m Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); while (iterator.hasNext()) { File file = iterator.next(); messageContent.setText( messageContent.getText() + FileUtils.readFileToString(file, UIConstants.CHARSET)); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void drop(@Nonnull final DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); File detectedFileObject = null; for (final DataFlavor df : dtde.getCurrentDataFlavors()) { final Class<?> representation = df.getRepresentationClass(); if (FileTransferable.class.isAssignableFrom(representation)) { final FileTransferable t = (FileTransferable) dtde.getTransferable(); final List<File> listOfFiles = t.getFiles(); detectedFileObject = listOfFiles.isEmpty() ? null : listOfFiles.get(0); break; } else if (df.isFlavorJavaFileListType()) { try { final List list = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (list != null && !list.isEmpty()) { detectedFileObject = (File) list.get(0); }/* w w w . ja v a 2s .c om*/ break; } catch (Exception ex) { LOGGER.error("Can't extract file from DnD", ex); } } } if (detectedFileObject != null) { addFileToElement(detectedFileObject, this.mindMapPanel.findTopicUnderPoint(dtde.getLocation())); } }
From source file:TreeDragTest.java
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); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent(); if (parent.isLeaf()) { dtde.rejectDrop();/*from ww w.j a v a 2 s .c o m*/ return; } try { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { if (tr.isDataFlavorSupported(flavors[i])) { dtde.acceptDrop(dtde.getDropAction()); TreePath p = (TreePath) tr.getTransferData(flavors[i]); DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent(); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.insertNodeInto(node, parent, 0); dtde.dropComplete(true); return; } } dtde.rejectDrop(); } catch (Exception e) { e.printStackTrace(); dtde.rejectDrop(); } }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
@Override public void drop(DropTargetDropEvent dtde) { if (dtde.getDropTargetContext().getComponent().equals(jTimeFrameList)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try {//from w w w. j a v a 2 s. c o m String data = (String) dtde.getTransferable().getTransferData(DataFlavor.stringFlavor); TimeSpan s = TimeSpan.fromPropertyString(data); if (s == null) { throw new UnsupportedFlavorException(DataFlavor.stringFlavor); } addTimeSpan(s); } catch (UnsupportedFlavorException | IOException usfe) { //invalid data } } }
From source file:com.mirth.connect.client.ui.components.MirthTree.java
public void drop(DropTargetDropEvent dtde) { if (parent.currentContentPage != parent.channelEditPanel.transformerPane) { return;/* ww w . ja v a 2 s.co m*/ } try { TreeNode selectedNode = (TreeNode) this.getLastSelectedPathComponent(); if (selectedNode == null) { return; } dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable tr = dtde.getTransferable(); if (supportedDropFlavor == TreeTransferable.MAPPER_DATA_FLAVOR) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data = (MapperDropData) transferData; parent.channelEditPanel.transformerPane.addNewStep( constructMessageBuilderStepName(data.getNode(), selectedNode), constructPath(selectedNode, prefix, suffix).toString(), data.getMapping(), TransformerPane.MESSAGE_BUILDER); } else if (supportedDropFlavor == TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR) { Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); MessageBuilderDropData data = (MessageBuilderDropData) transferData; parent.channelEditPanel.transformerPane.addNewStep( constructMessageBuilderStepName(selectedNode, data.getNode()), data.getMessageSegment(), constructPath(selectedNode, prefix, suffix).toString(), TransformerPane.MESSAGE_BUILDER); } else { dtde.rejectDrop(); } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:ScribbleDragAndDrop.java
/** * This is the key method of DropTargetListener. It is invoked when the user * drops something on us.//from w w w.ja v a2 s. c o m */ public void drop(DropTargetDropEvent e) { this.setBorder(normalBorder); // Restore the default border // First, check whether we understand the data that was dropped. // If we supports our data flavors, accept the drop, otherwise reject. if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor) || e.isDataFlavorSupported(DataFlavor.stringFlavor)) { e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); } else { e.rejectDrop(); return; } // We've accepted the drop, so now we attempt to get the dropped data // from the Transferable object. Transferable t = e.getTransferable(); // Holds the dropped data Scribble droppedScribble; // This will hold the Scribble object // First, try to get the data directly as a scribble object try { droppedScribble = (Scribble) t.getTransferData(Scribble.scribbleDataFlavor); } catch (Exception ex) { // unsupported flavor, IO exception, etc. // If that doesn't work, try to get it as a String and parse it try { String s = (String) t.getTransferData(DataFlavor.stringFlavor); droppedScribble = Scribble.parse(s); } catch (Exception ex2) { // If we still couldn't get the data, tell the system we failed e.dropComplete(false); return; } } // If we get here, we've got the Scribble object Point p = e.getLocation(); // Where did the drop happen? droppedScribble.translate(p.getX(), p.getY()); // Move it there scribbles.add(droppedScribble); // add to display list repaint(); // ask for redraw e.dropComplete(true); // signal success! }
From source file:net.sf.nmedit.jtheme.component.JTModuleContainer.java
public void copyMoveModules(DropTargetDropEvent dtde) { DataFlavor chosen = PDragDrop.ModuleSelectionFlavor; Transferable transfer = dtde.getTransferable(); Object data = null;//from w ww . jav a 2 s. co m try { // Get the data data = transfer.getTransferData(chosen); dtde.acceptDrop(dtde.getDropAction() & (DnDConstants.ACTION_MOVE | DnDConstants.ACTION_COPY | DnDConstants.ACTION_LINK)); } catch (Throwable t) { if (log.isWarnEnabled()) { log.warn("copyMoveModules(DropTargetDropEvent=" + dtde + ") failed", t); } dtde.dropComplete(false); return; } if (data != null && data instanceof PModuleTransferData) { // Cast the data and create a nice module. PModuleTransferData tdata = ((PModuleTransferData) data); boolean isSamePatch = false; if (tdata.getSourcePatch() == getModuleContainer().getPatch()) isSamePatch = true; //Point p = dtde.getLocation(); int action = dtde.getDropAction(); if ((action & DnDConstants.ACTION_MOVE) != 0 && isSamePatch) { MoveOperation op = tdata.getSourceModuleContainer().createMoveOperation(); op.setDestination(getModuleContainer()); executeOperationOnSelection(tdata, dtde.getLocation(), op); } else { copyModules(tdata, dtde.getLocation(), ((dtde.getDropAction() & DnDConstants.ACTION_LINK) != 0)); } } dtde.dropComplete(true); }