1 14 package org.compiere.util; 15 16 import java.awt.*; 17 import java.net.*; 18 19 import org.compiere.Compiere; 20 21 33 public class Splash extends Frame 34 { 35 39 public static Splash getSplash () 40 { 41 return getSplash ("Loading..."); 42 } 44 49 public static Splash getSplash (String 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 } 58 private static Splash s_splash = null; 59 60 61 62 66 public Splash (String text) 67 { 68 super("Compiere"); 69 message.setText(text); 70 try 71 { 72 jbInit(); 73 } 74 catch(Exception e) 75 { 76 System.out.println("Splash"); 77 e.printStackTrace(); 78 } 79 display(); 80 } 82 83 private MediaTracker tracker = new MediaTracker(this); 84 private CImage cImage = new CImage(); 86 private AImage aImage = new AImage(); 87 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 97 private void jbInit() throws Exception 98 { 99 this.setBackground(Color.white); 100 this.setName("splash"); 101 this.setUndecorated(true); 102 productLabel.setAlignment(Label.CENTER); 104 message.setFont(new java.awt.Font ("Serif", 3, 20)); message.setForeground(SystemColor.activeCaption); 106 message.setAlignment(Label.CENTER); 107 contentPanel.setLayout(contentLayout); 108 contentPanel.setName("splashContent"); 109 contentPanel.setBackground(Color.white); 110 productLabel.setFont(new java.awt.Font ("Serif", 2, 10)); 112 productLabel.setForeground(Color.blue); 113 productLabel.setText(Compiere.getSubtitle()); 114 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 this.add(aImage, BorderLayout.WEST); 124 this.add(contentPanel, BorderLayout.EAST); 125 } 127 131 public void setText (String text) 132 { 133 message.setText(text); 134 display(); 135 } 137 140 public void show() 141 { 142 super.show(); 143 toFront(); 144 } 146 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 } 159 162 public void dispose() 163 { 164 super.dispose(); 165 s_splash = null; 166 } 168 169 170 173 private class CImage extends Component 174 { 175 178 public CImage () 179 { 180 m_image = Compiere.getImageLogo(); 181 tracker.addImage(m_image, 0); 182 } 183 184 private Image m_image = null; 185 186 private Dimension m_dim = null; 187 188 192 public Dimension getPreferredSize() 193 { 194 try 195 { 196 tracker.waitForID(0); 197 } 198 catch (Exception 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 } 207 211 public void paint(Graphics g) 212 { 213 if (tracker.checkID(0)) 214 g.drawImage(m_image, 0, 0, this); 215 } 217 } 219 222 private class AImage extends Component 223 { 224 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 } 240 241 private Image m_image = null; 242 243 private Dimension m_dim = null; 244 245 249 public Dimension getPreferredSize() 250 { 251 try 252 { 253 tracker.waitForID(1); 254 } 255 catch (Exception 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 } 264 268 public void paint (Graphics g) 269 { 270 if (tracker.checkID(1)) 271 g.drawImage(m_image, 10, 10, this); 272 } 274 278 public void update (Graphics g) 279 { 280 paint(g); 281 } 283 } 285 } | Popular Tags |