Exemple #1
0
 /**
  * Notify any DialogListeners of changes having occurred If a listener returns false, do not call
  * further listeners and disable the OK button and preview Checkbox (if it exists). For
  * PlugInFilters, this ensures that the PlugInFilterRunner, which listens as the last one, is not
  * called if the PlugInFilter has detected invalid parameters. Thus, unnecessary calling the
  * run(ip) method of the PlugInFilter for preview is avoided in that case.
  */
 private void notifyListeners(AWTEvent e) {
   if (dialogListeners == null) return;
   boolean everythingOk = true;
   for (int i = 0; everythingOk && i < dialogListeners.size(); i++)
     try {
       resetCounters();
       if (!((DialogListener) dialogListeners.elementAt(i)).dialogItemChanged(this, e))
         everythingOk = false;
     } // disable further listeners if false (invalid parameters) returned
     catch (Exception err) { // for exceptions, don't cover the input by a window but
       IJ.beep(); // show them at in the "Log"
       IJ.log(
           "ERROR: "
               + err
               + "\nin DialogListener of "
               + dialogListeners.elementAt(i)
               + "\nat "
               + (err.getStackTrace()[0])
               + "\nfrom "
               + (err.getStackTrace()[1])); // requires Java 1.4
     }
   boolean workaroundOSXbug = IJ.isMacOSX() && okay != null && !okay.isEnabled() && everythingOk;
   if (previewCheckbox != null) previewCheckbox.setEnabled(everythingOk);
   if (okay != null) okay.setEnabled(everythingOk);
   if (workaroundOSXbug) repaint(); // OSX 10.4 bug delays update of enabled until the next input
 }
  /** CONSTRUCTOR */
  public CruiseControl(boolean waitallowed) {
    super();

    this.waitallowed = waitallowed;

    timeformatter = DateFormat.getDateTimeInstance();
    timeformatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    FlowLayout layout = new FlowLayout();
    this.setLayout(layout);

    l_time.setText("-- time --");
    add(l_time);

    final Checkbox c_wait = new Checkbox("wait (global scheduler)");
    c_wait.setState(true);
    c_wait.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            wait = c_wait.getState();
          }
        });
    if (!waitallowed) {
      c_wait.setEnabled(false);
      c_wait.setState(false);
      wait = false;
    }
    this.add(c_wait);

    final Checkbox c_update = new Checkbox("update");
    c_update.setState(true);
    c_update.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            update = c_update.getState();
            if (update) {
              c_wait.setState(true);
              wait = true;
            }
            // TODO @TSC What to do if update == false?
          }
        });
    this.add(c_update);

    JButton b = new JButton("go");
    b.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            synchronized (CruiseControl.this) {
              go = -1;
            }
          }
        });
    this.add(b);

    final JTextField tf = new JTextField(10);
    final Color normalColor = tf.getForeground();
    tf.getDocument()
        .addDocumentListener(
            new DocumentListener() {

              private void checkInput() {
                try {
                  Long.parseLong(tf.getText());
                  // parsed correctly
                  tf.setForeground(normalColor);
                } catch (NumberFormatException e) {
                  tf.setForeground(Color.RED);
                }
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                checkInput();
              }

              @Override
              public void insertUpdate(DocumentEvent e) {
                checkInput();
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                checkInput();
              }
            });
    this.add(tf);

    b = new JButton("go to time");
    b.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            synchronized (CruiseControl.this) {
              try {
                go = Long.parseLong(tf.getText());
              } catch (NumberFormatException e1) {
              }
              c_wait.setEnabled(true);
            }
          }
        });
    this.add(b);

    this.setPreferredSize(new Dimension(300, 200));
  }
Exemple #3
0
  /** Ensures that the options dialog has no mutually exclusive options. */
  private void verifyOptions(Object src) {
    // record GUI state

    boolean autoscaleEnabled = autoscaleBox.isEnabled();
    boolean colorModeEnabled = colorModeChoice.isEnabled();
    boolean concatenateEnabled = concatenateBox.isEnabled();
    boolean cropEnabled = cropBox.isEnabled();
    boolean groupFilesEnabled = groupFilesBox.isEnabled();
    boolean ungroupFilesEnabled = ungroupFilesBox.isEnabled();
    boolean openAllSeriesEnabled = openAllSeriesBox.isEnabled();
    // boolean recordEnabled = recordBox.isEnabled();
    boolean showMetadataEnabled = showMetadataBox.isEnabled();
    boolean showOMEXMLEnabled = showOMEXMLBox.isEnabled();
    boolean specifyRangesEnabled = specifyRangesBox.isEnabled();
    boolean splitZEnabled = splitZBox.isEnabled();
    boolean splitTEnabled = splitTBox.isEnabled();
    boolean splitCEnabled = splitCBox.isEnabled();
    // boolean stackFormatEnabled = stackFormatChoice.isEnabled();
    boolean stackOrderEnabled = stackOrderChoice.isEnabled();
    boolean swapDimsEnabled = swapDimsBox.isEnabled();
    boolean virtualEnabled = virtualBox.isEnabled();

    boolean isAutoscale = autoscaleBox.getState();
    String colorModeValue = colorModeChoice.getSelectedItem();
    boolean isConcatenate = concatenateBox.getState();
    boolean isCrop = cropBox.getState();
    boolean isGroupFiles = groupFilesBox.getState();
    boolean isUngroupFiles = ungroupFilesBox.getState();
    boolean isOpenAllSeries = openAllSeriesBox.getState();
    // boolean isRecord = recordBox.getState();
    boolean isShowMetadata = showMetadataBox.getState();
    boolean isShowOMEXML = showOMEXMLBox.getState();
    boolean isSpecifyRanges = specifyRangesBox.getState();
    boolean isSplitZ = splitZBox.getState();
    boolean isSplitT = splitTBox.getState();
    boolean isSplitC = splitCBox.getState();
    String stackFormatValue = stackFormatChoice.getSelectedItem();
    boolean isStackNone = stackFormatValue.equals(ImporterOptions.VIEW_NONE);
    boolean isStackStandard = stackFormatValue.equals(ImporterOptions.VIEW_STANDARD);
    boolean isStackHyperstack = stackFormatValue.equals(ImporterOptions.VIEW_HYPERSTACK);
    boolean isStackBrowser = stackFormatValue.equals(ImporterOptions.VIEW_BROWSER);
    boolean isStackImage5D = stackFormatValue.equals(ImporterOptions.VIEW_IMAGE_5D);
    boolean isStackView5D = stackFormatValue.equals(ImporterOptions.VIEW_VIEW_5D);
    String stackOrderValue = stackOrderChoice.getSelectedItem();
    boolean isSwap = swapDimsBox.getState();
    boolean isVirtual = virtualBox.getState();

    // toggle availability of each option based on state of earlier options

    // NB: The order the options are examined here defines their order of
    // precedence. This ordering is necessary because it affects which
    // component states are capable of graying out other components.

    // For example, we want to disable autoscaleBox when virtualBox is checked,
    // so the virtualBox logic must appear before the autoscaleBox logic.

    // To make it more intuitive for the user, the order of precedence should
    // match the component layout from left to right, top to bottom, according
    // to subsection.

    // == Stack viewing ==

    // stackOrderChoice
    stackOrderEnabled = isStackStandard;
    if (src == stackFormatChoice) {
      if (isStackHyperstack || isStackBrowser || isStackImage5D) {
        stackOrderValue = ImporterOptions.ORDER_XYCZT;
      } else if (isStackView5D) stackOrderValue = ImporterOptions.ORDER_XYZCT;
      else stackOrderValue = ImporterOptions.ORDER_DEFAULT;
    }

    // == Metadata viewing ==

    // showMetadataBox
    showMetadataEnabled = !isStackNone;
    if (!showMetadataEnabled) isShowMetadata = true;

    // showOMEXMLBox
    // NB: no other options affect showOMEXMLBox

    // == Dataset organization ==

    // groupFilesBox
    if (src == stackFormatChoice && isStackBrowser) {
      isGroupFiles = true;
    } else if (!options.isLocal()) {
      isGroupFiles = false;
      groupFilesEnabled = false;
    }

    // ungroupFilesBox

    if (options.isOMERO()) {
      isUngroupFiles = false;
      ungroupFilesEnabled = false;
    }

    // swapDimsBox
    // NB: no other options affect swapDimsBox

    // openAllSeriesBox
    // NB: no other options affect openAllSeriesBox

    // concatenateBox
    // NB: no other options affect concatenateBox

    // == Memory management ==

    // virtualBox
    virtualEnabled = !isStackNone && !isStackImage5D && !isStackView5D && !isConcatenate;
    if (!virtualEnabled) isVirtual = false;
    else if (src == stackFormatChoice && isStackBrowser) isVirtual = true;

    // recordBox
    // recordEnabled = isVirtual;
    // if (!recordEnabled) isRecord = false;

    // specifyRangesBox
    specifyRangesEnabled = !isStackNone && !isVirtual;
    if (!specifyRangesEnabled) isSpecifyRanges = false;

    // cropBox
    cropEnabled = !isStackNone && !isVirtual;
    if (!cropEnabled) isCrop = false;

    // == Color options ==

    // colorModeChoice
    colorModeEnabled = !isStackImage5D && !isStackView5D && !isStackStandard;
    if (!colorModeEnabled) colorModeValue = ImporterOptions.COLOR_MODE_DEFAULT;

    // autoscaleBox
    autoscaleEnabled = !isVirtual;
    if (!autoscaleEnabled) isAutoscale = false;

    // == Split into separate windows ==

    boolean splitEnabled = !isStackNone && !isStackBrowser && !isStackImage5D && !isStackView5D;
    // TODO: Make splitting work with Data Browser.

    // splitCBox
    splitCEnabled = splitEnabled;
    if (!splitCEnabled) isSplitC = false;

    // splitZBox
    splitZEnabled = splitEnabled;
    if (!splitZEnabled) isSplitZ = false;

    // splitTBox
    splitTEnabled = splitEnabled;
    if (!splitTEnabled) isSplitT = false;

    // update state of each option, in case anything changed

    autoscaleBox.setEnabled(autoscaleEnabled);
    colorModeChoice.setEnabled(colorModeEnabled);
    concatenateBox.setEnabled(concatenateEnabled);
    cropBox.setEnabled(cropEnabled);
    groupFilesBox.setEnabled(groupFilesEnabled);
    ungroupFilesBox.setEnabled(ungroupFilesEnabled);
    openAllSeriesBox.setEnabled(openAllSeriesEnabled);
    // recordBox.setEnabled(recordEnabled);
    showMetadataBox.setEnabled(showMetadataEnabled);
    showOMEXMLBox.setEnabled(showOMEXMLEnabled);
    specifyRangesBox.setEnabled(specifyRangesEnabled);
    splitZBox.setEnabled(splitZEnabled);
    splitTBox.setEnabled(splitTEnabled);
    splitCBox.setEnabled(splitCEnabled);
    // stackFormatChoice.setEnabled(stackFormatEnabled);
    stackOrderChoice.setEnabled(stackOrderEnabled);
    swapDimsBox.setEnabled(swapDimsEnabled);
    virtualBox.setEnabled(virtualEnabled);

    autoscaleBox.setState(isAutoscale);
    colorModeChoice.select(colorModeValue);
    concatenateBox.setState(isConcatenate);
    cropBox.setState(isCrop);
    groupFilesBox.setState(isGroupFiles);
    ungroupFilesBox.setState(isUngroupFiles);
    openAllSeriesBox.setState(isOpenAllSeries);
    // recordBox.setState(isRecord);
    showMetadataBox.setState(isShowMetadata);
    showOMEXMLBox.setState(isShowOMEXML);
    specifyRangesBox.setState(isSpecifyRanges);
    splitZBox.setState(isSplitZ);
    splitTBox.setState(isSplitT);
    splitCBox.setState(isSplitC);
    // stackFormatChoice.select(stackFormatValue);
    stackOrderChoice.select(stackOrderValue);
    swapDimsBox.setState(isSwap);
    virtualBox.setState(isVirtual);

    if (IS_GLITCHED) {
      // HACK - work around a Mac OS X bug where GUI components do not update

      // list of affected components
      Component[] c = {
        autoscaleBox,
        colorModeChoice,
        concatenateBox,
        cropBox,
        groupFilesBox,
        ungroupFilesBox,
        openAllSeriesBox,
        // recordBox,
        showMetadataBox,
        showOMEXMLBox,
        specifyRangesBox,
        splitZBox,
        splitTBox,
        splitCBox,
        stackFormatChoice,
        stackOrderChoice,
        swapDimsBox,
        virtualBox
      };

      // identify currently focused component
      Component focused = null;
      for (int i = 0; i < c.length; i++) {
        if (c[i].isFocusOwner()) focused = c[i];
      }

      // temporarily disable focus events
      for (int i = 0; i < c.length; i++) c[i].removeFocusListener(this);

      // cycle through focus on all components
      for (int i = 0; i < c.length; i++) c[i].requestFocusInWindow();

      // clear the focus globally
      KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      kfm.clearGlobalFocusOwner();
      sleep(100); // doesn't work if this value is too small

      // refocus the originally focused component
      if (focused != null) focused.requestFocusInWindow();

      // reenable focus events
      for (int i = 0; i < c.length; i++) c[i].addFocusListener(this);
    }
  }