Package net.sf.myjaut.ui

Source Code of net.sf.myjaut.ui.SplashScreen

/*
* Created on 11-jun-2006.
*
* This software is published under the "GNU General Public
* license", see http://www.gnu.org/copyleft/gpl.html for
* additional information.
*
*/
package net.sf.myjaut.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.HeadlessException;
import java.io.IOException;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.EmptyBorder;
import net.sf.myjaut.URLProvider;

public class SplashScreen extends JDialog {
    private JProgressBar progress;

    public SplashScreen(String label, String imageFileName, Color foreground, final String iconFileName) {
        super(createDummyFrameForRightIcon(iconFileName));
        JPanel root = new JPanel();
        root.setLayout(new BorderLayout());
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        try {
            JLabel image = new JLabel(new ImageIcon(new URLProvider(imageFileName).getImage()));
            image.setBorder(new EmptyBorder(0,0,0,0));
            root.add(image, BorderLayout.CENTER);
            progress = new JProgressBar(0, 100);
            progress.setString(label);
            progress.setStringPainted(true);
            progress.setBorder(new EmptyBorder(0,0,0,0));
            progress.setForeground(foreground);
            root.add(progress, BorderLayout.SOUTH);
        }
        catch (IOException exc) {
            throw new IllegalStateException(exc);
        }
        add(root);
        setUndecorated(true);
        pack();
        new CenterOnScreenCommand<JDialog>(this).execute();
        setVisible(true);
        requestFocus();
    }

    private static JFrame createDummyFrameForRightIcon(final String iconFileName) {
        try {
            JFrame frame = new JFrame();
            frame.setIconImage(new URLProvider(iconFileName).getImage());
            return frame;
        }
        catch (HeadlessException exc) {
            throw new IllegalStateException(exc);
        }
        catch (IOException exc) {
            throw new IllegalStateException(exc);
        }
    }

    public void setProgress(double value) {
        progress.setValue((int) (100 * value));
    }

    public double getProgress() {
        return ((double)progress.getValue()) / 100;
    }
}
TOP

Related Classes of net.sf.myjaut.ui.SplashScreen

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.