1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package fr.ens.transcriptome.doelan.gui;
23
24 import java.awt.BorderLayout;
25 import java.awt.GridLayout;
26 import java.awt.event.KeyEvent;
27
28 import javax.swing.ButtonGroup;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JRadioButton;
35 import javax.swing.JTextField;
36
37 import fr.ens.transcriptome.doelan.DoelanException;
38 import fr.ens.transcriptome.doelan.data.QualityTestSuiteList;
39 import fr.ens.transcriptome.doelan.data.QualityTestSuiteURL;
40 import fr.ens.transcriptome.nividic.util.SystemUtils;
41
42 /***
43 * @author Laurent Jourdren
44 */
45 public class RenameTestSuiteWidget extends JDialog {
46
47 private JPanel jPanel;
48
49 private JButton okButton;
50 private JButton cancelButton;
51 private JPanel jPanel3;
52 private JLabel newNameLegendLabel;
53 private JTextField newNameTextField = new JTextField();;
54
55 private JRadioButton testSuiteRadioButton;
56 private JRadioButton chipTypeRadioButton;
57
58 private JDialog dialog = this;
59
60 private QualityTestSuiteList list;
61 private String chipName;
62 private QualityTestSuiteURL suite;
63 private boolean chipTypeMode;
64
65
66
67
68
69 /***
70 * Get the test suite.
71 * @return Returns the suite
72 */
73 private QualityTestSuiteURL getSuite() {
74 return suite;
75 }
76
77 /***
78 * Get the list.
79 * @return Returns the list
80 */
81 private QualityTestSuiteList getList() {
82 return list;
83 }
84
85 /***
86 * Test if is in chip type mode.
87 * @return Returns the chipTypeMode
88 */
89 public boolean isChipTypeMode() {
90 return chipTypeMode;
91 }
92
93
94
95
96
97 /***
98 * Set the test suite.
99 * @param suite The suite to set
100 */
101 private void setSuite(final QualityTestSuiteURL suite) {
102 this.suite = suite;
103 }
104
105 /***
106 * Set the list.
107 * @param list The list to set
108 */
109 private void setList(final QualityTestSuiteList list) {
110 this.list = list;
111 }
112
113 /***
114 * Set if the chip type mode is set.
115 * @param chipTypeMode The chipTypeMode to set
116 */
117 public void setChipTypeMode(final boolean chipTypeMode) {
118 this.chipTypeMode = chipTypeMode;
119 }
120
121
122
123
124
125
126
127
128 /***
129 * This method initializes the dialog
130 */
131 private void initialize() {
132 this.setTitle("Rename");
133 this.setSize(300, 160);
134
135
136 GridLayout gridLayout4 = new GridLayout(3, 1);
137
138 getContentPane().setLayout(new BorderLayout());
139
140 JPanel panel = new JPanel();
141
142 panel.setLayout(gridLayout4);
143
144
145
146
147 panel.add(getChipTypeRadioButton());
148
149 panel.add(getTestSuiteRadioButton());
150
151 panel.add(getJPanel3());
152
153 ButtonGroup group = new ButtonGroup();
154 group.add(getChipTypeRadioButton());
155 group.add(getTestSuiteRadioButton());
156
157 if (getSuite() == null)
158 setChipTypeMode(true);
159
160 if (isChipTypeMode())
161 getChipTypeRadioButton().setSelected(true);
162 else
163 getTestSuiteRadioButton().setSelected(true);
164
165 updateEditedNames();
166
167 getContentPane().add(panel, BorderLayout.CENTER);
168 getContentPane().add(getJPanel(), BorderLayout.SOUTH);
169
170 this.setResizable(false);
171 this.setModal(true);
172
173 setVisible(true);
174 this.newNameTextField.requestFocus();
175
176 }
177
178 /***
179 * Set the focus on the textField
180 */
181 public void requestFocus() {
182 this.newNameTextField.requestFocus();
183 }
184
185 private void updateEditedNames() {
186
187 if (isChipTypeMode()) {
188
189 final String oldName;
190
191 if (getName() == null)
192 oldName = this.chipName;
193 else
194 oldName = getList().getChipType(getSuite());
195
196 this.newNameTextField.setText(oldName);
197 } else if (getSuite() != null)
198 this.newNameTextField.setText(getSuite().getName());
199
200 }
201
202 /***
203 * This method initializes jPanel
204 * @return javax.swing.JPanel
205 */
206 private JPanel getJPanel() {
207 if (jPanel == null) {
208 jPanel = new JPanel();
209 jPanel.add(getOkButton(), null);
210 jPanel.add(getCancelButton(), null);
211 }
212 return jPanel;
213 }
214
215 /***
216 * This method initializes jButton
217 * @return javax.swing.JButton
218 */
219 private JButton getOkButton() {
220 if (okButton == null) {
221 okButton = new JButton();
222 okButton.setText("OK");
223 if (!SystemUtils.isMacOsX())
224 okButton.setMnemonic(KeyEvent.VK_O);
225 okButton.addActionListener(new java.awt.event.ActionListener() {
226 public void actionPerformed(final java.awt.event.ActionEvent e) {
227
228 if (isChipTypeMode()) {
229
230 try {
231 getList().renameChipType(RenameTestSuiteWidget.this.chipName,
232 newNameTextField.getText());
233 } catch (DoelanException e1) {
234 JOptionPane.showMessageDialog(getJPanel(), e1.getMessage());
235 }
236
237 } else {
238
239
240 try {
241 getList().renameTestSuite(chipName, getSuite().getName(),
242 newNameTextField.getText());
243 } catch (DoelanException e1) {
244 JOptionPane.showMessageDialog(getJPanel(), e1.getMessage());
245 }
246
247 }
248
249 hide();
250 }
251 });
252
253 }
254
255 return okButton;
256 }
257
258 /***
259 * This method initializes jButton1
260 * @return javax.swing.JButton
261 */
262 private JButton getCancelButton() {
263 if (cancelButton == null) {
264 cancelButton = new JButton();
265 cancelButton.setText("Cancel");
266 if (!SystemUtils.isMacOsX())
267 cancelButton.setMnemonic(KeyEvent.VK_C);
268 cancelButton.addActionListener(new java.awt.event.ActionListener() {
269 public void actionPerformed(final java.awt.event.ActionEvent e) {
270 dialog.hide();
271 }
272 });
273 }
274 return cancelButton;
275 }
276
277 /***
278 * This method initializes jPanel2
279 * @return javax.swing.JPanel
280 */
281
282
283
284
285
286
287
288
289
290
291
292 /***
293 * This method initializes jPanel3
294 * @return javax.swing.JPanel
295 */
296 private JPanel getJPanel3() {
297 if (jPanel3 == null) {
298 newNameLegendLabel = new JLabel();
299
300
301 jPanel3 = new JPanel();
302
303 BorderLayout layout = new BorderLayout();
304 jPanel3.setLayout(layout);
305
306 newNameLegendLabel.setText("New name: ");
307 newNameLegendLabel.setDisplayedMnemonic(KeyEvent.VK_N);
308 newNameLegendLabel.setLabelFor(this.newNameTextField);
309
310 jPanel3.add(newNameLegendLabel, BorderLayout.WEST);
311 jPanel3.add(this.newNameTextField, BorderLayout.CENTER);
312
313 }
314 return jPanel3;
315 }
316
317 /***
318 * This method initializes jRadioButton
319 * @return javax.swing.JRadioButton
320 */
321 private JRadioButton getTestSuiteRadioButton() {
322 if (testSuiteRadioButton == null) {
323 testSuiteRadioButton = new JRadioButton();
324 if (!SystemUtils.isMacOsX())
325 testSuiteRadioButton.setMnemonic(KeyEvent.VK_T);
326 if (getSuite() == null) {
327 testSuiteRadioButton.setText("Test suite: ");
328 testSuiteRadioButton.setEnabled(false);
329 } else
330 testSuiteRadioButton.setText("Test suite: " + getSuite().getName());
331
332 testSuiteRadioButton
333 .addActionListener(new java.awt.event.ActionListener() {
334 public void actionPerformed(final java.awt.event.ActionEvent e) {
335 setChipTypeMode(false);
336 updateEditedNames();
337 }
338 });
339
340 }
341 return testSuiteRadioButton;
342 }
343
344 /***
345 * This method initializes jRadioButton1
346 * @return javax.swing.JRadioButton
347 */
348 private JRadioButton getChipTypeRadioButton() {
349 if (chipTypeRadioButton == null) {
350 chipTypeRadioButton = new JRadioButton();
351 if (!SystemUtils.isMacOsX())
352 chipTypeRadioButton.setMnemonic(KeyEvent.VK_H);
353
354 chipTypeRadioButton.setText("Chip type: " + this.chipName);
355
356 chipTypeRadioButton
357 .addActionListener(new java.awt.event.ActionListener() {
358 public void actionPerformed(final java.awt.event.ActionEvent e) {
359 setChipTypeMode(true);
360 updateEditedNames();
361 }
362 });
363
364 }
365 return chipTypeRadioButton;
366 }
367
368 /***
369 * @param testSuiteRadioButton The testSuiteRadioButton to set
370 */
371 public void setTestSuiteRadioButton(final JRadioButton testSuiteRadioButton) {
372 this.testSuiteRadioButton = testSuiteRadioButton;
373 }
374
375
376
377
378
379 /***
380 * This is the default constructor
381 * @param list List of quality tests
382 * @param chipName The name of the chip
383 * @param suiteURL The URL of the suite
384 */
385 public RenameTestSuiteWidget(final QualityTestSuiteList list,
386 final String chipName, final QualityTestSuiteURL suiteURL) {
387 super();
388 setList(list);
389 setSuite(suiteURL);
390 this.chipName = chipName;
391 initialize();
392 }
393
394 }