View Javadoc
1   package net.logAnalyzer.gui.splash;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Dimension;
5   import java.awt.Toolkit;
6   
7   import javax.swing.ImageIcon;
8   import javax.swing.JLabel;
9   import javax.swing.JPanel;
10  import javax.swing.JWindow;
11  import javax.swing.UIManager;
12  
13  import net.logAnalyzer.LogAnalyzerBatch;
14  import net.logAnalyzer.LogAnalyzerBatchListener;
15  import net.logAnalyzer.resources.LAResourceBundle;
16  import net.logAnalyzer.utils.gui.GraphicsAttributes;
17  import net.logAnalyzer.utils.gui.GraphicsDecoratorPanel;
18  import net.logAnalyzer.utils.gui.JStatusBar;
19  
20  /***
21   * The initial Splash Screen shown while logAnalyzer loads.
22   */
23  public final class SplashWindow extends JWindow implements
24          LogAnalyzerBatchListener {
25      /***
26       * Used for Swing serialization.
27       */
28      private static final long serialVersionUID = 1L;
29  
30      /***
31       * Default window dimension.
32       */
33      private static final Dimension DIMENSION = new Dimension(400, 120);
34  
35      /***
36       * StatusBar.
37       */
38      private JStatusBar statusbar;
39  
40      /***
41       * Singleton.
42       */
43      private static SplashWindow splash;
44  
45      /***
46       * Constructs the singleton.
47       * 
48       */
49      private SplashWindow() {
50          super();
51          setSize(DIMENSION);
52          addComponents();
53      }
54  
55      /***
56       * Adds the window components.
57       * 
58       */
59      private void addComponents() {
60  
61          JPanel mainPanel = new JPanel();
62          mainPanel.setBackground(GraphicsAttributes.BACKGROUND_COLOR);
63          mainPanel.setLayout(new BorderLayout());
64          ImageIcon urlImage = LAResourceBundle.getIcon("splash.image");
65          JLabel dispimage = new JLabel(urlImage);
66          mainPanel.add(dispimage, BorderLayout.CENTER);
67  
68          // Adds the statusbar
69          statusbar = new JStatusBar(false);
70          statusbar.setBackground(GraphicsAttributes.BACKGROUND_COLOR);
71          statusbar.setVisible(true);
72          statusbar.setFloatable(false);
73          statusbar.setMessage("");
74          statusbar.setMessageColor(GraphicsAttributes.TEXTNORMAL_COLOR);
75          mainPanel.add(statusbar, BorderLayout.SOUTH);
76          getContentPane().add(new GraphicsDecoratorPanel(mainPanel));
77  
78          Dimension size = getSize();
79          Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
80          setLocation((scr.width - size.width) / 2,
81                  (scr.height - size.height) / 2);
82  
83      }
84  
85      /***
86       * @param task
87       *            Task to show in message component.
88       */
89      public void reportCurrentTask(String task) {
90          statusbar.setMessage(task);
91      }
92  
93      /***
94       * @param percent
95       *            Percentages to show in progress bar.
96       */
97      public void reportPercent(int percent) {
98          statusbar.setProgressBar(Integer.toString(percent) + "%", percent);
99      }
100 
101     /***
102      * Closes the specified frame and terminate the programs.
103      * 
104      * @param batch
105      *            Listened batch.
106      */
107     public static void closeGUI(LogAnalyzerBatch batch) {
108         // Remove the frame from the frames list
109         batch.removeLogAnalyzerListener(splash);
110         splash.setVisible(false);
111         splash.dispose();
112 
113     }
114 
115     /***
116      * Creates the first frame.
117      * 
118      * @param batch
119      *            Log analyzer batch to listen.
120      */
121     public static void createAndShowGUI(LogAnalyzerBatch batch) {
122         // Set look & feel
123         try {
124             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
125         } catch (Exception e) {
126             // NOP
127         }
128         splash = new SplashWindow();
129         batch.addLogAnalyzerListener(splash);
130         splash.setVisible(true);
131     }
132 }