private void trackMouseEnterExit(Component targetOver, MouseEvent e) { if (e instanceof SunDropTargetEvent) { trackDropTargetEnterExit(targetOver, e); return; } int id = e.getID(); if ( id != MouseEvent.MOUSE_EXITED && id != MouseEvent.MOUSE_DRAGGED && id != LWD_MOUSE_DRAGGED_OVER && !isMouseInNativeContainer) { // any event but an exit or drag means we're in the native container isMouseInNativeContainer = true; startListeningForOtherDrags(); } else if (id == MouseEvent.MOUSE_EXITED) { isMouseInNativeContainer = false; stopListeningForOtherDrags(); } targetLastEntered = retargetMouseEnterExit(targetOver, e, targetLastEntered, isMouseInNativeContainer); }
private static int eventToCacheIndex(AWTEvent e) { switch(e.getID()) { case PaintEvent.PAINT: return PAINT; case PaintEvent.UPDATE: return UPDATE; case MouseEvent.MOUSE_MOVED: return MOVE; case MouseEvent.MOUSE_DRAGGED: // Return -1 for SunDropTargetEvent since they are usually synchronous // and we don't want to skip them by coalescing with MouseEvent or other drag events return e instanceof SunDropTargetEvent ? -1 : DRAG; default: return e instanceof PeerEvent ? PEER : -1; } }
@Override protected void processMotionMessage(SunDropTargetEvent event, boolean operationChanged) { boolean eventInsideTarget = isEventInsideTarget(event); if (event.getComponent().getDropTarget() == insideTarget) { if (!eventInsideTarget) { processExitMessage(event); return; } } else { if (eventInsideTarget) { processEnterMessage(event); } else { return; } } super.processMotionMessage(event, operationChanged); }
@Override protected void eventPosted(final SunDropTargetEvent e) { if (e.getID() != SunDropTargetEvent.MOUSE_DROPPED) { Runnable runnable = new Runnable() { @Override public void run() { e.getDispatcher().unregisterAllEvents(); } }; // NOTE: this PeerEvent must be a NORM_PRIORITY event to be // dispatched after this SunDropTargetEvent, but before the next // one, so we should pass zero flags. PeerEvent peerEvent = new PeerEvent(e.getSource(), runnable, 0); SunToolkit.executeOnEventHandlerThread(peerEvent); } }
protected void eventProcessed(SunDropTargetEvent e, int returnValue, boolean dispatcherDone) { /* The native context is the pointer to the XClientMessageEvent structure. */ long ctxt = getNativeDragContext(); /* If the event was not consumed, send a response to the source. */ try { if (ctxt != 0 && !e.isConsumed()) { Iterator dropTargetProtocols = XDragAndDropProtocols.getDropTargetProtocols(); while (dropTargetProtocols.hasNext()) { XDropTargetProtocol dropTargetProtocol = (XDropTargetProtocol)dropTargetProtocols.next(); if (dropTargetProtocol.sendResponse(ctxt, e.getID(), returnValue)) { break; } } } } finally { if (dispatcherDone && ctxt != 0) { unsafe.freeMemory(ctxt); } } }
private void trackMouseEnterExit(Component targetOver, MouseEvent e) { if (e instanceof SunDropTargetEvent) { trackDropTargetEnterExit(targetOver, e); return; } int id = e.getID(); if ( id != MouseEvent.MOUSE_EXITED && id != MouseEvent.MOUSE_DRAGGED && id != LWD_MOUSE_DRAGGED_OVER && !isMouseInNativeContainer) { // any event but an exit or drag means we're in the native container isMouseInNativeContainer = true; startListeningForOtherDrags(); } else if (id == MouseEvent.MOUSE_EXITED) { isMouseInNativeContainer = false; stopListeningForOtherDrags(); } Component tle = retargetMouseEnterExit(targetOver, e, targetLastEntered.get(), isMouseInNativeContainer); targetLastEntered = new WeakReference<>(tle); }
protected void eventProcessed(SunDropTargetEvent e, int returnValue, boolean dispatcherDone) { /* The native context is the pointer to the XClientMessageEvent structure. */ long ctxt = getNativeDragContext(); /* If the event was not consumed, send a response to the source. */ try { if (ctxt != 0 && !e.isConsumed()) { Iterator<XDropTargetProtocol> dropTargetProtocols = XDragAndDropProtocols.getDropTargetProtocols(); while (dropTargetProtocols.hasNext()) { XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next(); if (dropTargetProtocol.sendResponse(ctxt, e.getID(), returnValue)) { break; } } } } finally { if (dispatcherDone && ctxt != 0) { unsafe.freeMemory(ctxt); } } }
private boolean coalesceMouseEvent(MouseEvent e) { if (e instanceof SunDropTargetEvent) { // SunDropTargetEvent should not coalesce with MouseEvent return false; } EventQueueItem[] cache = ((Component)e.getSource()).eventCache; if (cache == null) { return false; } int index = eventToCacheIndex(e); if (index != -1 && cache[index] != null) { cache[index].event = e; return true; } return false; }