Ejemplo n.º 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();
   }
 }
Ejemplo n.º 2
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();
      }
    }
  }
Ejemplo n.º 3
0
  public synchronized void startModal() {
    logger.debug("Starting modal");
    if (isVisible() && !isShowing()) {
      Component parent = this.getParent();
      while (parent != null) {
        if (!(parent.isVisible())) {
          parent.setVisible(true);
        }

        parent = parent.getParent();
      }
    }

    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 src2 = (Component) src;

            if (!(event instanceof MouseEvent)) {
              src2.dispatchEvent(event);
            } else {
              MouseEvent mouseEvent = (MouseEvent) event;

              if (isVisible()
                  && (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED
                      || mouseEvent.getID() == MouseEvent.MOUSE_CLICKED)) {
                Component target =
                    SwingUtilities.getDeepestComponentAt(
                        src2, mouseEvent.getX(), mouseEvent.getY());

                // It would be nice if we could go
                // SwingUtilities.isDescendingFrom(target, this)
                // But it dosent account for popups

                if (isChild(target)) {
                  src2.dispatchEvent(event);
                } else {
                  if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
                    // Beep
                    getToolkit().beep();
                  }
                }
              } else {
                src2.dispatchEvent(event);
              }
            }
          }
        }
      } else {
        while (isVisible()) {
          wait();
        }
      }
    } catch (InterruptedException exception) {
      logger.error("Error: ", exception);
    }
  }