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.Color;
25  import java.awt.GridBagConstraints;
26  
27  import javax.swing.JLabel;
28  import javax.swing.JOptionPane;
29  import javax.swing.JPanel;
30  
31  import fr.ens.transcriptome.doelan.Core;
32  
33  /***
34   * Status widget.
35   * @author Laurent Jourdren
36   */
37  public class StatusWidget {
38  
39    /*** Testsuite not started. */
40    public static final int STATUS_NOT_STARTED = 0;
41    /*** Testsuite started. */
42    public static final int STATUS_STARTED = 1;
43    /*** Testsuite success. */
44    public static final int STATUS_PASS = 2;
45    /*** Testsuite failled. */
46    public static final int STATUS_FAILLED = 3;
47    /*** Testsuite no data to test. */
48    public static final int STATUS_NO_DATA_TO_TEST = 4;
49    /*** Testsuite error. */
50    public static final int STATUS_ERROR = 5;
51  
52    /*** Variable for static accessor. */
53    private static StatusWidget statusWidget;
54  
55    private JLabel statusLabel = new JLabel();
56    private JLabel testSuiteLabel = new JLabel();
57    private int status;
58  
59    private JPanel panel;
60    private int yPosition;
61  
62    //
63    // Getters
64    //
65  
66    /***
67     * Get the status of the testsuite.
68     * @return The status of the testsuite
69     */
70    public int getStatus() {
71      return status;
72    }
73  
74    /***
75     * Get the panel.
76     * @return Returns the panel
77     */
78    public JPanel getPanel() {
79      return panel;
80    }
81  
82    /***
83     * Get the y position of the panel.
84     * @return Returns the yPosition
85     */
86    public int getYPosition() {
87      return yPosition;
88    }
89  
90    //
91    // Setters
92    //
93  
94    /***
95     * Set the status of the testsuite.
96     * @param status The status of the testsuite
97     */
98    public void setStatus(final int status) {
99  
100     this.status = status;
101     statusLabel.setForeground(Color.black);
102 
103     switch (status) {
104     case STATUS_NOT_STARTED:
105       statusLabel.setForeground(Color.black);
106       statusLabel.setText("Not started");
107 
108       break;
109     case STATUS_STARTED:
110       statusLabel.setForeground(Color.black);
111       statusLabel.setText("Started");
112 
113       break;
114     case STATUS_PASS:
115       statusLabel.setForeground(Color.green);
116       statusLabel.setText("This scan pass successfully all the tests");
117 
118       break;
119     case STATUS_FAILLED:
120       statusLabel.setForeground(Color.red);
121       statusLabel.setText("This scan fail to pass one or more test");
122       break;
123 
124     case STATUS_NO_DATA_TO_TEST:
125       statusLabel.setForeground(Color.red);
126       statusLabel.setText("You must enter a Genepix file");
127       break;
128 
129     case STATUS_ERROR:
130       statusLabel.setForeground(Color.black);
131       statusLabel.setText("Error !!!");
132 
133       break;
134 
135     default:
136       break;
137     }
138 
139   }
140 
141   /***
142    * Set the y position of the widget.
143    * @param position The yPosition to set
144    */
145   public void setYPosition(final int position) {
146     yPosition = position;
147   }
148 
149   /***
150    * Set the panel.
151    * @param panel The panel to set
152    */
153   public void setPanel(final JPanel panel) {
154     this.panel = panel;
155   }
156 
157   /***
158    * Set the test suite name.
159    * @param testSuiteName The testSuiteName to set
160    */
161   public void setTestSuiteName(final String testSuiteName) {
162 
163     if (testSuiteName == null) {
164       testSuiteLabel.setText("no test suite selected");
165       testSuiteLabel.setEnabled(false);
166     } else {
167       testSuiteLabel.setText(testSuiteName);
168       testSuiteLabel.setEnabled(true);
169     }
170 
171   }
172 
173   //
174   // Other methods
175   //
176 
177   private void init() {
178 
179     GridBagConstraints gridBagConstraints;
180 
181     JLabel jLabel1 = new JLabel("Test suite loaded:");
182     gridBagConstraints = new java.awt.GridBagConstraints();
183     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
184     gridBagConstraints.gridx = 0;
185     gridBagConstraints.gridy = getYPosition();
186     getPanel().add(jLabel1, gridBagConstraints);
187 
188     gridBagConstraints = new java.awt.GridBagConstraints();
189     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
190     gridBagConstraints.gridx = 1;
191     gridBagConstraints.gridy = getYPosition();
192     gridBagConstraints.gridwidth = 5;
193     getPanel().add(testSuiteLabel, gridBagConstraints);
194 
195     JLabel jLabel2 = new JLabel("Test suite result:");
196     gridBagConstraints = new java.awt.GridBagConstraints();
197     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
198     gridBagConstraints.gridx = 0;
199     gridBagConstraints.gridy = getYPosition() + 1;
200     getPanel().add(jLabel2, gridBagConstraints);
201 
202     setStatus(STATUS_NOT_STARTED);
203     gridBagConstraints = new java.awt.GridBagConstraints();
204     gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
205     gridBagConstraints.gridx = 1;
206     gridBagConstraints.gridy = getYPosition() + 1;
207     gridBagConstraints.gridwidth = 5;
208     getPanel().add(statusLabel, gridBagConstraints);
209 
210   }
211 
212   //
213   // Static method
214   //
215 
216   /***
217    * Get the status Widget.
218    */
219   public static StatusWidget getStatusWidget() {
220     return statusWidget;
221   }
222 
223   //
224   // Constructor
225   //
226 
227   /***
228    * Public constructor.
229    * @param panel Panel of the widget
230    * @param position of the widget in the panel
231    */
232   public StatusWidget(final JPanel panel, final int position) {
233 
234     statusWidget = this;
235     setPanel(panel);
236     setYPosition(position);
237     setTestSuiteName(null);
238     init();
239   }
240 
241 }