/** * 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()