下面列出了javax.swing.TransferHandler#COPY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
*/
protected MouseEvent createEvent(DropTargetEvent e)
{
JComponent component = getDropTarget(e);
Point location = null;
int action = 0;
if (e instanceof DropTargetDropEvent)
{
location = ((DropTargetDropEvent) e).getLocation();
action = ((DropTargetDropEvent) e).getDropAction();
}
else if (e instanceof DropTargetDragEvent)
{
location = ((DropTargetDragEvent) e).getLocation();
action = ((DropTargetDragEvent) e).getDropAction();
}
if (location != null)
{
location = convertPoint(location);
Rectangle r = graphComponent.getViewport().getViewRect();
location.translate(r.x, r.y);
}
// LATER: Fetch state of modifier keys from event or via global
// key listener using Toolkit.getDefaultToolkit().addAWTEventListener(
// new AWTEventListener() {...}, AWTEvent.KEY_EVENT_MASK). Problem
// is the event does not contain the modifier keys and the global
// handler is not called during drag and drop.
int mod = (action == TransferHandler.COPY) ? InputEvent.CTRL_MASK : 0;
return new MouseEvent(component, 0, System.currentTimeMillis(), mod,
location.x, location.y, 1, false, MouseEvent.BUTTON1);
}
/**
* Display messages.
*
* @param destinationTreeNode the destination tree node
* @param transferredData the transferred data
* @param action the action
*/
public static void displayMessages(
NodeInterface destinationTreeNode, TransferredData transferredData, int action) {
if ((destinationTreeNode == null) || (transferredData == null)) {
return;
}
String actionString = "???";
if (action == TransferHandler.MOVE) {
actionString = "Moved";
} else if (action == TransferHandler.COPY) {
actionString = "Copied";
}
String destinationString =
destinationTreeNode.getHandler().getDestinationText(destinationTreeNode);
for (int index = 0; index < transferredData.getDataListSize(); index++) {
NodeInterface nodeToTransfer =
(NodeInterface) transferredData.getTreePath(index).getLastPathComponent();
SelectedFiles selectedFiles =
nodeToTransfer.getHandler().getSLDContents(nodeToTransfer);
for (SLDDataInterface sldData : selectedFiles.getSldData()) {
ConsoleManager.getInstance()
.information(
DataFlavourManager.class,
String.format(
"%s %s -> %s",
actionString, sldData.getLayerName(), destinationString));
}
}
}
/**
* We support copy
*/
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}
@Override
public int getSourceActions(JComponent c) {
return TransferHandler.COPY;
}