Java Code Examples for java.awt.dnd.DropTargetDragEvent#getTransferable()
The following examples show how to use
java.awt.dnd.DropTargetDragEvent#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: FileDrop.java From PDF4Teachers with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public void dragEnter(DropTargetDragEvent e){ Transferable transferable = e.getTransferable(); DataFlavor[] types = transferable.getTransferDataFlavors(); for(DataFlavor type : types){ try{ if(type.equals(DataFlavor.javaFileListFlavor)){ e.acceptDrag(DnDConstants.ACTION_COPY); Iterator iterator = ((List) transferable.getTransferData(type)).iterator(); File file = (File) iterator.next(); if(isFileAcceptable(file)){ e.acceptDrag(1); }else{ e.rejectDrag(); } } }catch (Exception e1){ e1.printStackTrace(); } } }
Example 2
Source File: AbstractTreeTransferHandler.java From binnavi with Apache License 2.0 | 6 votes |
@Override public final void dragEnter(final DropTargetDragEvent dtde) { final Point pt = dtde.getLocation(); final int action = dtde.getDropAction(); if (drawImage) { paintImage(pt); } final Transferable transferable = dtde.getTransferable(); if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) { if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(), action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } else { if (canPerformAction(tree, draggedNode, action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } }
Example 3
Source File: AbstractTreeTransferHandler.java From binnavi with Apache License 2.0 | 6 votes |
@Override public final void dragOver(final DropTargetDragEvent dtde) { final Point pt = dtde.getLocation(); final int action = dtde.getDropAction(); tree.autoscroll(pt); if (drawImage) { paintImage(pt); } final Transferable transferable = dtde.getTransferable(); if (!transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)) { if (canPerformAction(tree, dtde.getCurrentDataFlavorsAsList().get(0), dtde.getTransferable(), action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } else { if (canPerformAction(tree, draggedNode, action, pt)) { dtde.acceptDrag(action); } else { dtde.rejectDrag(); } } }
Example 4
Source File: CakePHPExternalDropHandler.java From cakephp3-netbeans with Apache License 2.0 | 6 votes |
@Override public boolean canDrop(DropTargetDragEvent event) { JEditorPane editorPane = findPane(event.getDropTargetContext().getComponent()); if (editorPane == null || !isInCakePHP(editorPane)) { return false; } Transferable t = event.getTransferable(); canDrop = canDrop(t); if (!canDrop) { return false; } editorPane.setCaretPosition(getOffset(editorPane, event.getLocation())); editorPane.requestFocusInWindow(); //pity we need to call this all the time when dragging, but ExternalDropHandler don't handle dragEnter event return canDrop(event.getCurrentDataFlavors()); }
Example 5
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
private boolean isDropAcceptable(DropTargetDragEvent e) { DropTargetContext c = e.getDropTargetContext(); Transferable t = e.getTransferable(); DataFlavor[] f = t.getTransferDataFlavors(); Point pt = e.getLocation(); targetTabIndex = -1; Component o = c.getComponent(); if (o instanceof JTabbedPane) { JTabbedPane jtp = (JTabbedPane) o; for (int i = 0; i < jtp.getTabCount(); i++) { if (jtp.getBoundsAt(i).contains(pt)) { targetTabIndex = i; break; } } return targetTabIndex >= 0 && targetTabIndex != jtp.getSelectedIndex() && t.isDataFlavorSupported(f[0]); } return false; }
Example 6
Source File: GenericDNDHandler.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site * for the <code>DropTarget</code> registered with this listener. * * @param dtde the <code>DropTargetDragEvent</code> */ public void dragOver( final DropTargetDragEvent dtde ) { final Transferable transferable = dtde.getTransferable(); for ( int i = 0; i < acceptedFlavors.length; i++ ) { final DataFlavor acceptedFlavor = acceptedFlavors[ i ]; if ( transferable.isDataFlavorSupported( acceptedFlavor ) ) { // a transfer from the palette. try { transferData = transferable.getTransferData( acceptedFlavor ); position = dtde.getLocation(); flavor = acceptedFlavor; final int result = updateDragOver( dtde ); if ( result > 0 ) { dtde.acceptDrag( DnDConstants.ACTION_COPY ); } else { transferData = null; position = null; flavor = null; dtde.rejectDrag(); } break; } catch ( Exception e ) { if ( logger.isDebugEnabled() ) { logger.debug( "ReportPanel.dragOver ", e ); // NON-NLS } transferData = null; position = null; flavor = null; dtde.rejectDrag(); } } } }
Example 7
Source File: mxGraphHandler.java From blog-codes with Apache License 2.0 | 4 votes |
/** * */ public void dragEnter(DropTargetDragEvent e) { JComponent component = getDropTarget(e); TransferHandler th = component.getTransferHandler(); boolean isLocal = th instanceof mxGraphTransferHandler && ((mxGraphTransferHandler) th).isLocalDrag(); if (isLocal) { canImport = true; } else { canImport = graphComponent.isImportEnabled() && th.canImport(component, e.getCurrentDataFlavors()); } if (canImport) { transferBounds = null; setVisible(false); try { Transferable t = e.getTransferable(); if (t.isDataFlavorSupported(mxGraphTransferable.dataFlavor)) { mxGraphTransferable gt = (mxGraphTransferable) t .getTransferData(mxGraphTransferable.dataFlavor); dragCells = gt.getCells(); if (gt.getBounds() != null) { mxGraph graph = graphComponent.getGraph(); double scale = graph.getView().getScale(); transferBounds = gt.getBounds(); int w = (int) Math.ceil((transferBounds.getWidth() + 1) * scale); int h = (int) Math .ceil((transferBounds.getHeight() + 1) * scale); setPreviewBounds(new Rectangle( (int) transferBounds.getX(), (int) transferBounds.getY(), w, h)); if (imagePreview) { // Does not render fixed cells for local preview // but ignores movable state for non-local previews if (isLocal) { if (!isLivePreview()) { updateDragImage(graph .getMovableCells(dragCells)); } } else { Object[] tmp = graphComponent .getImportableCells(dragCells); updateDragImage(tmp); // Shows no drag icon if import is allowed but none // of the cells can be imported if (tmp == null || tmp.length == 0) { canImport = false; e.rejectDrag(); return; } } } setVisible(true); } } e.acceptDrag(TransferHandler.COPY_OR_MOVE); } catch (Exception ex) { // do nothing log.log(Level.SEVERE, "Failed to handle dragEnter", ex); } } else { e.rejectDrag(); } }