Package jsynoptic.ui

Source Code of jsynoptic.ui.JSynopticSplashSreen$SplashPanel

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: JSynopticSplashSreen.java,v 1.6 2009/02/04 15:49:50 ogor Exp $
*
* Changes
* -------
* 21 avr. 2006  : Initial public release (CC);
*
*/
package jsynoptic.ui;

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;

import simtools.ui.MenuResourceBundle;
import simtools.ui.ResourceFinder;

/**
*
* JSynoptic splash screen is created by JSynoptic Run class before the
* JSynoptic Panel displays.
*
* Only a single instance of this class can exist, and it may be obtained using the {@link #getSplashScreen()}
* @author zxpletran007
*
*/
public class JSynopticSplashSreen extends JWindow {

    public static MenuResourceBundle resources = ResourceFinder.getMenu(JSynopticSplashSreen.class);

    public static final String JSYNOPTIC_VERSION = "Version: " + Run.fullProductVersion;
    public static final String JSYNOPTIC_COPYRIGHT = "� 2009 EADS Astrium. All rights reserved";
   
    protected URL imageURL;
    protected BufferedImage splashBufferedImage;
    protected JProgressBar progressBar;

    protected String currentMessage;
    protected Font messageFont;

    protected SplashPanel jsSplashPanel;

    protected JSynopticSplashSreen(){  // non-public constructor
        URL url = resources.getClass().getResource(resources.getString("splash"));
        try {
            setImageURL(url);
            this.messageFont= new Font("Arial", 0, 11);

            // Since 2.7: progress bar is not used any more
            this.progressBar = new JProgressBar();
            progressBar.setMinimum(0);
            setProgressBarPosition(0);
            progressBar.setMaximum(100);
            progressBar.setBorder(null);


            jsSplashPanel = new SplashPanel();

            getContentPane().add(jsSplashPanel);           
            setVisible(true);

        } catch (IllegalStateException e) {
            System.err.print("Unable to load image " + url);
            e.printStackTrace();
        } catch (IOException e) {
            System.err.print("Unable to load image " + url);
            e.printStackTrace();
       
    }


    public void setProgressBarPosition(int position){
        progressBar.setValue(position);
    }
    public void setMessage(String message){
        currentMessage = message;
        jsSplashPanel.repaint();
    }


    public void setImageURL(URL imageURL) throws IOException, IllegalStateException {
        this.imageURL = imageURL;

        // Create shadow image
        BufferedImage image;
        image = ImageIO.read(imageURL);

        int width = image.getWidth();
        int height = image.getHeight();
        int extra = 31;

        setSize(new Dimension(width, height + extra));
        setLocationRelativeTo(null);
        Rectangle windowRect = getBounds();
        splashBufferedImage = new BufferedImage(width , height + extra, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) splashBufferedImage.getGraphics();

        try {
            Robot robot = new Robot(getGraphicsConfiguration().getDevice());
            BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width + extra, windowRect.height + extra));
            g2.drawImage(capture, null, 0, 0);
        } catch (AWTException e) { }

        g2.drawImage(image, 0, 0, this);
    }

    public synchronized URL getImageURL() {
        return imageURL;
    }

    private class SplashPanel extends JPanel {
      
        public void paint(Graphics g) {
            if (splashBufferedImage != null) {
                g.drawImage(splashBufferedImage, 0, 0, null);

                g.setColor(new Color(255,255,255,180));
                g.setFont(messageFont);

                if (currentMessage != null){
                    g.drawString(currentMessage, 27,315);
                }
                g.drawString(JSYNOPTIC_COPYRIGHT, 27,330);
                g.drawString(JSYNOPTIC_VERSION, 500,315);
            }
        }
    }
}





TOP

Related Classes of jsynoptic.ui.JSynopticSplashSreen$SplashPanel

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.