31 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
32 |
|
|
33 |
import javax.swing.JButton; |
import javax.swing.JButton; |
34 |
|
import javax.swing.JComboBox; |
35 |
import javax.swing.JFileChooser; |
import javax.swing.JFileChooser; |
36 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
37 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
66 |
|
|
67 |
private final JTextField tfName = new JTextField(); |
private final JTextField tfName = new JTextField(); |
68 |
private final JTextField tfDesc = new JTextField(); |
private final JTextField tfDesc = new JTextField(); |
69 |
private final JTextField tfPath = new JTextField(); |
private final JComboBox cbPath = new JComboBox(); |
70 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
71 |
|
|
72 |
private Instrument instrument; |
private Instrument instrument; |
87 |
|
|
88 |
instrument = instr; |
instrument = instr; |
89 |
|
|
90 |
|
cbPath.setEditable(true); |
91 |
|
String[] files = preferences().getStringListProperty("recentInstrumentFiles"); |
92 |
|
for(String s : files) cbPath.addItem(s); |
93 |
|
cbPath.setSelectedItem(null); |
94 |
|
|
95 |
|
cbPath.setPreferredSize ( |
96 |
|
new Dimension(200, cbPath.getPreferredSize().height) |
97 |
|
); |
98 |
|
|
99 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
100 |
|
|
101 |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
149 |
c.gridx = 1; |
c.gridx = 1; |
150 |
c.gridy = 2; |
c.gridy = 2; |
151 |
c.gridwidth = 1; |
c.gridwidth = 1; |
152 |
gridbag.setConstraints(tfPath, c); |
gridbag.setConstraints(cbPath, c); |
153 |
p.add(tfPath); |
p.add(cbPath); |
154 |
|
|
155 |
c.gridx = 1; |
c.gridx = 1; |
156 |
c.gridy = 3; |
c.gridy = 3; |
168 |
setLocationRelativeTo(getOwner()); |
setLocationRelativeTo(getOwner()); |
169 |
|
|
170 |
tfName.getDocument().addDocumentListener(getHandler()); |
tfName.getDocument().addDocumentListener(getHandler()); |
|
tfPath.getDocument().addDocumentListener(getHandler()); |
|
171 |
btnBrowse.addActionListener(getHandler()); |
btnBrowse.addActionListener(getHandler()); |
172 |
|
cbPath.addActionListener(new ActionListener() { |
173 |
|
public void |
174 |
|
actionPerformed(ActionEvent e) { updateState(); } |
175 |
|
}); |
176 |
|
|
177 |
updateInfo(); |
updateInfo(); |
178 |
updateState(); |
updateState(); |
185 |
updateInfo() { |
updateInfo() { |
186 |
tfName.setText(getInstrument().getName()); |
tfName.setText(getInstrument().getName()); |
187 |
tfDesc.setText(getInstrument().getDescription()); |
tfDesc.setText(getInstrument().getDescription()); |
188 |
tfPath.setText(getInstrument().getPath()); |
cbPath.setSelectedItem(getInstrument().getPath()); |
189 |
spinnerIndex.setValue(getInstrument().getInstrumentIndex()); |
spinnerIndex.setValue(getInstrument().getInstrumentIndex()); |
190 |
} |
} |
191 |
|
|
193 |
updateState() { |
updateState() { |
194 |
boolean b = true; |
boolean b = true; |
195 |
if(tfName.getText().length() == 0) b = false; |
if(tfName.getText().length() == 0) b = false; |
196 |
if(tfPath.getText().length() == 0) b = false; |
Object o = cbPath.getSelectedItem(); |
197 |
|
if(o == null || o.toString().length() == 0) b = false; |
198 |
|
|
199 |
btnOk.setEnabled(b); |
btnOk.setEnabled(b); |
200 |
} |
} |
205 |
|
|
206 |
instrument.setName(tfName.getText()); |
instrument.setName(tfName.getText()); |
207 |
instrument.setDescription(tfDesc.getText()); |
instrument.setDescription(tfDesc.getText()); |
208 |
instrument.setPath(tfPath.getText()); |
instrument.setPath(cbPath.getSelectedItem().toString()); |
209 |
int idx = Integer.parseInt(spinnerIndex.getValue().toString()); |
int idx = Integer.parseInt(spinnerIndex.getValue().toString()); |
210 |
instrument.setInstrumentIndex(idx); |
instrument.setInstrumentIndex(idx); |
211 |
|
|
212 |
|
StdUtils.updateRecentElements("recentInstrumentFiles", instrument.getPath()); |
213 |
|
|
214 |
setVisible(false); |
setVisible(false); |
215 |
setCancelled(false); |
setCancelled(false); |
216 |
} |
} |
252 |
int result = fc.showOpenDialog(JSAddOrEditInstrumentDlg.this); |
int result = fc.showOpenDialog(JSAddOrEditInstrumentDlg.this); |
253 |
if(result != JFileChooser.APPROVE_OPTION) return; |
if(result != JFileChooser.APPROVE_OPTION) return; |
254 |
|
|
255 |
tfPath.setText(fc.getSelectedFile().getAbsolutePath()); |
cbPath.setSelectedItem(fc.getSelectedFile().getAbsolutePath()); |
256 |
path = fc.getCurrentDirectory().getAbsolutePath(); |
path = fc.getCurrentDirectory().getAbsolutePath(); |
257 |
preferences().setStringProperty("lastInstrumentLocation", path); |
preferences().setStringProperty("lastInstrumentLocation", path); |
258 |
} |
} |