1 package net.suberic.pooka.gui; 2 3 import javax.swing.*; 4 import java.awt.*; 5 6 import net.suberic.pooka.Pooka; 7 8 11 public class PookaStartup { 12 13 JLabel mStatusField; 14 JProgressBar mProgressBar; 15 16 JFrame mFrame; 17 18 21 public void show() { 22 mFrame = new JFrame(); 23 JPanel fullPanel = new JPanel(); 24 fullPanel.setLayout(new BorderLayout()); 25 26 ImagePanel imagePanel = null; 27 try { 28 java.net.URL sourceUrl = this.getClass().getResource(Pooka.getProperty("Pooka.startupImage", "images/PookaSplashscreen.jpg")); 29 Image image = Toolkit.getDefaultToolkit().getImage(sourceUrl); 30 31 imagePanel = new ImagePanel(image); 32 imagePanel.setSize(300,300); 33 imagePanel.setPreferredSize(new java.awt.Dimension (300,300)); 34 35 } catch (Exception e) { 36 e.printStackTrace(); 37 } 38 39 mStatusField = new JLabel("Loading Pooka...", SwingConstants.CENTER); 40 41 mProgressBar = new JProgressBar(0, 100); 42 43 Box progressBox = Box.createVerticalBox(); 44 progressBox.add(mStatusField); 45 progressBox.add(mProgressBar); 46 47 fullPanel.add(imagePanel, BorderLayout.CENTER); 48 fullPanel.add(progressBox, BorderLayout.SOUTH); 49 50 fullPanel.setBorder(BorderFactory.createEtchedBorder()); 51 52 mFrame.getContentPane().add(fullPanel); 53 54 SwingUtilities.invokeLater(new Runnable () { 55 public void run() { 56 mFrame.setUndecorated(true); 57 mFrame.pack(); 58 59 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 60 Dimension frameSize = mFrame.getSize(); 61 int x = Math.max(0, (screenSize.width - frameSize.width) / 2); 62 int y = Math.max(0, (screenSize.height - frameSize.height) / 2); 63 64 mFrame.setLocation(x, y); 65 mFrame.setLocation(x, y); 67 } 68 }); 69 } 70 71 75 public void setStatus(String pStatus) { 76 final String fStatus = pStatus; 77 Runnable runMe = new Runnable () { 78 public void run() { 79 String text = Pooka.getProperty(fStatus + ".label", fStatus); 80 int weight = 10; 81 try { 82 weight = Integer.parseInt(Pooka.getProperty(fStatus + ".weight", "10")); 83 } catch (NumberFormatException nfe) { 84 } 85 mStatusField.setText(text); 86 mStatusField.repaint(); 87 88 try { 89 mProgressBar.setValue(mProgressBar.getValue() + weight); 90 } catch (Exception e) { 91 mProgressBar.setIndeterminate(true); 94 } 95 } 96 }; 97 98 if (SwingUtilities.isEventDispatchThread()) { 99 runMe.run(); 100 } else { 101 SwingUtilities.invokeLater(runMe); 102 } 103 } 104 105 108 public void hide() { 109 123 } 124 125 class ImagePanel extends JPanel { 126 Image mImage; 127 128 ImagePanel(Image pImage) { 129 mImage = pImage; 130 } 131 132 public void paintComponent(Graphics g) { 133 super.paintComponent(g); 134 135 int x = (getSize().width - mImage.getWidth(this)) / 2; 136 int y = (getSize().height - mImage.getHeight(this)) / 2; 137 138 g.drawImage(mImage, x, y, this); 139 140 } 141 } 142 143 } 144 | Popular Tags |