KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > common > Splash


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
13 import java.awt.event.ComponentAdapter JavaDoc;
14 import java.awt.event.ComponentEvent JavaDoc;
15 import java.io.File JavaDoc;
16 import java.io.IOException JavaDoc;
17
18 import javax.swing.BorderFactory JavaDoc;
19 import javax.swing.ImageIcon JavaDoc;
20 import javax.swing.JPanel JavaDoc;
21 import javax.swing.JProgressBar JavaDoc;
22 import javax.swing.SwingConstants JavaDoc;
23 import javax.swing.UIManager JavaDoc;
24 import javax.swing.border.EmptyBorder JavaDoc;
25
26 public class Splash extends Dialog {
27   public Splash(String JavaDoc 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 JavaDoc(getClass().getResource("/com/tc/admin/icons/logo.gif")));
35     Container contentPane = (Container)getContentPane();
36     contentPane.setBorder(BorderFactory.createEtchedBorder());
37     contentPane.setLayout(new BorderLayout JavaDoc());
38     contentPane.add(label, BorderLayout.CENTER);
39     JProgressBar JavaDoc progressBar = new JProgressBar JavaDoc();
40     progressBar.setIndeterminate(true);
41     JPanel JavaDoc progressPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
42     progressPanel.setBorder(new EmptyBorder JavaDoc(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 JavaDoc getJavaCmd() {
51     File JavaDoc javaBin = new File JavaDoc(System.getProperty("java.home"), "bin");
52     return new File JavaDoc(javaBin, "java" + (Os.isWindows() ? ".exe" : ""));
53   }
54
55   public static Process JavaDoc start(final String JavaDoc title, final Runnable JavaDoc callback) throws IOException JavaDoc {
56     String JavaDoc[] cmdarray = {
57       getJavaCmd().getAbsolutePath(),
58       "-cp", System.getProperty("java.class.path"),
59       Splash.class.getName(),
60       title
61     };
62
63     Process JavaDoc 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 JavaDoc[] args) {
81     try {
82       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
83     } catch(Exception JavaDoc e) {/**/}
84     
85     Splash splash = new Splash(args[0]);
86     splash.addComponentListener(new ComponentAdapter JavaDoc() {
87       public void componentShown(ComponentEvent JavaDoc e) {
88         System.out.println("GO");
89       }
90     });
91     splash.setVisible(true);
92   }
93 }
94
Popular Tags