View Javadoc

1   /*
2    *                Doelan development code
3    *
4    * This code may be freely distributed and modified under the
5    * terms of the GNU General Public Licence.  This should
6    * be distributed with the code. If you do not have a copy,
7    * see:
8    *
9    *      http://www.gnu.org/copyleft/gpl.txt
10   *
11   * Copyright (c) 2004-2005 ENS Microarray Platform
12   * Copyright for this code is held jointly by the individual
13   * authors.  These should be listed in @author doc comments.
14   *
15   * For more information on the Doelan project and its aims,
16   * or to join the Doelan mailing list, visit the home page
17   * at:
18   *
19   *      http://www.transcriptome.ens.fr/doelan
20   */
21  
22  package fr.ens.transcriptome.doelan.gui;
23  
24  import java.awt.BorderLayout;
25  import java.awt.FlowLayout;
26  import java.awt.GridLayout;
27  import java.awt.event.KeyEvent;
28  
29  import javax.swing.ButtonGroup;
30  import javax.swing.JButton;
31  import javax.swing.JDialog;
32  import javax.swing.JLabel;
33  import javax.swing.JOptionPane;
34  import javax.swing.JPanel;
35  import javax.swing.JRadioButton;
36  import javax.swing.JTextField;
37  
38  import org.apache.log4j.Logger;
39  
40  import fr.ens.transcriptome.doelan.Core;
41  import fr.ens.transcriptome.doelan.DoelanException;
42  import fr.ens.transcriptome.doelan.data.QualityTestSuiteList;
43  import fr.ens.transcriptome.doelan.data.QualityTestSuiteURL;
44  import fr.ens.transcriptome.nividic.util.SystemUtils;
45  
46  /***
47   * Widget to create a new test suite list.
48   * @author Laurent Jourdren
49   */
50  public class NewTestSuiteWidget extends JDialog {
51  
52    private javax.swing.JPanel jContentPane;
53  
54    private JPanel jPanel;
55    private JButton okButton;
56    private JButton cancelButton;
57    private JPanel jPanel1;
58    private JPanel jPanel2;
59    private JPanel jPanel3;
60    private JRadioButton chipTypeRadioButton;
61    private JRadioButton testSuiteRadioButton;
62    private JPanel jPanel4;
63    private JLabel jLabel;
64    private JTextField jTextField;
65  
66    private QualityTestSuiteList list;
67    private String chipType;
68  
69    // private boolean chipTypeMode;
70  
71    //
72    // Getters
73    //
74  
75    /***
76     * Get the list.
77     * @return Returns the list
78     */
79    private QualityTestSuiteList getList() {
80      return list;
81    }
82  
83    /***
84     * Test if is in chip type mode.
85     * @return Returns the chipTypeMode
86     */
87    private boolean isChipTypeMode() {
88      return getChipTypeRadioButton().isSelected();
89    }
90  
91    /***
92     * Get the chip type.
93     * @return Returns the chipType
94     */
95    private String getChipType() {
96      return chipType;
97    }
98  
99    //
100   // Setters
101   //
102 
103   /***
104    * Set the list.
105    * @param list The list to set
106    */
107   private void setList(final QualityTestSuiteList list) {
108     this.list = list;
109   }
110 
111   /***
112    * Set the chip type.
113    * @param chipType The chipType to set
114    */
115   private void setChipType(final String chipType) {
116     this.chipType = chipType;
117   }
118 
119   //
120   // Other methods
121   //
122 
123   /***
124    * This method initializes this
125    * @return void
126    */
127   private void initialize() {
128     this.setResizable(false);
129     this.setModal(true);
130     this.setBounds(0, 0, 300, 150);
131     this.setTitle("Add");
132     this.setContentPane(getJContentPane());
133 
134     ButtonGroup group = new ButtonGroup();
135     group.add(getChipTypeRadioButton());
136     group.add(getTestSuiteRadioButton());
137 
138     if (getList() == null || getList().getChipTypes() == null
139         || getList().getChipTypes().length == 0) {
140       getTestSuiteRadioButton().setEnabled(false);
141       getChipTypeRadioButton().setSelected(true);
142     } else if (isChipTypeMode())
143       getChipTypeRadioButton().setSelected(true);
144     else
145       getTestSuiteRadioButton().setSelected(true);
146 
147   }
148 
149   /***
150    * This method initializes jContentPane
151    * @return javax.swing.JPanel
152    */
153   private javax.swing.JPanel getJContentPane() {
154     if (jContentPane == null) {
155       jContentPane = new javax.swing.JPanel();
156       jContentPane.setLayout(new java.awt.BorderLayout());
157       jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
158       jContentPane.add(getJPanel1(), java.awt.BorderLayout.CENTER);
159     }
160     return jContentPane;
161   }
162 
163   /***
164    * This method initializes jPanel
165    * @return javax.swing.JPanel
166    */
167   private JPanel getJPanel() {
168     if (jPanel == null) {
169       jPanel = new JPanel();
170       jPanel.add(getOkButton(), null);
171       jPanel.add(getCancelButton(), null);
172     }
173     return jPanel;
174   }
175 
176   /***
177    * This method initializes jButton
178    * @return javax.swing.JButton
179    */
180   private JButton getOkButton() {
181     if (okButton == null) {
182       okButton = new JButton();
183       okButton.setText("OK");
184       if (!SystemUtils.isMacOsX())
185         okButton.setMnemonic(KeyEvent.VK_O);
186       okButton.addActionListener(new java.awt.event.ActionListener() {
187         public void actionPerformed(final java.awt.event.ActionEvent e) {
188 
189           if (isChipTypeMode()) {
190 
191             try {
192               getList().addChipType(getJTextField().getText());
193             } catch (DoelanException e1) {
194               JOptionPane.showMessageDialog(jPanel, e1.getMessage());
195             }
196 
197             /*
198              * if (getList() == null) setList(new QualityTestSuiteList());
199              * boolean result =
200              * getList().addChipType(getJTextField().getText()); if (!result)
201              * JOptionPane.showMessageDialog(jPanel, "Chip type already
202              * exists");
203              */
204 
205           } else {
206 
207             QualityTestSuiteURL qtsURL = new QualityTestSuiteURL();
208             qtsURL.setName(getJTextField().getText());
209 
210             try {
211               getList().addTestSuite(getChipType(), qtsURL);
212 
213               Core.getCore().createEmptyWorkflow();
214               Core.getCore().saveWorkflow(qtsURL);
215             } catch (DoelanException e1) {
216               JOptionPane.showMessageDialog(getJContentPane(), e1.getMessage());
217             }
218           }
219           hide();
220         }
221       });
222     }
223     return okButton;
224   }
225 
226   /***
227    * This method initializes jButton1
228    * @return javax.swing.JButton
229    */
230   private JButton getCancelButton() {
231     if (cancelButton == null) {
232       cancelButton = new JButton();
233       cancelButton.setText("Cancel");
234       if (!SystemUtils.isMacOsX())
235         cancelButton.setMnemonic(KeyEvent.VK_C);
236       cancelButton.addActionListener(new java.awt.event.ActionListener() {
237         public void actionPerformed(final java.awt.event.ActionEvent e) {
238           hide();
239         }
240       });
241 
242     }
243     return cancelButton;
244   }
245 
246   /***
247    * This method initializes jPanel1
248    * @return javax.swing.JPanel
249    */
250   private JPanel getJPanel1() {
251     if (jPanel1 == null) {
252       GridLayout gridLayout6 = new GridLayout();
253       jPanel1 = new JPanel();
254       jPanel1.setLayout(gridLayout6);
255       jPanel1.setPreferredSize(new java.awt.Dimension(124, 42));
256       jPanel1.add(getJPanel2(), null);
257       jPanel1.add(getJPanel3(), null);
258       gridLayout6.setRows(3);
259       gridLayout6.setColumns(1);
260       jPanel1.add(getJPanel4(), null);
261     }
262     return jPanel1;
263   }
264 
265   /***
266    * This method initializes jPanel2
267    * @return javax.swing.JPanel
268    */
269   private JPanel getJPanel2() {
270     if (jPanel2 == null) {
271       jPanel2 = new JPanel();
272       FlowLayout flowLayout2 = new FlowLayout();
273       jPanel2.setLayout(flowLayout2);
274 
275       flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
276       jPanel2.add(getChipTypeRadioButton(), null);
277     }
278     return jPanel2;
279   }
280 
281   /***
282    * This method initializes jPanel3
283    * @return javax.swing.JPanel
284    */
285   private JPanel getJPanel3() {
286     if (jPanel3 == null) {
287       jPanel3 = new JPanel();
288       FlowLayout flowLayout1 = new FlowLayout();
289       jPanel3.setLayout(flowLayout1);
290 
291       flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
292       jPanel3.add(getTestSuiteRadioButton(), null);
293     }
294     return jPanel3;
295   }
296 
297   /***
298    * This method initializes jRadioButton1
299    * @return javax.swing.JRadioButton
300    */
301   private JRadioButton getChipTypeRadioButton() {
302 
303     if (chipTypeRadioButton == null) {
304       chipTypeRadioButton = new JRadioButton();
305       chipTypeRadioButton.setText("Chip type");
306       if (!SystemUtils.isMacOsX())
307         chipTypeRadioButton.setMnemonic(KeyEvent.VK_H);
308     }
309     return chipTypeRadioButton;
310   }
311 
312   /***
313    * This method initializes jRadioButton
314    * @return javax.swing.JRadioButton
315    */
316   private JRadioButton getTestSuiteRadioButton() {
317 
318     if (testSuiteRadioButton == null) {
319       testSuiteRadioButton = new JRadioButton();
320       testSuiteRadioButton.setText("Test suite");
321       if (!SystemUtils.isMacOsX())
322         testSuiteRadioButton.setMnemonic(KeyEvent.VK_T);
323     }
324     return testSuiteRadioButton;
325   }
326 
327   /***
328    * This method initializes jPanel4
329    * @return javax.swing.JPanel
330    */
331   private JPanel getJPanel4() {
332     if (jPanel4 == null) {
333       jLabel = new JLabel();
334       // FlowLayout flowLayout3 = new FlowLayout();
335       BorderLayout flowLayout3 = new BorderLayout();
336       jPanel4 = new JPanel();
337       jPanel4.setLayout(flowLayout3);
338       jLabel.setText("Name: ");
339       jLabel.setDisplayedMnemonic(KeyEvent.VK_N);
340       jLabel.setLabelFor(getJTextField());
341       jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
342       jLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
343       // flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
344       jPanel4.add(jLabel, BorderLayout.WEST);
345       jPanel4.add(getJTextField(), BorderLayout.CENTER);
346     }
347     return jPanel4;
348   }
349 
350   /***
351    * This method initializes jTextField
352    * @return javax.swing.JTextField
353    */
354   private JTextField getJTextField() {
355     if (jTextField == null) {
356       jTextField = new JTextField();
357       jTextField.setName("Name");
358     }
359     return jTextField;
360   }
361 
362   //
363   // Constructor
364   //
365 
366   /***
367    * This is the default constructor.
368    * @param list Testsuite list
369    * @param chipType Chip type
370    */
371   public NewTestSuiteWidget(final QualityTestSuiteList list,
372       final String chipType) {
373     super();
374     setList(list);
375     setChipType(chipType);
376     initialize();
377     getChipTypeRadioButton().setSelected(false);
378     jTextField.requestFocusInWindow();
379   }
380 
381 }