Java Code Examples for java.awt.ActiveEvent

The following are top voted examples for showing how to use java.awt.ActiveEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: whackpad   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 2
Project: code404   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 3
Project: rhino-jscover   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 4
Project: astor   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 5
Project: Rhino-Prov-Mod   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 6
Project: closure-compiler-old   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 7
Project: closure-compiler-copy   File: SwingGui.java   View source code 6 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 8
Project: swingspy   File: CaddyDialog.java   View source code 5 votes vote down vote up
@Override
public void setVisible(boolean visible) {
	boolean blockParent = (visible && modal);
	owner.setEnabled(!blockParent);
	owner.setFocusableWindowState(!blockParent);
	super.setVisible(visible);

	if (blockParent) {
		owner.addWindowListener(parentWindowListener);
		try {
			if (SwingUtilities.isEventDispatchThread()) {
				EventQueue theQueue = getToolkit().getSystemEventQueue();
				while (isVisible()) {
					AWTEvent event = theQueue.getNextEvent();
					Object src = event.getSource();
					if (event instanceof ActiveEvent) {
						((ActiveEvent) event).dispatch();
					} else if (src instanceof Component) {
						((Component) src).dispatchEvent(event);
					}
				}
			} else {
				synchronized (getTreeLock()) {
					while (isVisible()) {
						try {
							getTreeLock().wait();
						} catch (InterruptedException e) {
							break;
						}
					}
				}
			}
		}
		catch (Exception ex) {
			ex.printStackTrace();
		}
	} else {
		owner.removeWindowListener(parentWindowListener);
		// added 2 lines
		owner.setEnabled(true);
		owner.setFocusableWindowState(true);
	}
}
 
Example 9
Project: manifold-ij   File: ModalEventQueue.java   View source code 5 votes vote down vote up
public void dispatchEvent( AWTEvent event )
{
  Object src = event.getSource();
  if( event instanceof ActiveEvent )
  {
    ((ActiveEvent)event).dispatch();
  }
  else if( src instanceof Component )
  {
    ((Component)src).dispatchEvent( event );
  }
  else if( src instanceof MenuComponent )
  {
    ((MenuComponent)src).dispatchEvent( event );
  }
}
 
Example 10
Project: minimal-j   File: SwingInternalFrame.java   View source code 5 votes vote down vote up
private void showModal() {
	EventQueue theQueue = getToolkit().getSystemEventQueue();
	while (isVisible()) {
		AWTEvent event = null;
		try {
			event = theQueue.getNextEvent();
		} catch (InterruptedException x) {
			LOG.warning(x.getLocalizedMessage());
			continue;
		}
		Object source = event.getSource();

		if (event instanceof MouseEvent) {
			MouseEvent e = (MouseEvent) event;
			MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
			if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) {
				continue;
			}
		}

		if (event instanceof ActiveEvent) {
			((ActiveEvent) event).dispatch();
		} else if (source instanceof Component) {
			((Component) source).dispatchEvent(event);
		} else if (source instanceof MenuComponent) {
			((MenuComponent) source).dispatchEvent(event);
		} else {
			LOG.warning("Not dispatched: " + event);
		}
	}
}
 
Example 11
Project: minimal-j   File: EditablePanel.java   View source code 5 votes vote down vote up
public void lock() {
	lockCount++;
	setCursorRecursive(this, Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	EventQueue theQueue = getToolkit().getSystemEventQueue();
	while (lockCount > 0) {
		AWTEvent event = null;
		try {
			event = theQueue.getNextEvent();
		} catch (InterruptedException x) {
			LOG.warning(x.getLocalizedMessage());
			continue;
		}
		Object source = event.getSource();

		if (event instanceof MouseEvent) {
			continue;
		}

		if (event instanceof ActiveEvent) {
			((ActiveEvent) event).dispatch();
		} else if (source instanceof Component) {
			((Component) source).dispatchEvent(event);
		} else if (source instanceof MenuComponent) {
			((MenuComponent) source).dispatchEvent(event);
		} else {
			LOG.warning("Not dispatched: " + event);
		}
	}
	setCursorRecursive(this, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
 
Example 12
Project: S3F   File: SwingGui.java   View source code 5 votes vote down vote up
/**
 * Processes the next GUI event.
 */
public void dispatchNextGuiEvent() throws InterruptedException {
    EventQueue queue = awtEventQueue;
    if (queue == null) {
        queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        awtEventQueue = queue;
    }
    AWTEvent event = queue.getNextEvent();
    if (event instanceof ActiveEvent) {
        ((ActiveEvent)event).dispatch();
    } else {
        Object source = event.getSource();
        if (source instanceof Component) {
            Component comp = (Component)source;
            comp.dispatchEvent(event);
        } else if (source instanceof MenuComponent) {
            ((MenuComponent)source).dispatchEvent(event);
        }
    }
}
 
Example 13
Project: javify   File: JOptionPane.java   View source code 4 votes vote down vote up
/**
 * This helper method makes the JInternalFrame wait until it is notified by
 * an InternalFrameClosing event. This method also adds the given
 * JOptionPane to the JInternalFrame and sizes it according to the
 * JInternalFrame's preferred size.
 *
 * @param f The JInternalFrame to make modal.
 */
private static void startModal(JInternalFrame f)
{
  // We need to add an additional glasspane-like component directly
  // below the frame, which intercepts all mouse events that are not
  // directed at the frame itself.
  JPanel modalInterceptor = new JPanel();
  modalInterceptor.setOpaque(false);
  JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f);
  lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue());
  modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight());
  modalInterceptor.addMouseListener(new MouseAdapter(){});
  modalInterceptor.addMouseMotionListener(new MouseMotionAdapter(){});
  lp.add(modalInterceptor);
  f.toFront();

  // We need to explicitly dispatch events when we are blocking the event
  // dispatch thread.
  EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
  try
    {
      while (! f.isClosed())
        {
          if (EventQueue.isDispatchThread())
            {
              // The getNextEventMethod() issues wait() when no
              // event is available, so we don't need do explicitly wait().
              AWTEvent ev = queue.getNextEvent();
              // This mimics EventQueue.dispatchEvent(). We can't use
              // EventQueue.dispatchEvent() directly, because it is
              // protected, unfortunately.
              if (ev instanceof ActiveEvent)
                ((ActiveEvent) ev).dispatch();
              else if (ev.getSource() instanceof Component)
                ((Component) ev.getSource()).dispatchEvent(ev);
              else if (ev.getSource() instanceof MenuComponent)
                ((MenuComponent) ev.getSource()).dispatchEvent(ev);
              // Other events are ignored as per spec in
              // EventQueue.dispatchEvent
            }
          else
            {
              // Give other threads a chance to become active.
              Thread.yield();
            }
        }
    }
  catch (InterruptedException ex)
    {
      // If we get interrupted, then leave the modal state.
    }
  finally
    {
      // Clean up the modal interceptor.
      lp.remove(modalInterceptor);

      // Remove the internal frame from its parent, so it is no longer
      // lurking around and clogging memory.
      Container parent = f.getParent();
      if (parent != null)
        parent.remove(f);
    }
}
 
Example 14
Project: jvm-stm   File: JOptionPane.java   View source code 4 votes vote down vote up
/**
 * This helper method makes the JInternalFrame wait until it is notified by
 * an InternalFrameClosing event. This method also adds the given
 * JOptionPane to the JInternalFrame and sizes it according to the
 * JInternalFrame's preferred size.
 *
 * @param f The JInternalFrame to make modal.
 */
private static void startModal(JInternalFrame f)
{
  // We need to add an additional glasspane-like component directly
  // below the frame, which intercepts all mouse events that are not
  // directed at the frame itself.
  JPanel modalInterceptor = new JPanel();
  modalInterceptor.setOpaque(false);
  JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f);
  lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue());
  modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight());
  modalInterceptor.addMouseListener(new MouseAdapter(){});
  modalInterceptor.addMouseMotionListener(new MouseMotionAdapter(){});
  lp.add(modalInterceptor);
  f.toFront();

  // We need to explicitly dispatch events when we are blocking the event
  // dispatch thread.
  EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
  try
    {
      while (! f.isClosed())
        {
          if (EventQueue.isDispatchThread())
            {
              // The getNextEventMethod() issues wait() when no
              // event is available, so we don't need do explicitly wait().
              AWTEvent ev = queue.getNextEvent();
              // This mimics EventQueue.dispatchEvent(). We can't use
              // EventQueue.dispatchEvent() directly, because it is
              // protected, unfortunately.
              if (ev instanceof ActiveEvent)
                ((ActiveEvent) ev).dispatch();
              else if (ev.getSource() instanceof Component)
                ((Component) ev.getSource()).dispatchEvent(ev);
              else if (ev.getSource() instanceof MenuComponent)
                ((MenuComponent) ev.getSource()).dispatchEvent(ev);
              // Other events are ignored as per spec in
              // EventQueue.dispatchEvent
            }
          else
            {
              // Give other threads a chance to become active.
              Thread.yield();
            }
        }
    }
  catch (InterruptedException ex)
    {
      // If we get interrupted, then leave the modal state.
    }
  finally
    {
      // Clean up the modal interceptor.
      lp.remove(modalInterceptor);

      // Remove the internal frame from its parent, so it is no longer
      // lurking around and clogging memory.
      Container parent = f.getParent();
      if (parent != null)
        parent.remove(f);
    }
}
 
Example 15
Project: VarJ   File: EventQueue.java   View source code 4 votes vote down vote up
/**
 * Dispatches an event. The manner in which the event is
 * dispatched depends upon the type of the event and the
 * type of the event's source object:
 * <p> </p>
 * <table border=1 summary="Event types, source types, and dispatch methods">
 * <tr>
 *     <th>Event Type</th>
 *     <th>Source Type</th> 
 *     <th>Dispatched To</th>
 * </tr>
 * <tr>
 *     <td>ActiveEvent</td>
 *     <td>Any</td>
 *     <td>event.dispatch()</td>
 * </tr>
 * <tr>
 *     <td>Other</td>
 *     <td>Component</td>
 *     <td>source.dispatchEvent(AWTEvent)</td>
 * </tr>
 * <tr>
 *     <td>Other</td>
 *     <td>MenuComponent</td>
 *     <td>source.dispatchEvent(AWTEvent)</td>
 * </tr>
 * <tr>
 *     <td>Other</td>
 *     <td>Other</td>
 *     <td>No action (ignored)</td>
 * </tr>
 * </table>
 * <p> </p>
 * @param event an instance of <code>java.awt.AWTEvent</code>,
 * 		or a subclass of it
 * @throws NullPointerException if <code>event</code> is <code>null</code>
 * @since           1.2
 */
protected void dispatchEvent(AWTEvent event) {
    event.isPosted = true;
    Object src = event.getSource();
    if (event instanceof ActiveEvent) {
        // This could become the sole method of dispatching in time.
        setCurrentEventAndMostRecentTimeImpl(event);

        ((ActiveEvent)event).dispatch();
    } else if (src instanceof Component) {
        ((Component)src).dispatchEvent(event);
        event.dispatched();
    } else if (src instanceof MenuComponent) {
        ((MenuComponent)src).dispatchEvent(event);
    } else if (src instanceof TrayIcon) {
        ((TrayIcon)src).dispatchEvent(event);
    } else if (src instanceof AWTAutoShutdown) {
        if (noEvents()) {
            dispatchThread.stopDispatching();
        }
    } else {
        System.err.println("unable to dispatch event: " + event);
    }
}
 
Example 16
Project: JamVM-PH   File: JOptionPane.java   View source code 4 votes vote down vote up
/**
 * This helper method makes the JInternalFrame wait until it is notified by
 * an InternalFrameClosing event. This method also adds the given
 * JOptionPane to the JInternalFrame and sizes it according to the
 * JInternalFrame's preferred size.
 *
 * @param f The JInternalFrame to make modal.
 */
private static void startModal(JInternalFrame f)
{
  // We need to add an additional glasspane-like component directly
  // below the frame, which intercepts all mouse events that are not
  // directed at the frame itself.
  JPanel modalInterceptor = new JPanel();
  modalInterceptor.setOpaque(false);
  JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f);
  lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue());
  modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight());
  modalInterceptor.addMouseListener(new MouseAdapter(){});
  modalInterceptor.addMouseMotionListener(new MouseMotionAdapter(){});
  lp.add(modalInterceptor);
  f.toFront();

  // We need to explicitly dispatch events when we are blocking the event
  // dispatch thread.
  EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
  try
    {
      while (! f.isClosed())
        {
          if (EventQueue.isDispatchThread())
            {
              // The getNextEventMethod() issues wait() when no
              // event is available, so we don't need do explicitly wait().
              AWTEvent ev = queue.getNextEvent();
              // This mimics EventQueue.dispatchEvent(). We can't use
              // EventQueue.dispatchEvent() directly, because it is
              // protected, unfortunately.
              if (ev instanceof ActiveEvent)
                ((ActiveEvent) ev).dispatch();
              else if (ev.getSource() instanceof Component)
                ((Component) ev.getSource()).dispatchEvent(ev);
              else if (ev.getSource() instanceof MenuComponent)
                ((MenuComponent) ev.getSource()).dispatchEvent(ev);
              // Other events are ignored as per spec in
              // EventQueue.dispatchEvent
            }
          else
            {
              // Give other threads a chance to become active.
              Thread.yield();
            }
        }
    }
  catch (InterruptedException ex)
    {
      // If we get interrupted, then leave the modal state.
    }
  finally
    {
      // Clean up the modal interceptor.
      lp.remove(modalInterceptor);

      // Remove the internal frame from its parent, so it is no longer
      // lurking around and clogging memory.
      Container parent = f.getParent();
      if (parent != null)
        parent.remove(f);
    }
}
 
Example 17
Project: classpath   File: JOptionPane.java   View source code 4 votes vote down vote up
/**
 * This helper method makes the JInternalFrame wait until it is notified by
 * an InternalFrameClosing event. This method also adds the given
 * JOptionPane to the JInternalFrame and sizes it according to the
 * JInternalFrame's preferred size.
 *
 * @param f The JInternalFrame to make modal.
 */
private static void startModal(JInternalFrame f)
{
  // We need to add an additional glasspane-like component directly
  // below the frame, which intercepts all mouse events that are not
  // directed at the frame itself.
  JPanel modalInterceptor = new JPanel();
  modalInterceptor.setOpaque(false);
  JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f);
  lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue());
  modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight());
  modalInterceptor.addMouseListener(new MouseAdapter(){});
  modalInterceptor.addMouseMotionListener(new MouseMotionAdapter(){});
  lp.add(modalInterceptor);
  f.toFront();

  // We need to explicitly dispatch events when we are blocking the event
  // dispatch thread.
  EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
  try
    {
      while (! f.isClosed())
        {
          if (EventQueue.isDispatchThread())
            {
              // The getNextEventMethod() issues wait() when no
              // event is available, so we don't need do explicitly wait().
              AWTEvent ev = queue.getNextEvent();
              // This mimics EventQueue.dispatchEvent(). We can't use
              // EventQueue.dispatchEvent() directly, because it is
              // protected, unfortunately.
              if (ev instanceof ActiveEvent)
                ((ActiveEvent) ev).dispatch();
              else if (ev.getSource() instanceof Component)
                ((Component) ev.getSource()).dispatchEvent(ev);
              else if (ev.getSource() instanceof MenuComponent)
                ((MenuComponent) ev.getSource()).dispatchEvent(ev);
              // Other events are ignored as per spec in
              // EventQueue.dispatchEvent
            }
          else
            {
              // Give other threads a chance to become active.
              Thread.yield();
            }
        }
    }
  catch (InterruptedException ex)
    {
      // If we get interrupted, then leave the modal state.
    }
  finally
    {
      // Clean up the modal interceptor.
      lp.remove(modalInterceptor);

      // Remove the internal frame from its parent, so it is no longer
      // lurking around and clogging memory.
      Container parent = f.getParent();
      if (parent != null)
        parent.remove(f);
    }
}
 
Example 18
Project: SOEN6471-FreeCol   File: FreeColDialog.java   View source code 4 votes vote down vote up
/**
 * Returns the <code>response</code> when set by
 * <code>setResponse(Object response)</code>.
 * Waits the thread until then.
 *
 * @return The object as set by {@link #setResponse}.
 */
public synchronized T getResponse() {
    // Wait the thread until 'response' is available. Notice that
    // we have to process the events manually if the current
    // thread is the Event Dispatch Thread (EDT).

    try {
        if (SwingUtilities.isEventDispatchThread()) {
            EventQueue theQueue = getToolkit().getSystemEventQueue();

            while (!responseGiven) {
                // This is essentially the body of EventDispatchThread
                AWTEvent event = theQueue.getNextEvent();
                Object src = event.getSource();

                try {
                    // We cannot call theQueue.dispatchEvent, so I
                    // pasted its body here:
                    if (event instanceof ActiveEvent) {
                        ((ActiveEvent) event).dispatch();
                    } else if (src instanceof Component) {
                        ((Component) src).dispatchEvent(event);
                    } else if (src instanceof MenuComponent) {
                        ((MenuComponent) src).dispatchEvent(event);
                    } else {
                        logger.warning("unable to dispatch event: "
                            + event);
                    }
                } finally {
                    continue;
                }
            }
        } else {
            while (!responseGiven) {
                wait();
            }
        }
    } catch (InterruptedException e) {}

    T tempResponse = response;
    response = null;
    responseGiven = false;

    return tempResponse;
}