/** 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;
  }
 /** 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 itemListenerAction(IItemType itemType, AWTEvent event) {
   if (event.getID() == FocusEvent.FOCUS_LOST) {
     if (itemType == validFrom) {
       checkValidFrom();
     }
     if (itemType == validUntil) {
       checkValidUntil();
     }
   }
 }
Esempio n. 5
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);
       }
     }
   }
 }
Esempio n. 6
0
 // WARNING: it's called on the Toolkit thread!
 void preprocessPostEvent(AWTEvent event) {
   if (event instanceof WindowEvent) {
     WindowListener listener = windowListener;
     if (listener != null) {
       switch (event.getID()) {
         case WindowEvent.WINDOW_CLOSING:
           listener.windowClosing((WindowEvent) event);
           break;
         case WindowEvent.WINDOW_ICONIFIED:
           listener.windowIconified((WindowEvent) event);
           break;
       }
     }
   }
 }
Esempio n. 7
0
 public void handleEvent(AWTEvent e) {
   super.handleEvent(e);
   if (isXEmbedActive()) {
     switch (e.getID()) {
       case FocusEvent.FOCUS_GAINED:
         canvasFocusGained((FocusEvent) e);
         break;
       case FocusEvent.FOCUS_LOST:
         canvasFocusLost((FocusEvent) e);
         break;
       case KeyEvent.KEY_PRESSED:
       case KeyEvent.KEY_RELEASED:
         if (!((InputEvent) e).isConsumed()) {
           forwardKeyEvent((KeyEvent) e);
         }
         break;
     }
   }
 }
Esempio n. 8
0
  public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
    if (IJ.isMacOSX()) IJ.wait(50);
    Calibration cal = imp.getCalibration();
    width = gd.getNextNumber();
    height = gd.getNextNumber();
    xRoi = gd.getNextNumber();
    yRoi = gd.getNextNumber();
    if (stackSize > 1) iSlice = (int) gd.getNextNumber();
    oval = gd.getNextBoolean();
    square = gd.getNextBoolean();
    centered = gd.getNextBoolean();
    if (cal.scaled()) scaledUnits = gd.getNextBoolean();
    if (gd.invalidNumber() || width <= 0 || height <= 0) return false;
    //
    Vector numFields = gd.getNumericFields();
    Vector checkboxes = gd.getCheckboxes();
    boolean newWidth = false, newHeight = false, newXY = false;
    if (e != null && e.getSource() == checkboxes.get(SQUARE) && square) {
      width = 0.5 * (width + height); // make square: same width&height
      height = width;
      newWidth = true;
      newHeight = true;
    }
    if (e != null && e.getSource() == checkboxes.get(CENTERED)) {
      double shiftBy = centered ? 0.5 : -0.5; // 'centered' changed:
      xRoi += shiftBy * width; // shift x, y to keep roi the same
      yRoi += shiftBy * height;
      newXY = true;
    }
    if (square && width != height && e != null) { // in 'square' mode, synchronize width&height
      if (e.getSource() == numFields.get(WIDTH)) {
        height = width;
        newHeight = true;
      } else if (e.getSource() == numFields.get(HEIGHT)) {
        width = height;
        newWidth = true;
      }
    }
    if (e != null && cal.scaled() && e.getSource() == checkboxes.get(SCALED_UNITS)) {
      double xFactor = scaledUnits ? cal.pixelWidth : 1. / cal.pixelWidth;
      double yFactor = scaledUnits ? cal.pixelHeight : 1. / cal.pixelHeight;
      width *= xFactor; // transform everything to keep roi the same
      height *= yFactor;
      xRoi *= xFactor;
      yRoi *= yFactor;
      newWidth = true;
      newHeight = true;
      newXY = true;
    }
    int digits = (scaledUnits || (int) width != width) ? 2 : 0;
    if (newWidth) ((TextField) (numFields.get(WIDTH))).setText(IJ.d2s(width, digits));
    if (newHeight) ((TextField) (numFields.get(HEIGHT))).setText(IJ.d2s(height, digits));
    digits = (scaledUnits || (int) xRoi != xRoi || (int) yRoi != yRoi) ? 2 : 0;
    if (newXY) {
      ((TextField) (numFields.get(X_ROI))).setText(IJ.d2s(xRoi, digits));
      ((TextField) (numFields.get(Y_ROI))).setText(IJ.d2s(yRoi, digits));
    }

    if (stackSize > 1 && iSlice > 0 && iSlice <= stackSize) imp.setSlice(iSlice);
    if (!newWidth && !newHeight && !newXY) // don't draw if an update will come immediately
    drawRoi();
    return true;
  }
Esempio n. 9
0
 /**
  * Copies all private data from this event into that. Space is allocated for the copied data that
  * will be freed when the that is finalized. Upon completion, this event is not changed.
  */
 void copyPrivateDataInto(AWTEvent that) {
   that.bdata = this.bdata;
 }