Search in sources :

Example 1 with PeerEvent

use of sun.awt.PeerEvent in project jdk8u_jdk by JetBrains.

the class WDropTargetContextPeerIStream method eventPosted.

@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);
    }
}
Also used : PeerEvent(sun.awt.PeerEvent)

Example 2 with PeerEvent

use of sun.awt.PeerEvent in project jdk8u_jdk by JetBrains.

the class WaitDispatchSupport method wakeupEDT.

private void wakeupEDT() {
    if (log.isLoggable(PlatformLogger.Level.FINEST)) {
        log.finest("wakeupEDT(): EDT == " + dispatchThread);
    }
    EventQueue eq = dispatchThread.getEventQueue();
    eq.postEvent(new PeerEvent(this, wakingRunnable, PeerEvent.PRIORITY_EVENT));
}
Also used : PeerEvent(sun.awt.PeerEvent)

Example 3 with PeerEvent

use of sun.awt.PeerEvent in project jdk8u_jdk by JetBrains.

the class WaitDispatchSupport method enter.

/**
     * {@inheritDoc}
     */
@Override
public boolean enter() {
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("enter(): blockingEDT=" + keepBlockingEDT.get() + ", blockingCT=" + keepBlockingCT.get());
    }
    if (!keepBlockingEDT.compareAndSet(false, true)) {
        log.fine("The secondary loop is already running, aborting");
        return false;
    }
    try {
        if (afterExit.get()) {
            log.fine("Exit was called already, aborting");
            return false;
        }
        final Runnable run = new Runnable() {

            public void run() {
                log.fine("Starting a new event pump");
                if (filter == null) {
                    dispatchThread.pumpEvents(condition);
                } else {
                    dispatchThread.pumpEventsForFilter(condition, filter);
                }
            }
        };
        // We have two mechanisms for blocking: if we're on the
        // dispatch thread, start a new event pump; if we're
        // on any other thread, call wait() on the treelock
        Thread currentThread = Thread.currentThread();
        if (currentThread == dispatchThread) {
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
                log.finest("On dispatch thread: " + dispatchThread);
            }
            if (interval != 0) {
                if (log.isLoggable(PlatformLogger.Level.FINEST)) {
                    log.finest("scheduling the timer for " + interval + " ms");
                }
                timer.schedule(timerTask = new TimerTask() {

                    @Override
                    public void run() {
                        if (keepBlockingEDT.compareAndSet(true, false)) {
                            wakeupEDT();
                        }
                    }
                }, interval);
            }
            // Dispose SequencedEvent we are dispatching on the current
            // AppContext, to prevent us from hang - see 4531693 for details
            SequencedEvent currentSE = KeyboardFocusManager.getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
            if (currentSE != null) {
                if (log.isLoggable(PlatformLogger.Level.FINE)) {
                    log.fine("Dispose current SequencedEvent: " + currentSE);
                }
                currentSE.dispose();
            }
            // In case the exit() method is called before starting
            // new event pump it will post the waking event to EDT.
            // The event will be handled after the new event pump
            // starts. Thus, the enter() method will not hang.
            //
            // Event pump should be privileged. See 6300270.
            AccessController.doPrivileged(new PrivilegedAction<Void>() {

                public Void run() {
                    run.run();
                    return null;
                }
            });
        } else {
            if (log.isLoggable(PlatformLogger.Level.FINEST)) {
                log.finest("On non-dispatch thread: " + currentThread);
            }
            keepBlockingCT.set(true);
            synchronized (getTreeLock()) {
                if (afterExit.get())
                    return false;
                if (filter != null) {
                    dispatchThread.addEventFilter(filter);
                }
                try {
                    EventQueue eq = dispatchThread.getEventQueue();
                    eq.postEvent(new PeerEvent(this, run, PeerEvent.PRIORITY_EVENT));
                    if (interval > 0) {
                        long currTime = System.currentTimeMillis();
                        while (keepBlockingCT.get() && ((extCondition != null) ? extCondition.evaluate() : true) && (currTime + interval > System.currentTimeMillis())) {
                            getTreeLock().wait(interval);
                        }
                    } else {
                        while (keepBlockingCT.get() && ((extCondition != null) ? extCondition.evaluate() : true)) {
                            getTreeLock().wait();
                        }
                    }
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
                        log.fine("waitDone " + keepBlockingEDT.get() + " " + keepBlockingCT.get());
                    }
                } catch (InterruptedException e) {
                    if (log.isLoggable(PlatformLogger.Level.FINE)) {
                        log.fine("Exception caught while waiting: " + e);
                    }
                } finally {
                    if (filter != null) {
                        dispatchThread.removeEventFilter(filter);
                    }
                }
            }
        }
        return true;
    } finally {
        keepBlockingEDT.set(false);
        keepBlockingCT.set(false);
        afterExit.set(false);
    }
}
Also used : PeerEvent(sun.awt.PeerEvent) TimerTask(java.util.TimerTask)

Example 4 with PeerEvent

use of sun.awt.PeerEvent in project jdk8u_jdk by JetBrains.

the class SunClipboard method lostOwnershipLater.

/**
     * Clears the clipboard state (contents, owner and contents context) and
     * notifies the current owner that ownership is lost. Does nothing if the
     * argument is not <code>null</code> and is not equal to the current
     * contents context.
     *
     * @param disposedContext the AppContext that is disposed or
     *        <code>null</code> if the ownership is lost because another
     *        application acquired ownership.
     */
protected void lostOwnershipLater(final AppContext disposedContext) {
    final AppContext context = this.contentsContext;
    if (context == null) {
        return;
    }
    SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext), PeerEvent.PRIORITY_EVENT));
}
Also used : PeerEvent(sun.awt.PeerEvent) AppContext(sun.awt.AppContext)

Example 5 with PeerEvent

use of sun.awt.PeerEvent in project jdk8u_jdk by JetBrains.

the class LightweightDispatcher method startLWModal.

private void startLWModal() {
    // Store the app context on which this component is being shown.
    // Event dispatch thread of this app context will be sleeping until
    // we wake it by any event from hideAndDisposeHandler().
    modalAppContext = AppContext.getAppContext();
    // keep the KeyEvents from being dispatched
    // until the focus has been transfered
    long time = Toolkit.getEventQueue().getMostRecentKeyEventTime();
    Component predictedFocusOwner = (Component.isInstanceOf(this, "javax.swing.JInternalFrame")) ? ((javax.swing.JInternalFrame) (this)).getMostRecentFocusOwner() : null;
    if (predictedFocusOwner != null) {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().enqueueKeyEvents(time, predictedFocusOwner);
    }
    // We have two mechanisms for blocking: 1. If we're on the
    // EventDispatchThread, start a new event pump. 2. If we're
    // on any other thread, call wait() on the treelock.
    final Container nativeContainer;
    synchronized (getTreeLock()) {
        nativeContainer = getHeavyweightContainer();
        if (nativeContainer.modalComp != null) {
            this.modalComp = nativeContainer.modalComp;
            nativeContainer.modalComp = this;
            return;
        } else {
            nativeContainer.modalComp = this;
        }
    }
    Runnable pumpEventsForHierarchy = new Runnable() {

        public void run() {
            EventDispatchThread dispatchThread = (EventDispatchThread) Thread.currentThread();
            dispatchThread.pumpEventsForHierarchy(new Conditional() {

                public boolean evaluate() {
                    return ((windowClosingException == null) && (nativeContainer.modalComp != null));
                }
            }, Container.this);
        }
    };
    if (EventQueue.isDispatchThread()) {
        SequencedEvent currentSequencedEvent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
        if (currentSequencedEvent != null) {
            currentSequencedEvent.dispose();
        }
        pumpEventsForHierarchy.run();
    } else {
        synchronized (getTreeLock()) {
            Toolkit.getEventQueue().postEvent(new PeerEvent(this, pumpEventsForHierarchy, PeerEvent.PRIORITY_EVENT));
            while ((windowClosingException == null) && (nativeContainer.modalComp != null)) {
                try {
                    getTreeLock().wait();
                } catch (InterruptedException e) {
                    break;
                }
            }
        }
    }
    if (windowClosingException != null) {
        windowClosingException.fillInStackTrace();
        throw windowClosingException;
    }
    if (predictedFocusOwner != null) {
        KeyboardFocusManager.getCurrentKeyboardFocusManager().dequeueKeyEvents(time, predictedFocusOwner);
    }
}
Also used : PeerEvent(sun.awt.PeerEvent)

Aggregations

PeerEvent (sun.awt.PeerEvent)7 AppContext (sun.awt.AppContext)2 FlavorEvent (java.awt.datatransfer.FlavorEvent)1 FlavorListener (java.awt.datatransfer.FlavorListener)1 Iterator (java.util.Iterator)1 TimerTask (java.util.TimerTask)1 EventListenerAggregate (sun.awt.EventListenerAggregate)1