C:\Java WorkShop\Lexx\src\lexx\gui\startup\StartupScreen.java

1    package lexx.gui.startup; 
2     
3    import java.awt.Color; 
4    import java.awt.Dimension; 
5    import java.awt.Font; 
6    import java.awt.Toolkit; 
7    import javax.swing.Box; 
8    import javax.swing.ImageIcon; 
9    import javax.swing.JFrame; 
10   import javax.swing.JLabel; 
11   import javax.swing.JLayeredPane; 
12   import javax.swing.SwingUtilities; 
13    
14   /** 
15    * <p>Splash or startup screen</p> 
16    * @since 20/02/2003 
17    * @author Mohammed Imran 
18    * @version 1.0 
19    */ 
20   public final class StartupScreen extends JFrame 
21   { 
22     private final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(this. 
23         getClass()); 
24     private boolean nowTurnOff = false; 
25     private final JLabel sent = new JLabel("Welcome to Lexx IDE"); 
26     private final int GAP = 50; 
27     private final int WIDTH = 600; 
28    
29     public StartupScreen(JLabel status) 
30     { 
31       super("Please select project"); 
32    
33       lexx.utils.Config.setStatusLabel(status); 
34       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
35    
36       status.setFont(new Font(status.getFont().getName(), Font.BOLD, 15)); 
37       status.setForeground(Color.MAGENTA); 
38       status.setHorizontalAlignment(JLabel.RIGHT); 
39    
40       //section from NativeSplashScreen.java - http://www.l2fprod.com 
41       ImageIcon image = new ImageIcon(StartupScreen.class.getResource("image.gif")); 
42       /*    if (NativeSkin.isSupported()) 
43           { 
44             NativeSkin.getInstance().setAlwaysOnTop(this, true); 
45   //     NativeSkin.getInstance().setWindowRegion(this,NativeSkin.getInstance().createRegion(image.getImage() ) ,true); 
46   //     NativeSkin.getInstance().setWindowTransparency(this, 50); 
47           }*/ 
48    
49       JLabel picture = new JLabel(image); 
50       JLayeredPane layer = this.getLayeredPane(); 
51    
52       layer.add(status, Integer.MIN_VALUE - 2); 
53       layer.add(sent, Integer.MIN_VALUE - 3); 
54    
55       layer.setPreferredSize(picture.getPreferredSize()); 
56       picture.setSize(picture.getPreferredSize()); 
57       status.setSize(WIDTH, picture.getHeight()); 
58       sent.setSize(WIDTH, picture.getHeight()); 
59       sent.setHorizontalAlignment(JLabel.CENTER); 
60       sent.setVerticalAlignment(JLabel.BOTTOM); 
61       sent.setForeground(Color.BLUE); 
62       sent.setFont(new Font(sent.getFont().getName(), Font.BOLD, 15)); 
63    
64       setSize(status.getSize()); 
65       Box b1 = Box.createHorizontalBox(); 
66       b1.add(picture); 
67       SelectProject sel = new SelectProject(status, this); 
68       b1.add(sel); 
69       this.getContentPane().add(b1); 
70    
71       Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
72       setLocation( (screen.width - getWidth()) / 2, 
73                   (screen.height - getHeight()) / 2); 
74       final Runnable closerRunner = new Runnable() 
75       { 
76         public void run() 
77         { 
78           setVisible(false); 
79           dispose(); 
80         } 
81       }; 
82       Runnable waitRunner = new Runnable() 
83       { 
84         public void run() 
85         { 
86           try 
87           { 
88             while(!nowTurnOff) 
89             { 
90               Thread.sleep(100); 
91             } 
92             SwingUtilities.invokeAndWait(closerRunner); 
93           } 
94           catch(Exception ex) 
95           { 
96             log.fatal(ex, ex); 
97           } 
98         } 
99       }; 
100      Thread splashThread = new Thread(waitRunner, "SplashThread"); 
101      splashThread.start(); 
102   
103      new Thread() 
104      { 
105        public void run() 
106        { 
107          this.setPriority(Thread.MIN_PRIORITY); 
108          while(!nowTurnOff) 
109          { 
110            try 
111            { 
112              if(lexx.utils.Config.getClient() != null) 
113              { 
114                sent.setText("Sent " + ( (int) (lexx.server.Chat.sent / 1024)) + 
115                             "Kb, Recieved " + 
116                             ( (int) (lexx.server.Chat.receieved / 1024)) + "Kb"); 
117              } 
118              else 
119              { 
120                this.sleep(500); 
121              } 
122            } 
123            catch(InterruptedException ex) 
124            { 
125              log.fatal(ex, ex); 
126            } 
127          } 
128        } 
129      }.start(); 
130   
131      this.setSize(WIDTH + 15, picture.getHeight() + GAP); 
132      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
133      setLocation(screenSize.width / 2 - (this.getWidth() / 2), 
134                  screenSize.height / 2 - (this.getHeight() / 2)); 
135   
136      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
137      setVisible(true); 
138    } 
139   
140    public final void turnOff() 
141    { 
142      nowTurnOff = true; 
143      this.dispose(); 
144    } 
145  }