OSPE_QuickJoinSlitsPanel.java
3.3 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
package osp.ui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import osp.Mask;
import osp.MaskHistory;
public class OSPE_QuickJoinSlitsPanel extends JDialog {
private static final long serialVersionUID = 1L;
private JComboBox<String> startSlit = new JComboBox<String>();
private JComboBox<String> stopSlit = new JComboBox<String>();
private JComboBox<String> modSlit = new JComboBox<String>();
private JButton jButtonOK;
private JButton jButtonCancel;
private Mask currentMask;
private OspeControl control;
public OSPE_QuickJoinSlitsPanel(Mask msk, OspeControl ctrl, int n, int m) {
currentMask = msk;
control=ctrl;
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
for (int i = 0; i < Mask._NBRSLITS_; i++) {
String texte = new String();
texte = "" + (i + 1);
startSlit.addItem(texte);
stopSlit.addItem(texte);
modSlit.addItem(texte);
}
startSlit.setSelectedIndex(n);
stopSlit.setSelectedIndex(m);
modSlit.setSelectedIndex(n);
JPanel firstPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
firstPanel.add(new JLabel("Join Slits from"));
firstPanel.add(startSlit);
firstPanel.add(new JLabel("to"));
firstPanel.add(stopSlit);
this.getContentPane().add(firstPanel, BorderLayout.NORTH);
JPanel secondPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
secondPanel.add(new JLabel("Keeping values of slit"));
secondPanel.add(modSlit);
this.getContentPane().add(secondPanel, BorderLayout.CENTER);
JPanel thirdPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
thirdPanel.add(getOkButton());
thirdPanel.add(getCancelButton());
this.getContentPane().add(thirdPanel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private JButton getCancelButton() {
if(jButtonCancel == null){
jButtonCancel = new JButton("Cancel");
jButtonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
}
return jButtonCancel;
}
private JButton getOkButton() {
if(jButtonOK == null){
jButtonOK = new JButton("OK");
jButtonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int startSlitNum = startSlit.getSelectedIndex();
int stopSlitNum = stopSlit.getSelectedIndex();
final MaskHistory history = currentMask.getHistory();
history.addEntry(
"Join slits " + (startSlitNum + 1) + " to " + (stopSlitNum + 1));
history.addAction("splitSlits " + startSlitNum + " " + stopSlitNum,
null);
for (int i = startSlitNum; i <= stopSlitNum; i++) {
Double position = new Double(currentMask.getSlit(i).getPosition());
Double aperture = new Double(currentMask.getSlit(i).getAperture());
history.addAction("setPosition " + i, position);
history.addAction("setAperture " + i, aperture);
}
currentMask.joinSlits(startSlitNum, stopSlitNum, modSlit.getSelectedIndex());
dispose();
}
});
}
return jButtonOK;
}
}