下面列出了java.awt.dnd.DropTargetDropEvent#getLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
@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();
}
}
/**
* 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;
}
@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);
}
}
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);
}
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);
}
}
public static Point convertDropTargetDropPointTo(DropTargetDropEvent dtde, Component comp) {
Point pt = dtde.getLocation();
convertPoint(pt, dtde.getDropTargetContext().getComponent(), comp);
return pt;
}
@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();
}
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);
}
}