| 1 15 16 18 38 package ixenon.free.install; 39 40 import javax.swing.*; 42 import javax.swing.event.*; 43 import javax.swing.border.*; 45 import java.awt.*; 46 import java.awt.event.*; 47 import java.util.*; 48 49 import ixenon.free.swing.*; import ixenon.free.util.*; 52 53 98 public class SplashScreen2 { 99 100 101 public final static String IMAGE_RESOURCE="splashScreen.image"; 102 103 public final static String IMAGE_NAME="Xenon-SQL.jpg"; 104 105 106 public static void main(String [] args) 107 { 108 ResourceBundle global_bundle; 109 global_bundle = ResourceBundle.getBundle( "XsqlBundle" ); 110 ApplicationResources.createInstance( global_bundle, "Xsql" ); 111 112 114 SplashScreen2.Closure myClosure = new SplashScreen2.Closure() { 115 public void waitAndCloseWindow() { 116 System.out.println("window:"+window ); 117 System.out.println("duration:"+duration ); 118 System.out.print("Sleeping now Zzzzz .... " ); 119 try { Thread.sleep(duration); } catch (Exception e) {} 120 121 System.out.println("*timeout* dispose now (terminating program)"); 122 SwingUtilities.invokeLater( new Runnable () { 123 public void run() { 124 window.setVisible(false); 125 window.dispose(); 126 window=null; 127 System.exit(0); 128 } 129 }); 130 } 131 }; 132 133 showSplash(10000, "splashScreen.image", "Xenon-SQL.jpg", myClosure); 134 } 135 136 137 148 public static JWindow showSplash(int duration) 149 { 150 return showSplash( duration, IMAGE_RESOURCE, IMAGE_NAME ); 151 } 152 153 163 public static JWindow showSplash( 164 int duration, String resName, String imageName ) 165 { 166 return showSplash( duration, resName, imageName, new Closure() ); 167 } 168 169 182 public static JWindow showSplash( 183 int duration, String resName, String imageName, 184 SplashScreen2.Closure closure 185 ) 186 { 187 189 ApplicationResources appres = ApplicationResources.getInstance(); 190 String splashImageName = 191 appres.getResourceString( resName, imageName ); 192 Image image = appres.getImage( "images", splashImageName, null ); 193 ImageIcon splashImage = new ImageIcon( image ); 194 195 JWindow splash = new JWindow(); 196 JPanel content = (JPanel)splash.getContentPane(); 197 198 int width = splashImage.getIconWidth() + 2; 200 int height = splashImage.getIconHeight() + 2; 201 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 202 int x = (screen.width-width)/2; 203 int y = (screen.height-height)/2; 204 splash.setBounds(x,y,width,height); 205 206 JLabel label = new JLabel( splashImage ); 208 JLabel copyrt = new JLabel 209 ("[c] Copyright 1999, XeNoNSoFT Ltd.", JLabel.CENTER); 210 copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 10)); 211 content.add(label, BorderLayout.CENTER); 212 content.add(copyrt, BorderLayout.SOUTH); 213 214 Border loweredBorder = BorderFactory.createLoweredBevelBorder(); 215 Border raisedBorder = BorderFactory.createRaisedBevelBorder(); 216 content.setBorder( BorderFactory.createCompoundBorder( 217 raisedBorder, loweredBorder) ); 218 220 223 splash.setVisible(true); 225 226 if (closure != null ) { 227 closure.setWindow( splash ); 229 closure.setDuration( duration ); 230 Thread t1 = new Thread ( closure ); 231 t1.start(); 232 } 233 234 return (splash); 235 } 236 237 238 245 public static class Closure implements Runnable { 246 247 248 protected JWindow window; 249 250 protected int duration; 251 252 253 public Closure() 254 { 255 window = null; duration = 1; 256 } 257 258 262 public Closure( JWindow window, int duration ) 263 { 264 this.window = window; 265 this.duration = duration; 266 } 267 268 271 public void setWindow( JWindow newWindow ) 272 { 273 window = newWindow; 274 } 275 276 279 public void setDuration( int newDuration ) 280 { 281 duration = newDuration; 282 } 283 284 287 public void waitAndCloseWindow( ) 288 { 289 try { Thread.sleep(duration); } catch (Exception e) {} 291 SwingUtilities.invokeLater( new Runnable () { 292 public void run() { 293 window.setVisible(false); 294 window.dispose(); 295 window=null; 296 } 297 }); 298 } 299 300 301 304 public void run() 305 { 306 309 if (window == null) 310 throw new NullPointerException ( "splash closure has null window parameter!!"); 311 waitAndCloseWindow(); 312 } 313 314 315 public void finalize() throws Throwable 316 { 317 if (window != null ) { 318 window.dispose(); 319 window = null; 320 } 321 } 322 } 323 324 } 325 326 | Popular Tags |