KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > gui > MainPanel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier.gui;
24
25 import javax.swing.JFrame JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JOptionPane JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.SwingUtilities JavaDoc;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.io.File JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.logging.LogRecord JavaDoc;
38
39 import com.sun.enterprise.tools.verifier.ResultManager;
40 import com.sun.enterprise.tools.verifier.StringManagerHelper;
41 import com.sun.enterprise.tools.verifier.Verifier;
42
43 public class MainPanel extends JPanel JavaDoc implements Runnable JavaDoc {
44
45     static com.sun.enterprise.util.LocalStringManagerImpl smh =
46             StringManagerHelper.getLocalStringsManager();
47     ResultsPanel resultsPanel = new ResultsPanel();
48     ControlPanel verifierControls;
49
50     JLabel JavaDoc statusLabel = new JLabel JavaDoc((smh.getLocalString
51             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
52
".Status_Idle", // NOI18N
53
"Idle"))); // NOI18N
54
Verifier verifier;
55     Enumeration JavaDoc components;
56     Thread JavaDoc running = null;
57
58     /**
59      * This is the top-level panel of the Verifier GUI
60      */

61     public MainPanel(JFrame JavaDoc parent) {
62         this(parent, null, null);
63     }
64
65     public MainPanel(JFrame JavaDoc parent, String JavaDoc jarFileName, Verifier verifier) {
66         super(new BorderLayout JavaDoc(), true);
67
68         // 508 compliance
69
this.getAccessibleContext().setAccessibleName(smh.getLocalString
70                 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
71
".panelName", // NOI18N
72
"Panel")); // NOI18N
73
this.getAccessibleContext().setAccessibleDescription(smh.getLocalString
74                 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
75
".PanelDesc", // NOI18N
76
"This is a panel")); // NOI18N
77
statusLabel.getAccessibleContext().setAccessibleName(smh.getLocalString
78                 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
79
".labelName", // NOI18N
80
"Label")); // NOI18N
81
statusLabel.getAccessibleContext().setAccessibleDescription
82                 (smh.getLocalString("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
83
".labelDesc", // NOI18N
84
"This is a label")); // NOI18N
85

86         //verifier.setFrame(parent);
87
verifierControls = new ControlPanel(parent);
88         // set the initial jar in file list
89
setJarFilename(jarFileName);
90         this.verifier = verifier;
91
92         add("North", verifierControls); // NOI18N
93
add("Center", resultsPanel); // NOI18N
94
add("South", statusLabel); // NOI18N
95

96
97         verifierControls.okButton.addActionListener(new ActionListener JavaDoc() {
98             public void actionPerformed(ActionEvent JavaDoc e) {
99                 if (getFileList().hasMoreElements()) {
100                     resultsPanel.clearOldResults();
101                     start();
102                 } else {
103                     JOptionPane.showMessageDialog(verifierControls, (smh.getLocalString
104                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
105
".optionPane.okButtonNoFiles", // NOI18N
106
"You must first select file to verify.")) + // NOI18N
107
"\n" + // NOI18N
108
(smh.getLocalString
109                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
110
".optionPane.okButtonNoFiles2", // NOI18N
111
"Use the Add button to select file to be verified," + // NOI18N
112
" then click on OK button."))); // NOI18N
113
}
114             }
115         });
116
117         verifierControls.closeButton.addActionListener(new ActionListener JavaDoc() {
118             public void actionPerformed(ActionEvent JavaDoc e) {
119                 if (MainFrame.getExitOnClose()) {
120                     System.exit(0);
121                 } else {
122                     stop();
123                     enableOK();
124                     enableClose();
125                     reset();
126                     try {
127                         Class JavaDoc cls = Class.forName("javax.swing.JFrame"); // NOI18N
128
JFrame JavaDoc frame = (JFrame JavaDoc) SwingUtilities.getAncestorOfClass(cls, resultsPanel);
129                         frame.setVisible(false);
130
131                         //frame.dispose();
132
} catch (ClassNotFoundException JavaDoc ex) {
133                         // ??can this happen
134
ex.getMessage();
135                     }
136                 }
137             }
138         });
139     }
140
141     /**
142      * Retrieve the verifierControls panel of the Verifier GUI
143      */

144     public ControlPanel getVerifierControlPanel() {
145         return verifierControls;
146     }
147
148     public void setJarFilename(String JavaDoc jarFileName) {
149         // set the initial jar in file list
150
if (jarFileName != null) {
151             File JavaDoc jarFile = new File JavaDoc(jarFileName);
152             if (jarFile.exists()) {
153                 getVerifierControlPanel().addJarFile(jarFile);
154             }
155         }
156     }
157
158     private Verifier getVerifier() {
159         return verifier;
160     }
161
162     public void reset() {
163         resultsPanel.clearOldResults();
164         resultsPanel.clearResults();
165         verifierControls.removeAllJarFiles();
166     }
167
168     public void setStatus(String JavaDoc stat) {
169         statusLabel.setText(stat);
170     }
171
172     public Enumeration JavaDoc getFileList() {
173         return verifierControls.listModel.elements();
174     }
175
176     public void clearResults() {
177         resultsPanel.clearResults();
178     }
179
180     void disableOK() {
181         verifierControls.okButton.setEnabled(false);
182     }
183
184     void enableOK() {
185         verifierControls.okButton.setEnabled(true);
186     }
187
188     void disableClose() {
189         verifierControls.closeButton.setEnabled(false);
190     }
191
192     void enableClose() {
193         verifierControls.closeButton.setEnabled(true);
194     }
195
196     public void start() {
197
198         if (running == null) {
199             components = getFileList();
200             clearResults();
201             running = new Thread JavaDoc(this);
202             running.setPriority(Thread.MIN_PRIORITY);
203             running.start();
204         }
205     }
206
207     public void stop() {
208         if (running != null) {
209             running = null;
210             setStatus((smh.getLocalString
211                     ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
212
".Status_Closed", // NOI18N
213
"Closed"))); // NOI18N
214
}
215     }
216
217     public void run() {
218         try {
219             disableOK();
220
221             while (components.hasMoreElements() && running != null) {
222                 File JavaDoc jarFile = ((File JavaDoc) components.nextElement());
223                 String JavaDoc jarName = ((jarFile).getPath());
224                 try {
225                     setStatus((smh.getLocalString
226                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
227
".Status_Verifying", // NOI18N
228
"Verifying archive {0}...", // NOI18N
229
new Object JavaDoc[]{jarName})));
230                     ResultManager resultManager = getVerifier().verify(jarName);
231                     Iterator JavaDoc itr = resultManager.getError().iterator();
232                     while (itr.hasNext()) {
233                         LogRecord JavaDoc log = (LogRecord JavaDoc) itr.next();
234                         log.setLoggerName(jarFile.getName());
235                         resultsPanel.addError(log);
236                     }
237                     setStatus((smh.getLocalString
238                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
239
".Status_WritingReport", // NOI18N
240
"Writing report..."))); // NOI18N
241
verifier.generateReports();
242
243                     if (resultManager.getFailedCount() +
244                             resultManager.getErrorCount() ==
245                             0) { // this code might not be called
246
resultsPanel.addDetailText((smh.getLocalString
247                                 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
248
".AllTestsPassed", // NOI18N
249
"{0}: All tests passed.", // NOI18N
250
new Object JavaDoc[]{jarFile.getName()})) +
251                                 "\n"); // NOI18N
252
} else {
253                         resultsPanel.addDetailText((smh.getLocalString
254                                 ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
255
".SomeTestsFailed", // NOI18N
256
"{0}: Some tests failed.", // NOI18N
257
new Object JavaDoc[]{jarFile.getName()})) +
258                                 "\n"); // NOI18N
259
}
260
261                 } catch (Throwable JavaDoc t) {
262                     JOptionPane.showMessageDialog(this,
263                             (smh.getLocalString
264                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
265
".ErrorLoading", // NOI18N
266
"Error verifying {0}: {1}", // NOI18N
267
new Object JavaDoc[]{jarName, t.getMessage()})));
268                     resultsPanel.addDetailText((smh.getLocalString
269                             ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
270
".ErrorLoading", // NOI18N
271
"Error verifying {0}: {1}", // NOI18N
272
new Object JavaDoc[]{jarName, t.getMessage()})) +
273                             "\n"); // NOI18N
274
}
275             }
276
277             setStatus((smh.getLocalString
278                     ("com.sun.enterprise.tools.verifier.gui.MainPanel" + // NOI18N
279
".Status_Idle", // NOI18N
280
"Idle"))); // NOI18N
281
enableOK();
282             enableClose();
283         } finally {
284             running = null;
285         }
286     }
287 }
288
Popular Tags