Package java.awt

Examples of java.awt.EventQueue


*/
public class EventQueueMapping_addQueueFor_Test extends EventQueueMapping_TestCase {
  @Test
  public void should_add_EventQueue() {
    mapping.addQueueFor(component);
    EventQueue storedEventQueue = queueMap.get(component).get();
    assertThat(storedEventQueue).isSameAs(eventQueue);
  }
View Full Code Here


  EventQueueMapping mapping;
  Map<Component, WeakReference<EventQueue>> queueMap;

  @Before
  public final void setUp() {
    eventQueue = new EventQueue();
    toolkit = newToolkitStub(eventQueue);
    component = new ComponentWithCustomEventQueue(toolkit);
    mapping = new EventQueueMapping();
    queueMap = mapping.queueMap;
  }
View Full Code Here

    verifyZeroInteractions(windows);
  }

  @Test
  public void shouldAddToContextIfComponentEventQueueNotEqualToSystemEventQueue() {
    when(context.storedQueueFor(window)).thenReturn(new EventQueue());
    monitor.eventDispatched(new ComponentEvent(window, WINDOW_CLOSING));
    verify(context).addContextFor(window);
  }
View Full Code Here

    queue.pop();
  }

  @Test
  public void should_not_pop_if_SystemEventQueue_is_not_same_as_queue_under_test() {
    toolkit.eventQueue(new EventQueue());
    queue.pop(); // if really pops should throw an EmptyStackException
  }
View Full Code Here

  // Post the given event to the corresponding event queue for the given component.
  void postEvent(@Nullable Component c, @Nonnull AWTEvent event) {
    // Force an update of the input state, so that we're in synch internally. Otherwise we might post more events before
    // this one gets processed and end up using stale values for those events.
    inputState.update(event);
    EventQueue eventQueue = eventQueueFor(c);
    if (eventQueue != null) {
      eventQueue.postEvent(event);
    }
    pause(settings.delayBetweenEvents());
  }
View Full Code Here

  public void close(@Nonnull Window w) {
    WindowEvent event = new WindowEvent(w, WINDOW_CLOSING);
    // If the window contains an applet, send the event on the applet's queue instead to ensure a shutdown from the
    // applet's context (assists AppletViewer cleanup).
    Component applet = findAppletDescendent(w);
    EventQueue eventQueue = windowMonitor.eventQueueFor(applet != null ? applet : w);
    checkNotNull(eventQueue).postEvent(event);
    waitForIdle();
  }
View Full Code Here

        };

        final JDesktopPane desktop = toolkit.getAwtContext().getDesktop();
        AppContext ac = SunToolkit.targetToAppContext(desktop);
        if (ac != null) {
            EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
            if (eq != null) {
                eq.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), run));
                return;
            }
        }
        //shouldn't get here
        throw new RuntimeException("Desktop event queue not found!");
View Full Code Here

                //peer frames should be created in the same app context where the desktop is
                //todo refactor this into a generic inter-appcontext invoke and wait
                AppContext ac = SunToolkit.targetToAppContext(target);
                if (ac != null) {
                    EventQueue eq = (EventQueue) ac.get(sun.awt.AppContext.EVENT_QUEUE_KEY);
                    if (eq != null) {
                        try {
                            Method met = EventQueue.class.getDeclaredMethod("initDispatchThread");
                            met.setAccessible(true);
                            met.invoke(eq);
                        } catch (Exception x) {
                            x.printStackTrace();
                        }
                    }
                }

                // invoke and wait --
                EventQueue eq = getMainEventQueue();

                if (eq == getSystemEventQueueImpl()) {
                    run.run();
                    synchronized (ret) {
                        return ret[0];
                    }
                }

                try {
                    Field field = EventQueue.class.getField("dispatchThread");
                    field.setAccessible(true);
                    Thread edt = (Thread) field.get(eq);
                    if (Thread.currentThread() == edt) {
                        run.run();
                        synchronized (ret) {
                            return ret[0];
                        }
                    }
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }

                class AWTInvocationLock {
                }
                Object lock = new AWTInvocationLock();

                InvocationEvent event = new InvocationEvent(Toolkit.getDefaultToolkit(), run, lock, true);

                try {
                    synchronized (lock) {
                        eq.postEvent(event);
                        lock.wait();
                    }
                } catch (Exception x) {
                    throw new RuntimeException(x);
                }
View Full Code Here

    protected final void processEvent(AWTEvent event) {
        AppContext ac = SunToolkit.targetToAppContext(target);
        if (ac == null) {
            target.dispatchEvent(SwingToolkit.convertEvent(event, target));
        } else {
            EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
            if (eq == null) {
                target.dispatchEvent(SwingToolkit.convertEvent(event, target));
            } else {
                eq.postEvent(SwingToolkit.convertEvent(event, target));
            }
        }
    }
View Full Code Here

     * @return The event queue
     */
    protected final EventQueue getSystemEventQueueImpl() {
        AppContext ac = AppContext.getAppContext();
        if (ac != null) {
            EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
            if (eq != null) {
                return eq;
            }
        }

View Full Code Here

TOP

Related Classes of java.awt.EventQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.