Java Code Examples for java.awt.dnd.DropTargetDropEvent#getLocation()
The following examples show how to use
java.awt.dnd.DropTargetDropEvent#getLocation() .
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: JTableRenderer.java From blog-codes with Apache License 2.0 | 6 votes |
public void drop(DropTargetDropEvent e) { if (dragSource != null) { e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Point p = e.getLocation(); int targetRow = rowAtPoint(p); Object edge = graph.insertEdge(null, null, null, dragSource.cell, JTableRenderer.this.cell, "sourceRow=" + sourceRow + ";targetRow=" + targetRow); graph.setSelectionCell(edge); // System.out.println("clearing drag source"); dragSource = null; e.dropComplete(true); } else { e.rejectDrop(); } }
Example 2
Source File: DnDTree.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override public void drop(@Nonnull final DropTargetDropEvent dtde) { if (this.dragAcceptableType) { final Point dragPoint = dtde.getLocation(); final TreePath path = getPathForLocation(dragPoint.x, dragPoint.y); if (path != null) { final Object dropTargetNode = path.getLastPathComponent(); if (dropTargetNode instanceof NodeFileOrFolder) { final NodeFileOrFolder node = (NodeFileOrFolder) dropTargetNode; if (!node.isLeaf()) { //TODO processing of file drag in tree System.out.println("Not implemented yet!"); //NOI18N } else { dtde.rejectDrop(); } } } repaint(); } }
Example 3
Source File: WidgetAction.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a drop target drop event. * @param id the event id * @param event the Swing event */ public WidgetDropTargetDropEvent (long id, DropTargetDropEvent event) { this.id = id; this.event = event; Point location = event.getLocation (); x = location.x; y = location.y; }
Example 4
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 5
Source File: CustomizedToolbar.java From pumpernickel with MIT License | 5 votes |
public void drop(DropTargetDropEvent dtde) { if (draggingComponent == null) { dtde.rejectDrop(); } else { if (draggingDefaults) { setContents(getDefaultContents()); } else { Point p = dtde.getLocation(); p = SwingUtilities.convertPoint( ((DropTarget) dtde.getSource()).getComponent(), p, CustomizedToolbar.this); String[] contents = getContents(p); setContents(contents); dtde.acceptDrop(DnDConstants.ACTION_MOVE); JComponent theComponent = getComponent(draggingComponent); Rectangle r = getLayout().getDestinationMap( CustomizedToolbar.this).get(theComponent); if (r != null) { theComponent.setBounds(r); } if (hideActiveComponents) theComponent.setVisible(true); } } dtde.dropComplete(true); }
Example 6
Source File: AbstractTreeTransferHandler.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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: UIUtilities.java From gcs with Mozilla Public License 2.0 | 4 votes |
public static Point convertDropTargetDropPointTo(DropTargetDropEvent dtde, Component comp) { Point pt = dtde.getLocation(); convertPoint(pt, dtde.getDropTargetContext().getComponent(), comp); return pt; }
Example 8
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
@Override public void drop(DropTargetDropEvent dtde) { // System.out.println("drop"); // if (!isWebStart()) { // try { // draggingObject = dtde.getTransferable().getTransferData(FLAVOR); // } catch (Exception ex) { // rejectDrag(dtde); // return; // } // } else { // draggingObject = getSelectionPath().getLastPathComponent(); // } Object draggingObject = getSelectionPath().getLastPathComponent(); Point pt = dtde.getLocation(); TreePath path = getPathForLocation(pt.x, pt.y); if (Objects.isNull(path) || !(draggingObject instanceof MutableTreeNode)) { dtde.dropComplete(false); return; } // System.out.println("drop path is " + path); MutableTreeNode draggingNode = (MutableTreeNode) draggingObject; DefaultMutableTreeNode targetNode = (DefaultMutableTreeNode) path.getLastPathComponent(); if (targetNode.equals(draggingNode)) { // Cannot move the node to the node itself dtde.dropComplete(false); return; } dtde.acceptDrop(DnDConstants.ACTION_MOVE); DefaultTreeModel model = (DefaultTreeModel) getModel(); model.removeNodeFromParent(draggingNode); TreeNode parent = targetNode.getParent(); if (parent instanceof MutableTreeNode && targetNode.isLeaf()) { model.insertNodeInto(draggingNode, (MutableTreeNode) parent, parent.getIndex(targetNode)); } else { model.insertNodeInto(draggingNode, targetNode, targetNode.getChildCount()); } dtde.dropComplete(true); dropTargetNode = null; draggedNode = null; repaint(); }
Example 9
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); } }