下面列出了java.awt.dnd.DnDConstants#ACTION_NONE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void doUpdateTargetWindow(long subwindow, long time) {
long clientWindow = 0;
long proxyWindow = 0;
XDragSourceProtocol protocol = null;
boolean isReceiver = false;
if (subwindow != 0) {
clientWindow = findClientWindow(subwindow);
}
if (clientWindow != 0) {
Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
while (dragProtocols.hasNext()) {
XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
if (dragProtocol.attachTargetWindow(clientWindow, time)) {
protocol = dragProtocol;
break;
}
}
}
/* Update the global state. */
dragProtocol = protocol;
targetAction = DnDConstants.ACTION_NONE;
targetRootSubwindow = subwindow;
}
/**
* determine the drop action from the event
*/
protected int mapDragOperationFromModifiers(MouseEvent e) {
int mods = e.getModifiersEx();
int btns = mods & ButtonMask;
// Prohibit multi-button drags.
if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
btns == InputEvent.BUTTON2_DOWN_MASK ||
btns == InputEvent.BUTTON3_DOWN_MASK)) {
return DnDConstants.ACTION_NONE;
}
return
SunDragSourceContextPeer.convertModifiersToDropAction(mods,
getSourceActions());
}
public void handleDragReply(int action, int x, int y, int modifiers) {
if (action == DnDConstants.ACTION_NONE &&
targetAction != DnDConstants.ACTION_NONE) {
dragExit(x, y);
} else if (action != DnDConstants.ACTION_NONE) {
int type = 0;
if (targetAction == DnDConstants.ACTION_NONE) {
type = SunDragSourceContextPeer.DISPATCH_ENTER;
} else {
type = SunDragSourceContextPeer.DISPATCH_MOTION;
}
// Note that we use the modifiers state a
postDragSourceDragEvent(action, modifiers, x, y, type);
}
targetAction = action;
}
private void doUpdateTargetWindow(long subwindow, long time) {
long clientWindow = 0;
long proxyWindow = 0;
XDragSourceProtocol protocol = null;
boolean isReceiver = false;
if (subwindow != 0) {
clientWindow = findClientWindow(subwindow);
}
if (clientWindow != 0) {
Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
while (dragProtocols.hasNext()) {
XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
if (dragProtocol.attachTargetWindow(clientWindow, time)) {
protocol = dragProtocol;
break;
}
}
}
/* Update the global state. */
dragProtocol = protocol;
targetAction = DnDConstants.ACTION_NONE;
targetRootSubwindow = subwindow;
}
private void doUpdateTargetWindow(long subwindow, long time) {
long clientWindow = 0;
long proxyWindow = 0;
XDragSourceProtocol protocol = null;
boolean isReceiver = false;
if (subwindow != 0) {
clientWindow = findClientWindow(subwindow);
}
if (clientWindow != 0) {
Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols();
while (dragProtocols.hasNext()) {
XDragSourceProtocol dragProtocol = (XDragSourceProtocol)dragProtocols.next();
if (dragProtocol.attachTargetWindow(clientWindow, time)) {
protocol = dragProtocol;
break;
}
}
}
/* Update the global state. */
dragProtocol = protocol;
targetAction = DnDConstants.ACTION_NONE;
targetRootSubwindow = subwindow;
}
/**
* reject Drop
*/
public synchronized void rejectDrop() {
if (dropStatus != STATUS_WAIT) {
throw new InvalidDnDOperationException("invalid rejectDrop()");
}
dropStatus = STATUS_REJECT;
/*
* Fix for 4285634.
* The target rejected the drop means that it doesn't perform any
* drop action. This change is to make Solaris behavior consistent
* with Win32.
*/
currentDA = DnDConstants.ACTION_NONE;
dropComplete(false);
}
static int getJavaActionForXDnDAction(long xdndAction) {
if (xdndAction == XA_XdndActionCopy.getAtom()) {
return DnDConstants.ACTION_COPY;
} else if (xdndAction == XA_XdndActionMove.getAtom()) {
return DnDConstants.ACTION_MOVE;
} else if (xdndAction == XA_XdndActionLink.getAtom()) {
return DnDConstants.ACTION_LINK;
} else {
return DnDConstants.ACTION_NONE;
}
}
/**
* Reset the state of the object.
*/
public void cleanup() {
// Clear the reference to this protocol.
XDropTargetEventProcessor.reset();
if (targetXWindow != null) {
notifyProtocolListener(targetXWindow, 0, 0,
DnDConstants.ACTION_NONE, null,
MouseEvent.MOUSE_EXITED);
}
if (sourceWindow != 0) {
XToolkit.awtLock();
try {
XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
sourceWindowMask);
XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
} finally {
XToolkit.awtUnlock();
}
}
sourceWindow = 0;
sourceWindowMask = 0;
sourceProtocolVersion = 0;
sourceActions = DnDConstants.ACTION_NONE;
sourceFormats = null;
trackSourceActions = false;
userAction = DnDConstants.ACTION_NONE;
sourceX = 0;
sourceY = 0;
targetXWindow = null;
}
/**
* signal drop complete
*/
public synchronized void dropComplete(boolean success) {
if (dropStatus == STATUS_NONE) {
throw new InvalidDnDOperationException("No Drop pending");
}
if (currentDTC != null) currentDTC.removeNotify();
currentDT = null;
currentDTC = null;
currentT = null;
currentA = DnDConstants.ACTION_NONE;
synchronized(_globalLock) {
currentJVMLocalSourceTransferable = null;
}
dropStatus = STATUS_NONE;
dropComplete = true;
try {
doDropDone(success, currentDA, local != null);
} finally {
currentDA = DnDConstants.ACTION_NONE;
// The native context is invalid after the drop is done.
// Clear the reference to prohibit access.
nativeDragContext = 0;
}
}
/**
* Reset the state of the object.
*/
public void cleanup() {
// Clear the reference to this protocol.
XDropTargetEventProcessor.reset();
if (targetXWindow != null) {
notifyProtocolListener(targetXWindow, 0, 0,
DnDConstants.ACTION_NONE, sourceActions,
null, MouseEvent.MOUSE_EXITED);
}
if (sourceWindow != 0) {
XToolkit.awtLock();
try {
XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
XlibWrapper.XSelectInput(XToolkit.getDisplay(), sourceWindow,
sourceWindowMask);
XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
} finally {
XToolkit.awtUnlock();
}
}
sourceWindow = 0;
sourceWindowMask = 0;
sourceProtocolVersion = 0;
sourceActions = DnDConstants.ACTION_NONE;
sourceFormats = null;
sourceAtom = 0;
userAction = DnDConstants.ACTION_NONE;
sourceX = 0;
sourceY = 0;
targetXWindow = null;
topLevelLeavePostponed = false;
}
/**
* rejectDrag
*/
public synchronized void rejectDrag() {
if (currentDT == null) {
throw new InvalidDnDOperationException("No Drag pending");
}
currentDA = DnDConstants.ACTION_NONE;
dragRejected = true;
}
/**
* actual processing on EventQueue Thread
*/
protected void processEnterMessage(SunDropTargetEvent event) {
Component c = (Component)event.getSource();
DropTarget dt = c.getDropTarget();
Point hots = event.getPoint();
local = getJVMLocalSourceTransferable();
if (currentDTC != null) { // some wreckage from last time
currentDTC.removeNotify();
currentDTC = null;
}
if (c.isShowing() && dt != null && dt.isActive()) {
currentDT = dt;
currentDTC = currentDT.getDropTargetContext();
currentDTC.addNotify(this);
currentA = dt.getDefaultActions();
try {
((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
hots,
currentDA,
currentSA));
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDT = null;
currentDTC = null;
currentDA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentA = DnDConstants.ACTION_NONE;
}
}
static int getJavaActionForXDnDAction(long xdndAction) {
if (xdndAction == XA_XdndActionCopy.getAtom()) {
return DnDConstants.ACTION_COPY;
} else if (xdndAction == XA_XdndActionMove.getAtom()) {
return DnDConstants.ACTION_MOVE;
} else if (xdndAction == XA_XdndActionLink.getAtom()) {
return DnDConstants.ACTION_LINK;
} else {
return DnDConstants.ACTION_NONE;
}
}
/**
* Invoked when the mouse exits a component.
*/
@Override
public void mouseExited(MouseEvent e) {
if (!events.isEmpty()) { // gesture pending
int dragAction = mapDragOperationFromModifiers(e);
if (dragAction == DnDConstants.ACTION_NONE) {
events.clear();
}
}
}
/**
* acceptDrop
*/
public synchronized void acceptDrop(int dropOperation) {
if (dropOperation == DnDConstants.ACTION_NONE)
throw new IllegalArgumentException("invalid acceptDrop() action");
if (dropStatus == STATUS_WAIT || dropStatus == STATUS_ACCEPT) {
currentDA = currentA = mapOperation(dropOperation & currentSA);
dropStatus = STATUS_ACCEPT;
dropComplete = false;
} else {
throw new InvalidDnDOperationException("invalid acceptDrop()");
}
}
/**
* Invoked when a mouse button has been pressed on a component.
*/
public void mousePressed(MouseEvent e) {
events.clear();
if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
try {
motionThreshold = DragSource.getDragThreshold();
} catch (Exception exc) {
motionThreshold = 5;
}
appendEvent(e);
}
}
private void doUpdateTargetWindow(long subwindow, long time) {
long clientWindow = 0;
long proxyWindow = 0;
XDragSourceProtocol protocol = null;
boolean isReceiver = false;
if (subwindow != 0) {
clientWindow = findClientWindow(subwindow);
}
if (clientWindow != 0) {
Iterator<XDragSourceProtocol> dragProtocols =
XDragAndDropProtocols.getDragSourceProtocols();
while (dragProtocols.hasNext()) {
XDragSourceProtocol dragProtocol = dragProtocols.next();
if (dragProtocol.attachTargetWindow(clientWindow, time)) {
protocol = dragProtocol;
break;
}
}
}
/* Update the global state. */
dragProtocol = protocol;
targetAction = DnDConstants.ACTION_NONE;
targetRootSubwindow = subwindow;
}
/**
*
*/
protected void processExitMessage(SunDropTargetEvent event) {
Component c = (Component)event.getSource();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (dt == null) {
currentDT = null;
currentT = null;
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = null;
return;
}
if (dt != currentDT) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = dt.getDropTargetContext();
currentDTC.addNotify(this);
}
dtc = currentDTC;
if (dt.isActive()) try {
((DropTargetListener)dt).dragExit(new DropTargetEvent(dtc));
} catch (Exception e) {
e.printStackTrace();
} finally {
currentA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentDA = DnDConstants.ACTION_NONE;
currentDT = null;
currentT = null;
currentDTC.removeNotify();
currentDTC = null;
local = null;
dragRejected = false;
}
}
/**
*
*/
protected void processExitMessage(SunDropTargetEvent event) {
Component c = (Component)event.getSource();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (dt == null) {
currentDT = null;
currentT = null;
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = null;
return;
}
if (dt != currentDT) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = dt.getDropTargetContext();
currentDTC.addNotify(this);
}
dtc = currentDTC;
if (dt.isActive()) try {
((DropTargetListener)dt).dragExit(new DropTargetEvent(dtc));
} catch (Exception e) {
e.printStackTrace();
} finally {
currentA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentDA = DnDConstants.ACTION_NONE;
currentDT = null;
currentT = null;
currentDTC.removeNotify();
currentDTC = null;
local = null;
dragRejected = false;
}
}
public boolean sendResponse(long ctxt, int eventID, int action) {
XClientMessageEvent xclient = new XClientMessageEvent(ctxt);
if (xclient.get_message_type() !=
XDnDConstants.XA_XdndPosition.getAtom()) {
return false;
}
if (eventID == MouseEvent.MOUSE_EXITED) {
action = DnDConstants.ACTION_NONE;
}
XClientMessageEvent msg = new XClientMessageEvent();
try {
msg.set_type((int)XConstants.ClientMessage);
msg.set_window(xclient.get_data(0));
msg.set_format(32);
msg.set_message_type(XDnDConstants.XA_XdndStatus.getAtom());
/* target window */
msg.set_data(0, xclient.get_window());
/* flags */
long flags = 0;
if (action != DnDConstants.ACTION_NONE) {
flags |= XDnDConstants.XDND_ACCEPT_DROP_FLAG;
}
msg.set_data(1, flags);
/* specify an empty rectangle */
msg.set_data(2, 0); /* x, y */
msg.set_data(3, 0); /* w, h */
/* action accepted by the target */
msg.set_data(4, XDnDConstants.getXDnDActionForJavaAction(action));
XToolkit.awtLock();
try {
XlibWrapper.XSendEvent(XToolkit.getDisplay(),
xclient.get_data(0),
false, XConstants.NoEventMask,
msg.pData);
} finally {
XToolkit.awtUnlock();
}
} finally {
msg.dispose();
}
return true;
}