< prev index next >

src/java.desktop/share/classes/java/awt/SequencedEvent.java

Print this page

        

*** 23,32 **** --- 23,34 ---- * questions. */ package java.awt; + import java.security.AccessController; + import java.security.PrivilegedAction; import java.util.LinkedList; import sun.awt.AWTAccessor; import sun.awt.AppContext; import sun.awt.SunToolkit;
*** 53,62 **** --- 55,66 ---- private final AWTEvent nested; private AppContext appContext; private boolean disposed; + private static boolean fxAppThreadIsDispatchThread; + private Thread fxCheckSequenceThread; static { AWTAccessor.setSequencedEventAccessor(new AWTAccessor.SequencedEventAccessor() { public AWTEvent getNested(AWTEvent sequencedEvent) { return ((SequencedEvent)sequencedEvent).nested; }
*** 66,75 **** --- 70,86 ---- public AWTEvent create(AWTEvent event) { return new SequencedEvent(event); } }); + AccessController.doPrivileged(new PrivilegedAction<Object>() { + public Object run() { + fxAppThreadIsDispatchThread = + "true".equals(System.getProperty("javafx.embed.singleThread")); + return null; + } + }); } /** * Constructs a new SequencedEvent which will dispatch the specified * nested event.
*** 81,90 **** --- 92,116 ---- super(nested.getSource(), ID); this.nested = nested; // All AWTEvents that are wrapped in SequencedEvents are (at // least currently) implicitly generated by the system SunToolkit.setSystemGenerated(nested); + + if (fxAppThreadIsDispatchThread) { + fxCheckSequenceThread = new Thread() { + @Override + public void run() { + while(!isFirstOrDisposed()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + break; + } + } + } + }; + } synchronized (SequencedEvent.class) { list.add(this); } }
*** 104,121 **** --- 130,163 ---- try { appContext = AppContext.getAppContext(); if (getFirst() != this) { if (EventQueue.isDispatchThread()) { + if (Thread.currentThread() instanceof EventDispatchThread) { EventDispatchThread edt = (EventDispatchThread) Thread.currentThread(); edt.pumpEvents(SentEvent.ID, new Conditional() { public boolean evaluate() { return !SequencedEvent.this.isFirstOrDisposed(); } }); } else { + if (fxAppThreadIsDispatchThread) { + fxCheckSequenceThread.start(); + try { + // check if event is dispatched or disposed + // but since this user app thread is same as + // dispatch thread in fx when run with + // javafx.embed.singleThread=true + // we do not wait infinitely to avoid deadlock + // as dispatch will ultimately be done by this thread + fxCheckSequenceThread.join(500); + } catch (InterruptedException e) { + } + } + } + } else { while(!isFirstOrDisposed()) { synchronized (SequencedEvent.class) { try { SequencedEvent.class.wait(1000); } catch (InterruptedException e) {
< prev index next >