1
22package ee.ut.mrz.volumest;
23
24import ij.ImagePlus;
25import ij.measure.Calibration;
26import java.awt.Color;
27import java.awt.TextField;
28import java.awt.event.ActionEvent;
29import java.awt.event.ActionListener;
30import java.awt.event.TextEvent;
31import java.awt.event.TextListener;
32import javax.swing.border.Border;
33
34
38public class SetupDialog extends java.awt.Dialog implements TextListener, ActionListener {
39
40 private Color errorBackgroundColor = Color.YELLOW;
41 private Color okBackgroundColor = Color.WHITE;
42 private Color passiveBackgroundColor = Color.LIGHT_GRAY;
43 private boolean userInputCompleted = false;
44 private double sliceThickness;
45 private int numberOfSteps;
46 private final boolean DONTCLEAR = false;
47 private final boolean CLEAR = true;
48 private double gridWidth;
49 private Calibration calibration;
50 private ImagePlus imp;
51
52
58 public SetupDialog(java.awt.Frame parent, boolean modal, String unit, ImagePlus imp) {
59 super(parent, modal);
60 initComponents();
61
62 this.imp = imp;
63
64 unitLabel1.setText(unit);
65 unitLabel2.setText(unit);
66 unitLabel3.setText(unit);
67 unitLabel4.setText(unit);
68
69 slicesToBeEstimatedButton.addActionListener(this);
70 numberOfStepButton.addActionListener(this);
71 pointsToBeCountedButton.addActionListener(this);
72 gridWidthButton.addActionListener(this);
73 quadrantAreaButton.addActionListener(this);
74
75 sliceThicknessBox.addTextListener(this);
76 slicesToBeEstimatedBox.addTextListener(this);
77 countOfSlicesWhereImageIsVisibleBox.addTextListener(this);
78 numberOfStepsBox.addTextListener(this);
79 pointsToBeCountedBox.addTextListener(this);
80 rougthVolumeEstimationBox.addTextListener(this);
81 gridWidthBox.addTextListener(this);
82 quadrantAreaBox.addTextListener(this);
83
84 slicesToBeEstimatedButton.setSelected(true);
85 actionPerformed(new ActionEvent(slicesToBeEstimatedButton, ActionEvent.ACTION_PERFORMED, ""));
86
87 pointsToBeCountedButton.setSelected(true);
88 actionPerformed(new ActionEvent(pointsToBeCountedButton, ActionEvent.ACTION_PERFORMED, ""));
89
90
91 }
92
93 void setSliceThickness(double sliceThickness) {
94 Settings.getInstance().setSliceThickness(sliceThickness);
95 sliceThicknessBox.setText(Double.toString(sliceThickness));
96 }
97
98 void setRoughVolumeEstimation(String estvol) {
99 rougthVolumeEstimationBox.setText(estvol);
00 }
01
02
07 private void initComponents() {
09 java.awt.GridBagConstraints gridBagConstraints;
10
11 numberOfStepsButtonGroup = new javax.swing.ButtonGroup();
12 gridWidthButtonGroup = new javax.swing.ButtonGroup();
13 jPanel2 = new javax.swing.JPanel();
14 label2 = new java.awt.Label();
15 sliceThicknessBox = new java.awt.TextField();
16 unitLabel1 = new java.awt.Label();
17 jPanel3 = new javax.swing.JPanel();
18 numberOfStepsPanel = new javax.swing.JPanel();
19 label4 = new java.awt.Label();
20 numberOfStepsBox = new java.awt.TextField();
21 slicesToBeEstimatedPanel = new javax.swing.JPanel();
22 label17 = new java.awt.Label();
23 slicesToBeEstimatedBox = new java.awt.TextField();
24 label18 = new java.awt.Label();
25 countOfSlicesWhereImageIsVisibleBox = new java.awt.TextField();
26 numberOfStepButton = new javax.swing.JRadioButton();
27 slicesToBeEstimatedButton = new javax.swing.JRadioButton();
28 jPanel6 = new javax.swing.JPanel();
29 gridWidthPanel = new javax.swing.JPanel();
30 label8 = new java.awt.Label();
31 gridWidthBox = new java.awt.TextField();
32 unitLabel2 = new java.awt.Label();
33 quadrantAreaPanel = new javax.swing.JPanel();
34 label19 = new java.awt.Label();
35 quadrantAreaBox = new java.awt.TextField();
36 unitLabel3 = new java.awt.Label();
37 label21 = new java.awt.Label();
38 pointsToBeCountedPanel = new javax.swing.JPanel();
39 label22 = new java.awt.Label();
40 pointsToBeCountedBox = new java.awt.TextField();
41 label23 = new java.awt.Label();
42 rougthVolumeEstimationBox = new java.awt.TextField();
43 unitLabel4 = new java.awt.Label();
44 label25 = new java.awt.Label();
45 pointsToBeCountedButton = new javax.swing.JRadioButton();
46 gridWidthButton = new javax.swing.JRadioButton();
47 quadrantAreaButton = new javax.swing.JRadioButton();
48 jPanel4 = new javax.swing.JPanel();
49 label6 = new java.awt.Label();
50 objectTypeChoice = new java.awt.Choice();
51 okButton = new java.awt.Button();
52 cancelButton = new java.awt.Button();
53 helpButton = new java.awt.Button();
54 pilotButton = new java.awt.Button();
55
56 setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
57 addWindowListener(new java.awt.event.WindowAdapter() {
58 public void windowClosing(java.awt.event.WindowEvent evt) {
59 closeDialog(evt);
60 }
61 });
62 setLayout(new java.awt.GridBagLayout());
63
64 jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
65
66 label2.setText("Slice thickness:");
67 jPanel2.add(label2);
68
69 sliceThicknessBox.setColumns(5);
70 jPanel2.add(sliceThicknessBox);
71
72 unitLabel1.setText("unit");
73 jPanel2.add(unitLabel1);
74
75 gridBagConstraints = new java.awt.GridBagConstraints();
76 gridBagConstraints.gridx = 0;
77 gridBagConstraints.gridy = 1;
78 gridBagConstraints.gridwidth = 4;
79 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
80 add(jPanel2, gridBagConstraints);
81
82 jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Number of steps"));
83 jPanel3.setLayout(new java.awt.GridBagLayout());
84
85 numberOfStepsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
86
87 label4.setText("Number of steps:");
88 numberOfStepsPanel.add(label4);
89
90 numberOfStepsBox.setColumns(5);
91 numberOfStepsPanel.add(numberOfStepsBox);
92
93 gridBagConstraints = new java.awt.GridBagConstraints();
94 gridBagConstraints.gridx = 1;
95 gridBagConstraints.gridy = 1;
96 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
97 jPanel3.add(numberOfStepsPanel, gridBagConstraints);
98
99 slicesToBeEstimatedPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
00 slicesToBeEstimatedPanel.setLayout(new java.awt.GridBagLayout());
01
02 label17.setText("slices to be estimated");
03 slicesToBeEstimatedPanel.add(label17, new java.awt.GridBagConstraints());
04
05 slicesToBeEstimatedBox.setColumns(4);
06 slicesToBeEstimatedPanel.add(slicesToBeEstimatedBox, new java.awt.GridBagConstraints());
07
08 label18.setText("count of slices where object is visible");
09 gridBagConstraints = new java.awt.GridBagConstraints();
10 gridBagConstraints.gridx = 0;
11 gridBagConstraints.gridy = 1;
12 slicesToBeEstimatedPanel.add(label18, gridBagConstraints);
13
14 countOfSlicesWhereImageIsVisibleBox.setColumns(4);
15 gridBagConstraints = new java.awt.GridBagConstraints();
16 gridBagConstraints.gridx = 1;
17 gridBagConstraints.gridy = 1;
18 slicesToBeEstimatedPanel.add(countOfSlicesWhereImageIsVisibleBox, gridBagConstraints);
19
20 gridBagConstraints = new java.awt.GridBagConstraints();
21 gridBagConstraints.gridx = 1;
22 gridBagConstraints.gridy = 0;
23 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
24 jPanel3.add(slicesToBeEstimatedPanel, gridBagConstraints);
25
26 numberOfStepsButtonGroup.add(numberOfStepButton);
27 numberOfStepButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
28 gridBagConstraints = new java.awt.GridBagConstraints();
29 gridBagConstraints.gridx = 0;
30 gridBagConstraints.gridy = 1;
31 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
32 jPanel3.add(numberOfStepButton, gridBagConstraints);
33
34 numberOfStepsButtonGroup.add(slicesToBeEstimatedButton);
35 slicesToBeEstimatedButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
36 gridBagConstraints = new java.awt.GridBagConstraints();
37 gridBagConstraints.gridx = 0;
38 gridBagConstraints.gridy = 0;
39 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
40 jPanel3.add(slicesToBeEstimatedButton, gridBagConstraints);
41
42 gridBagConstraints = new java.awt.GridBagConstraints();
43 gridBagConstraints.gridx = 0;
44 gridBagConstraints.gridy = 2;
45 gridBagConstraints.gridwidth = 4;
46 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
47 add(jPanel3, gridBagConstraints);
48
49 jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Grid width"));
50 jPanel6.setLayout(new java.awt.GridBagLayout());
51
52 gridWidthPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
53 gridWidthPanel.setLayout(new java.awt.GridBagLayout());
54
55 label8.setText("Grid width:");
56 gridBagConstraints = new java.awt.GridBagConstraints();
57 gridBagConstraints.gridx = 0;
58 gridBagConstraints.gridy = 0;
59 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
60 gridWidthPanel.add(label8, gridBagConstraints);
61
62 gridWidthBox.setColumns(8);
63 gridBagConstraints = new java.awt.GridBagConstraints();
64 gridBagConstraints.gridx = 1;
65 gridBagConstraints.gridy = 0;
66 gridWidthPanel.add(gridWidthBox, gridBagConstraints);
67
68 unitLabel2.setText("unit");
69 gridBagConstraints = new java.awt.GridBagConstraints();
70 gridBagConstraints.gridx = 2;
71 gridBagConstraints.gridy = 0;
72 gridWidthPanel.add(unitLabel2, gridBagConstraints);
73
74 gridBagConstraints = new java.awt.GridBagConstraints();
75 gridBagConstraints.gridx = 1;
76 gridBagConstraints.gridy = 1;
77 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
78 jPanel6.add(gridWidthPanel, gridBagConstraints);
79
80 quadrantAreaPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
81 quadrantAreaPanel.setLayout(new java.awt.GridBagLayout());
82
83 label19.setText("Quadrant area:");
84 quadrantAreaPanel.add(label19, new java.awt.GridBagConstraints());
85
86 quadrantAreaBox.setColumns(8);
87 quadrantAreaPanel.add(quadrantAreaBox, new java.awt.GridBagConstraints());
88
89 unitLabel3.setAlignment(java.awt.Label.RIGHT);
90 unitLabel3.setText("unit");
91 gridBagConstraints = new java.awt.GridBagConstraints();
92 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
93 quadrantAreaPanel.add(unitLabel3, gridBagConstraints);
94
95 label21.setFont(new java.awt.Font("Dialog", 0, 8));
96 label21.setText("2");
97 gridBagConstraints = new java.awt.GridBagConstraints();
98 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
99 quadrantAreaPanel.add(label21, gridBagConstraints);
00
01 gridBagConstraints = new java.awt.GridBagConstraints();
02 gridBagConstraints.gridx = 1;
03 gridBagConstraints.gridy = 2;
04 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
05 jPanel6.add(quadrantAreaPanel, gridBagConstraints);
06
07 pointsToBeCountedPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
08 pointsToBeCountedPanel.setLayout(new java.awt.GridBagLayout());
09
10 label22.setText("Points to be counted:");
11 pointsToBeCountedPanel.add(label22, new java.awt.GridBagConstraints());
12
13 pointsToBeCountedBox.setColumns(8);
14 pointsToBeCountedPanel.add(pointsToBeCountedBox, new java.awt.GridBagConstraints());
15
16 label23.setText("Rough volume estimation:");
17 gridBagConstraints = new java.awt.GridBagConstraints();
18 gridBagConstraints.gridx = 0;
19 gridBagConstraints.gridy = 1;
20 pointsToBeCountedPanel.add(label23, gridBagConstraints);
21
22 rougthVolumeEstimationBox.setColumns(8);
23 gridBagConstraints = new java.awt.GridBagConstraints();
24 gridBagConstraints.gridx = 1;
25 gridBagConstraints.gridy = 1;
26 pointsToBeCountedPanel.add(rougthVolumeEstimationBox, gridBagConstraints);
27
28 unitLabel4.setAlignment(java.awt.Label.RIGHT);
29 unitLabel4.setText("unit");
30 gridBagConstraints = new java.awt.GridBagConstraints();
31 gridBagConstraints.gridx = 2;
32 gridBagConstraints.gridy = 1;
33 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
34 pointsToBeCountedPanel.add(unitLabel4, gridBagConstraints);
35
36 label25.setFont(new java.awt.Font("Dialog", 0, 8));
37 label25.setText("3");
38 gridBagConstraints = new java.awt.GridBagConstraints();
39 gridBagConstraints.gridx = 3;
40 gridBagConstraints.gridy = 1;
41 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
42 pointsToBeCountedPanel.add(label25, gridBagConstraints);
43
44 gridBagConstraints = new java.awt.GridBagConstraints();
45 gridBagConstraints.gridx = 1;
46 gridBagConstraints.gridy = 0;
47 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
48 jPanel6.add(pointsToBeCountedPanel, gridBagConstraints);
49
50 gridWidthButtonGroup.add(pointsToBeCountedButton);
51 pointsToBeCountedButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
52 gridBagConstraints = new java.awt.GridBagConstraints();
53 gridBagConstraints.gridx = 0;
54 gridBagConstraints.gridy = 0;
55 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
56 jPanel6.add(pointsToBeCountedButton, gridBagConstraints);
57
58 gridWidthButtonGroup.add(gridWidthButton);
59 gridWidthButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
60 gridBagConstraints = new java.awt.GridBagConstraints();
61 gridBagConstraints.gridx = 0;
62 gridBagConstraints.gridy = 1;
63 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
64 jPanel6.add(gridWidthButton, gridBagConstraints);
65
66 gridWidthButtonGroup.add(quadrantAreaButton);
67 quadrantAreaButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
68 gridBagConstraints = new java.awt.GridBagConstraints();
69 gridBagConstraints.gridx = 0;
70 gridBagConstraints.gridy = 2;
71 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
72 jPanel6.add(quadrantAreaButton, gridBagConstraints);
73
74 gridBagConstraints = new java.awt.GridBagConstraints();
75 gridBagConstraints.gridx = 0;
76 gridBagConstraints.gridy = 3;
77 gridBagConstraints.gridwidth = 4;
78 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
79 add(jPanel6, gridBagConstraints);
80
81 jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
82 jPanel4.setLayout(new java.awt.GridBagLayout());
83
84 label6.setText("Object type:");
85 gridBagConstraints = new java.awt.GridBagConstraints();
86 gridBagConstraints.gridx = 0;
87 gridBagConstraints.gridy = 1;
88 gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
89 jPanel4.add(label6, gridBagConstraints);
90
91 objectTypeChoice.add( "irregular" );
92 objectTypeChoice.add( "ellipsoid like" );
93 gridBagConstraints = new java.awt.GridBagConstraints();
94 gridBagConstraints.gridx = 1;
95 gridBagConstraints.gridy = 1;
96 gridBagConstraints.gridwidth = 2;
97 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
98 gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
99 jPanel4.add(objectTypeChoice, gridBagConstraints);
00
01 gridBagConstraints = new java.awt.GridBagConstraints();
02 gridBagConstraints.gridx = 0;
03 gridBagConstraints.gridy = 5;
04 gridBagConstraints.gridwidth = 4;
05 gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
06 add(jPanel4, gridBagConstraints);
07
08 okButton.setLabel("OK");
09 okButton.addActionListener(new java.awt.event.ActionListener() {
10 public void actionPerformed(java.awt.event.ActionEvent evt) {
11 okPressed(evt);
12 }
13 });
14 gridBagConstraints = new java.awt.GridBagConstraints();
15 gridBagConstraints.gridx = 0;
16 gridBagConstraints.gridy = 6;
17 gridBagConstraints.insets = new java.awt.Insets(20, 20, 20, 20);
18 add(okButton, gridBagConstraints);
19
20 cancelButton.setLabel("Cancel");
21 cancelButton.addActionListener(new java.awt.event.ActionListener() {
22 public void actionPerformed(java.awt.event.ActionEvent evt) {
23 cancelPressed(evt);
24 }
25 });
26 gridBagConstraints = new java.awt.GridBagConstraints();
27 gridBagConstraints.gridx = 2;
28 gridBagConstraints.gridy = 6;
29 gridBagConstraints.insets = new java.awt.Insets(20, 20, 20, 20);
30 add(cancelButton, gridBagConstraints);
31
32 helpButton.setLabel("Help");
33 helpButton.addActionListener(new java.awt.event.ActionListener() {
34 public void actionPerformed(java.awt.event.ActionEvent evt) {
35 helpPressed(evt);
36 }
37 });
38 gridBagConstraints = new java.awt.GridBagConstraints();
39 gridBagConstraints.gridx = 3;
40 gridBagConstraints.gridy = 6;
41 gridBagConstraints.insets = new java.awt.Insets(20, 20, 20, 20);
42 add(helpButton, gridBagConstraints);
43
44 pilotButton.setActionCommand("pilotButton1");
45 pilotButton.setEnabled(false);
46 pilotButton.setLabel(String.format("Pilot(%-2d)", Settings.getInstance().getPilotCoefficent()));
47 pilotButton.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
48 public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
49 pilotWheelMoved(evt);
50 }
51 });
52 pilotButton.addActionListener(new java.awt.event.ActionListener() {
53 public void actionPerformed(java.awt.event.ActionEvent evt) {
54 pilotPressed(evt);
55 }
56 });
57 gridBagConstraints = new java.awt.GridBagConstraints();
58 gridBagConstraints.gridx = 1;
59 gridBagConstraints.gridy = 6;
60 add(pilotButton, gridBagConstraints);
61
62 pack();
63 } private void helpPressed(java.awt.event.ActionEvent evt) { HelpBrowser hb = new HelpBrowser("/help/setupdialoghelp.html");
66 hb.setVisible(true);
67}
69 private void okPressed(java.awt.event.ActionEvent evt) {
71 Settings settings = Settings.getInstance();
72
73 if (this.objectTypeChoice.getSelectedItem().contains("ellipsoid")) {
74 settings.setObjectType(Settings.REGULAR);
75 } else {
76 settings.setObjectType(Settings.IRREGULAR);
77 }
78
79 settings.setSliceThickness(sliceThickness);
80 settings.setNumberOfSteps(numberOfSteps);
81 settings.setGridWidth(gridWidth);
82
83 userInputCompleted = true;
84
85 closeDialog(null);
86
87 }
89 private void cancelPressed(java.awt.event.ActionEvent evt) { closeDialog(null);
91 }
93
97 public boolean isUserInputCompleted() {
98 return userInputCompleted;
99 }
00
01
02 private void closeDialog(java.awt.event.WindowEvent evt) { setVisible(false);
04 dispose();
05 }
07 private void pilotPressed(java.awt.event.ActionEvent evt) { int witdh = imp.getWidth();
09 double perpix = imp.getCalibration().pixelWidth;
10 double gridwitdh = witdh * perpix / Settings.getInstance().getPilotCoefficent();
11
12 gridWidthButton.doClick();
13
14 gridWidthBox.setText(Double.toString(gridwitdh));
15
16 }
18 private void pilotWheelMoved(java.awt.event.MouseWheelEvent evt) { if (pilotButton.isEnabled()) {
20 int pilotCoefficent = Settings.getInstance().getPilotCoefficent();
21 if (evt.getWheelRotation() < 0 && pilotCoefficent > 1) {
22 pilotCoefficent--;
23 } else if (evt.getWheelRotation() > 0 && pilotCoefficent < 100) {
24 pilotCoefficent++;
25 }
26
27 pilotButton.setLabel(String.format("Pilot (%-2d)", pilotCoefficent));
28
29 Settings.getInstance().setPilotCoefficent(pilotCoefficent);
30
31 if (gridWidthBox.isEnabled()) {
32 int witdh = imp.getWidth();
33 double perpix = imp.getCalibration().pixelWidth;
34 double gridwitdh = witdh * perpix / Settings.getInstance().getPilotCoefficent();
35 gridWidthBox.setText(Double.toString(gridwitdh));
36 }
37 }
38 }
40 private java.awt.Button cancelButton;
42 private java.awt.TextField countOfSlicesWhereImageIsVisibleBox;
43 private java.awt.TextField gridWidthBox;
44 private javax.swing.JRadioButton gridWidthButton;
45 private javax.swing.ButtonGroup gridWidthButtonGroup;
46 private javax.swing.JPanel gridWidthPanel;
47 private java.awt.Button helpButton;
48 private javax.swing.JPanel jPanel2;
49 private javax.swing.JPanel jPanel3;
50 private javax.swing.JPanel jPanel4;
51 private javax.swing.JPanel jPanel6;
52 private java.awt.Label label17;
53 private java.awt.Label label18;
54 private java.awt.Label label19;
55 private java.awt.Label label2;
56 private java.awt.Label label21;
57 private java.awt.Label label22;
58 private java.awt.Label label23;
59 private java.awt.Label label25;
60 private java.awt.Label label4;
61 private java.awt.Label label6;
62 private java.awt.Label label8;
63 private javax.swing.JRadioButton numberOfStepButton;
64 private java.awt.TextField numberOfStepsBox;
65 private javax.swing.ButtonGroup numberOfStepsButtonGroup;
66 private javax.swing.JPanel numberOfStepsPanel;
67 private java.awt.Choice objectTypeChoice;
68 private java.awt.Button okButton;
69 private java.awt.Button pilotButton;
70 private java.awt.TextField pointsToBeCountedBox;
71 private javax.swing.JRadioButton pointsToBeCountedButton;
72 private javax.swing.JPanel pointsToBeCountedPanel;
73 private java.awt.TextField quadrantAreaBox;
74 private javax.swing.JRadioButton quadrantAreaButton;
75 private javax.swing.JPanel quadrantAreaPanel;
76 private java.awt.TextField rougthVolumeEstimationBox;
77 private java.awt.TextField sliceThicknessBox;
78 private java.awt.TextField slicesToBeEstimatedBox;
79 private javax.swing.JRadioButton slicesToBeEstimatedButton;
80 private javax.swing.JPanel slicesToBeEstimatedPanel;
81 private java.awt.Label unitLabel1;
82 private java.awt.Label unitLabel2;
83 private java.awt.Label unitLabel3;
84 private java.awt.Label unitLabel4;
85
89 public void textValueChanged(TextEvent e) {
90 validateInput();
91 }
92
93
94 private void validateInput() {
95 boolean allOK = true;
96
97 try {
98 sliceThickness = Double.parseDouble(this.sliceThicknessBox.getText().replace(",", "."));
99 if (sliceThickness <= 0) {
00 throw new NumberFormatException();
01 }
02 sliceThicknessBox.setBackground(okBackgroundColor);
03 } catch (NumberFormatException numberFormatException) {
04 sliceThicknessBox.setBackground(errorBackgroundColor);
05 allOK = false;
06 }
07
08 if (slicesToBeEstimatedButton.isSelected()) {
09
10 int stbe = 0;
11 int coswoiw = 0;
12 try {
13 stbe = Integer.parseInt(slicesToBeEstimatedBox.getText());
14 if (stbe <= 0) {
15 throw new NumberFormatException();
16 }
17 slicesToBeEstimatedBox.setBackground(okBackgroundColor);
18 } catch (NumberFormatException numberFormatException) {
19 slicesToBeEstimatedBox.setBackground(errorBackgroundColor);
20 allOK = false;
21 }
22
23 try {
24 coswoiw = Integer.parseInt(countOfSlicesWhereImageIsVisibleBox.getText());
25 if (coswoiw <= 0) {
26 throw new NumberFormatException();
27 }
28 countOfSlicesWhereImageIsVisibleBox.setBackground(okBackgroundColor);
29 } catch (NumberFormatException numberFormatException) {
30 countOfSlicesWhereImageIsVisibleBox.setBackground(errorBackgroundColor);
31 allOK = false;
32 }
33
34
35 numberOfSteps = (int) Math.floor((double) coswoiw / (double) stbe);
36 if (numberOfSteps < 1) {
37 numberOfSteps = 1;
38 }
39
40 if (!numberOfStepsBox.getText().equals(Integer.toString(numberOfSteps))) {
41 numberOfStepsBox.setText(Integer.toString(numberOfSteps));
42 }
43
44
45 }
46
47 if (numberOfStepButton.isSelected()) {
48 try {
49 int nos = Integer.parseInt(numberOfStepsBox.getText());
50 if (nos <= 0) {
51 throw new NumberFormatException();
52 }
53 numberOfStepsBox.setBackground(okBackgroundColor);
54 numberOfSteps = nos;
55 } catch (NumberFormatException ex) {
56 numberOfStepsBox.setBackground(errorBackgroundColor);
57 allOK = false;
58 }
59 }
60
61 if (pointsToBeCountedButton.isSelected()) {
62 int ptbc = 0;
63 double rve = 0;
64
65 try {
66 ptbc = Integer.parseInt(this.pointsToBeCountedBox.getText());
67 if (ptbc <= 0) {
68 throw new NumberFormatException();
69 }
70 pointsToBeCountedBox.setBackground(okBackgroundColor);
71 } catch (NumberFormatException numberFormatException) {
72 pointsToBeCountedBox.setBackground(errorBackgroundColor);
73 allOK = false;
74 }
75
76 try {
77 rve = Double.parseDouble(this.rougthVolumeEstimationBox.getText().replace(",", "."));
78 if (rve <= 0) {
79 throw new NumberFormatException();
80 }
81 rougthVolumeEstimationBox.setBackground(okBackgroundColor);
82 } catch (NumberFormatException numberFormatException) {
83 rougthVolumeEstimationBox.setBackground(errorBackgroundColor);
84 allOK = false;
85 }
86
87 if (rve > 0 && ptbc > 0 && numberOfSteps > 0 && sliceThickness > 0) {
88 gridWidth = Math.sqrt(rve / ((double) ptbc * (double) numberOfSteps * sliceThickness));
89
90 String qwt = Double.toString(gridWidth);
91 if (qwt.substring(qwt.indexOf(".")).length() > 3) {
92 qwt = qwt.substring(0, qwt.indexOf(".") + 4);
93 }
94 if (!gridWidthBox.getText().equals(qwt)) {
95 gridWidthBox.setText(qwt);
96 }
97
98 double qa = Math.pow(gridWidth, 2);
99 String qat = Double.toString(qa);
00 if (qat.substring(qat.indexOf(".")).length() > 3) {
01 qat = qat.substring(0, qat.indexOf(".") + 4);
02 }
03 if (!quadrantAreaBox.getText().equals(qat)) {
04 quadrantAreaBox.setText(qat);
05 }
06
07 }
08 }
09
10 if (this.gridWidthButton.isSelected()) {
11 double gw;
12 try {
13 gw = Double.parseDouble(this.gridWidthBox.getText().replace(",", "."));
14 if (gw <= 0) {
15 throw new NumberFormatException();
16 }
17 gridWidth = gw;
18 gridWidthBox.setBackground(okBackgroundColor);
19
20 double qa = Math.pow(gridWidth, 2);
21 String qat = Double.toString(qa);
22 if (qat.substring(qat.indexOf(".")).length() > 3) {
23 qat = qat.substring(0, qat.indexOf(".") + 4);
24 }
25 if (!quadrantAreaBox.getText().equals(qat)) {
26 quadrantAreaBox.setText(qat);
27 }
28
29 } catch (NumberFormatException numberFormatException) {
30 gridWidthBox.setBackground(errorBackgroundColor);
31 allOK = false;
32 }
33 }
34
35 if (this.quadrantAreaButton.isSelected()) {
36 double qa;
37 try {
38 qa = Double.parseDouble(this.quadrantAreaBox.getText().replace(",", "."));
39 if (qa <= 0) {
40 throw new NumberFormatException();
41 }
42 gridWidth = Math.sqrt(qa);
43 quadrantAreaBox.setBackground(okBackgroundColor);
44
45
46 String gwt = Double.toString(gridWidth);
47 if (gwt.substring(gwt.indexOf(".")).length() > 3) {
48 gwt = gwt.substring(0, gwt.indexOf(".") + 4);
49 }
50 if (!gridWidthBox.getText().equals(gwt)) {
51 gridWidthBox.setText(gwt);
52 }
53
54 } catch (NumberFormatException numberFormatException) {
55 quadrantAreaBox.setBackground(errorBackgroundColor);
56 allOK = false;
57 }
58 }
59 okButton.setEnabled(allOK);
60 pilotButton.setEnabled(isOkForPilot());
61 }
62
63
67 public void actionPerformed(ActionEvent e) {
68 Border raised = javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED);
69 Border lowered = javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED);
70
71 if (e.getSource() == slicesToBeEstimatedButton) {
72
73 slicesToBeEstimatedPanel.setBorder(raised);
74 activateTextBox(slicesToBeEstimatedBox, DONTCLEAR);
75 activateTextBox(countOfSlicesWhereImageIsVisibleBox, DONTCLEAR);
76
77 numberOfStepsPanel.setBorder(lowered);
78 passivateTextBox(numberOfStepsBox, DONTCLEAR);
79
80 } else if (e.getSource() == numberOfStepButton) {
81
82 numberOfStepsPanel.setBorder(raised);
83 activateTextBox(numberOfStepsBox, DONTCLEAR);
84
85 slicesToBeEstimatedPanel.setBorder(lowered);
86 passivateTextBox(slicesToBeEstimatedBox, CLEAR);
87 passivateTextBox(countOfSlicesWhereImageIsVisibleBox, CLEAR);
88
89 } else if (e.getSource() == pointsToBeCountedButton) {
90
91 pointsToBeCountedPanel.setBorder(raised);
92 activateTextBox(pointsToBeCountedBox, DONTCLEAR);
93 activateTextBox(rougthVolumeEstimationBox, DONTCLEAR);
94
95 gridWidthPanel.setBorder(lowered);
96 passivateTextBox(gridWidthBox, DONTCLEAR);
97
98 quadrantAreaPanel.setBorder(lowered);
99 passivateTextBox(quadrantAreaBox, DONTCLEAR);
00
01 } else if (e.getSource() == gridWidthButton) {
02
03 gridWidthPanel.setBorder(raised);
04 activateTextBox(gridWidthBox, DONTCLEAR);
05
06 pointsToBeCountedPanel.setBorder(lowered);
07 passivateTextBox(pointsToBeCountedBox, CLEAR);
08 passivateTextBox(rougthVolumeEstimationBox, CLEAR);
09
10 quadrantAreaPanel.setBorder(lowered);
11 passivateTextBox(quadrantAreaBox, DONTCLEAR);
12
13 } else if (e.getSource() == quadrantAreaButton) {
14
15 quadrantAreaPanel.setBorder(raised);
16 activateTextBox(quadrantAreaBox, DONTCLEAR);
17
18 pointsToBeCountedPanel.setBorder(lowered);
19 passivateTextBox(pointsToBeCountedBox, CLEAR);
20 passivateTextBox(rougthVolumeEstimationBox, CLEAR);
21
22 gridWidthPanel.setBorder(lowered);
23 passivateTextBox(gridWidthBox, DONTCLEAR);
24
25 }
26
27 validateInput();
28 }
29
30 private void activateTextBox(TextField tf, boolean clear) {
31 if (clear) {
32 tf.setText("");
33 }
34 tf.setBackground(okBackgroundColor);
35 tf.setEnabled(true);
36 tf.repaint();
37 }
38
39 private void passivateTextBox(TextField tf, boolean clear) {
40 if (clear) {
41 tf.setText("");
42 }
43 tf.setBackground(passiveBackgroundColor);
44 tf.setEnabled(false);
45 tf.repaint();
46 }
47
48 private boolean isOkForPilot() {
49 if (sliceThicknessBox.getBackground() == errorBackgroundColor ||
50 slicesToBeEstimatedBox.getBackground() == errorBackgroundColor ||
51 countOfSlicesWhereImageIsVisibleBox.getBackground() == errorBackgroundColor ||
52 numberOfStepsBox.getBackground() == errorBackgroundColor) {
53 return false;
54 } else {
55 return true;
56 }
57 }
58}
59