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 ; 7 8 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 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 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("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 e) { 54 e.printStackTrace(); 55 } 56 imgWidth = result.getWidth(this); 57 imgHeight = result.getHeight(this); 58 } 59 return (result); 60 } 61 62 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 80 public void paint(Graphics g) { 81 g.drawImage(splashImage, BORDERSIZE, BORDERSIZE, 82 imgWidth, imgHeight, this); 83 } 84 85 90 class WindowListener extends WindowAdapter { 91 public void windowActivated(WindowEvent we) { 92 setVisible(false); 93 dispose(); 94 } 95 } 96 } | Popular Tags |