FileDocCategorySizeDatePackage
EventQueueCore.javaAPI DocAndroid 1.5 API7449Wed May 06 22:41:54 BST 2009java.awt

EventQueueCore

public final class EventQueueCore extends Object
The events storage for EventQueue

Fields Summary
private final LinkedList
queueStack
private final LinkedList
events
private Toolkit
toolkit
private EventQueue
activeQueue
private Thread
dispatchThread
AWTEvent
currentEvent
long
mostRecentEventTime
Constructors Summary
EventQueueCore(EventQueue eq)

    
      
        synchronized (this) {
            queueStack.addLast(eq);
            activeQueue = eq;
        }
    
EventQueueCore(EventQueue eq, Toolkit t)

        synchronized (this) {
            queueStack.addLast(eq);
            activeQueue = eq;
            setToolkit(t);
        }
    
Methods Summary
synchronized voiddispatchEvent(java.awt.AWTEvent event)

        updateCurrentEventAndTime(event);
        try {
            activeQueue.dispatchEvent(event);
        } finally {
            currentEvent = null;
        }
    
voiddispatchEventImpl(java.awt.AWTEvent event)

        if (event instanceof ActiveEvent) {
            updateCurrentEventAndTime(event);
            try {
                ((ActiveEvent) event).dispatch();
            } finally {
                currentEvent = null;
            }
            return;
        }

        Object src = event.getSource();

        if (src instanceof Component) {
            if (preprocessComponentEvent(event)) {
                ((Component) src).dispatchEvent(event);
            }
        } else {
            if (toolkit != null) {
                toolkit.dispatchAWTEvent(event);
            }
            if (src instanceof MenuComponent) {
                ((MenuComponent) src).dispatchEvent(event);
            }
        }
    
synchronized java.awt.EventQueuegetActiveEventQueue()

        return activeQueue;
    
synchronized java.awt.AWTEventgetCurrentEvent()

        return currentEvent;
    
synchronized longgetMostRecentEventTime()

        return mostRecentEventTime;
    
synchronized java.awt.AWTEventgetNextEvent()

        while (events.isEmpty()) {
            wait();
        }
        AWTEvent event = events.removeFirst();
        // TODO: add event coalescing
        return event;
    
synchronized java.awt.AWTEventgetNextEventNoWait()

        try {
            return events.isEmpty() ? null : activeQueue.getNextEvent();
        } catch (InterruptedException e) {
            return null;
        }
    
synchronized booleanisEmpty()

        return (currentEvent == null) && events.isEmpty();
    
synchronized booleanisEmpty(long timeout)

        if (!isEmpty()) {
            return false;
        }
        try {
            wait(timeout);
        } catch (InterruptedException e) {}
        return isEmpty();
    
synchronized booleanisSystemEventQueue()

        return toolkit != null;
    
voidnotifyEventMonitor(java.awt.Toolkit t)

        Object em = t.getNativeEventQueue().getEventMonitor();
        synchronized (em) {
            em.notifyAll();
        }
    
synchronized java.awt.AWTEventpeekEvent()

        return events.isEmpty() ? null : events.getFirst();
    
synchronized java.awt.AWTEventpeekEvent(int id)

        for (AWTEvent event : events) {
            if (event.getID() == id) {
                return event;
            }
        }
        return null;
    
synchronized voidpop()

        EventQueue removed = queueStack.removeLast();
        if (removed != activeQueue) {
            // awt.6C=Event queue stack is broken
            throw new IllegalStateException(Messages.getString("awt.6C")); //$NON-NLS-1$
        }
        activeQueue = queueStack.getLast();
        removed.setCore(null);
    
synchronized voidpostEvent(java.awt.AWTEvent event)

        //???AWT
        /*
        events.addLast(event);
        if ((toolkit == null) && (dispatchThread == null)) {
            dispatchThread = new EventQueueThread(this);
            dispatchThread.start();
        }
        // TODO: add event coalescing
        if (toolkit != null) {
            toolkit.shutdownWatchdog.setAwtQueueEmpty(false);
            if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
                notifyEventMonitor(toolkit);
            }
        }
        notifyAll();
        */
    
private final booleanpreprocessComponentEvent(java.awt.AWTEvent event)

      if (event instanceof MouseEvent) {
          return preprocessMouseEvent((MouseEvent)event);
      }
      return true;
    
private final booleanpreprocessMouseEvent(java.awt.event.MouseEvent event)

        //???AWT
        /*
      if (toolkit != null && toolkit.mouseEventPreprocessor != null) {
          toolkit.lockAWT();
          try {
              return toolkit.mouseEventPreprocessor.preprocess(event);
          } finally {
              toolkit.unlockAWT();
          }
      }
      return true;
        */
        return true;
    
synchronized voidpush(java.awt.EventQueue newEventQueue)

        // TODO: handle incorrect situations
        if (queueStack.isEmpty()) {
            // awt.6B=Queue stack is empty
            throw new IllegalStateException(Messages.getString("awt.6B")); //$NON-NLS-1$
        }
        
        queueStack.addLast(newEventQueue);
        activeQueue = newEventQueue;
        activeQueue.setCore(this);
    
private voidsetToolkit(java.awt.Toolkit t)

        toolkit = t;
        if (toolkit != null) {
            toolkit.setSystemEventQueueCore(this);
            dispatchThread = toolkit.dispatchThread;
        }
    
private voidupdateCurrentEventAndTime(java.awt.AWTEvent event)

        currentEvent = event;
        long when = 0;
        if (event instanceof ActionEvent) {
            when = ((ActionEvent) event).getWhen();
        } else if (event instanceof InputEvent) {
            when = ((InputEvent) event).getWhen();
        } else if (event instanceof InputMethodEvent) {
            when = ((InputMethodEvent) event).getWhen();
        } else if (event instanceof InvocationEvent) {
            when = ((InvocationEvent) event).getWhen();
        }
        if (when != 0) {
            mostRecentEventTime = when;
        }