Addition of SplashScreen class.

This commit is contained in:
MobiusDev
2018-04-30 21:06:40 +00:00
parent 7fb5418186
commit d92c73b8cb
80 changed files with 928 additions and 56 deletions

View File

@ -0,0 +1,78 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.commons.util;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JWindow;
/**
* @author Mobius
*/
public class SplashScreen extends JWindow
{
Image image;
JFrame parentFrame;
/**
* @param path of image file
* @param time in milliseconds
* @param parent frame to set visible after time ends
*/
public SplashScreen(String path, long time, JFrame parent)
{
parentFrame = parent;
setBackground(new Color(0, 255, 0, 0)); // Transparency.
image = Toolkit.getDefaultToolkit().getImage(path);
ImageIcon imageIcon = new ImageIcon(image);
setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());
setLocationRelativeTo(null);
setVisible(true);
// Schedule to dispose.
Executors.newScheduledThreadPool(1).schedule(this::dispose, imageIcon.getIconWidth() > 0 ? time : 100, TimeUnit.MILLISECONDS);
}
@Override
public void dispose()
{
setVisible(false);
if (parentFrame != null)
{
// Make parent visible.
parentFrame.setVisible(true);
// Focus parent window.
parentFrame.toFront();
parentFrame.setState(Frame.NORMAL);
}
super.dispose();
}
@Override
public void paint(Graphics g)
{
g.drawImage(image, 0, 0, null);
}
}