KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > Splash


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.util;
15
16 import java.awt.*;
17 import java.net.*;
18
19 import org.compiere.Compiere;
20
21 /**
22  * Splash Screen.
23  * - don't use environment as not set up yet -
24  * <code>
25  * Splash splash = new Splash("Processing");
26  * .. do something here
27  * splash.dispose();
28  * splash = null;
29  * </code>
30  * @author Jorg Janke
31  * @version $Id: Splash.java,v 1.2 2003/09/27 01:22:18 jjanke Exp $
32  */

33 public class Splash extends Frame
34 {
35     /**
36      * Get Splash Screen
37      * @return Splash Screen
38      */

39     public static Splash getSplash ()
40     {
41         return getSplash ("Loading...");
42     } // getSplash
43

44     /**
45      * Get Splash Screen
46      * @param text splash text
47      * @return Splash Screen
48      */

49     public static Splash getSplash (String JavaDoc text)
50     {
51         if (s_splash == null)
52             s_splash = new Splash (text);
53         else
54             s_splash.setText(text);
55         return s_splash;
56     } // getSplash
57

58     private static Splash s_splash = null;
59
60     /*************************************************************************/
61
62     /**
63      * Standard constructor
64      * @param text clear text
65      */

66     public Splash (String JavaDoc text)
67     {
68         super("Compiere");
69         message.setText(text);
70         try
71         {
72             jbInit();
73         }
74         catch(Exception JavaDoc e)
75         {
76             System.out.println("Splash");
77             e.printStackTrace();
78         }
79         display();
80     } // Splash
81

82     /** Tracker */
83     private MediaTracker tracker = new MediaTracker(this);
84     //
85
private CImage cImage = new CImage();
86     private AImage aImage = new AImage();
87     //
88
private Label productLabel = new Label();
89     private Panel contentPanel = new Panel();
90     private GridBagLayout contentLayout = new GridBagLayout();
91     private Label message = new Label();
92
93     /**
94      * Static Init
95      * @throws Exception
96      */

97     private void jbInit() throws Exception JavaDoc
98     {
99         this.setBackground(Color.white);
100         this.setName("splash");
101         this.setUndecorated(true);
102         //
103
productLabel.setAlignment(Label.CENTER);
104         message.setFont(new java.awt.Font JavaDoc("Serif", 3, 20)); // italic bold 20 pt
105
message.setForeground(SystemColor.activeCaption);
106         message.setAlignment(Label.CENTER);
107         contentPanel.setLayout(contentLayout);
108         contentPanel.setName("splashContent");
109         contentPanel.setBackground(Color.white);
110         //
111
productLabel.setFont(new java.awt.Font JavaDoc("Serif", 2, 10));
112         productLabel.setForeground(Color.blue);
113         productLabel.setText(Compiere.getSubtitle());
114     // productLabel.setToolTipText(Compiere.getURL());
115
//
116
contentPanel.add(cImage, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
117             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 5, 0, 10), 0, 0));
118         contentPanel.add(productLabel, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
119             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 0, 10), 0, 0));
120         contentPanel.add(message, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
121             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 10, 10), 0, 0));
122         //
123
this.add(aImage, BorderLayout.WEST);
124         this.add(contentPanel, BorderLayout.EAST);
125     } // jbInit
126

127     /**
128      * Set Text (20 pt)
129      * @param text translated text to display
130      */

131     public void setText (String JavaDoc text)
132     {
133         message.setText(text);
134         display();
135     } // setText
136

137     /**
138      * Show Window
139      */

140     public void show()
141     {
142         super.show();
143         toFront();
144     } // show
145

146     /**
147      * Calculate size and display
148      */

149     private void display()
150     {
151         pack();
152         Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
153         Rectangle bounds = getBounds();
154         setBounds((ss.width - bounds.width) / 2, (ss.height - bounds.height) / 2,
155             bounds.width, bounds.height);
156         show();
157     } // display
158

159     /**
160      * Dispose Splash
161      */

162     public void dispose()
163     {
164         super.dispose();
165         s_splash = null;
166     } // dispose
167

168     /*************************************************************************/
169
170     /**
171      * Compiere Image
172      */

173     private class CImage extends Component
174     {
175         /**
176          * Compiere Image
177          */

178         public CImage ()
179         {
180             m_image = Compiere.getImageLogo();
181             tracker.addImage(m_image, 0);
182         }
183         /** The Image */
184         private Image m_image = null;
185         /* The Dimansion */
186         private Dimension m_dim = null;
187
188         /**
189          * Calculate Size
190          * @return size
191          */

192         public Dimension getPreferredSize()
193         {
194             try
195             {
196                 tracker.waitForID(0);
197             }
198             catch (Exception JavaDoc e)
199             {
200                 System.err.println("Splash.CImage");
201                 e.printStackTrace();
202             }
203             m_dim = new Dimension (m_image.getWidth(this), m_image.getHeight(this));
204             return m_dim;
205         } // getPreferredSize
206

207         /**
208          * Paint
209          * @param g Graphics
210          */

211         public void paint(Graphics g)
212         {
213             if (tracker.checkID(0))
214                 g.drawImage(m_image, 0, 0, this);
215         } // paint
216

217     } // CImage
218

219     /**
220      * Animation Image
221      */

222     private class AImage extends Component
223     {
224         /**
225          * Animation Image
226          */

227         public AImage()
228         {
229             super();
230             URL url = org.compiere.Compiere.class.getResource("images/Java_anim.gif");
231             if (url == null)
232                 url = org.compiere.Compiere.class.getResource("images/Java_logo.gif");
233             if (url != null)
234             {
235                 m_image = Toolkit.getDefaultToolkit().getImage(url);
236                 tracker.addImage(m_image, 1);
237             }
238         } // AImage
239

240         /** The image */
241         private Image m_image = null;
242         /** The dimansion */
243         private Dimension m_dim = null;
244
245         /**
246          * Calculate Size
247          * @return size
248          */

249         public Dimension getPreferredSize()
250         {
251             try
252             {
253                 tracker.waitForID(1);
254             }
255             catch (Exception JavaDoc e)
256             {
257                 System.err.println("Splash.AImage");
258                 e.printStackTrace();
259             }
260             m_dim = new Dimension (m_image.getWidth(this)+15, m_image.getHeight(this)+15);
261             return m_dim;
262         } // getPreferredSize
263

264         /**
265          * Paint
266          * @param g Graphics
267          */

268         public void paint (Graphics g)
269         {
270             if (tracker.checkID(1))
271                 g.drawImage(m_image, 10, 10, this);
272         } // paint
273

274         /**
275          * Update
276          * @param g Graphics
277          */

278         public void update (Graphics g)
279         {
280             paint(g);
281         } // update
282

283     } // AImage
284

285 } // Splash
286
Popular Tags