View Javadoc

1   package org.wcb.common;
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  public class SplashScreen extends Window {
34  
35      JLabel statusBar;
36      
37      public SplashScreen(ImageIcon picture) {
38  	super(new Frame());
39  	JPanel borderPanel = new JPanel(new BorderLayout());
40  	borderPanel.setLayout(new BorderLayout());
41  	borderPanel.add(new JLabel(picture), BorderLayout.CENTER);
42  	borderPanel.add(statusBar=new JLabel("...", SwingConstants.CENTER), BorderLayout.SOUTH);
43  	borderPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
44  	add(borderPanel);
45  	pack();
46  	Dimension windowSize=getSize(), screenSize=Toolkit.getDefaultToolkit().getScreenSize();
47  	setBounds((screenSize.width-windowSize.width)/2,(screenSize.height-windowSize.height)/2, windowSize.width,windowSize.height);
48  	setVisible(true);
49      }
50  
51      public void showStatus(String currStatus) {
52  	try {
53  	    SwingUtilities.invokeLater(new UpdateStatus(currStatus));
54  	} catch(RuntimeException err) {err.printStackTrace(); }
55      }
56  
57      public void close() {
58  	try { 
59  	    SwingUtilities.invokeLater(new CloseSpashScreen());
60  	}catch(RuntimeException e) {e.printStackTrace();}
61      }
62  
63      class UpdateStatus implements Runnable {
64  	String newStatus;
65  	public UpdateStatus(String status) {newStatus=status;}
66  	public void run(){statusBar.setText(newStatus); }
67      }
68  
69      class CloseSpashScreen implements Runnable {
70  	public void run() {
71  	    setVisible(false);
72  	    dispose();
73  	}
74      }
75  }
76      
77  
78  	
79  	
80  
81  
82  
83  
84  
85