/**
   * 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;
  }
  /** 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);
  }