All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.izforge.izpack.installer.gui.SplashScreen Maven / Gradle / Ivy

There is a newer version: 5.2.3
Show newest version
package com.izforge.izpack.installer.gui;

import com.izforge.izpack.api.resource.Resources;
import com.izforge.izpack.installer.data.GUIInstallData;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

/**
 * Splash screen to show before loading any other panels.
 */
public class SplashScreen extends JFrame
{

    private final Resources resources;
    private final GUIInstallData installData;

    public SplashScreen(Resources resources, GUIInstallData installData)
    {
        this.installData = installData;
        this.resources = resources;
        this.setResizable(false);
        this.setVisible(false);
    }

    /**
     * Display the splash screen.
     * Will only display if the user has set the guipref modifier.
     * Splash screen will display for a minimum fo X milliseconds based on the user's useSplashScreen modifier's value.
     */
    public void displaySplashScreen()
    {
        if (installData.guiPrefs.modifier.containsKey("useSplashScreen"))
        {
            ImageIcon splashIcon = resources.getImageIcon("/resources/Splash.image");
            if (splashIcon != null)
            {
                this.add(new JLabel(splashIcon));
                this.setSize(splashIcon.getIconWidth(), splashIcon.getIconHeight());
                this.setLocationRelativeTo(null);
            }

            this.setVisible(true);
            try
            {
                int duration = Integer.parseInt(installData.guiPrefs.modifier.get("useSplashScreen"));
                if(duration > 0)
                {
                    Thread.sleep(duration);
                }
            }
            catch (Exception e)
            {
                //Failed to sleep
                //Failed to get duration
                //Failed to get splash screen resource
            }
        }
    }

    /**
     * Remove the splash screen screen.
     */
    public void removeSplashScreen()
    {
        this.setVisible(false);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy