1 4 package com.tc.admin.common; 5 6 import org.dijon.Container; 7 import org.dijon.Dialog; 8 import org.dijon.Label; 9 10 import com.tc.util.runtime.Os; 11 12 import java.awt.BorderLayout ; 13 import java.awt.event.ComponentAdapter ; 14 import java.awt.event.ComponentEvent ; 15 import java.io.File ; 16 import java.io.IOException ; 17 18 import javax.swing.BorderFactory ; 19 import javax.swing.ImageIcon ; 20 import javax.swing.JPanel ; 21 import javax.swing.JProgressBar ; 22 import javax.swing.SwingConstants ; 23 import javax.swing.UIManager ; 24 import javax.swing.border.EmptyBorder ; 25 26 public class Splash extends Dialog { 27 public Splash(String title) { 28 super(title); 29 30 Label label = new Label(title); 31 label.setFont(UIManager.getFont("InternalFrame.titleFont")); 32 label.setVerticalTextPosition(SwingConstants.TOP); 33 label.setHorizontalTextPosition(SwingConstants.CENTER); 34 label.setIcon(new ImageIcon (getClass().getResource("/com/tc/admin/icons/logo.gif"))); 35 Container contentPane = (Container)getContentPane(); 36 contentPane.setBorder(BorderFactory.createEtchedBorder()); 37 contentPane.setLayout(new BorderLayout ()); 38 contentPane.add(label, BorderLayout.CENTER); 39 JProgressBar progressBar = new JProgressBar (); 40 progressBar.setIndeterminate(true); 41 JPanel progressPanel = new JPanel (new BorderLayout ()); 42 progressPanel.setBorder(new EmptyBorder (2,2,2,2)); 43 progressPanel.add(progressBar); 44 contentPane.add(progressPanel, BorderLayout.SOUTH); 45 setUndecorated(true); 46 pack(); 47 center(); 48 } 49 50 private static File getJavaCmd() { 51 File javaBin = new File (System.getProperty("java.home"), "bin"); 52 return new File (javaBin, "java" + (Os.isWindows() ? ".exe" : "")); 53 } 54 55 public static Process start(final String title, final Runnable callback) throws IOException { 56 String [] cmdarray = { 57 getJavaCmd().getAbsolutePath(), 58 "-cp", System.getProperty("java.class.path"), 59 Splash.class.getName(), 60 title 61 }; 62 63 Process p = Runtime.getRuntime().exec(cmdarray); 64 InputStreamDrainer errDrainer = new InputStreamDrainer(p.getErrorStream()); 65 StreamReader outReader = new StreamReader( 66 p.getInputStream(), 67 new OutputStreamListener() { 68 public void triggerEncountered() { 69 callback.run(); 70 } 71 }, 72 "GO"); 73 74 errDrainer.start(); 75 outReader.start(); 76 77 return p; 78 } 79 80 public static void main(String [] args) { 81 try { 82 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 83 } catch(Exception e) {} 84 85 Splash splash = new Splash(args[0]); 86 splash.addComponentListener(new ComponentAdapter () { 87 public void componentShown(ComponentEvent e) { 88 System.out.println("GO"); 89 } 90 }); 91 splash.setVisible(true); 92 } 93 } 94 | Popular Tags |