01: package com.calipso.reportgenerator.userinterface;
02:
03: import javax.swing.*;
04: import java.awt.*;
05: import java.awt.event.*;
06: import java.net.URL;
07:
08: /**
09: * Visualiza el Splash de la aplicacion
10: */
11:
12: public class ApplicationSplash extends Window {
13: private Image splashImage;
14: private int imgWidth, imgHeight;
15: private String imgName;
16: private static final int BORDERSIZE = 5;
17: private static final Color BORDERCOLOR = Color.blue;
18: Toolkit tk;
19:
20: /**
21: * Inicializa una instancia de <></ApplicationSplash>
22: * @param f
23: * @param imgName
24: */
25: public ApplicationSplash(JFrame f, String imgName, String platform) {
26: super (f);
27: this .imgName = imgName;
28: tk = Toolkit.getDefaultToolkit();
29: splashImage = loadSplashImage(platform);
30: f.addWindowListener(new WindowListener());
31: }
32:
33: /**
34: * Carga el Splash
35: * @return
36: */
37: public Image loadSplashImage(String platform) {
38: MediaTracker tracker = new MediaTracker(this );
39: Image result = null;
40: if (imgName != null) {
41: result = tk.getImage(imgName);
42: } else {
43: URL url = this .getClass().getClassLoader().getResource(
44: "com/calipso/reportgenerator/userinterface/images/"
45: + platform + "/" + "splash.jpg");
46: if (url != null) {
47: result = tk.getImage(url);
48: }
49: }
50: if (result != null) {
51: tracker.addImage(result, 0);
52: try {
53: tracker.waitForAll();
54: } catch (Exception e) {
55: e.printStackTrace();
56: }
57: imgWidth = result.getWidth(this );
58: imgHeight = result.getHeight(this );
59: }
60: return (result);
61: }
62:
63: /**
64: * Muestra el Splash por pantalla
65: */
66: public void showSplashScreen() {
67: Dimension screenSize = tk.getScreenSize();
68: setBackground(BORDERCOLOR);
69: int w = imgWidth + (BORDERSIZE * 2);
70: int h = imgHeight + (BORDERSIZE * 2);
71: int x = (screenSize.width - w) / 2;
72: int y = (screenSize.height - h) / 2;
73: setBounds(x, y, w, h);
74: setVisible(true);
75: }
76:
77: /**
78: * Dibuja el marco del Splash
79: * @param g
80: */
81: public void paint(Graphics g) {
82: g.drawImage(splashImage, BORDERSIZE, BORDERSIZE, imgWidth,
83: imgHeight, this );
84: }
85:
86: /**
87: * Evento que destruye el Splash una vez que
88: * se ha levantado la ventana principal
89: * de la aplicacion
90: */
91: class WindowListener extends WindowAdapter {
92: public void windowActivated(WindowEvent we) {
93: setVisible(false);
94: dispose();
95: }
96: }
97: }
|