/**
   * Closes dialog box when the OK button is pressed, sets variables and calls algorithm.
   *
   * @param event Event that triggers function.
   */
  public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    Object source = event.getSource();

    if (command.equals("OK")) {

      if (setVariables()) {
        callAlgorithm();
      }
    } else if (command.equals("Cancel")) {
      dispose();
    } else if (command.equals("Help")) {
      // MipavUtil.showHelp("");
    } else if (source.equals(doRicianCheckBox)) {
      if (doRicianCheckBox.isSelected()) {
        labelDegree.setEnabled(true);
        textDegree.setEnabled(true);
      } else {
        labelDegree.setEnabled(false);
        textDegree.setEnabled(false);
      }
    } else { // else if (source == thresholdCheckbox)
      super.actionPerformed(event);
    }
  }
  /** Loads the default settings from Preferences to set up the dialog. */
  public void legacyLoadDefaults() {
    String defaultsString = Preferences.getDialogDefaults(getDialogName());

    if ((defaultsString != null) && (newImage != null)) {

      try {
        StringTokenizer st = new StringTokenizer(defaultsString, ",");

        textSearchWindowSide.setText("" + MipavUtil.getInt(st));
        textSimilarityWindowSide.setText("" + MipavUtil.getInt(st));
        textNoiseStandardDeviation.setText("" + MipavUtil.getFloat(st));
        textDegree.setText("" + MipavUtil.getFloat(st));
        doRician = MipavUtil.getBoolean(st);
        doRicianCheckBox.setSelected(doRician);
        textDegree.setEnabled(doRician);
        labelDegree.setEnabled(doRician);
        image25DCheckBox.setSelected(MipavUtil.getBoolean(st));

        if (MipavUtil.getBoolean(st)) {
          newImage.setSelected(true);
        } else {
          replaceImage.setSelected(true);
        }

      } catch (Exception ex) {

        // since there was a problem parsing the defaults string, start over with the original
        // defaults
        Preferences.debug("Resetting defaults for dialog: " + getDialogName());
        Preferences.removeProperty(getDialogName());
      }
    }
  }
  /**
   * Closes dialog box when the OK button is pressed and calls the algorithm.
   *
   * @param event Event that triggers function.
   */
  public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    Object source = event.getSource();

    if (command.equals("OK")) {

      if (setVariables()) {
        callAlgorithm();
      }
    } else if (command.equals("Script")) {
      callAlgorithm();
    } else if (command.equals("Cancel")) {
      dispose();
    } else if (source == blueSmoothBox) {
      if (blueSmoothBox.isSelected()) {
        interpolationLabel.setEnabled(true);
        interpolationText.setEnabled(true);
      } else {
        interpolationLabel.setEnabled(false);
        interpolationText.setEnabled(false);
      }
    } else {
      super.actionPerformed(event);
    }
  }
  /**
   * Use the GUI results to set up the variables needed to run the algorithm.
   *
   * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise.
   */
  private boolean setVariables() {
    String tmpStr;

    System.gc();

    if (replaceImage.isSelected()) {
      displayLoc = REPLACE;
    } else if (newImage.isSelected()) {
      displayLoc = NEW;
    }

    tmpStr = textSearchWindowSide.getText();

    if (testParameter(tmpStr, 5, 101)) {
      searchWindowSide = Integer.valueOf(tmpStr).intValue();
    } else {
      MipavUtil.displayError("Search window side must be between 5 and 101");
      textSearchWindowSide.requestFocus();
      textSearchWindowSide.selectAll();

      return false;
    }

    if ((searchWindowSide % 2) == 0) {
      MipavUtil.displayError("Search window side must be an odd number");
      textSearchWindowSide.requestFocus();
      textSearchWindowSide.selectAll();
      return false;
    }

    tmpStr = textSimilarityWindowSide.getText();

    if (testParameter(tmpStr, 3, 99)) {
      similarityWindowSide = Integer.valueOf(tmpStr).intValue();
    } else {
      MipavUtil.displayError("Similarity window side must be between 3 and 99");
      textSimilarityWindowSide.requestFocus();
      textSimilarityWindowSide.selectAll();

      return false;
    }

    if ((similarityWindowSide % 2) == 0) {
      MipavUtil.displayError("Similarity window side must be an odd number");
      textSimilarityWindowSide.requestFocus();
      textSimilarityWindowSide.selectAll();
      return false;
    }

    if (similarityWindowSide >= searchWindowSide) {
      MipavUtil.displayError("Similarity window side must be less than search window side");
      textSimilarityWindowSide.requestFocus();
      textSimilarityWindowSide.selectAll();
      return false;
    }

    tmpStr = textNoiseStandardDeviation.getText();

    if (testParameter(tmpStr, 0.001, 1000.0)) {
      noiseStandardDeviation = Float.valueOf(tmpStr).floatValue();
    } else {
      MipavUtil.displayError("Radius must be between 0.001 and 1000.0");
      textNoiseStandardDeviation.requestFocus();
      textNoiseStandardDeviation.selectAll();

      return false;
    }

    doRician = doRicianCheckBox.isSelected();

    if (doRician) {
      tmpStr = textDegree.getText();
      if (testParameter(tmpStr, 1.0, 10.0)) {
        degreeOfFiltering = Float.valueOf(tmpStr).floatValue();
      } else {
        MipavUtil.displayError("Degree of filtering must be between 1.0 and 10.0");
        textDegree.requestFocus();
        textDegree.selectAll();
      }
    }

    if (image.getNDims() > 2) {
      image25D = image25DCheckBox.isSelected();
    }

    return true;
  }
  /**
   * Initializes the GUI by creating the components, placing them in the dialog, and displaying
   * them.
   */
  private void init() {
    setForeground(Color.black);

    setTitle("Nonlocal Means Filter");

    JPanel mainPanel;
    mainPanel = new JPanel();
    mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    mainPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weightx = 1;
    gbc.insets = new Insets(3, 3, 3, 3);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;

    paramPanel = new JPanel(new GridBagLayout());
    paramPanel.setForeground(Color.black);
    paramPanel.setBorder(buildTitledBorder("Parameters"));
    mainPanel.add(paramPanel, gbc);

    GridBagConstraints gbc2 = new GridBagConstraints();
    gbc2.gridwidth = 1;
    gbc2.gridheight = 1;
    gbc2.anchor = GridBagConstraints.WEST;
    gbc2.weightx = 1;
    gbc2.insets = new Insets(3, 3, 3, 3);
    gbc2.gridx = 0;
    gbc2.gridy = 0;
    gbc2.fill = GridBagConstraints.HORIZONTAL;

    labelSearchWindowSide = createLabel("Search window side (odd)");

    paramPanel.add(labelSearchWindowSide, gbc2);

    gbc2.gridx = 1;
    textSearchWindowSide = createTextField("15");
    paramPanel.add(textSearchWindowSide, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    labelSimilarityWindowSide = createLabel("Similarity window side (odd) ");
    paramPanel.add(labelSimilarityWindowSide, gbc2);

    gbc2.gridx = 1;
    textSimilarityWindowSide = createTextField("7");
    paramPanel.add(textSimilarityWindowSide, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    labelNoiseStandardDeviation = createLabel("Noise standard deviation ");
    paramPanel.add(labelNoiseStandardDeviation, gbc2);

    gbc2.gridx = 1;
    textNoiseStandardDeviation = createTextField("10.0");
    paramPanel.add(textNoiseStandardDeviation, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 3;
    labelDegree = createLabel("Degree of filtering ");
    labelDegree.setEnabled(doRician);
    paramPanel.add(labelDegree, gbc2);

    gbc2.gridx = 1;
    textDegree = createTextField("1.414");
    textDegree.setEnabled(doRician);
    paramPanel.add(textDegree, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 4;
    doRicianCheckBox = new JCheckBox("Deal with Rician noise in MRI");
    doRicianCheckBox.setFont(serif12);
    doRicianCheckBox.setSelected(false);
    doRicianCheckBox.addActionListener(this);
    paramPanel.add(doRicianCheckBox, gbc2);

    if (image.getNDims() > 2) {
      gbc2.gridx = 0;
      gbc2.gridy = 5;
      gbc2.gridwidth = 2;

      image25DCheckBox = new JCheckBox("Process each slice independently (2.5D)");
      image25DCheckBox.setFont(serif12);
      paramPanel.add(image25DCheckBox, gbc2);
      image25DCheckBox.setSelected(false);
    } // if (image.getNDims > 2)

    JPanel outputOptPanel = new JPanel(new GridLayout(1, 2));
    destinationPanel = new JPanel(new BorderLayout());
    destinationPanel.setForeground(Color.black);
    destinationPanel.setBorder(buildTitledBorder("Destination"));
    outputOptPanel.add(destinationPanel);

    destinationGroup = new ButtonGroup();
    newImage = new JRadioButton("New image", true);
    newImage.setBounds(10, 16, 120, 25);
    newImage.setFont(serif12);
    destinationGroup.add(newImage);
    destinationPanel.add(newImage, BorderLayout.NORTH);

    replaceImage = new JRadioButton("Replace image", false);
    replaceImage.setFont(serif12);
    destinationGroup.add(replaceImage);
    destinationPanel.add(replaceImage, BorderLayout.CENTER);

    // Only if the image is unlocked can it be replaced.
    if (image.getLockStatus() == ModelStorageBase.UNLOCKED) {
      replaceImage.setEnabled(true);
    } else {
      replaceImage.setEnabled(false);
    }

    gbc.gridx = 0;
    gbc.gridy = 1;
    mainPanel.add(outputOptPanel, gbc);

    mainDialogPanel.add(mainPanel, BorderLayout.CENTER);
    mainDialogPanel.add(buildButtons(), BorderLayout.SOUTH);

    getContentPane().add(mainDialogPanel);

    pack();
    setResizable(true);
    // setVisible(true);

    System.gc();
  }
  /**
   * Use the GUI results to set up the variables needed to run the algorithm.
   *
   * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise.
   */
  private boolean setVariables() {
    String tmpStr;
    int i;

    int totLength = image.getExtents()[0];

    for (i = 1; i < image.getNDims(); i++) {
      totLength *= image.getExtents()[i];
    }

    tmpStr = greenMergingText.getText();
    mergingDistance = Float.parseFloat(tmpStr);
    if (mergingDistance < 0.0f) {
      MipavUtil.displayError("Merging distance cannot be less than 0");
      greenMergingText.requestFocus();
      greenMergingText.selectAll();
      return false;
    }

    tmpStr = redMinText.getText();
    redMin = Integer.parseInt(tmpStr);

    if (redMin < 1) {
      MipavUtil.displayError("red minimum must be at least 1");
      redMinText.requestFocus();
      redMinText.selectAll();

      return false;
    } else if (redMin > totLength) {
      MipavUtil.displayError("red minimum must not exceed " + totLength);
      redMinText.requestFocus();
      redMinText.selectAll();

      return false;
    }

    tmpStr = redFractionText.getText();
    redFraction = Float.parseFloat(tmpStr);

    if (redFraction <= 0.0f) {
      MipavUtil.displayError("red fraction must be greater than zero");
      redFractionText.requestFocus();
      redFractionText.selectAll();

      return false;
    } else if (redFraction > 1.0f) {
      MipavUtil.displayError("red fraction must not exceed one");
      redFractionText.requestFocus();
      redFractionText.selectAll();

      return false;
    }

    tmpStr = greenMinText.getText();
    greenMin = Integer.parseInt(tmpStr);

    if (greenMin < 1) {
      MipavUtil.displayError("green minimum must be at least 1");
      greenMinText.requestFocus();
      greenMinText.selectAll();

      return false;
    } else if (greenMin > totLength) {
      MipavUtil.displayError("green minimum must not exceed " + totLength);
      greenMinText.requestFocus();
      greenMinText.selectAll();

      return false;
    }

    tmpStr = greenFractionText.getText();
    greenFraction = Float.parseFloat(tmpStr);

    if (greenFraction <= 0.0f) {
      MipavUtil.displayError("green fraction must be greater than zero");
      greenFractionText.requestFocus();
      greenFractionText.selectAll();

      return false;
    } else if (greenFraction > 1.0f) {
      MipavUtil.displayError("green fraction must not exceed one");
      greenFractionText.requestFocus();
      greenFractionText.selectAll();

      return false;
    }

    tmpStr = blueMinText.getText();
    blueMin = Integer.parseInt(tmpStr);
    if (blueMin <= 0) {
      MipavUtil.displayError("Number of blue pixels must be greater than 0");
      blueMinText.requestFocus();
      blueMinText.selectAll();
      return false;
    } else if (blueMin > totLength) {
      MipavUtil.displayError("blue minimum must not exceed " + totLength);
      blueMinText.requestFocus();
      blueMinText.selectAll();

      return false;
    }

    if (oneButton.isSelected()) {
      greenRegionNumber = 1;
    } else if (twoButton.isSelected()) {
      greenRegionNumber = 2;
    } else if (threeButton.isSelected()) {
      greenRegionNumber = 3;
    } else {
      greenRegionNumber = 4;
    }

    twoGreenLevels = twoBox.isSelected();

    tmpStr = blueValueText.getText();
    blueBoundaryFraction = Float.parseFloat(tmpStr);
    if (blueBoundaryFraction < 0.0f) {
      MipavUtil.displayError("Blue boundary fraction cannot be less than 0.0");
      blueValueText.requestFocus();
      blueValueText.selectAll();
      return false;
    } else if (blueBoundaryFraction > 1.0f) {
      MipavUtil.displayError("Blue boundary value cannot be greater than 1.0");
      blueValueText.requestFocus();
      blueValueText.selectAll();
      return false;
    }

    blueSmooth = blueSmoothBox.isSelected();

    tmpStr = interpolationText.getText();
    interpolationDivisor = Float.parseFloat(tmpStr);
    if (interpolationDivisor <= 1.0f) {
      MipavUtil.displayError("Interpolation divisor must be greater than 1");
      interpolationText.requestFocus();
      interpolationText.selectAll();
      return false;
    }

    return true;
  } // end setVariables()
  /** Sets up the GUI (panels, buttons, etc) and displays it on the screen. */
  private void init() {
    DecimalFormat df;
    int xUnits;
    String unitStr;
    String distStr;
    setForeground(Color.black);
    setTitle("Center Distances version 2  07/14/08");

    df = new DecimalFormat("0.000E0");

    GridBagConstraints gbc = new GridBagConstraints();
    int yPos = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weightx = 1;
    gbc.insets = new Insets(3, 3, 3, 3);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = yPos++;

    JPanel mainPanel = new JPanel(new GridBagLayout());
    mainPanel.setForeground(Color.black);
    mainPanel.setBorder(buildTitledBorder("Input parameters"));

    blueMinLabel = new JLabel("Minimum number of blue pixels per nucleus");
    blueMinLabel.setForeground(Color.black);
    blueMinLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(blueMinLabel, gbc);

    blueMinText = new JTextField(5);
    if (image.getNDims() == 2) {
      blueMinText.setText("1000");
    } else {
      blueMinText.setText("20000");
    }
    blueMinText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(blueMinText, gbc);

    redMinLabel = new JLabel("Minimum red pixel count");
    redMinLabel.setForeground(Color.black);
    redMinLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(redMinLabel, gbc);

    redMinText = new JTextField(5);
    redMinText.setText("50");
    redMinText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(redMinText, gbc);

    redFractionLabel = new JLabel("Fraction of red pixels to consider");
    redFractionLabel.setForeground(Color.black);
    redFractionLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(redFractionLabel, gbc);

    redFractionText = new JTextField(5);
    redFractionText.setText("0.15");
    redFractionText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(redFractionText, gbc);

    xUnits = image.getFileInfo(0).getUnitsOfMeasure()[0];
    if (xUnits != Unit.UNKNOWN_MEASURE.getLegacyNum()) {
      unitStr = (Unit.getUnitFromLegacyNum(xUnits)).toString();
      greenMergingLabel = new JLabel("Green merging radius around peak (" + unitStr + ")");
    } else {
      greenMergingLabel = new JLabel("Green merging radius around peak");
    }
    greenMergingLabel.setForeground(Color.black);
    greenMergingLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(greenMergingLabel, gbc);

    if (image.getNDims() == 2) {
      // mergingDistance = 8.0f * image.getFileInfo(0).getResolutions()[0];
      mergingDistance = 0.0f;
    } else {
      // mergingDistance = 4.0f * image.getFileInfo(0).getResolutions()[0];
      mergingDistance = 0.0f;
    }
    distStr = df.format(mergingDistance);
    greenMergingText = new JTextField(10);
    greenMergingText.setText(distStr);
    greenMergingText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(greenMergingText, gbc);

    greenMinLabel = new JLabel("Minimum green pixel count");
    greenMinLabel.setForeground(Color.black);
    greenMinLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(greenMinLabel, gbc);

    greenMinText = new JTextField(5);
    greenMinText.setText("10");
    greenMinText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(greenMinText, gbc);

    greenFractionLabel = new JLabel("Fraction of green pixels to consider");
    greenFractionLabel.setForeground(Color.black);
    greenFractionLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(greenFractionLabel, gbc);

    greenFractionText = new JTextField(5);
    greenFractionText.setText("0.01");
    greenFractionText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(greenFractionText, gbc);

    greenRegionsLabel = new JLabel("Green regions per cell");
    greenRegionsLabel.setForeground(Color.black);
    greenRegionsLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(greenRegionsLabel, gbc);

    JPanel buttonPanel = new JPanel(new GridBagLayout());

    greenGroup = new ButtonGroup();

    oneButton = new JRadioButton("1", false);
    oneButton.setForeground(Color.black);
    oneButton.setFont(serif12);
    greenGroup.add(oneButton);
    gbc.gridx = 0;
    gbc.gridy = 0;
    buttonPanel.add(oneButton, gbc);

    twoButton = new JRadioButton("2", true);
    twoButton.setForeground(Color.black);
    twoButton.setFont(serif12);
    greenGroup.add(twoButton);
    gbc.gridx = 1;
    gbc.gridy = 0;
    buttonPanel.add(twoButton, gbc);

    threeButton = new JRadioButton("3", false);
    threeButton.setForeground(Color.black);
    threeButton.setFont(serif12);
    greenGroup.add(threeButton);
    gbc.gridx = 2;
    gbc.gridy = 0;
    buttonPanel.add(threeButton, gbc);

    fourButton = new JRadioButton("4", false);
    fourButton.setForeground(Color.black);
    fourButton.setFont(serif12);
    greenGroup.add(fourButton);
    gbc.gridx = 3;
    gbc.gridy = 0;
    buttonPanel.add(fourButton, gbc);

    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(buttonPanel, gbc);

    twoBox = new JCheckBox("Use 2 top gray levels in green segmentation", true);
    twoBox.setForeground(Color.black);
    twoBox.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos++;
    mainPanel.add(twoBox, gbc);

    blueValueLabel =
        new JLabel("Fraction of blue transition from image min to max at nucleus boundary");
    blueValueLabel.setForeground(Color.black);
    blueValueLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(blueValueLabel, gbc);

    blueValueText = new JTextField(5);
    blueValueText.setText("0.15");
    blueValueText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(blueValueText, gbc);

    blueSmoothBox = new JCheckBox("Smooth blue VOI contours with AlgorithmBSmooth", true);
    blueSmoothBox.setForeground(Color.black);
    blueSmoothBox.setFont(serif12);
    blueSmoothBox.addActionListener(this);
    gbc.gridx = 0;
    gbc.gridy = yPos++;
    mainPanel.add(blueSmoothBox, gbc);

    interpolationLabel = new JLabel("Number of interpolation points determined by divisor (> 1.0)");
    interpolationLabel.setForeground(Color.black);
    interpolationLabel.setFont(serif12);
    gbc.gridx = 0;
    gbc.gridy = yPos;
    mainPanel.add(interpolationLabel, gbc);

    interpolationText = new JTextField(5);
    interpolationText.setText("24.0");
    interpolationText.setFont(serif12);
    gbc.gridx = 1;
    gbc.gridy = yPos++;
    mainPanel.add(interpolationText, gbc);

    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(buildButtons(), BorderLayout.SOUTH);

    pack();
    setVisible(true);
    setResizable(false);
    System.gc();
  } // end init()
예제 #8
0
  /**
   * Use the GUI results to set up the variables needed to run the algorithm.
   *
   * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise.
   */
  private boolean setVariables() {
    String tmpStr;

    tmpStr = textXDim.getText();
    try {
      subXDim = Integer.parseInt(tmpStr);
    } catch (NumberFormatException e) {
      MipavUtil.displayError("New XDIM string is not a valid integer");
      textXDim.requestFocus();
      textXDim.selectAll();

      return false;
    }
    if (subXDim < 3) {
      MipavUtil.displayError("New XDIM must be at least 3");
      textXDim.requestFocus();
      textXDim.selectAll();

      return false;
    } else if (subXDim > image.getExtents()[0]) {
      MipavUtil.displayError("New XDIM cannot exceed " + image.getExtents()[0]);
      textXDim.requestFocus();
      textXDim.selectAll();

      return false;
    }

    tmpStr = textYDim.getText();
    try {
      subYDim = Integer.parseInt(tmpStr);
    } catch (NumberFormatException e) {
      MipavUtil.displayError("New YDIM string is not a valid integer");
      textYDim.requestFocus();
      textYDim.selectAll();

      return false;
    }
    if (subYDim < 3) {
      MipavUtil.displayError("New YDIM must be at least 3");
      textYDim.requestFocus();
      textYDim.selectAll();

      return false;
    } else if (subYDim > image.getExtents()[1]) {
      MipavUtil.displayError("New YDIM cannot exceed " + image.getExtents()[1]);
      textYDim.requestFocus();
      textYDim.selectAll();

      return false;
    }

    tmpStr = textNumberImages.getText();
    try {
      numberOfImagesInMosaic = Integer.parseInt(tmpStr);
    } catch (NumberFormatException e) {
      MipavUtil.displayError("New numberOfImagesInMosaic string is not a valid integer");
      textNumberImages.requestFocus();
      textNumberImages.selectAll();

      return false;
    }
    if (numberOfImagesInMosaic < 1) {
      MipavUtil.displayError("New numberOfImagesInMosaic must be at least 1");
      textNumberImages.requestFocus();
      textNumberImages.selectAll();

      return false;
    } else if (numberOfImagesInMosaic > (subXDim * subYDim)) {
      MipavUtil.displayError("New numberOfImagesInMosaic cannot exceed (newXDim) * (newYDim)");
      textNumberImages.requestFocus();
      textNumberImages.selectAll();

      return false;
    }

    displayLoc = NEW;

    return true;
  }
예제 #9
0
  /** Sets up the GUI (panels, buttons, etc) and displays it on the screen. */
  private void init() {
    if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM) {
      FileInfoDicom dicomInfo = (FileInfoDicom) image.getFileInfo(0);
      FileDicomTagTable tagTable = dicomInfo.getTagTable();
      if (tagTable.getValue("0018,1310") != null) {
        // Acquisition matrix
        FileDicomTag tag = tagTable.get(new FileDicomKey("0018,1310"));
        Object[] values = tag.getValueList();
        int valNumber = values.length;
        if ((valNumber == 4) && (values instanceof Short[])) {
          int frequencyRows = ((Short) values[0]).intValue();
          Preferences.debug("frequencyRows = " + frequencyRows + "\n");
          int frequencyColumns = ((Short) values[1]).intValue();
          Preferences.debug("frequencyColumns = " + frequencyColumns + "\n");
          int phaseRows = ((Short) values[2]).intValue();
          Preferences.debug("phaseRows = " + phaseRows + "\n");
          int phaseColumns = ((Short) values[3]).intValue();
          Preferences.debug("phaseColumns = " + phaseColumns + "\n");
          if ((frequencyRows > 0) && (phaseRows == 0)) {
            subYDim = frequencyRows;
          } else if ((frequencyRows == 0) && (phaseRows > 0)) {
            subYDim = phaseRows;
          }
          if ((frequencyColumns > 0) && (phaseColumns == 0)) {
            subXDim = frequencyColumns;
          } else if ((frequencyColumns == 0) && (phaseColumns > 0)) {
            subXDim = phaseColumns;
          }
        }
      } // if (tagTable.getValue("0018,1310") != null)
      if (tagTable.getValue("0019,100A") != null) {
        FileDicomTag tag = tagTable.get(new FileDicomKey("0019,100A"));
        Object value = tag.getValue(false);
        if (value instanceof Short) {
          numberOfImagesInMosaic = ((Short) value).intValue();
          Preferences.debug("Number of images in mosaic = " + numberOfImagesInMosaic + "\n");
        }
      } // if (tagTable.getValue("0019,100A") != null)
    } // if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM)*/
    setForeground(Color.black);
    setTitle("Mosaic To 3D Volume");

    JPanel inputPanel = new JPanel(new GridBagLayout());
    inputPanel.setForeground(Color.black);

    inputPanel.setBorder(buildTitledBorder("Image"));

    JLabel labelUse = new JLabel("Image:");
    labelUse.setForeground(Color.black);
    labelUse.setFont(serif12);

    JLabel labelImage = new JLabel(image.getImageName());
    labelImage.setForeground(Color.black);
    labelImage.setFont(serif12);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridheight = 1;
    gbc.gridwidth = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weightx = 1;
    gbc.insets = new Insets(5, 5, 5, 5);
    inputPanel.add(labelUse, gbc);
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    inputPanel.add(labelImage, gbc);

    JPanel dimensionPanel = new JPanel(new GridBagLayout());
    dimensionPanel.setForeground(Color.black);
    dimensionPanel.setBorder(buildTitledBorder("X and Y Dimensions of Result"));

    JLabel labelXDim = new JLabel("X dimension of slices");
    labelXDim.setForeground(Color.black);
    labelXDim.setFont(serif12);

    textXDim = new JTextField(10);
    if (subXDim != 0) {
      textXDim.setText(String.valueOf(subXDim));
    }
    textXDim.setFont(serif12);
    textXDim.setForeground(Color.black);

    JLabel labelYDim = new JLabel("Y dimension of slices");
    labelYDim.setForeground(Color.black);
    labelYDim.setFont(serif12);

    textYDim = new JTextField(10);
    if (subYDim != 0) {
      textYDim.setText(String.valueOf(subYDim));
    }
    textYDim.setFont(serif12);
    textYDim.setForeground(Color.black);

    JLabel labelNumberImages = new JLabel("Number of images in mosaic");
    labelNumberImages.setForeground(Color.black);
    labelNumberImages.setFont(serif12);

    textNumberImages = new JTextField(10);
    if (numberOfImagesInMosaic != 0) {
      textNumberImages.setText(String.valueOf(numberOfImagesInMosaic));
    }
    textNumberImages.setFont(serif12);
    textNumberImages.setForeground(Color.black);

    gbc.gridx = 0;
    gbc.gridy = 0;
    dimensionPanel.add(labelXDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textXDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    dimensionPanel.add(labelYDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textYDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    dimensionPanel.add(labelNumberImages, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textNumberImages, gbc);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(inputPanel, BorderLayout.NORTH);
    mainPanel.add(dimensionPanel, BorderLayout.CENTER);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(buildButtons());

    getContentPane().add(mainPanel);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    pack();
    setVisible(true);
  }