https://hal.archives-ouvertes.fr/hal-02177293
Tip revision: a5c3a632ff52caf942ac0457ce1ec733926a867b authored by Software Heritage on 01 January 2004, 00:00:00 UTC
hal: Deposit 315 in collection hal
hal: Deposit 315 in collection hal
Tip revision: a5c3a63
PanelSplash.java
/*
* Créé le 15 sept. 2004
*
*/
package gui.principal;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.net.URL;
import principal.Commun;
/**
* Affiche une image au démarrage, pour faire patienter l'utilisateur avant que
* la fenętre principale ne s'ouvre. Adaptée d'un code trouvé sur le net dont voici
* la présentation :
* <p>
* Present a simple graphic to the user upon launch of the application, to
* provide a faster initial response than is possible with the main window.
* <P>
* Adapted from an
* <a href=http://developer.java.sun.com/developer/qow/archive/24/index.html>item</a>
* on Sun's Java Developer Connection.
* <P>
* This splash screen appears within about 2.5 seconds on a development
* machine. The main screen takes about 6.0 seconds to load, so use of a splash
* screen cuts down the initial display delay by about 55 percent.
*
* @author <a href="http://www.javapractices.com/">javapractices.com</a>
* @author Vincent Labatut
* @version 1
*/
public final class PanelSplash extends Frame
{ /**
* nom du fichier contenant l'image ŕ afficher
*/
private final String fImageId;
/**
* ...
*/
private MediaTracker fMediaTracker;
/**
* image ŕ afficher
*/
private Image fImage;
//----------------------------------------
// Constructeur
//----------------------------------------
/**
* aImageId must have content, and is used by
* <code>Class.getResource</code> to retrieve the splash screen image.
*/
public PanelSplash()
{
/* Implementation Note
* Args.checkForContent is not called here, in an attempt to minimize
* class loading.
*/
String aImageId = Commun.PATH_SPLASH;
if ( aImageId == null || aImageId.trim().length() == 0 )
{ throw new IllegalArgumentException(Commun.TITRE_ERREUR);
}
fImageId = aImageId;
}
/**
* Show the splash screen to the end user.
*
* <P>Once this method returns, the splash screen is realized, which means
* that almost all work on the splash screen should proceed through the event
* dispatch thread. In particular, any call to <code>dispose</code> for the
* splash screen must be performed in the event dispatch thread.
*/
public void splash()
{ initImageAndTracker();
setSize(fImage.getWidth(null), fImage.getHeight(null));
center();
URL url = getClass().getResource(Commun.PATH_ICONE_RAGE);
setIconImage((new javax.swing.ImageIcon(url)).getImage());
//System.out.println("splash:"+url);
fMediaTracker.addImage(fImage, 0);
try
{
fMediaTracker.waitForID(0);
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
SplashWindow splashWindow = new SplashWindow(this,fImage);
}
/**
* récupčre l'image
*
*/
private void initImageAndTracker()
{
fMediaTracker = new MediaTracker(this);
URL imageURL = PanelSplash.class.getResource(fImageId);
fImage = Toolkit.getDefaultToolkit().getImage(imageURL);
}
/**
* Centers the frame on the screen.
*/
private void center()
{
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle frame = getBounds();
setLocation((screen.width - frame.width)/2, (screen.height - frame.height)/2);
}
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/**
* Fenętre qui va contenir l'image
*
*/
private class SplashWindow extends Window
{ /**
* l'image ŕ afficher
*
*/
private Image fImage;
SplashWindow(Frame aParent, Image aImage)
{ super(aParent);
fImage = aImage;
setSize(fImage.getWidth(null), fImage.getHeight(null));
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle window = getBounds();
setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
setVisible(true);
}
/*
*
*/
public void paint(Graphics graphics)
{ if (fImage != null)
{ // on dessine l'image
graphics.drawImage(fImage,0,0,this);
// on incruste du texte (version, etc)
Font f = new Font("Courrier",Font.PLAIN, 10);
graphics.setFont(f);
graphics.drawString(Commun.STRING_COEUR+":v"+Commun.VERSION+" / "+Commun.STRING_GUI+":v"+syl.principal.Commun.VERSION,10,570);
}
}
}
}