Пример #1
0
 /** 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;
 }
Пример #2
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;
 }
Пример #3
0
  /** 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;
  }
Пример #4
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();
      }
    }
  }