src/org/gel/mauve/gui/SplashScreen.java

Go to the documentation of this file.
00001 package org.gel.mauve.gui;
00002 
00003 import java.awt.BorderLayout;
00004 import java.awt.Color;
00005 import java.awt.Dimension;
00006 import java.awt.Frame;
00007 import java.awt.Toolkit;
00008 import java.awt.event.MouseAdapter;
00009 import java.awt.event.MouseEvent;
00010 import java.lang.reflect.InvocationTargetException;
00011 
00012 import javax.swing.BorderFactory;
00013 import javax.swing.ImageIcon;
00014 import javax.swing.JLabel;
00015 import javax.swing.JPanel;
00016 import javax.swing.JWindow;
00017 import javax.swing.SwingConstants;
00018 import javax.swing.SwingUtilities;
00019 import javax.swing.border.Border;
00020 
00021 import org.gel.mauve.MyConsole;
00022 
00031 class SplashScreen extends JWindow {
00032         public SplashScreen (String filename, String message, Frame f, int waitTime) {
00033                 super (f);
00034                 JPanel bg_panel = new JPanel ();
00035                 Border panel_border = BorderFactory.createLineBorder (Color.gray, 4);
00036                 bg_panel.setBackground (Color.white);
00037                 bg_panel.setBorder (panel_border);
00038                 getContentPane ().add (bg_panel);
00039                 JLabel il = new JLabel (new ImageIcon (SplashScreen.class
00040                                 .getResource (filename)));
00041                 JLabel tl = new JLabel (message, SwingConstants.CENTER);
00042                 bg_panel.setLayout (new BorderLayout ());
00043                 bg_panel.add (il, BorderLayout.NORTH);
00044                 bg_panel.add (tl, BorderLayout.SOUTH);
00045                 pack ();
00046                 Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
00047                 Dimension labelSize = il.getPreferredSize ();
00048                 setLocation (screenSize.width / 2 - (labelSize.width / 2),
00049                                 screenSize.height / 2 - (labelSize.height / 2));
00050 
00051                 addMouseListener (new MouseAdapter () {
00052                         public void mousePressed (MouseEvent e) {
00053                                 setVisible (false);
00054                                 dispose ();
00055                         }
00056                 });
00057                 final int pause = waitTime;
00058                 final Runnable closerRunner = new Runnable () {
00059                         public void run () {
00060                                 setVisible (false);
00061                                 dispose ();
00062                         }
00063                 };
00064 
00065                 Runnable waitRunner = new Runnable () {
00066                         public void run () {
00067                                 try {
00068                                         Thread.sleep (pause);
00069                                 } catch (InterruptedException e) {
00070                                         MyConsole.err ().print (
00071                                                         "Interrupted waiting for splash start.");
00072                                         e.printStackTrace (MyConsole.err ());
00073                                 }
00074 
00075                                 try {
00076                                         SwingUtilities.invokeAndWait (closerRunner);
00077                                 } catch (InterruptedException e) {
00078                                         MyConsole.err ().print ("Interrupted splash screen.");
00079                                         e.printStackTrace (MyConsole.err ());
00080                                 } catch (InvocationTargetException e) {
00081                                         MyConsole.err ().print (
00082                                                         "Error in splash screen invocation.");
00083                                         e.printStackTrace (MyConsole.err ());
00084                                 }
00085                         }
00086                 };
00087                 setVisible (true);
00088                 Thread splashThread = new Thread (waitRunner, "SplashThread");
00089                 splashThread.start ();
00090         }
00091 }

Generated on Mon Aug 19 06:03:43 2013 for Mauve by doxygen 1.3.6