OSPE_SlitPropPanel.java
5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package osp.ui;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.JTextField;
import osp.FieldOfView;
import osp.Mask;
import osp.Slit;
import osp.utils.PropertiesPanel;
/**
* This class represents the slit properties panel on the left of the visu
* panel, displaying the various slit properties.
*/
public class OSPE_SlitPropPanel extends PropertiesPanel
{
private static final long serialVersionUID = 1L;
/** Title of the properties panel. */
private static String title = " Slit Properties ";
/** Number of the "position" field */
public static final int posit = 0;
/** Number of the "width" field */
public static final int aperture = 1;
/** Number of the "lambda min" field */
public static final int lMin = 2;
/** Number of the "lambda" field */
public static final int lambda = 3;
/** Number of the "lambda max" field */
public static final int lMax = 4;
/** Number of the "length" field */
//public static final int length = 5;
/** Number of the "object position" field */
// public static final int posObj = 6;
/** The visu panel - parent */
private OSPE_VisuPanel visualPanel;
/** The field of view */
private FieldOfView fov;
private double value = 0.0;
private JTextField textFieldPos, textFieldWidth;
private JComponent compPosit, compWidth;
private StatusInterface statusInterface;
/**
* Constructs a new slit properties panel with all the text fields
* corresponding to the properties.
*
* @param p
* : The visu panel of the application.
* @param statusInterface
* @param fov
*/
public OSPE_SlitPropPanel(final OSPE_VisuPanel p, FieldOfView fov,
StatusInterface statusInterface) {
this.visualPanel = p;
this.fov = fov;
this.statusInterface = statusInterface;
setTitle(title);
/* Add component Position */
addTextField(posit, "Position (arcsec)");
getJComponent(posit).setInputVerifier(new DoubleInputVerifier());
compPosit = getJComponent(posit);
textFieldPos = (JTextField) compPosit;
textFieldPos.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
positionAction(e);
}
});
addTextField(aperture, "Width (arcsec)");
getJComponent(aperture).setInputVerifier(new DoubleInputVerifier());
compWidth = getJComponent(aperture);
textFieldWidth = (JTextField) compWidth;
textFieldWidth.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
apertureAction(e);
}
}); // End Action Listener on aperture
addTextField(lMin, "lambdaMin");
getJComponent(lMin).setEnabled(false);
addTextField(lambda, "lambda");
getJComponent(lambda).setEnabled(false);
addTextField(lMax, "lambdaMax");
getJComponent(lMax).setEnabled(false);
// addTextField(length, "length");
// getJComponent(length).setEnabled(false);
// addTextField(posObj, "Object Pos");
// getJComponent(posObj).setEnabled(false);
} // End OSPE_SlitPropPanel constructor
/**
* Modification of slit position by typing on position slit propriety field
*
* @param e
*/
private void positionAction(ActionEvent e) {
Mask currentMask = fov.getCurrentMaskOfCurrentImage();
JTextField tf = (JTextField) e.getSource();
if (tf == getJComponent(posit)) // Slit Position
{
if (tf.getInputVerifier().verify(getJComponent(posit))) {
value = Double.valueOf(tf.getText()).doubleValue();
final Slit currentSlit = currentMask.getCurrentSlit();
if (value > currentSlit.PosMax)
value = currentSlit.PosMax;
if (value < currentSlit.PosMin)
value = currentSlit.PosMin;
Double oldPosition = new Double(currentSlit.getPosition());
if (oldPosition.doubleValue() != value) {
currentMask.getHistory().addEntry("Change position of slit");
currentMask.getHistory().addAction(
"setPosition " + currentMask.getSelectedSlit(), oldPosition);
}
currentSlit.setPosition(value);
visualPanel.isFromSlitComboBox = true;
visualPanel.slide_position.setValue((int) (Math.floor(value)));
currentMask.update();
statusInterface.setStatusBarText(Color.black,
"INFO: Slit Position value is " + value);
visualPanel.updateByHand();
} else
statusInterface.setStatusBarText(Color.red,
"WARNING: Slit Position value must be a double !!!");
} // End if component(posit)
}
/**
* Modification of slit aperture by typing on aperture slit propriety field
*
* @param e
*/
private void apertureAction(ActionEvent e) {
Mask currentMask = fov.getCurrentMaskOfCurrentImage();
JTextField tf = (JTextField) e.getSource();
if (tf == getJComponent(aperture)) // Slit Aperture
{
if (tf.getInputVerifier().verify(getJComponent(aperture))) {
value = Double.valueOf(tf.getText()).doubleValue();
if (value > currentMask.getCurrentSlit().ApeMax)
value = currentMask.getCurrentSlit().ApeMax;
if (value < currentMask.getCurrentSlit().ApeMin)
value = currentMask.getCurrentSlit().ApeMin;
Double oldAperture = new Double(currentMask.getCurrentSlit().getAperture());
if (oldAperture.doubleValue() != value) {
currentMask.getHistory().addEntry("Change aperture of slit");
currentMask.getHistory().addAction(
"setAperture " + currentMask.getSelectedSlit(), oldAperture);
}
currentMask.getCurrentSlit().setAperture(value);
visualPanel.isFromSlitComboBox = true;
visualPanel.slide_aperture.setValue((int) (Math.floor(value)));
currentMask.update();
statusInterface.setStatusBarText(Color.black,
"INFO: Slit Aperture value is " + value);
visualPanel.updateByHand();
} else
statusInterface.setStatusBarText(Color.red,
"WARNING: Slit Aperture value must be a double !!!");
}
visualPanel.isFromSlitComboBox = false;
}
}