Exemple #1
0
 /** Called by ImageJ when the user selects Quit. */
 public void quit() {
   quitMacro = IJ.macroRunning();
   Thread thread = new Thread(this, "Quit");
   thread.setPriority(Thread.NORM_PRIORITY);
   thread.start();
   IJ.wait(10);
 }
 byte[] getJar(String address) {
   // System.out.println("getJar: "+address);
   byte[] data;
   try {
     URL url = new URL(address);
     IJ.showStatus("Connecting to " + IJ.URL);
     URLConnection uc = url.openConnection();
     int len = uc.getContentLength();
     if (IJ.debugMode) IJ.log("Updater (url): " + address + " " + len);
     if (len <= 0) return null;
     String name = address.contains("wsr") ? "daily build (" : "ij.jar (";
     IJ.showStatus("Downloading " + name + IJ.d2s((double) len / 1048576, 1) + "MB)");
     InputStream in = uc.getInputStream();
     data = new byte[len];
     int n = 0;
     while (n < len) {
       int count = in.read(data, n, len - n);
       if (count < 0) throw new EOFException();
       n += count;
       IJ.showProgress(n, len);
     }
     in.close();
   } catch (IOException e) {
     if (IJ.debugMode) IJ.log("" + e);
     return null;
   }
   if (IJ.debugMode) IJ.wait(6000);
   return data;
 }
 protected void handlePopupMenu(MouseEvent e) {
   if (disablePopupMenu) return;
   if (IJ.debugMode) IJ.log("show popup: " + (e.isPopupTrigger() ? "true" : "false"));
   int x = e.getX();
   int y = e.getY();
   Roi roi = imp.getRoi();
   if (roi != null
       && (roi.getType() == Roi.POLYGON
           || roi.getType() == Roi.POLYLINE
           || roi.getType() == Roi.ANGLE)
       && roi.getState() == roi.CONSTRUCTING) {
     roi.handleMouseUp(x, y); // simulate double-click to finalize
     roi.handleMouseUp(x, y); // polygon or polyline selection
     return;
   }
   PopupMenu popup = Menus.getPopupMenu();
   if (popup != null) {
     add(popup);
     if (IJ.isMacOSX()) IJ.wait(10);
     popup.show(this, x, y);
   }
 }
Exemple #4
0
 public void windowActivated(WindowEvent e) {
   if (IJ.isMacintosh() && !quitting) {
     IJ.wait(10); // may be needed for Java 1.4 on OS X
     setMenuBar(Menus.getMenuBar());
   }
 }
Exemple #5
0
 /** Called by ImageJ when the user selects Quit. */
 public void quit() {
   Thread thread = new Thread(this, "Quit");
   thread.setPriority(Thread.NORM_PRIORITY);
   thread.start();
   IJ.wait(10);
 }
Exemple #6
0
 /** Displays this dialog box. */
 public void showDialog() {
   if (macro) {
     dispose();
     recorderOn = Recorder.record && Recorder.recordInMacros;
   } else {
     if (pfr != null) // prepare preview (not in macro mode): tell the PlugInFilterRunner to listen
     pfr.setDialog(this);
     Panel buttons = new Panel();
     buttons.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 0));
     cancel = new Button(cancelLabel);
     cancel.addActionListener(this);
     cancel.addKeyListener(this);
     if (yesNoCancel) {
       okLabel = yesLabel;
       no = new Button(noLabel);
       no.addActionListener(this);
       no.addKeyListener(this);
     }
     okay = new Button(okLabel);
     okay.addActionListener(this);
     okay.addKeyListener(this);
     boolean addHelp = helpURL != null;
     if (addHelp) {
       help = new Button(helpLabel);
       help.addActionListener(this);
       help.addKeyListener(this);
     }
     if (IJ.isMacintosh()) {
       if (addHelp) buttons.add(help);
       if (yesNoCancel) buttons.add(no);
       if (!hideCancelButton) buttons.add(cancel);
       buttons.add(okay);
     } else {
       buttons.add(okay);
       if (yesNoCancel) buttons.add(no);
       ;
       if (!hideCancelButton) buttons.add(cancel);
       if (addHelp) buttons.add(help);
     }
     c.gridx = 0;
     c.gridy = y;
     c.anchor = GridBagConstraints.EAST;
     c.gridwidth = 2;
     c.insets = new Insets(15, 0, 0, 0);
     grid.setConstraints(buttons, c);
     add(buttons);
     if (IJ.isMacintosh()) setResizable(false);
     pack();
     setup();
     if (centerDialog) GUI.center(this);
     setVisible(true);
     recorderOn = Recorder.record;
     IJ.wait(50); // work around for Sun/WinNT bug
   }
   /* For plugins that read their input only via dialogItemChanged, call it at least once */
   if (!wasCanceled && dialogListeners != null && dialogListeners.size() > 0) {
     resetCounters();
     ((DialogListener) dialogListeners.elementAt(0)).dialogItemChanged(this, null);
     recorderOn = false;
   }
   resetCounters();
 }
Exemple #7
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;
  }