1 package net.logAnalyzer;
2
3 import javax.swing.JFrame;
4 import javax.swing.SwingUtilities;
5 import javax.swing.UIManager;
6
7 import net.logAnalyzer.gui.LAFrame;
8 import net.logAnalyzer.handlers.EmptyLogHandler;
9 import net.logAnalyzer.handlers.LALogHandler;
10 import net.logAnalyzer.reports.LAReport;
11 import net.logAnalyzer.resources.LAResourceBundle;
12
13 /***
14 * This class is the GUI launcher. It contains the
15 * {@link net.logAnalyzer.handlers.LALogHandler} and
16 * {@link net.logAnalyzer.reports.LAReport}(s) references displayed by the Log
17 * Analyzer main window and shared by all the classes of the GUI.
18 *
19 * @author Karim REFEYTON
20 * @version 0.1
21 */
22 public final class LogAnalyzerGUI {
23 /***
24 * Log handler displayed.
25 */
26 private static LALogHandler handler = null;
27
28 /***
29 * Reports displayed.
30 */
31 private static LAReport[] reports = null;
32
33 /***
34 * Utilities classes have no public constructor.
35 */
36 private LogAnalyzerGUI() {
37 }
38
39 /***
40 * Returns the Log handler displayed. The default value is an
41 * {@link EmptyLogHandler}.
42 *
43 * @return Current log handler.
44 */
45 public static LALogHandler getHandler() {
46 if (handler == null) {
47 handler = new EmptyLogHandler();
48 }
49 return handler;
50 }
51
52 /***
53 * Returns the reports displayed. The default value is an empty
54 * {@link LAReport} array.
55 *
56 * @return Reports array.
57 */
58 public static LAReport[] getReports() {
59 if (reports == null) {
60 reports = new LAReport[0];
61 }
62 return reports;
63 }
64
65 /***
66 * Closes the specified frame and terminate the programs.
67 *
68 * @param frame
69 * Frame to close.
70 */
71 public static void closeGUI(final LAFrame frame) {
72
73 frame.setVisible(false);
74 frame.dispose();
75 Runtime.getRuntime().exit(0);
76 }
77
78 /***
79 * Creates the first frame.
80 */
81 public static void createAndShowGUI() {
82
83 LAFrame frame = new LAFrame(LAResourceBundle
84 .getLocalizedString("LAFrame.title"));
85 frame.setVisible(true);
86 }
87
88 /***
89 * Launches a new GUI for the specified handler and reports.
90 *
91 * @param logHandler
92 * Log handler to display.
93 * @param logReports
94 * Reports to display.
95 */
96 public static void launchGUI(final LALogHandler logHandler,
97 final LAReport[] logReports) {
98
99 LogAnalyzerGUI.handler = logHandler;
100 LogAnalyzerGUI.reports = logReports;
101
102 try {
103 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
104 } catch (Exception e) {
105
106 JFrame.setDefaultLookAndFeelDecorated(true);
107 }
108
109 SwingUtilities.invokeLater(new Runnable() {
110 public void run() {
111 createAndShowGUI();
112 }
113 });
114 }
115 }