PageRenderTime 69ms CodeModel.GetById 62ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/SplashScreen.java

#
Java | 154 lines | 89 code | 26 blank | 39 comment | 2 complexity | 2ef9270848465afe81b9e613a8b0870f MD5 | raw file
  1/*
  2 * SplashScreen.java - Splash screen
  3 * Copyright (C) 1998, 1999, 2000, 2001 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit.gui;
 21
 22import java.awt.*;
 23import org.gjt.sp.jedit.jEdit;
 24import org.gjt.sp.util.Log;
 25
 26/**
 27 * The splash screen displayed on startup.<p>
 28 *
 29 * This file only uses AWT APIs so that it can be displayed as soon as possible
 30 * after jEdit is launched.
 31 */
 32public class SplashScreen extends Canvas
 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 Window(new Frame());
 58
 59		Dimension screen = getToolkit().getScreenSize();
 60		Dimension size = new Dimension(image.getWidth(this) + 2,
 61			image.getHeight(this) + 2 + PROGRESS_HEIGHT);
 62		win.setSize(size);
 63
 64		win.setLayout(new BorderLayout());
 65		win.add(BorderLayout.CENTER,this);
 66
 67		win.setLocation((screen.width - size.width) / 2,
 68			(screen.height - size.height) / 2);
 69		win.validate();
 70		win.show();
 71
 72		/*synchronized(this)
 73		{
 74			try
 75			{
 76				wait();
 77			}
 78			catch(InterruptedException ie)
 79			{
 80				Log.log(Log.ERROR,this,ie);
 81			}
 82		}*/
 83	}
 84
 85	public void dispose()
 86	{
 87		win.dispose();
 88	}
 89
 90	public synchronized void advance()
 91	{
 92		progress++;
 93		repaint();
 94
 95		// wait for it to be painted to ensure progress is updated
 96		// continuously
 97		try
 98		{
 99			wait();
100		}
101		catch(InterruptedException ie)
102		{
103			Log.log(Log.ERROR,this,ie);
104		}
105	}
106
107	public void update(Graphics g)
108	{
109		paint(g);
110	}
111
112	public synchronized void paint(Graphics g)
113	{
114		Dimension size = getSize();
115
116		if(offscreenImg == null)
117		{
118			offscreenImg = createImage(size.width,size.height);
119			offscreenGfx = offscreenImg.getGraphics();
120			offscreenGfx.setFont(getFont());
121		}
122
123		offscreenGfx.setColor(Color.gray);
124		offscreenGfx.drawRect(0,0,size.width - 1,size.height - 1);
125
126		offscreenGfx.drawImage(image,1,1,this);
127
128		// XXX: This should not be hardcoded
129		offscreenGfx.setColor(new Color(168,173,189));
130		offscreenGfx.fillRect(1,image.getHeight(this) + 1,
131			((win.getWidth() - 2) * progress) / 5,PROGRESS_HEIGHT);
132
133		offscreenGfx.setColor(Color.gray);
134
135		String str = "Version " + jEdit.getVersion();
136
137		offscreenGfx.drawString(str,
138			(getWidth() - fm.stringWidth(str)) / 2,
139			image.getHeight(this)+1 - fm.getDescent() - 10);
140
141		g.drawImage(offscreenImg,0,0,this);
142
143		notify();
144	}
145
146	// private members
147	private FontMetrics fm;
148	private Window win;
149	private Image image;
150	private Image offscreenImg;
151	private Graphics offscreenGfx;
152	private int progress;
153	private static final int PROGRESS_HEIGHT = 20;
154}