示例#1
0
 /** see: http://www.javakey.net/4-java-gui/686df4a3d194cade.htm */
 private synchronized void startModal() {
   if (this.isVisible() && !this.isShowing()) {
     Container parent = this.getParent();
     while (parent != null) {
       if (parent.isVisible() == false) {
         parent.setVisible(true);
       }
       parent = parent.getParent();
     }
   }
   try {
     if (SwingUtilities.isEventDispatchThread()) {
       EventQueue theQueue = getToolkit().getSystemEventQueue();
       while (this.isVisible()) {
         AWTEvent event = theQueue.getNextEvent();
         Object source = event.getSource();
         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 {
           System.err.println("Unable to dispatch: " + event);
         }
       }
     } else {
       while (this.isVisible()) {
         wait();
       }
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
 void dispatchEventImpl(AWTEvent e) {
   if (newEventsOnly
       || (parent != null
           && parent instanceof MenuComponent
           && ((MenuComponent) parent).newEventsOnly)) {
     if (eventEnabled(e)) {
       processEvent(e);
     } else if (e instanceof ActionEvent && parent != null) {
       ((MenuComponent) parent)
           .dispatchEvent(
               new ActionEvent(parent, e.getID(), ((ActionEvent) e).getActionCommand()));
     }
   } else { // backward compatibility
     Event olde = e.convertToOld();
     if (olde != null) {
       postEvent(olde);
     }
   }
 }
示例#3
0
  public void setActivo(boolean val) {
    glass.setVisible(val);
    setVisible(val);
    JLayeredPane.getLayeredPaneAbove(glass).moveToFront(glass);

    if (val) {
      synchronized (syncMonitor) {
        try {
          if (SwingUtilities.isEventDispatchThread()) {
            EventQueue theQueue = getToolkit().getSystemEventQueue();
            while (isVisible()) {
              AWTEvent event = theQueue.getNextEvent();
              Object source = event.getSource();

              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 {
                System.out.println("No se puede despachar: " + event);
              }
            }
          } else {
            while (isVisible()) {
              syncMonitor.wait();
            }
          }
        } catch (InterruptedException ignored) {
          System.out.println("Excepción de interrupción: " + ignored.getMessage());
        }
      }
    } else {
      synchronized (syncMonitor) {
        setVisible(false);
        glass.setVisible(false);
        syncMonitor.notifyAll();

        eliminarDelContenedor();
      }
    }
  }
示例#4
0
  /**
   * 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.
   *
   * @exception NullPointerException If event is null.
   */
  protected void dispatchEvent(AWTEvent evt) {
    currentEvent = evt;

    if (evt instanceof InputEvent) lastWhen = ((InputEvent) evt).getWhen();
    else if (evt instanceof ActionEvent) lastWhen = ((ActionEvent) evt).getWhen();
    else if (evt instanceof InvocationEvent) lastWhen = ((InvocationEvent) evt).getWhen();

    if (evt instanceof ActiveEvent) {
      ActiveEvent active_evt = (ActiveEvent) evt;
      active_evt.dispatch();
    } else {
      Object source = evt.getSource();

      if (source instanceof Component) {
        Component srccmp = (Component) source;
        srccmp.dispatchEvent(evt);
      } else if (source instanceof MenuComponent) {
        MenuComponent srccmp = (MenuComponent) source;
        srccmp.dispatchEvent(evt);
      }
    }
  }