KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ApplicationSplash


1 package com.calipso.reportgenerator.userinterface;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.net.URL JavaDoc;
7
8 /**
9  * 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 JavaDoc 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 JavaDoc imgName, String JavaDoc 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 JavaDoc platform) {
38     MediaTracker tracker = new MediaTracker(this);
39     Image result = null;
40     if(imgName!=null){
41      result = tk.getImage(imgName);
42     }else{
43       URL JavaDoc url = this.getClass().getClassLoader().getResource("com/calipso/reportgenerator/userinterface/images/" + platform + "/" + "splash.jpg");
44       if(url!=null){
45         result = tk.getImage(url);
46       }
47     }
48     if(result!=null){
49       tracker.addImage(result, 0);
50       try {
51         tracker.waitForAll();
52         }
53       catch (Exception JavaDoc e) {
54         e.printStackTrace();
55         }
56       imgWidth = result.getWidth(this);
57       imgHeight = result.getHeight(this);
58     }
59     return (result);
60   }
61
62   /**
63    * Muestra el Splash por pantalla
64    */

65   public void showSplashScreen() {
66      Dimension screenSize = tk.getScreenSize();
67      setBackground(BORDERCOLOR);
68      int w = imgWidth + (BORDERSIZE * 2);
69      int h = imgHeight + (BORDERSIZE * 2);
70      int x = (screenSize.width - w) /2;
71      int y = (screenSize.height - h) /2;
72      setBounds(x, y, w, h);
73      setVisible(true);
74      }
75
76     /**
77      * Dibuja el marco del Splash
78      * @param g
79      */

80     public void paint(Graphics g) {
81      g.drawImage(splashImage, BORDERSIZE, BORDERSIZE,
82        imgWidth, imgHeight, this);
83      }
84
85   /**
86    * Evento que destruye el Splash una vez que
87    * se ha levantado la ventana principal
88    * de la aplicacion
89    */

90   class WindowListener extends WindowAdapter {
91      public void windowActivated(WindowEvent we) {
92        setVisible(false);
93        dispose();
94        }
95      }
96    }
Popular Tags