001package apps; 002 003import java.awt.Dimension; 004import java.awt.Image; 005import java.awt.MediaTracker; 006import java.awt.Rectangle; 007import java.awt.Toolkit; 008import javax.swing.BoxLayout; 009import javax.swing.ImageIcon; 010import javax.swing.JFrame; 011import javax.swing.JLabel; 012import javax.swing.JPanel; 013import jmri.util.FileUtil; 014 015/** 016 * A splash screen for showing during JMRI startup 017 * 018 * @author Bob Jacobsen Copyright 2003 019 * @author Dennis Miller Copyright 2007 020 */ 021public class SplashWindow extends JFrame { 022 023 Image splashIm; 024 025 public SplashWindow() { 026 super("JMRI"); 027 SplashWindow.this.splashWindowDisplay(null); 028 } 029 030 public SplashWindow(JPanel splashMsg) { 031 super("JMRI"); 032 SplashWindow.this.splashWindowDisplay(splashMsg); 033 } 034 035 public void splashWindowDisplay(JPanel splashMsg) { 036 //super("JMRI"); 037 this.setUndecorated(true); 038 039 // get the splash image 040 MediaTracker mt = new MediaTracker(this); 041 splashIm = Toolkit.getDefaultToolkit().getImage(FileUtil.findURL("resources/logo.gif", FileUtil.Location.INSTALLED)); 042 mt.addImage(splashIm, 0); 043 try { 044 mt.waitForID(0); 045 } catch (InterruptedException ie) { 046 Thread.currentThread().interrupt(); // retain if needed later 047 } 048 049 JLabel l = new JLabel(new ImageIcon(splashIm, "JMRI splash screen")); 050 l.setOpaque(true); 051 052 if (splashMsg != null) { 053 JPanel full = new JPanel(); 054 full.setLayout( 055 new BoxLayout(full, BoxLayout.Y_AXIS)); 056 l.setAlignmentX(CENTER_ALIGNMENT); 057 splashMsg.setAlignmentX(CENTER_ALIGNMENT); 058 full.add(l); 059 full.add(splashMsg); 060 getContentPane().add(full); 061 } else { 062 getContentPane().add(l); 063 } 064 065 pack(); 066 067 /* Center the window and pad the frame size slightly to put some space 068 * between logo and frame border*/ 069 Dimension screenDim 070 = Toolkit.getDefaultToolkit().getScreenSize(); 071 Rectangle winDim = getBounds(); 072 winDim.height = winDim.height + 10; 073 winDim.width = winDim.width + 10; 074 setLocation((screenDim.width - winDim.width) / 2, 075 (screenDim.height - winDim.height) / 2); 076 setSize(winDim.width, winDim.height); 077 078 // set Icon for Win Taskbar / profile selection dialog 079 setIconImage(Toolkit.getDefaultToolkit().getImage( 080 FileUtil.findURL("resources/jmri48x48.gif", FileUtil.Location.INSTALLED))); 081 082 // and show 083 setVisible(true); 084 } 085}