| Home >> All >> org >> embl >> ebi >> escience >> scuflui >> [ workbench Javadoc ] |
Source code: org/embl/ebi/escience/scuflui/workbench/SplashScreen.java
1 /** 2 * This file is a component of the Taverna project, 3 * and is licensed under the GNU LGPL. 4 * Copyright Tom Oinn, EMBL-EBI 5 */ 6 package org.embl.ebi.escience.scuflui.workbench; 7 8 import java.awt.BorderLayout; 9 import java.awt.Dimension; 10 import java.awt.Toolkit; 11 import java.awt.event.MouseAdapter; 12 import java.awt.event.MouseEvent; 13 import javax.swing.ImageIcon; 14 import javax.swing.JLabel; 15 import javax.swing.JWindow; 16 import javax.swing.SwingUtilities; 17 18 import java.lang.Class; 19 import java.lang.ClassNotFoundException; 20 import java.lang.Exception; 21 import java.lang.Runnable; 22 import java.lang.Thread; 23 24 25 26 /** 27 * A splash screen for the workbench, code derived heavily from 28 * http://www.javaworld.com/javaworld/javatips/jw-javatip104.html 29 * @author Tom Oinn 30 */ 31 class SplashScreen extends JWindow { 32 33 static ImageIcon logo; 34 35 static { 36 try { 37 Class c = Class.forName("org.embl.ebi.escience.scuflui.workbench.SplashScreen"); 38 logo = new ImageIcon(c.getResource("splashscreen.png")); 39 } 40 catch (ClassNotFoundException cnfe) { 41 // 42 } 43 } 44 45 public SplashScreen(int waitTime) { 46 super(); 47 JLabel l = new JLabel(logo); 48 getContentPane().add(l, BorderLayout.CENTER); 49 pack(); 50 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 51 Dimension labelSize = l.getPreferredSize(); 52 setLocation(screenSize.width/2 - (labelSize.width/2), screenSize.height/2 - (labelSize.height/2)); 53 addMouseListener(new MouseAdapter() { 54 public void mousePressed(MouseEvent e) { 55 setVisible(false); 56 dispose(); 57 } 58 }); 59 final int pause = waitTime; 60 final Runnable closerRunner = new Runnable() { 61 public void run() { 62 setVisible(false); 63 dispose(); 64 } 65 }; 66 Runnable waitRunner = new Runnable() { 67 public void run() { 68 try { 69 Thread.sleep(pause); 70 SwingUtilities.invokeAndWait(closerRunner); 71 } 72 catch(Exception e) { 73 e.printStackTrace(); 74 // can catch InvocationTargetException 75 // can catch InterruptedException 76 } 77 } 78 }; 79 setVisible(true); 80 Thread splashThread = new Thread(waitRunner, "SplashThread"); 81 splashThread.start(); 82 } 83 }