001    /******************************************************************************
002     * Copyright (C) MActor Developers. All rights reserved.                        *
003     * ---------------------------------------------------------------------------*
004     * This file is part of MActor.                                               *
005     *                                                                            *
006     * MActor is free software; you can redistribute it and/or modify             *
007     * it under the terms of the GNU General Public License as published by       *
008     * the Free Software Foundation; either version 2 of the License, or          *
009     * (at your option) any later version.                                        *
010     *                                                                            *
011     * MActor is distributed in the hope that it will be useful,                  *
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
014     * GNU General Public License for more details.                               *
015     *                                                                            *
016     * You should have received a copy of the GNU General Public License          *
017     * along with MActor; if not, write to the Free Software                      *
018     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
019     ******************************************************************************/
020    package org.mactor.ui.gui;
021    
022    import java.awt.Dimension;
023    import java.awt.Frame;
024    import java.awt.Graphics;
025    import java.awt.Image;
026    import java.awt.MediaTracker;
027    import java.awt.Rectangle;
028    import java.awt.Toolkit;
029    import java.awt.Window;
030    import java.net.URL;
031    
032    public class Splash extends Frame {
033            public Splash() {
034                    MediaTracker mediaTracker = new MediaTracker(this);
035                    URL imageURL = Thread.currentThread().getContextClassLoader().getResource("loading.PNG");
036                    Image fImage = Toolkit.getDefaultToolkit().getImage(imageURL);
037                    setSize(fImage.getWidth(null), fImage.getHeight(null));
038                    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
039                    Rectangle frame = getBounds();
040                    setLocation((screen.width - frame.width) / 2, (screen.height - frame.height) / 2);
041                    mediaTracker.addImage(fImage, 0);
042                    try {
043                            mediaTracker.waitForID(0);
044                    } catch (InterruptedException ie) {
045                            System.out.println("Cannot track image load");
046                    }
047                    SplashWindow splashWindow = new SplashWindow(this, fImage);
048            }
049            private class SplashWindow extends Window {
050                    private Image fImage;
051                    SplashWindow(Frame aParent, Image aImage) {
052                            super(aParent);
053                            fImage = aImage;
054                            setSize(fImage.getWidth(null), fImage.getHeight(null));
055                            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
056                            Rectangle window = getBounds();
057                            setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
058                            setVisible(true);
059                    }
060                    public void paint(Graphics graphics) {
061                            if (fImage != null) {
062                                    graphics.drawImage(fImage, 0, 0, this);
063                            }
064                    }
065            }
066    }