Java Code Examples for java.awt.dnd.DropTargetDropEvent#getTransferable()
The following examples show how to use
java.awt.dnd.DropTargetDropEvent#getTransferable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataObjectTransferHandler.java From nextreports-designer with Apache License 2.0 | 6 votes |
public void drop(DropTargetDropEvent event) { int dropAction = event.getDropAction(); JComponent c = (JComponent) event.getDropTargetContext().getComponent(); DataObjectTransferHandler transferHandler = (DataObjectTransferHandler) c.getTransferHandler(); if (canImport && (transferHandler != null) && actionSupported(dropAction)) { event.acceptDrop(dropAction); try { Transferable transferable = event.getTransferable(); transferHandler.setDropPoint(event.getLocation()); transferHandler.setDropComponent(c); event.dropComplete(transferHandler.importData(c, transferable)); } catch (RuntimeException e) { event.dropComplete(false); } } else { event.rejectDrop(); } }
Example 2
Source File: FileDropTargetListener.java From rest-client with Apache License 2.0 | 6 votes |
@Override public void drop(DropTargetDropEvent evt) { final int action = evt.getDropAction(); evt.acceptDrop(action); try { Transferable data = evt.getTransferable(); if (data.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { java.util.List<File> list = (java.util.List<File>) data.getTransferData( DataFlavor.javaFileListFlavor); for(DndAction a: actions) { a.onDrop(list); } } } catch (UnsupportedFlavorException | IOException e) { LOG.log(Level.WARNING, null, e); } finally { evt.dropComplete(true); evt.getDropTargetContext().getComponent() .setCursor(Cursor.getDefaultCursor()); } }
Example 3
Source File: AbstractDSWorkbenchFrame.java From dsworkbench with Apache License 2.0 | 6 votes |
@Override public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); } else { dtde.rejectDrop(); return; } Transferable t = dtde.getTransferable(); List<Village> v; MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor()); try { v = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor); fireVillagesDraggedEvent(v, dtde.getLocation()); } catch (Exception ignored) { } }
Example 4
Source File: DBTableInternalFrame.java From nextreports-designer with Apache License 2.0 | 6 votes |
public void drop(DropTargetDropEvent dtde) { gestureStarted = false; if ((dtde.getDropAction() & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); Transferable t = dtde.getTransferable(); try { DBTableInternalFrame iFrame = (DBTableInternalFrame) t .getTransferData(InternalFrameTransferable.DATA_FLAVOR); if (iFrame != DBTableInternalFrame.this) { JoinLine joinLine = new JoinLine(iFrame, iFrame .getSelectedRow(), DBTableInternalFrame.this, columnsListBox.getSelectedIndex()); desktop.addJoinLine(joinLine); desktop.repaint(); } } catch (Exception e) { e.printStackTrace(); } dtde.dropComplete(true); } }
Example 5
Source File: ProductExplorerTopComponent.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public void drop(DropTargetDropEvent dtde) { try { final Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); if (fileList.size() > 0) { final OpenProductAction open = new OpenProductAction(); open.setFiles(fileList.toArray(new File[fileList.size()])); dtde.dropComplete(Boolean.TRUE.equals(open.execute())); } } else { dtde.rejectDrop(); } } catch (UnsupportedFlavorException | IOException e) { SystemUtils.LOG.log(Level.SEVERE, "Exception during drag-and-drop operation", e); dtde.rejectDrop(); } }
Example 6
Source File: SqueakDisplay.java From trufflesqueak with MIT License | 6 votes |
@Override public void drop(final DropTargetDropEvent dtde) { final Transferable transferable = dtde.getTransferable(); for (final DataFlavor flavor : transferable.getTransferDataFlavors()) { if (DataFlavor.javaFileListFlavor.equals(flavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try { @SuppressWarnings("unchecked") final List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); final String[] fileArray = new String[fileList.size()]; int i = 0; for (final File file : fileList) { fileArray[i++] = file.getCanonicalPath(); } image.dropPluginFileList = fileArray; addDragEvent(DRAG.DROP, dtde.getLocation()); dtde.getDropTargetContext().dropComplete(true); return; } catch (final IOException | UnsupportedFlavorException e) { CompilerDirectives.transferToInterpreter(); e.printStackTrace(); } } } dtde.rejectDrop(); }
Example 7
Source File: MainDropTarget.java From jadx with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public void drop(DropTargetDropEvent dtde) { if (!dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.rejectDrop(); return; } dtde.acceptDrop(dtde.getDropAction()); try { Transferable transferable = dtde.getTransferable(); List<File> transferData = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); if (!transferData.isEmpty()) { dtde.dropComplete(true); // load first file mainWindow.open(transferData.get(0).toPath()); } } catch (Exception e) { LOG.error("File drop operation failed", e); } }
Example 8
Source File: FileDragLabel.java From Spark with Apache License 2.0 | 6 votes |
@Override public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) { try { final Transferable transferable = dropTargetDropEvent.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY); dropTargetDropEvent.getDropTargetContext().dropComplete(true); } else { dropTargetDropEvent.rejectDrop(); } } catch (Exception ex) { Log.error(ex); dropTargetDropEvent.rejectDrop(); } }
Example 9
Source File: JTreeUtil.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public final void drop(DropTargetDropEvent dtde) { try { if (drawImage) { clearImage(); } int action = dtde.getDropAction(); Transferable transferable = dtde.getTransferable(); Point pt = dtde.getLocation(); if (transferable.isDataFlavorSupported(NODE_FLAVOR) && controller.canPerformAction(tree, draggedNode, action, pt)) { TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y); Object node = transferable.getTransferData(NODE_FLAVOR); Object newParentNode = pathTarget.getLastPathComponent(); if (controller.executeDrop(tree, node, newParentNode, action)) { dtde.acceptDrop(action); dtde.dropComplete(true); return; } } dtde.rejectDrop(); dtde.dropComplete(false); } catch (Exception e) { dtde.rejectDrop(); dtde.dropComplete(false); } }
Example 10
Source File: DroppableFrame.java From Spark with Apache License 2.0 | 5 votes |
@Override public void drop(DropTargetDropEvent dropTargetDropEvent) { try { Transferable transferable = dropTargetDropEvent.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor); for (File aFileList : fileList) { File file = aFileList; if (file.isFile()) { fileDropped(file); } if (file.isDirectory()) { directoryDropped(file); } } dropTargetDropEvent.getDropTargetContext().dropComplete(true); } else { dropTargetDropEvent.rejectDrop(); } } catch (Exception io) { Log.error(io); dropTargetDropEvent.rejectDrop(); } }
Example 11
Source File: TraceTabbedPane.java From pega-tracerviewer with Apache License 2.0 | 5 votes |
@Override public void drop(DropTargetDropEvent dtde) { try { Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); // Get a useful list @SuppressWarnings("unchecked") List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); for (File file : fileList) { loadFile(file); } // Mark that drop is completed. dtde.getDropTargetContext().dropComplete(true); } } catch (Exception e) { LOG.error("Error in drop operation", e); } finally { // reset border setBorder(normalBorder); } }
Example 12
Source File: ImageTransferTest.java From hottub with GNU General Public License v2.0 | 5 votes |
void checkImage(DropTargetDropEvent dtde) { final Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); Image im; try { im = (Image) t.getTransferData(DataFlavor.imageFlavor); System.err.println("getTransferData was successful"); } catch (Exception e) { System.err.println("Can't getTransferData: " + e); dtde.dropComplete(false); notifyTransferSuccess(false); return; } if (im == null) { System.err.println("getTransferData returned null"); dtde.dropComplete(false); notifyTransferSuccess(false); } else if (areImagesIdentical(image, im)) { dtde.dropComplete(true); notifyTransferSuccess(true); } else { System.err.println("transferred image is different from initial image"); dtde.dropComplete(false); notifyTransferSuccess(false); } } else { System.err.println("imageFlavor is not supported by Transferable"); dtde.rejectDrop(); notifyTransferSuccess(false); } }
Example 13
Source File: ImageTransferTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void checkImage(DropTargetDropEvent dtde) { final Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); Image im; try { im = (Image) t.getTransferData(DataFlavor.imageFlavor); System.err.println("getTransferData was successful"); } catch (Exception e) { System.err.println("Can't getTransferData: " + e); dtde.dropComplete(false); notifyTransferSuccess(false); return; } if (im == null) { System.err.println("getTransferData returned null"); dtde.dropComplete(false); notifyTransferSuccess(false); } else if (areImagesIdentical(image, im)) { dtde.dropComplete(true); notifyTransferSuccess(true); } else { System.err.println("transferred image is different from initial image"); dtde.dropComplete(false); notifyTransferSuccess(false); } } else { System.err.println("imageFlavor is not supported by Transferable"); dtde.rejectDrop(); notifyTransferSuccess(false); } }
Example 14
Source File: ImageTransferTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void checkImage(DropTargetDropEvent dtde) { final Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); Image im; try { im = (Image) t.getTransferData(DataFlavor.imageFlavor); System.err.println("getTransferData was successful"); } catch (Exception e) { System.err.println("Can't getTransferData: " + e); dtde.dropComplete(false); notifyTransferSuccess(false); return; } if (im == null) { System.err.println("getTransferData returned null"); dtde.dropComplete(false); notifyTransferSuccess(false); } else if (areImagesIdentical(image, im)) { dtde.dropComplete(true); notifyTransferSuccess(true); } else { System.err.println("transferred image is different from initial image"); dtde.dropComplete(false); notifyTransferSuccess(false); } } else { System.err.println("imageFlavor is not supported by Transferable"); dtde.rejectDrop(); notifyTransferSuccess(false); } }
Example 15
Source File: FileDrop.java From PDF4Teachers with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public void drop(DropTargetDropEvent e){ Transferable transferable = e.getTransferable(); DataFlavor[] types = transferable.getTransferDataFlavors(); for(DataFlavor type : types){ try{ if(type.equals(DataFlavor.javaFileListFlavor)){ e.acceptDrop(DnDConstants.ACTION_COPY); for(Object o : (List) transferable.getTransferData(type)){ File file = (File) o; if (isFileAcceptable(file)) { if (component == 1) { MainWindow.mainScreen.openFile(file); } else if (component == 2) { MainWindow.lbFilesTab.openFiles(new File[]{file}); } } } } }catch (Exception e1){ e1.printStackTrace(); } } e.dropComplete(true); }
Example 16
Source File: ImageTransferTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
void checkImage(DropTargetDropEvent dtde) { final Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY); Image im; try { im = (Image) t.getTransferData(DataFlavor.imageFlavor); System.err.println("getTransferData was successful"); } catch (Exception e) { System.err.println("Can't getTransferData: " + e); dtde.dropComplete(false); notifyTransferSuccess(false); return; } if (im == null) { System.err.println("getTransferData returned null"); dtde.dropComplete(false); notifyTransferSuccess(false); } else if (areImagesIdentical(image, im)) { dtde.dropComplete(true); notifyTransferSuccess(true); } else { System.err.println("transferred image is different from initial image"); dtde.dropComplete(false); notifyTransferSuccess(false); } } else { System.err.println("imageFlavor is not supported by Transferable"); dtde.rejectDrop(); notifyTransferSuccess(false); } }
Example 17
Source File: TypeDropper.java From constellation with Apache License 2.0 | 4 votes |
@Override public BiConsumer<Graph, DropInfo> drop(final DropTargetDropEvent dtde) { final Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(VX_DATA_FLAVOR) || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { final String data; if (transferable.isDataFlavorSupported(VX_DATA_FLAVOR)) { final InputStream in = new ByteArrayInputStream(((ByteBuffer) transferable.getTransferData(VX_DATA_FLAVOR)).array()); final ObjectInputStream oin = new ObjectInputStream(in); data = (String) oin.readObject(); } else { final String t = (String) transferable.getTransferData(DataFlavor.stringFlavor); // Do we have the correct indicator? if (t != null && t.startsWith(INDICATOR)) { // Skip the leading "indicator=". data = t.substring(INDICATOR.length()); } else { data = null; } } if (data != null) { return (graph, dropInfo) -> { PluginExecution.withPlugin(new SimpleEditPlugin("Drag and Drop: Type to Vertex") { @Override public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException { final int ix = data.indexOf(':'); if (ix != -1) { final String attrLabel = data.substring(0, ix); final String value = data.substring(ix + 1); final int attrId = wg.getAttribute(GraphElementType.VERTEX, attrLabel); if (attrId != Graph.NOT_FOUND) { final int vxId; if (dropInfo.isIsVertex()) { vxId = dropInfo.id; // If the vertex is selected, modify all of the selected vertices. // Otherwise, just modify the dropped-on vertex. final int selectedId = VisualConcept.VertexAttribute.SELECTED.ensure(wg); if (wg.getBooleanValue(selectedId, vxId)) { final GraphIndexResult gir = GraphIndexUtilities.filterElements(wg, selectedId, true); while (true) { final int selVxId = gir.getNextElement(); if (selVxId == Graph.NOT_FOUND) { break; } wg.setStringValue(attrId, selVxId, data); if (graph.getSchema() != null) { graph.getSchema().completeVertex(wg, selVxId); } } } else { wg.setStringValue(attrId, vxId, data); if (graph.getSchema() != null) { graph.getSchema().completeVertex(wg, vxId); } } } else { vxId = wg.addVertex(); final int xId = VisualConcept.VertexAttribute.X.ensure(wg); final int yId = VisualConcept.VertexAttribute.Y.ensure(wg); final int zId = VisualConcept.VertexAttribute.Z.ensure(wg); wg.setStringValue(attrId, vxId, value); wg.setFloatValue(xId, vxId, dropInfo.location.getX()); wg.setFloatValue(yId, vxId, dropInfo.location.getY()); wg.setFloatValue(zId, vxId, dropInfo.location.getZ()); if (graph.getSchema() != null) { graph.getSchema().newVertex(wg, vxId); graph.getSchema().completeVertex(wg, vxId); } } ConstellationLoggerHelper.importPropertyBuilder( this, Arrays.asList(data), null, ConstellationLoggerHelper.SUCCESS ); } } } }).executeLater(graph); }; } } catch (final UnsupportedFlavorException | IOException | ClassNotFoundException ex) { Exceptions.printStackTrace(ex); } } return null; }
Example 18
Source File: QueryBuilderPanel.java From nextreports-designer with Apache License 2.0 | 4 votes |
public void drop(DropTargetDropEvent dtde) { if ((dtde.getDropAction() & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); Transferable t = dtde.getTransferable(); Point point = dtde.getLocation(); try { DBProcedure proc = (DBProcedure) t.getTransferData(DBProcTransferable.DATA_FLAVOR); List<DBProcedureColumn> columns = Globals.getDBViewer().getProcedureColumns(proc.getSchema(), proc.getCatalog(), proc.getName()); if (!Globals.getDBViewer().isValidProcedure(columns)) { Show.info(I18NSupport.getString("procedure.invalid")); return; } else { StringBuilder sb = new StringBuilder("call "); boolean order = Globals.getDialect().schemaBeforeCatalog(); if (!order) { if (proc.getCatalog() != null) { sb.append(proc.getCatalog()).append("."); } } if (!"%".equals(proc.getSchema())) { sb.append(proc.getSchema()).append("."); } if (order) { if (proc.getCatalog() != null) { sb.append(proc.getCatalog()).append("."); } } sb.append(proc.getName()); sb.append("("); int index = 1; for (int i = 0, size = columns.size(); i < size; i++) { DBProcedureColumn col = columns.get(i); if (ProcUtil.IN.equals(col.getReturnType())) { sb.append("${P").append(index).append("}"); index++; if (i < size - 1) { sb.append(", "); } } else if (ProcUtil.OUT.equals(col.getReturnType())) { if (ProcUtil.REF_CURSOR.equals(col.getDataType())) { sb.append("?"); if (i < size - 1) { sb.append(" , "); } } } } sb.append(")"); sqlView.setQueryString(sb.toString()); } } catch (Exception e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } dtde.dropComplete(true); } }
Example 19
Source File: CssExternalDropHandler.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean handleDrop(DropTargetDropEvent e) { Transferable t = e.getTransferable(); if (null == t) { return false; } List<File> fileList = getFileList(t); if ((fileList == null) || fileList.isEmpty()) { return false; } //handle just the first file File file = fileList.get(0); FileObject target = FileUtil.toFileObject(file); if (file.isDirectory()) { return true; //as we previously claimed we canDrop() it so we need to say we've handled it even if did nothing. } JEditorPane pane = findPane(e.getDropTargetContext().getComponent()); if (pane == null) { return false; } final BaseDocument document = (BaseDocument) pane.getDocument(); FileObject current = DataLoadersBridge.getDefault().getFileObject(document); String relativePath = WebUtils.getRelativePath(current, target); final StringBuilder sb = new StringBuilder(); //hardcoded support for common file types String mimeType = target.getMIMEType(); switch (mimeType) { //NOI18N -- whole switch content case "text/css": case "text/less": case "text/scss": sb.append("@import \"").append(relativePath).append("\";"); break; default: LOG.log(Level.INFO, "Dropping of files with mimetype {0} is not supported - what would you like to generate? Let me know in the issue 219985 please. Thank you!", mimeType); return true; } //check if the line is white, and if not, insert a new line before the text final int offset = getLineEndOffset(pane, e.getLocation()); final Indent indent = Indent.get(document); indent.lock(); try { document.runAtomic(new Runnable() { @Override public void run() { try { int ofs = offset; if (!Utilities.isRowWhite(document, ofs)) { document.insertString(ofs, "\n", null); ofs++; } document.insertString(ofs, sb.toString(), null); //reformat the line final int from = Utilities.getRowStart(document, ofs); final int to = Utilities.getRowEnd(document, ofs); indent.reindent(from, to); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); } finally { indent.unlock(); } return true; }
Example 20
Source File: CardSetDndHandler.java From opencards with BSD 2-Clause "Simplified" License | 4 votes |
public void drop(DropTargetDropEvent dtde) { try { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (DataFlavor flavor : flavors) { // Check for file lists specifically if (flavor.isFlavorJavaFileListType()) { // Great! Accept copy drops... dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); // And add the list of file names to our text area boolean invalidDrop = false; List<File> droppedFiles = (List<File>) tr.getTransferData(flavor); for (File file : droppedFiles) { if (CardFileBackend.hasSupportedExtension(file)) { Category curCat = CategoryUtils.getSelectedCategory(); curCat.registerCardSet(CardFileCache.getCardFile(file)); } else { invalidDrop = true; } } if (invalidDrop) { Runnable task2 = () -> { JOptionPane.showMessageDialog(OpenCards.getInstance(), "Just PowerPoint (ppt) and MarkDown (md) are supported as flashcard-sets by OpenCards", "Invalid file format of dropped file", JOptionPane.WARNING_MESSAGE) ; }; // start the thread new Thread(task2).start(); } // If we made it this far, everything worked. dtde.dropComplete(true); return; } } // Hmm, the user must not have dropped a file list System.out.println("Drop failed: " + dtde); dtde.rejectDrop(); } catch (Exception e) { e.printStackTrace(); dtde.rejectDrop(); } }