1 19 20 package org.gjt.sp.jedit.gui; 21 22 import javax.swing.*; 23 import java.awt.*; 24 25 import org.gjt.sp.jedit.jEdit; 26 import org.gjt.sp.util.Log; 27 28 32 public class SplashScreen extends JComponent 33 { 34 public SplashScreen() 35 { 36 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 37 setBackground(Color.white); 38 39 Font font = new Font("Dialog",Font.PLAIN,10); 40 setFont(font); 41 fm = getFontMetrics(font); 42 43 image = getToolkit().getImage( 44 getClass().getResource("/org/gjt/sp/jedit/icons/splash.png")); 45 MediaTracker tracker = new MediaTracker(this); 46 tracker.addImage(image,0); 47 48 try 49 { 50 tracker.waitForAll(); 51 } 52 catch(Exception e) 53 { 54 Log.log(Log.ERROR,this,e); 55 } 56 57 win = new JWindow(); 58 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 59 GraphicsDevice[] gs = ge.getScreenDevices(); 60 int height = gs[0].getDisplayMode().getHeight(); 61 int width = gs[0].getDisplayMode().getWidth(); 62 Dimension screen = new Dimension(width, height); 63 Dimension size = new Dimension(image.getWidth(this) + 2, 64 image.getHeight(this) + 2 + PROGRESS_HEIGHT); 65 win.setSize(size); 66 67 win.getContentPane().add(this, BorderLayout.CENTER); 68 69 win.setLocation((screen.width - size.width) / 2, 70 (screen.height - size.height) / 2); 71 win.validate(); 72 win.setVisible(true); 73 } 74 75 public void dispose() 76 { 77 win.dispose(); 78 } 79 80 public synchronized void advance() 81 { 82 logAdvanceTime(null); 83 progress++; 84 repaint(); 85 86 try 89 { 90 wait(); 91 } 92 catch(InterruptedException ie) 93 { 94 Log.log(Log.ERROR,this,ie); 95 } 96 } 97 98 public synchronized void advance(String label) 99 { 100 logAdvanceTime(label); 101 progress++; 102 this.label = label; 103 repaint(); 104 105 try 108 { 109 wait(); 110 } 111 catch(InterruptedException ie) 112 { 113 Log.log(Log.ERROR,this,ie); 114 } 115 } 116 117 private void logAdvanceTime(String label) 118 { 119 long currentTime = System.currentTimeMillis(); 120 if (lastLabel != null) 121 { 122 Log.log(Log.DEBUG, SplashScreen.class, lastLabel +':'+(currentTime - lastAdvanceTime) + "ms"); 123 } 124 if (label != null) 125 { 126 lastLabel = label; 127 lastAdvanceTime = currentTime; 128 129 } 130 131 } 132 133 public synchronized void paintComponent(Graphics g) 134 { 135 Dimension size = getSize(); 136 137 g.setColor(Color.black); 138 g.drawRect(0,0,size.width - 1,size.height - 1); 139 140 g.drawImage(image,1,1,this); 141 142 g.setColor(Color.white); 144 g.fillRect(1,image.getHeight(this) + 1, 145 ((win.getWidth() - 2) * progress) / PROGRESS_COUNT, PROGRESS_HEIGHT); 146 147 g.setColor(Color.black); 148 149 if (label != null) 150 { 151 g.drawString(label, 152 (getWidth() - fm.stringWidth(label)) / 2, 153 image.getHeight(this) + (PROGRESS_HEIGHT 154 + fm.getAscent() + fm.getDescent()) / 2); 155 } 156 157 158 String version = jEdit.getVersion(); 159 g.drawString(version, 160 getWidth() - fm.stringWidth(version) - 2, 161 image.getHeight(this) - fm.getDescent()); 162 notify(); 163 } 164 165 private final FontMetrics fm; 167 private final JWindow win; 168 private final Image image; 169 private int progress; 170 private static final int PROGRESS_HEIGHT = 20; 171 private static final int PROGRESS_COUNT = 28; 172 private String label; 173 private String lastLabel; 174 private long lastAdvanceTime = System.currentTimeMillis(); 175 } 176 | Popular Tags |