org.lwjgl.util.applet
Class AppletLoader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by org.lwjgl.util.applet.AppletLoader
All Implemented Interfaces:
java.applet.AppletStub, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible

public class AppletLoader
extends java.applet.Applet
implements java.lang.Runnable, java.applet.AppletStub

The AppletLoader enables deployment of LWJGL to applets in an easy and polished way. The loader will display a configurable logo and progressbar while the relevant jars (generic and native) are downloaded from a specified source.

The downloaded jars are extracted to the users temporary directory - and if enabled, cached for faster loading in future uses.

The following applet parameters are required:

Additionally the following parameters can be supplied to tweak the behaviour of the AppletLoader.

Version:
$Revision$ $Id$
Author:
kappaOne, Brian Matzon
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.Thread animationThread
          animation thread that renders our load screen while loading
protected  java.awt.Color bgColor
          background color of applet
protected  boolean certificateRefused
          whether a certificate refused error occured
protected  java.lang.String[] certificateRefusedMessage
          error message to display if user refuses to accept certicate
protected  java.lang.ClassLoader classLoader
          classLoader used to add downloaded jars to the classpath
protected  int currentSizeDownload
          current size of download in bytes
protected  int currentSizeExtract
          current size of extracted in bytes
protected  boolean debugMode
          whether we're running in debug mode
protected  java.awt.Color errorColor
          Color to write errors in
protected  boolean fatalError
          whether a fatal error occured
protected  java.lang.String fatalErrorDescription
          fatal error that occured
protected  java.awt.Color fgColor
          color to write foreground in
protected  java.lang.String[] genericErrorMessage
          generic error message to display on error
protected  java.lang.Thread loaderThread
          actual thread that does the loading
protected  java.awt.Image logo
          logo to be shown while loading
protected  java.applet.Applet lwjglApplet
          applet to load after all downloads are complete
protected  boolean lzmaSupported
          whether lzma is supported
protected static boolean natives_loaded
          have natives been loaded by another instance of this applet
protected  java.awt.Image offscreen
          offscreen image used
protected  boolean pack200Supported
          whether pack200 is supported
protected  int percentage
          used to calculate length of progress bar
protected  boolean prependHost
          whether to prepend host to cache path
protected  java.awt.Image progressbar
          progressbar to render while loading
protected  int state
          state of applet loader
static int STATE_CHECKING_CACHE
          checking for already downloaded files
static int STATE_DETERMINING_PACKAGES
          determining which packages that are required
static int STATE_DONE
          done
static int STATE_DOWNLOADING
          downloading packages
static int STATE_EXTRACTING_PACKAGES
          extracting packages
static int STATE_INIT
          initializing
static int STATE_INITIALIZE_REAL_APPLET
          initializing real applet
static int STATE_START_REAL_APPLET
          stating real applet
static int STATE_SWITCHING_APPLET
          switching to real applet
static int STATE_UPDATING_CLASSPATH
          updating the classpath
protected  java.lang.String subtaskMessage
          String to display as a subtask
protected  int totalSizeDownload
          total size of download in bytes
protected  int totalSizeExtract
          total size of extracted in bytes
protected  java.net.URL[] urlList
          urls of the jars to download
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AppletLoader()
           
 
Method Summary
 void appletResize(int width, int height)
          Transfers the call of AppletResize from the stub to the lwjglApplet.
protected  void debug_sleep(long ms)
          Utility method for sleeping Will only really sleep if debug has been enabled
 void destroy()
           
protected  void downloadJars(java.lang.String path)
          Will download the jars from the server using the list of urls in urlList, while at the same time updating progress bar
protected  void extractJars(java.lang.String path)
          Extract all jars from any lzma/pack files
protected  void extractLZMA(java.lang.String in, java.lang.String out)
          Extract LZMA File
protected  void extractNatives(java.lang.String path)
          This method will extract all file from the native jar and extract them to the subdirectory called "natives" in the local path, will also check to see if the native jar files is signed properly
protected  void extractPack(java.lang.String in, java.lang.String out)
          Extract Pack File
protected  void fatalErrorOccured(java.lang.String error, java.lang.Exception e)
          Sets the state of the loaded and prints some debug information
 java.applet.Applet getApplet()
          Retrieves the applet that has been loaded.
protected  boolean getBooleanParameter(java.lang.String name, boolean defaultValue)
          Retrieves the boolean value for the applet
protected  java.awt.Color getColor(java.lang.String color, java.awt.Color defaultColor)
          Retrieves the color
protected  java.lang.String getDescriptionForState()
           
protected  java.lang.String getFileName(java.net.URL url)
          Get file name portion of URL.
protected  java.awt.Image getImage(java.lang.String s)
          Get Image from path provided
protected  java.io.InputStream getJarInputStream(java.lang.String currentFile, java.net.URLConnection urlconnection)
          Retrieves a jar files input stream.
protected  java.lang.String getJarName(java.net.URL url)
          Get jar name from URL.
 void init()
           
protected  void loadJarURLs()
          Reads list of jars to download and adds the urls to urlList also finds out which OS you are on and adds appropriate native jar to the urlList
 void paint(java.awt.Graphics g)
           
protected  float readVersionFile(java.io.File file)
          read the current version file
 void run()
          4 steps 1) check version of applet and decide whether to download jars 2) download the jars 3) extract natives 4) add to jars to class path 5) switch applets
protected  void sleep(long ms)
          Utility method for sleeping
 void start()
           
 void stop()
           
protected  void switchApplet()
          replace the current applet with the lwjgl applet using AppletStub and initialise and start it
protected  java.lang.String trimExtensionByCapabilities(java.lang.String file)
          Trims the passed file string based on the available capabilities
 void update(java.awt.Graphics g)
           
protected  void updateClassPath(java.lang.String path)
          Edits the ClassPath at runtime to include the jars that have just been downloaded and then adds the lwjgl natives folder property.
protected static void validateCertificateChain(java.security.cert.Certificate[] ownCerts, java.security.cert.Certificate[] native_certs)
          Validates the certificate chain for a single file
protected  void writeVersionFile(java.io.File file, float version)
          write out version file of applet
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.applet.AppletStub
getAppletContext, getCodeBase, getDocumentBase, getParameter, isActive
 

Field Detail

STATE_INIT

public static final int STATE_INIT
initializing

See Also:
Constant Field Values

STATE_DETERMINING_PACKAGES

public static final int STATE_DETERMINING_PACKAGES
determining which packages that are required

See Also:
Constant Field Values

STATE_CHECKING_CACHE

public static final int STATE_CHECKING_CACHE
checking for already downloaded files

See Also:
Constant Field Values

STATE_DOWNLOADING

public static final int STATE_DOWNLOADING
downloading packages

See Also:
Constant Field Values

STATE_EXTRACTING_PACKAGES

public static final int STATE_EXTRACTING_PACKAGES
extracting packages

See Also:
Constant Field Values

STATE_UPDATING_CLASSPATH

public static final int STATE_UPDATING_CLASSPATH
updating the classpath

See Also:
Constant Field Values

STATE_SWITCHING_APPLET

public static final int STATE_SWITCHING_APPLET
switching to real applet

See Also:
Constant Field Values

STATE_INITIALIZE_REAL_APPLET

public static final int STATE_INITIALIZE_REAL_APPLET
initializing real applet

See Also:
Constant Field Values

STATE_START_REAL_APPLET

public static final int STATE_START_REAL_APPLET
stating real applet

See Also:
Constant Field Values

STATE_DONE

public static final int STATE_DONE
done

See Also:
Constant Field Values

percentage

protected int percentage
used to calculate length of progress bar


currentSizeDownload

protected int currentSizeDownload
current size of download in bytes


totalSizeDownload

protected int totalSizeDownload
total size of download in bytes


currentSizeExtract

protected int currentSizeExtract
current size of extracted in bytes


totalSizeExtract

protected int totalSizeExtract
total size of extracted in bytes


logo

protected java.awt.Image logo
logo to be shown while loading


progressbar

protected java.awt.Image progressbar
progressbar to render while loading


offscreen

protected java.awt.Image offscreen
offscreen image used


bgColor

protected java.awt.Color bgColor
background color of applet


errorColor

protected java.awt.Color errorColor
Color to write errors in


fgColor

protected java.awt.Color fgColor
color to write foreground in


urlList

protected java.net.URL[] urlList
urls of the jars to download


classLoader

protected java.lang.ClassLoader classLoader
classLoader used to add downloaded jars to the classpath


loaderThread

protected java.lang.Thread loaderThread
actual thread that does the loading


animationThread

protected java.lang.Thread animationThread
animation thread that renders our load screen while loading


lwjglApplet

protected java.applet.Applet lwjglApplet
applet to load after all downloads are complete


fatalError

protected boolean fatalError
whether a fatal error occured


fatalErrorDescription

protected java.lang.String fatalErrorDescription
fatal error that occured


debugMode

protected boolean debugMode
whether we're running in debug mode


prependHost

protected boolean prependHost
whether to prepend host to cache path


subtaskMessage

protected java.lang.String subtaskMessage
String to display as a subtask


state

protected int state
state of applet loader


lzmaSupported

protected boolean lzmaSupported
whether lzma is supported


pack200Supported

protected boolean pack200Supported
whether pack200 is supported


genericErrorMessage

protected java.lang.String[] genericErrorMessage
generic error message to display on error


certificateRefused

protected boolean certificateRefused
whether a certificate refused error occured


certificateRefusedMessage

protected java.lang.String[] certificateRefusedMessage
error message to display if user refuses to accept certicate


natives_loaded

protected static boolean natives_loaded
have natives been loaded by another instance of this applet

Constructor Detail

AppletLoader

public AppletLoader()
Method Detail

init

public void init()
Overrides:
init in class java.applet.Applet

start

public void start()
Overrides:
start in class java.applet.Applet

stop

public void stop()
Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Overrides:
destroy in class java.applet.Applet

getApplet

public java.applet.Applet getApplet()
Retrieves the applet that has been loaded. Useful for liveconnect.


appletResize

public void appletResize(int width,
                         int height)
Transfers the call of AppletResize from the stub to the lwjglApplet.

Specified by:
appletResize in interface java.applet.AppletStub

update

public final void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container

getDescriptionForState

protected java.lang.String getDescriptionForState()
Returns:
string describing the state of the loader

trimExtensionByCapabilities

protected java.lang.String trimExtensionByCapabilities(java.lang.String file)
Trims the passed file string based on the available capabilities

Parameters:
file - string of files to be trimmed
Returns:
trimmed string based on capabilities of client

loadJarURLs

protected void loadJarURLs()
                    throws java.lang.Exception
Reads list of jars to download and adds the urls to urlList also finds out which OS you are on and adds appropriate native jar to the urlList

Throws:
java.lang.Exception

run

public void run()
4 steps 1) check version of applet and decide whether to download jars 2) download the jars 3) extract natives 4) add to jars to class path 5) switch applets

Specified by:
run in interface java.lang.Runnable

readVersionFile

protected float readVersionFile(java.io.File file)
                         throws java.lang.Exception
read the current version file

Parameters:
file - the file to read
Returns:
the version value of saved file
Throws:
java.lang.Exception - if it fails to read value

writeVersionFile

protected void writeVersionFile(java.io.File file,
                                float version)
                         throws java.lang.Exception
write out version file of applet

Parameters:
file - the file to write out to
version - the version of the applet as a float
Throws:
java.lang.Exception - if it fails to write file

updateClassPath

protected void updateClassPath(java.lang.String path)
                        throws java.lang.Exception
Edits the ClassPath at runtime to include the jars that have just been downloaded and then adds the lwjgl natives folder property.

Parameters:
path - location where applet is stored
Throws:
java.lang.Exception - if it fails to add classpath

switchApplet

protected void switchApplet()
                     throws java.lang.Exception
replace the current applet with the lwjgl applet using AppletStub and initialise and start it

Throws:
java.lang.Exception

downloadJars

protected void downloadJars(java.lang.String path)
                     throws java.lang.Exception
Will download the jars from the server using the list of urls in urlList, while at the same time updating progress bar

Parameters:
path - location of the directory to save to
Throws:
java.lang.Exception - if download fails

getJarInputStream

protected java.io.InputStream getJarInputStream(java.lang.String currentFile,
                                                java.net.URLConnection urlconnection)
                                         throws java.lang.Exception
Retrieves a jar files input stream. This method exists primarily to fix an Opera hang in getInputStream

Parameters:
urlconnection - connection to get input stream from
Returns:
InputStream or null if not possible
Throws:
java.lang.Exception

extractLZMA

protected void extractLZMA(java.lang.String in,
                           java.lang.String out)
                    throws java.lang.Exception
Extract LZMA File

Parameters:
in - Input path to pack file
out - output path to resulting file
Throws:
exception - if any errors occur
java.lang.Exception

extractPack

protected void extractPack(java.lang.String in,
                           java.lang.String out)
                    throws java.lang.Exception
Extract Pack File

Parameters:
in - Input path to pack file
out - output path to resulting file
Throws:
exception - if any errors occur
java.lang.Exception

extractJars

protected void extractJars(java.lang.String path)
                    throws java.lang.Exception
Extract all jars from any lzma/pack files

Parameters:
path - output path
Throws:
exception - if any errors occur
java.lang.Exception

extractNatives

protected void extractNatives(java.lang.String path)
                       throws java.lang.Exception
This method will extract all file from the native jar and extract them to the subdirectory called "natives" in the local path, will also check to see if the native jar files is signed properly

Parameters:
path - base folder containing all downloaded jars
Throws:
java.lang.Exception - if it fails to extract files

validateCertificateChain

protected static void validateCertificateChain(java.security.cert.Certificate[] ownCerts,
                                               java.security.cert.Certificate[] native_certs)
                                        throws java.lang.Exception
Validates the certificate chain for a single file

Parameters:
ownCerts - Chain of certificates to check against
native_certs - Chain of certificates to check
Throws:
java.lang.Exception

getImage

protected java.awt.Image getImage(java.lang.String s)
Get Image from path provided

Parameters:
s - location of the image
Returns:
the Image file

getJarName

protected java.lang.String getJarName(java.net.URL url)
Get jar name from URL.

Parameters:
url - Get jar file name from this url
Returns:
file name as string

getFileName

protected java.lang.String getFileName(java.net.URL url)
Get file name portion of URL.

Parameters:
url - Get file name from this url
Returns:
file name as string

getColor

protected java.awt.Color getColor(java.lang.String color,
                                  java.awt.Color defaultColor)
Retrieves the color

Parameters:
color - Color to load
defaultColor - Default color to use if no color to load
Returns:
Color to use

getBooleanParameter

protected boolean getBooleanParameter(java.lang.String name,
                                      boolean defaultValue)
Retrieves the boolean value for the applet

Parameters:
name - Name of parameter
defaultValue - default value to return if no such parameter
Returns:
value of parameter or defaultValue

fatalErrorOccured

protected void fatalErrorOccured(java.lang.String error,
                                 java.lang.Exception e)
Sets the state of the loaded and prints some debug information

Parameters:
error - Error message to print

debug_sleep

protected void debug_sleep(long ms)
Utility method for sleeping Will only really sleep if debug has been enabled

Parameters:
ms - milliseconds to sleep

sleep

protected void sleep(long ms)
Utility method for sleeping

Parameters:
ms - milliseconds to sleep


Copyright © 2002-2009 lwjgl.org. All Rights Reserved.