001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui;
022:
023: import java.awt.*;
024: import java.awt.event.*;
025:
026: public class Splash {
027: protected Image m_splashImage;
028: protected Window m_window;
029: protected String m_version = "";
030:
031: public class MyWindow extends Window {
032: public MyWindow(Frame f) {
033: super (f);
034: }
035:
036: public void paint(Graphics g) {
037: g.drawImage(Splash.this .m_splashImage, 0, 0, this );
038: g.setFont(g.getFont().deriveFont(Font.BOLD).deriveFont(
039: 16.0f));
040: FontMetrics fm = g.getFontMetrics();
041: int width = fm.stringWidth(Splash.this .m_version) + 20;
042: int height = fm.getHeight();
043: g.setColor(Color.black);
044: g.drawString(Splash.this .m_version,
045: this .getWidth() - width, this .getHeight() - height);
046: }
047: }
048:
049: public class MyDialog extends Dialog {
050: public MyDialog(Frame f) {
051: super (f, true);
052: setResizable(false);
053: }
054:
055: public void paint(Graphics g) {
056: g.drawImage(Splash.this .m_splashImage, 0, 0, this );
057: }
058: }
059:
060: public Splash(Frame parent, String imagefilename, boolean dialog) {
061: if (dialog) {
062: m_window = new MyDialog(parent);
063: } else {
064: m_window = new MyWindow(parent);
065: }
066: javax.swing.ImageIcon icon = new javax.swing.ImageIcon(
067: getClass().getResource(imagefilename));
068: m_splashImage = icon.getImage();
069: MediaTracker loader = new MediaTracker(m_window);
070: loader.addImage(m_splashImage, 0);
071: try {
072: loader.waitForAll();
073: } catch (Exception e) {
074: }
075: }
076:
077: public void show() {
078: Dimension screendim = Toolkit.getDefaultToolkit()
079: .getScreenSize();
080: m_window.setSize(m_splashImage.getWidth(m_window),
081: m_splashImage.getHeight(m_window));
082: m_window
083: .setLocation((screendim.width - m_splashImage
084: .getWidth(m_window)) / 2,
085: (screendim.height - m_splashImage
086: .getHeight(m_window)) / 2);
087: m_window.setVisible(true);
088: }
089:
090: public void dispose() {
091: m_window.dispose();
092: }
093:
094: public void setVersion(String version) {
095: m_version = version;
096: }
097:
098: public void toFront() {
099: m_window.toFront();
100: }
101:
102: }
|