1   package org.wcb.gui.component;
2   /**
3    * Copyright (C) 1999  Walter Bogaardt
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18   *
19   * Abstract: throws a generic splash screen for new applications loading
20   */
21  import javax.swing.JPanel;
22  import javax.swing.JLabel;
23  import javax.swing.SwingUtilities;
24  import javax.swing.SwingConstants;
25  import javax.swing.ImageIcon;
26  import java.awt.BorderLayout;
27  import java.awt.Window;
28  import java.awt.Frame;
29  import java.awt.Toolkit;
30  import java.awt.Dimension;
31  import javax.swing.border.BevelBorder;
32  
33  
34  public class SplashScreen extends Window {
35  
36      /**
37  	 * 
38  	 */
39  	private static final long serialVersionUID = 0L;
40  	JLabel statusBar;
41  
42      public SplashScreen(ImageIcon picture) {
43          super(new Frame());
44          JPanel borderPanel = new JPanel(new BorderLayout());
45          borderPanel.setLayout(new BorderLayout());
46          borderPanel.add(new JLabel(picture), BorderLayout.CENTER);
47          borderPanel.add(statusBar = new JLabel("...", SwingConstants.CENTER), BorderLayout.SOUTH);
48          borderPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
49          add(borderPanel);
50          pack();
51          Dimension windowSize=getSize(), screenSize = Toolkit.getDefaultToolkit().getScreenSize();
52          setBounds((screenSize.width-windowSize.width) / 2, (screenSize.height - windowSize.height) / 2, windowSize.width, windowSize.height);
53          setVisible(true);
54      }
55  
56      public void showStatus(String currStatus) {
57          try {
58              SwingUtilities.invokeLater(new UpdateStatus(currStatus));
59          }
60          catch(RuntimeException err) {
61              err.printStackTrace();
62          }
63      }
64  
65      public void close() {
66          try {
67              SwingUtilities.invokeLater(new CloseSpashScreen());
68          }
69          catch(RuntimeException e) {
70              e.printStackTrace();
71          }
72      }
73  
74      class UpdateStatus implements Runnable {
75          String newStatus;
76          public UpdateStatus(String status) { newStatus = status; }
77          public void run(){ statusBar.setText(newStatus); }
78      }
79  
80      class CloseSpashScreen implements Runnable {
81          public void run() {
82              setVisible(false);
83              dispose();
84          }
85      }
86  }