OSPE_SettingsPanel.java
14.7 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
package osp.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import osp.FiltersValues;
import osp.utils.ParamInputsVerifier;
import osp.utils.ULabel;
public class OSPE_SettingsPanel extends JDialog
implements ActionListener
{
private static final long serialVersionUID = 1L;
// JComboBox<String> filterComboBox, grismComboBox;
JComboBox<String> filterComboBox, grismComboBox;
JLabel warningLabel;
JTextField lCentTextField;
JRadioButton ditheringRadioButton;
JTextField ditherTextField;
JCheckBox noddingCheckBox;
JTextField noddTextField;
private List <String> wavelengthValues;
private List <String> grismList;
private JRadioButton radioButtonNone, radioButtonCentroid, radioButtonBrightest;
private JTextField wsizeTextField;
private JButton jButtonOK;
private JLabel statusBar;
public OSPE_SettingsPanel()
{
setTitle("OSP - Display Settings");
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel mainPanel = new JPanel(new BorderLayout());
// JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP);
BorderLayout borderLayout = new BorderLayout();
this.setLayout(borderLayout);
JPanel configPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
buildConfigPanel(configPanel);
// tabPane.addTab("Configuration", configPanel);
// JPanel displayPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
// buildDisplayPanel(displayPanel);
// tabPane.addTab("Display", displayPanel);
mainPanel.add(configPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
jButtonOK = new JButton("OK");
buttonsPanel.add(jButtonOK);
//jButtonOK.addActionListener( new ActionOK() );
jButtonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
JPanel statusPanel = new JPanel(new FlowLayout());
statusPanel.setBorder(BorderFactory.createEtchedBorder());
//statusBar = new JLabel("Information...");
statusBar = new JLabel("This panel is in construction.");
JLabel noEff= new JLabel("There is no effect with thoses parameters");
statusBar.setForeground(Color.red);
noEff.setForeground(Color.black);
statusPanel.add(statusBar);
statusPanel.add(noEff);
this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
pack();
// setVisible(true);
}
private void buildConfigPanel(JPanel panel)
{
GridBagLayout gridbag = new GridBagLayout();
panel.setLayout(gridbag);
JPanel filterGrismPanel = new JPanel(new BorderLayout());
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1; c.weighty = 1;
c.insets = new Insets(0, 0, 5, 5);
c.fill = GridBagConstraints.BOTH;
c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1;
JLabel labelT = new JLabel("Configuration :");
gridbag.setConstraints(labelT, c);
panel.add(labelT);
c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.gridheight = 1;
ULabel label1 = new ULabel("Instrument :", Color.black, 1);
gridbag.setConstraints(label1, c);
panel.add(label1);
c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight = 1;
Box invisibleBox1 = Box.createHorizontalBox();
invisibleBox1.setPreferredSize(new Dimension(10,10));
gridbag.setConstraints(invisibleBox1, c);
panel.add(invisibleBox1);
JPanel lPanel = new JPanel(new BorderLayout());
JLabel label2 = new JLabel("Filter :");
lPanel.add(label2, BorderLayout.NORTH);
JLabel label3 = new JLabel("Grism :");
lPanel.add(label3,BorderLayout.SOUTH);
JPanel comboPanel = new JPanel(new BorderLayout());
grismList=new ArrayList <String>();
filterComboBox = new JComboBox<String>();
grismComboBox = new JComboBox<String>();
filterComboBox.addItem("None");
filterComboBox.addItem("J");
filterComboBox.addItem("H"); filterComboBox.addItem("K");
filterComboBox.setSelectedIndex(1);
displayAllowedGrism(filterComboBox.getSelectedIndex());
filterComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
displayAllowedGrism(filterComboBox.getSelectedIndex());
}
});
comboPanel.add(filterComboBox,BorderLayout.NORTH);
comboPanel.add(grismComboBox);
filterGrismPanel.add(lPanel,BorderLayout.WEST);
filterGrismPanel.add(comboPanel,BorderLayout.EAST);
int yNb=1;
yNb++;
c.gridx = 1; c.gridy = yNb; c.gridwidth = 2; c.gridheight = 2;
gridbag.setConstraints(filterGrismPanel, c);
panel.add(filterGrismPanel);
c.gridx = 4; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 2;
warningLabel = new JLabel("] warning");
warningLabel.setForeground(Color.red);
warningLabel.setVisible(false);
gridbag.setConstraints(warningLabel, c);
panel.add(warningLabel);
yNb++;
yNb++;
yNb++;
c.gridx = 1; c.gridy = yNb; c.gridwidth = 2; c.gridheight = 1;
JLabel label4 = new JLabel("Wavelength :");
gridbag.setConstraints(label4, c);
panel.add(label4);
wavelengthValues= initWavelengthValues();
c.gridx = 3; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
JLabel wavelengthLabel = new JLabel(wavelengthValues.get(1));
gridbag.setConstraints(wavelengthLabel, c);
panel.add(wavelengthLabel);
yNb++;
c.gridx = 0; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
ULabel labelAcq = new ULabel("Acquisition :", Color.black, 1);
gridbag.setConstraints(labelAcq, c);
panel.add(labelAcq);
yNb++;
c.gridx = 1; c.gridy = yNb; c.gridwidth = 2; c.gridheight = 1;
JRadioButton stareRadioButton = new JRadioButton("Stare");
stareRadioButton.setSelected(true);
stareRadioButton.addActionListener(this);
gridbag.setConstraints(stareRadioButton, c);
panel.add(stareRadioButton);
yNb++;
c.gridx = 1; c.gridy = yNb; c.gridwidth = 2; c.gridheight = 1;
ditheringRadioButton = new JRadioButton("Dithering");
ditheringRadioButton.addActionListener(this);
gridbag.setConstraints(ditheringRadioButton, c);
panel.add(ditheringRadioButton);
c.gridx = 3; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
JLabel ditherLabel = new JLabel("jitter box size");
gridbag.setConstraints(ditherLabel, c);
panel.add(ditherLabel);
c.gridx = 4; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
JPanel ditherBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
ditherTextField = new JTextField("0.0");
ditherTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray));
ditherTextField.setName("ditherSize");
ditherTextField.setInputVerifier(new ParamInputsVerifier(this));
ditherTextField.setEnabled(false);
ditherTextField.setPreferredSize(new Dimension(50, 20));
ditherBoxPanel.add(ditherTextField);
ditherTextField.addActionListener(this);
ditherBoxPanel.add(new JLabel("arcsec."));
gridbag.setConstraints(ditherBoxPanel, c);
panel.add(ditherBoxPanel);
yNb++;
c.gridx = 1; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
Box invisibleBox2 = Box.createHorizontalBox();
invisibleBox2.setPreferredSize(new Dimension(10,10));
gridbag.setConstraints(invisibleBox2, c);
panel.add(invisibleBox2);
c.gridx = 2; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
noddingCheckBox = new JCheckBox("Nodding");
noddingCheckBox.addActionListener(this);
noddingCheckBox.setEnabled(false);
gridbag.setConstraints(noddingCheckBox, c);
panel.add(noddingCheckBox);
c.gridx = 3; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
JLabel noddLabel = new JLabel("nod throw");
gridbag.setConstraints(noddLabel, c);
panel.add(noddLabel);
c.gridx = 4; c.gridy = yNb; c.gridwidth = 1; c.gridheight = 1;
JPanel noddBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
noddTextField = new JTextField("0.0");
noddTextField.setBorder(BorderFactory.createLineBorder(Color.lightGray));
noddTextField.setName("noddSize");
noddTextField.setInputVerifier(new ParamInputsVerifier(this));
noddTextField.addActionListener(this);
noddTextField.setEnabled(false);
noddTextField.setPreferredSize(new Dimension(50, 20));
noddBoxPanel.add(noddTextField);
noddBoxPanel.add(new JLabel("arcsec."));
gridbag.setConstraints(noddBoxPanel, c);
panel.add(noddBoxPanel);
ButtonGroup acqGroup = new ButtonGroup();
acqGroup.add(stareRadioButton);
acqGroup.add(ditheringRadioButton);
}
/**
* Allowing to choose convenient grism when selecting a filter
* @param selectedIndex : Selected filter value
*/
protected void displayAllowedGrism(int selectedIndex) {
// TODO Auto-generated method stub
int nbFilter = selectedIndex;
grismComboBox.removeAllItems();
switch (nbFilter)
{
case 1 : // J filter
grismList.clear();
grismList.add("J");
grismList.add("YJ");
break;
case 2 : // H filter
grismList.clear();
grismList.add("H");
grismList.add("HK");
break;
case 3 :
grismList.clear();
grismList.add("K");
grismList.add("HK");
break;
default :
grismList.clear();
grismList.add("None");
grismList.add("J");
grismList.add("H");
grismList.add("K");
grismList.add("HK");
grismList.add("YJ");
break;
}
for (int i=0; i<grismList.size(); i++)
{
grismComboBox.addItem(grismList.get(i).toString());
}
grismComboBox.setSelectedIndex(0);
}
private List <String> initWavelengthValues() {
List <String> values=new ArrayList <String>();
values.add(String.valueOf(FiltersValues._Jband_));
values.add(String.valueOf(FiltersValues._Hband_));
values.add(String.valueOf(FiltersValues._Kband_));
values.add(String.valueOf(FiltersValues._YJband_));
values.add(String.valueOf(FiltersValues._HKband_));
return values;
}
/**
* Display panel : tabPane second tab
* Check boxes of elements which user chooses to display.
* @param panel
*/
private void buildDisplayPanel(JPanel panel)
{
JPanel subPanel = new JPanel();
subPanel.setLayout(new BoxLayout(subPanel, BoxLayout.Y_AXIS));
JCheckBox imageCheck = new JCheckBox("Image");
imageCheck.setSelected(true);
subPanel.add(imageCheck);
// JCheckBox detectorCheck = new JCheckBox("Detector");
// detectorCheck.setSelected(true);
// subPanel.add(detectorCheck);
JCheckBox refObjectsCheck = new JCheckBox("Reference objects");
refObjectsCheck.setSelected(true);
subPanel.add(refObjectsCheck);
JCheckBox targetObjectsCheck = new JCheckBox("Target objects");
targetObjectsCheck.setSelected(true);
subPanel.add(targetObjectsCheck);
JCheckBox maskCheck = new JCheckBox("Mask");
maskCheck.setSelected(true);
subPanel.add(maskCheck);
JCheckBox slitsCheck = new JCheckBox("Slits");
slitsCheck.setSelected(true);
subPanel.add(slitsCheck);
JCheckBox spatialExtSlitCheck = new JCheckBox("Spatial extension of slits");
spatialExtSlitCheck.setSelected(true);
subPanel.add(spatialExtSlitCheck);
JCheckBox brokenSlitsCheck = new JCheckBox("Broken slits");
brokenSlitsCheck.setSelected(true);
subPanel.add(brokenSlitsCheck);
panel.add(subPanel);
}
public void setStatusBarText( Color c, String text )
{
statusBar.setForeground(c);
statusBar.setText(text);
}
@Override
public void actionPerformed(ActionEvent arg0)
{
if ( getFilter() != getGrism() )
warningLabel.setVisible(true);
else
warningLabel.setVisible(false);
if ( ditheringRadioButton.isSelected() )
{
ditherTextField.setEnabled(true);
noddingCheckBox.setEnabled(true);
}
else
{
ditherTextField.setEnabled(false);
noddingCheckBox.setEnabled(false);
}
if ( noddingCheckBox.isSelected() )
{ noddTextField.setEnabled(true); }
else
{ noddTextField.setEnabled(false); }
}
public String getFilter() { return filterComboBox.getSelectedItem().toString(); };
public String getGrism() { return grismComboBox.getSelectedItem().toString(); };
public double getCentWave() { return Double.parseDouble(lCentTextField.getText()); }
public String getAcqMode()
{
if ( ditheringRadioButton.isSelected() )
{
if ( noddingCheckBox.isSelected() )
return "NoddingDithering";
else
return "Dithering";
}
else
return "Stare";
}
public double getDitherSize() { return Double.parseDouble(ditherTextField.getText()); }
public double getNoddSize() { return Double.parseDouble(noddTextField.getText()); }
public boolean isNoneSelected() { return ( radioButtonNone.isSelected() ); }
public boolean isBrightestSelected() { return ( radioButtonBrightest.isSelected() ); }
public boolean isCentroidSelected() { return ( radioButtonCentroid.isSelected() ); }
public void setNoneTo(boolean b) { radioButtonNone.setSelected(b); }
public void setBrightestTo(boolean b) { radioButtonBrightest.setSelected(b); }
public void setCentroidTo(boolean b) { radioButtonCentroid.setSelected(b); }
public double getWinSize() { return Double.parseDouble(wsizeTextField.getText()); }
class ActionOK extends AbstractAction
{
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e)
{
dispose();
// if ( lCentTextField.getInputVerifier().verify(lCentTextField) == true
// && ditherTextField.getInputVerifier().verify(ditherTextField) == true
// && noddTextField.getInputVerifier().verify(noddTextField) == true )
// dispose();
}
}
}