PageRenderTime 38ms CodeModel.GetById 30ms app.highlight 4ms RepoModel.GetById 3ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/SplashScreen.java

#
Java | 136 lines | 77 code | 23 blank | 36 comment | 0 complexity | 4c932bbe13d5a5a2a79931a7266d91dc MD5 | raw file
  1/*
  2 * SplashScreen.java - Splash screen
  3 * Copyright (C) 1998, 2004 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 javax.swing.*;
 23import java.awt.*;
 24import org.gjt.sp.jedit.jEdit;
 25import org.gjt.sp.util.Log;
 26
 27/**
 28 * The splash screen displayed on startup.
 29 */
 30public class SplashScreen extends JComponent
 31{
 32	public SplashScreen()
 33	{
 34		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 35		setBackground(Color.white);
 36
 37		Font font = new Font("Dialog",Font.PLAIN,10);
 38		setFont(font);
 39		fm = getFontMetrics(font);
 40
 41		image = getToolkit().getImage(
 42			getClass().getResource("/org/gjt/sp/jedit/icons/splash.png"));
 43		MediaTracker tracker = new MediaTracker(this);
 44		tracker.addImage(image,0);
 45
 46		try
 47		{
 48			tracker.waitForAll();
 49		}
 50		catch(Exception e)
 51		{
 52			Log.log(Log.ERROR,this,e);
 53		}
 54
 55		win = new JWindow();
 56
 57		Dimension screen = getToolkit().getScreenSize();
 58		Dimension size = new Dimension(image.getWidth(this) + 2,
 59			image.getHeight(this) + 2 + PROGRESS_HEIGHT);
 60		win.setSize(size);
 61
 62		win.getContentPane().add(BorderLayout.CENTER,this);
 63
 64		win.setLocation((screen.width - size.width) / 2,
 65			(screen.height - size.height) / 2);
 66		win.validate();
 67		win.setVisible(true);
 68
 69		/*synchronized(this)
 70		{
 71			try
 72			{
 73				wait();
 74			}
 75			catch(InterruptedException ie)
 76			{
 77				Log.log(Log.ERROR,this,ie);
 78			}
 79		}*/
 80	}
 81
 82	public void dispose()
 83	{
 84		win.dispose();
 85	}
 86
 87	public synchronized void advance()
 88	{
 89		progress++;
 90		repaint();
 91
 92		// wait for it to be painted to ensure progress is updated
 93		// continuously
 94		try
 95		{
 96			wait();
 97		}
 98		catch(InterruptedException ie)
 99		{
100			Log.log(Log.ERROR,this,ie);
101		}
102	}
103
104	public synchronized void paintComponent(Graphics g)
105	{
106		Dimension size = getSize();
107
108		g.setColor(Color.black);
109		g.drawRect(0,0,size.width - 1,size.height - 1);
110
111		g.drawImage(image,1,1,this);
112
113		// XXX: This should not be hardcoded
114		g.setColor(Color.white);
115		g.fillRect(1,image.getHeight(this) + 1,
116			((win.getWidth() - 2) * progress) / 5,PROGRESS_HEIGHT);
117
118		g.setColor(Color.black);
119
120		String str = "VERSION " + jEdit.getVersion();
121
122		g.drawString(str,
123			(getWidth() - fm.stringWidth(str)) / 2,
124			image.getHeight(this) + (PROGRESS_HEIGHT
125			+ fm.getAscent() + fm.getDescent()) / 2);
126
127		notify();
128	}
129
130	// private members
131	private FontMetrics fm;
132	private JWindow win;
133	private Image image;
134	private int progress;
135	private static final int PROGRESS_HEIGHT = 20;
136}