Java Code Examples for java.awt.dnd.DropTargetDropEvent#getDropAction()

The following examples show how to use java.awt.dnd.DropTargetDropEvent#getDropAction() . 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: FileDropTargetListener.java    From rest-client with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: DBTableInternalFrame.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
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 3
Source File: DataObjectTransferHandler.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
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 4
Source File: JTreeUtil.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: ImportPanel.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
	for (DataFlavor dataFlover : dtde.getCurrentDataFlavors()) {
		if (dataFlover.isFlavorJavaFileListType()) {
			try {
				dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

				List<File> files = new ArrayList<>();
				for (File file : (List<File>)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor))
					if (file.exists())
						files.add(file.getAbsoluteFile());
					else
						log.warn("Failed to drop from clipboard: '" + file.getAbsolutePath() + "' is not a file.");

				if (!files.isEmpty()) {
					if (dtde.getDropAction() != DnDConstants.ACTION_COPY)
						fileListModel.clear();

					addFiles(files);
				}

				dtde.getDropTargetContext().dropComplete(true);	
			} catch (UnsupportedFlavorException | IOException e) {
				//
			}
		}
	}
}
 
Example 6
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
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(TransferableNode.NODE_FLAVOR) && canPerformAction(tree, draggedNode, action, pt)) {
                        TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
                        DefaultMutableTreeNode newParentNode = (DefaultMutableTreeNode)pathTarget.getLastPathComponent();
                        if (executeDrop(tree, node, newParentNode, action)) {
                                dtde.acceptDrop(action);
                                dtde.dropComplete(true);
                                return;                                 
                        }
                }
                dtde.rejectDrop();
                dtde.dropComplete(false);
        }
        catch (Exception e) {   
                System.out.println(e);
                dtde.rejectDrop();
                dtde.dropComplete(false);
        }
}
 
Example 7
Source File: QueryBuilderPanel.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
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);
    }
}