001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.common;
005:
006: import org.dijon.Container;
007: import org.dijon.Dialog;
008: import org.dijon.Label;
009:
010: import com.tc.util.runtime.Os;
011:
012: import java.awt.BorderLayout;
013: import java.awt.event.ComponentAdapter;
014: import java.awt.event.ComponentEvent;
015: import java.io.File;
016: import java.io.IOException;
017:
018: import javax.swing.BorderFactory;
019: import javax.swing.ImageIcon;
020: import javax.swing.JPanel;
021: import javax.swing.JProgressBar;
022: import javax.swing.SwingConstants;
023: import javax.swing.UIManager;
024: import javax.swing.border.EmptyBorder;
025:
026: public class Splash extends Dialog {
027: public Splash(String title) {
028: super (title);
029:
030: Label label = new Label(title);
031: label.setFont(UIManager.getFont("InternalFrame.titleFont"));
032: label.setVerticalTextPosition(SwingConstants.TOP);
033: label.setHorizontalTextPosition(SwingConstants.CENTER);
034: label.setIcon(new ImageIcon(getClass().getResource(
035: "/com/tc/admin/icons/logo.gif")));
036: Container contentPane = (Container) getContentPane();
037: contentPane.setBorder(BorderFactory.createEtchedBorder());
038: contentPane.setLayout(new BorderLayout());
039: contentPane.add(label, BorderLayout.CENTER);
040: JProgressBar progressBar = new JProgressBar();
041: progressBar.setIndeterminate(true);
042: JPanel progressPanel = new JPanel(new BorderLayout());
043: progressPanel.setBorder(new EmptyBorder(2, 2, 2, 2));
044: progressPanel.add(progressBar);
045: contentPane.add(progressPanel, BorderLayout.SOUTH);
046: setUndecorated(true);
047: pack();
048: center();
049: }
050:
051: private static File getJavaCmd() {
052: File javaBin = new File(System.getProperty("java.home"), "bin");
053: return new File(javaBin, "java"
054: + (Os.isWindows() ? ".exe" : ""));
055: }
056:
057: public static Process start(final String title,
058: final Runnable callback) throws IOException {
059: String[] cmdarray = { getJavaCmd().getAbsolutePath(), "-cp",
060: System.getProperty("java.class.path"),
061: Splash.class.getName(), title };
062:
063: final Process p = Runtime.getRuntime().exec(cmdarray);
064: InputStreamDrainer errDrainer = new InputStreamDrainer(p
065: .getErrorStream());
066: StreamReader outReader = new StreamReader(p.getInputStream(),
067: new OutputStreamListener() {
068: public void triggerEncountered() {
069: Thread shutdownHook = new Thread() {
070: public void run() {
071: p.destroy();
072: }
073: };
074: Runtime.getRuntime().addShutdownHook(
075: shutdownHook);
076: callback.run();
077: Runtime.getRuntime().removeShutdownHook(
078: shutdownHook);
079: }
080: }, "GO");
081:
082: errDrainer.start();
083: outReader.start();
084:
085: return p;
086: }
087:
088: public static void main(String[] args) {
089: try {
090: UIManager.setLookAndFeel(UIManager
091: .getSystemLookAndFeelClassName());
092: } catch (Exception e) {/**/
093: }
094:
095: Splash splash = new Splash(args[0]);
096: splash.addComponentListener(new ComponentAdapter() {
097: public void componentShown(ComponentEvent e) {
098: System.out.println("GO");
099: }
100: });
101: splash.setVisible(true);
102: }
103: }
|