/** Parse clicks to cancel the recording if we get a click that's not in the JList (or ESC). */
  protected boolean parseClick(AWTEvent event) {

    if (isFinished()) {
      return false;
    }

    // FIXME add key-based activation/termination?
    boolean consumed = true;
    if (combo == null) {
      combo = getComboBox(event);
      listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
              index = combo.getSelectedIndex();
              if (!combo.isPopupVisible()) {
                combo.removeActionListener(listener);
                setFinished(true);
              }
            }
          };
      combo.addActionListener(listener);
      setStatus("Waiting for selection");
    } else if (event.getID() == KeyEvent.KEY_RELEASED
        && (((KeyEvent) event).getKeyCode() == KeyEvent.VK_SPACE
            || ((KeyEvent) event).getKeyCode() == KeyEvent.VK_ENTER)) {
      index = combo.getSelectedIndex();
      setFinished(true);
    }
    // Cancel via click somewhere else
    else if (event.getID() == MouseEvent.MOUSE_PRESSED
        && !AWT.isOnPopup((Component) event.getSource())
        && combo != getComboBox(event)) {
      setFinished(true);
      consumed = false;
    }
    // Cancel via ESC key
    else if (event.getID() == KeyEvent.KEY_RELEASED
        && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_ESCAPE) {
      setStatus("Selection canceled");
      setFinished(true);
    } else {
      Log.debug("Event ignored");
    }
    if (list == null && combo.isPopupVisible()) list = tester.findComboList(combo);

    if (isFinished()) {
      combo.removeActionListener(listener);
      listener = null;
    }

    return consumed;
  }
  private boolean dispatchMouseEvent(AWTEvent event) {
    if (event.getID() != MouseEvent.MOUSE_PRESSED) {
      return false;
    }

    if (ourShowingStep == null) {
      return false;
    }

    WizardPopup eachParent = ourShowingStep;
    final MouseEvent mouseEvent = ((MouseEvent) event);

    Point point = (Point) mouseEvent.getPoint().clone();
    SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent());

    while (true) {
      JComponent content = eachParent.getContent();
      if (content == null || !content.isShowing()) {
        getActiveRoot().cancel();
        return false;
      }

      if (eachParent.getBounds().contains(point) || !eachParent.canClose()) {
        return false;
      }

      eachParent = eachParent.getParent();
      if (eachParent == null) {
        getActiveRoot().cancel();
        return false;
      }
    }
  }
 /** Return the JComboBox for the given event, or null if none. */
 private JComboBox getComboBox(AWTEvent event) {
   Component comp = (Component) event.getSource();
   // Depends somewhat on LAF; sometimes the combo box is itself the
   // button, sometimes a panel containing the button.
   if (comp instanceof javax.swing.JButton) comp = comp.getParent();
   if (comp instanceof JComboBox) return (JComboBox) comp;
   return null;
 }
 public void eventDispatched(final AWTEvent event) {
   if (event.getID() == WindowEvent.WINDOW_ACTIVATED) {
     if (myCancelOnWindow
         && myPopup != null
         && !myPopup.isPopupWindow(((WindowEvent) event).getWindow())) {
       cancel();
     }
   } else if (event.getID() == MouseEvent.MOUSE_ENTERED) {
     if (withinPopup(event)) {
       myEverEntered = true;
     }
   } else if (event.getID() == MouseEvent.MOUSE_MOVED) {
     if (myCancelOnMouseOutCallback != null && myEverEntered && !withinPopup(event)) {
       if (myCancelOnMouseOutCallback.check((MouseEvent) event)) {
         cancel();
       }
     }
   }
 }
  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();
      }
    }
  }
Beispiel #6
0
 /**
  * Tries to find the owning window for the AWT-event's source.
  *
  * @param aEvent the AWT event to find the owning window for, may be <code>null</code>.
  * @return the owning window, or <code>null</code> if no such window could be found, or a <code>
  *     null</code> event was given.
  */
 public static final Window getOwningWindow(final AWTEvent aEvent) {
   Window owner = null;
   if (aEvent != null) {
     final Object source = aEvent.getSource();
     if (source instanceof Component) {
       owner = getOwningWindow((Component) source);
     }
   }
   return owner;
 }
 public void itemListenerAction(IItemType itemType, AWTEvent event) {
   if (event.getID() == FocusEvent.FOCUS_LOST) {
     if (itemType == validFrom) {
       checkValidFrom();
     }
     if (itemType == validUntil) {
       checkValidUntil();
     }
   }
 }
Beispiel #8
0
 @Override
 public void eventDispatched(AWTEvent event) {
   if (event.getID() == WindowEvent.WINDOW_OPENED) {
     final WindowEvent we = (WindowEvent) event;
     for (JBPopup each : JBPopupFactory.getInstance().getChildPopups(this)) {
       if (each.getContent() != null
           && SwingUtilities.isDescendingFrom(each.getContent(), we.getWindow())) {
         super.setPopupVisible(false);
       }
     }
   }
 }
    @Override
    protected void focusedComponentChanged(final Component component, final AWTEvent cause) {
      EditorWindow newWindow = null;

      if (component != null) {
        newWindow = findWindowWith(component);
      } else if (cause instanceof ContainerEvent
          && cause.getID() == ContainerEvent.COMPONENT_REMOVED) {
        // do not change current window in case of child removal as in JTable.removeEditor
        // otherwise Escape in a toolwindow will not focus editor with JTable content
        return;
      }

      setCurrentWindow(newWindow);
      setCurrentWindow(newWindow, false);
    }