001: /*
002: * WbSplash.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dialogs;
013:
014: import java.awt.Color;
015: import java.awt.Dimension;
016: import java.awt.Font;
017: import java.awt.FontMetrics;
018: import java.awt.Frame;
019: import java.awt.Graphics;
020: import java.awt.Image;
021: import java.awt.MediaTracker;
022: import java.awt.Toolkit;
023: import java.awt.Window;
024: import java.net.URL;
025: import workbench.resource.ResourceMgr;
026:
027: /**
028: * @author support@sql-workbench.net
029: */
030: public class WbSplash extends Window {
031: private Image splashImage;
032: private final int windowWidth = 280;
033: private final int windowHeight = 230;
034:
035: private final int imageWidth = 172;
036: private final int imageHeight = 128;
037: private final int imageX;
038: private final int imageY = 25;
039:
040: private final int panicX;
041: private final int panicY = imageHeight + imageY + 40;
042:
043: private final int loadingX;
044: private final int loadingY = panicY + 25;
045:
046: private final String dontPanic = "Don't panic";
047: private final String loading = "Loading SQL Workbench/J ...";
048: private final Font panicFont;
049: private final Font loadingFont;
050:
051: public WbSplash() {
052: super (new Frame());
053: splashImage = ResourceMgr.getPicture("hitchguide").getImage();
054: /*
055: URL location = ResourceMgr.class.getClassLoader().getResource("workbench/resource/images/hitchguide.gif");
056: splashImage = Toolkit.getDefaultToolkit().getImage(location);
057:
058: MediaTracker tracker = new MediaTracker(this);
059: tracker.addImage(splashImage, 1);
060: try
061: {
062: tracker.waitForID(1, 0);
063: }
064: catch (InterruptedException e)
065: {
066: System.out.println("INTERRUPTED while loading Image");
067: }
068: int loadStatus = tracker.statusID(1, false);
069: tracker.removeImage(splashImage, 1);
070: */
071:
072: setBackground(Color.LIGHT_GRAY);
073:
074: Dimension screenSize = Toolkit.getDefaultToolkit()
075: .getScreenSize();
076: setBounds((screenSize.width - windowWidth) / 2,
077: (screenSize.height - windowHeight) / 2, windowWidth,
078: windowHeight);
079: imageX = (int) ((windowWidth - imageWidth) / 2);
080:
081: panicFont = new Font("Serif", Font.PLAIN, 36);
082: loadingFont = new Font("Dialog", Font.PLAIN, 12);
083: FontMetrics fm = getFontMetrics(panicFont);
084: int w = fm.stringWidth(dontPanic);
085: panicX = (int) ((windowWidth - w) / 2);
086: fm = getFontMetrics(loadingFont);
087: w = fm.stringWidth(loading);
088: loadingX = (int) ((windowWidth - w) / 2);
089: }
090:
091: public void paint(Graphics g) {
092: g.setColor(Color.GRAY);
093: g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
094: g.drawImage(splashImage, imageX, imageY, 172, 128, null);
095: g.setColor(Color.BLACK);
096: g.setFont(panicFont);
097: g.drawString(dontPanic, panicX, panicY);
098: g.setColor(Color.BLUE);
099: g.setFont(loadingFont);
100: g.drawString(loading, loadingX, loadingY);
101: }
102:
103: // public static void main(String args[])
104: // {
105: // try
106: // {
107: // WbSplash s = new WbSplash();
108: // s.show();
109: // }
110: // catch (Throwable th)
111: // {
112: // th.printStackTrace();
113: // }
114: // System.out.println("Done.");
115: // }
116:
117: }
|