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.
java.applet.Applet.AccessibleApplet
Modifier and Type | Field and Description |
---|---|
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 |
cacheEnabled
whether to use caching system, only download files that have changed
|
protected boolean |
certificateRefused
whether a certificate refused error occurred
|
protected java.lang.String[] |
certificateRefusedMessage
error message to display if user refuses to accept certificate
|
protected java.lang.ClassLoader |
classLoader
classLoader used to add downloaded jars to the classpath
|
protected int |
concurrentLookupThreads
threads to use when fetching information of files to be downloaded
|
protected int |
currentSizeExtract
current size of extracted in bytes
|
protected boolean |
debugMode
whether we're running in debug mode
|
protected java.lang.String[] |
errorMessage
fatal error message to display
|
protected boolean |
fatalError
whether a fatal error occurred
|
protected java.awt.Color |
fgColor
color to write foreground in
|
protected int[] |
fileSizes
Sizes of files to download
|
protected java.util.HashMap<java.lang.String,java.lang.Long> |
filesLastModified
Used to store file names with lastModified time
|
protected java.lang.String[] |
genericErrorMessage
generic error message to display on error
|
protected boolean |
headless
whether to run in headless mode
|
protected java.lang.String[] |
headlessMessage
messages to be passed via liveconnect in headless mode
|
protected boolean |
headlessWaiting
whether to switch applets in headless mode or wait longer
|
protected java.lang.Thread |
loaderThread
actual thread that does the loading
|
protected java.awt.Image |
logo
logo to be shown while loading
|
protected java.awt.Image |
logoBuffer
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 java.lang.String[] |
minimumJREMessage
error message to display if minimum JRE version is not met
|
protected boolean |
minimumJreNotFound
whether the minimum required JRE version is not found
|
protected int |
nativeJarCount
Number of native jars
|
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 boolean |
painting
set to true while painting is done
|
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 java.awt.Image |
progressbarBuffer
progressbar to render while loading
|
protected int |
state
state of applet loader
|
static int |
STATE_CHECK_JRE_VERSION
checking version of jre
|
static int |
STATE_CHECKING_CACHE
checking for already downloaded files
|
static int |
STATE_CHECKING_FOR_UPDATES
checking if any updates are available for cache 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
|
static int |
STATE_VALIDATING_PACKAGES
validating packages
|
protected java.lang.String |
subtaskMessage
String to display as a subtask
|
protected int |
totalDownloadSize
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
|
Constructor and Description |
---|
AppletLoader() |
Modifier and Type | Method and Description |
---|---|
void |
appletResize(int width,
int height)
Transfers the call of AppletResize from the stub to the lwjglApplet.
|
protected static boolean |
certificatesMatch(java.security.cert.Certificate[] certs1,
java.security.cert.Certificate[] certs2)
Compare two certificate chains to see if they match
|
protected void |
cleanUp()
Clean up resources
|
protected boolean |
compareVersion(java.io.File versionFile,
java.lang.String version)
This method will return true if the version stored in the file
matches the supplied String version.
|
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 |
extractGZip(java.lang.String in,
java.lang.String out)
Extract GZip File
|
protected void |
extractJars(java.lang.String path)
Extract all jars from any lzma/gz/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 error message and print 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 parameter
|
protected java.lang.String |
getCacheDirectory()
This method will return the location of the cache directory.
|
protected java.awt.Color |
getColor(java.lang.String param,
java.awt.Color defaultColor)
Retrieves the color
|
protected static java.security.cert.Certificate[] |
getCurrentCertificates()
Returns the current certificate chain of the AppletLoader
|
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
|
java.awt.Image |
getImage(java.net.URL url)
Get Image from path provided
|
protected int |
getIntParameter(java.lang.String name,
int defaultValue)
Retrieves the int value for the applet
|
protected void |
getJarInfo(java.io.File dir)
This method will get the files sizes of the files to download.
|
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.
|
protected java.lang.String |
getLWJGLCacheDir()
Get path to the lwjgl cache directory.
|
java.lang.String[] |
getMessages()
Retrieves the current message for the current status.
|
int |
getStatus()
Retrieves the current status of the AppletLoader and is
used by liveconnect when running in headless mode.
|
protected java.lang.String |
getStringParameter(java.lang.String name,
java.lang.String defaultValue)
Retrieves the String value for the parameter
|
boolean |
imageUpdate(java.awt.Image img,
int flag,
int x,
int y,
int width,
int height)
When an animated gif frame is ready to be drawn the ImageObserver
will call this method.
|
void |
init() |
boolean |
isMinJREVersionAvailable()
When this method is supplied with a JRE version it will compare it to the
current JRE version.
|
protected boolean |
isZipValid(java.io.File file)
This method will check if a zip file is valid by running through it
and checking for any corruption and CRC failures
|
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 java.util.HashMap<java.lang.String,java.lang.Long> |
readHashMapFile(java.io.File file)
read the HashMap from File
|
protected java.lang.Object |
readObjectFile(java.io.File file)
read the object from the File
|
protected java.lang.String |
readStringFile(java.io.File file)
read String object from File
|
java.lang.String |
replaceLast(java.lang.String original,
java.lang.String target,
java.lang.String replacement)
Replaces the last occurrence of the specified target substring with
the specified replacement string in a string.
|
void |
run()
9 steps
1) check jre version meets minimum requirements
2) check applet cache and decide which jars to download
3) download the jars
4) extract native files
5) validate jars for any corruption
6) save applet cache information
7) add jars to class path
8) set any lwjgl properties
9) switch to loaded applet
|
protected void |
setLWJGLProperties()
Parses the java_arguments list and sets lwjgl specific
properties accordingly, before the launch.
|
protected void |
setState(int state)
set the state of applet loader
|
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 void |
validateJars(java.lang.String path)
Check and validate jars which will be loaded into the classloader to make
sure that they are not corrupt.
|
protected void |
writeObjectFile(java.io.File file,
java.lang.Object object)
write object to specified File
|
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getLocale, getParameter, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus
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
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, 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, revalidate, 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
public static final int STATE_INIT
public static final int STATE_CHECK_JRE_VERSION
public static final int STATE_DETERMINING_PACKAGES
public static final int STATE_CHECKING_CACHE
public static final int STATE_CHECKING_FOR_UPDATES
public static final int STATE_DOWNLOADING
public static final int STATE_EXTRACTING_PACKAGES
public static final int STATE_VALIDATING_PACKAGES
public static final int STATE_UPDATING_CLASSPATH
public static final int STATE_SWITCHING_APPLET
public static final int STATE_INITIALIZE_REAL_APPLET
public static final int STATE_START_REAL_APPLET
public static final int STATE_DONE
protected volatile int percentage
protected int totalDownloadSize
protected int currentSizeExtract
protected int totalSizeExtract
protected java.awt.Image logo
protected java.awt.Image logoBuffer
protected java.awt.Image progressbar
protected java.awt.Image progressbarBuffer
protected java.awt.Image offscreen
protected boolean painting
protected java.awt.Color bgColor
protected java.awt.Color fgColor
protected java.net.URL[] urlList
protected java.lang.ClassLoader classLoader
protected java.lang.Thread loaderThread
protected java.lang.Thread animationThread
protected java.applet.Applet lwjglApplet
protected boolean debugMode
protected boolean prependHost
protected java.util.HashMap<java.lang.String,java.lang.Long> filesLastModified
protected int[] fileSizes
protected int nativeJarCount
protected boolean cacheEnabled
protected java.lang.String subtaskMessage
protected volatile int state
protected boolean lzmaSupported
protected boolean pack200Supported
protected boolean headless
protected boolean headlessWaiting
protected java.lang.String[] headlessMessage
protected int concurrentLookupThreads
protected boolean fatalError
protected boolean certificateRefused
protected boolean minimumJreNotFound
protected java.lang.String[] genericErrorMessage
protected java.lang.String[] certificateRefusedMessage
protected java.lang.String[] minimumJREMessage
protected java.lang.String[] errorMessage
protected static boolean natives_loaded
public void init()
init
in class java.applet.Applet
public void start()
start
in class java.applet.Applet
public void stop()
stop
in class java.applet.Applet
public void destroy()
destroy
in class java.applet.Applet
protected void cleanUp()
public java.applet.Applet getApplet()
public int getStatus()
public java.lang.String[] getMessages()
public void appletResize(int width, int height)
appletResize
in interface java.applet.AppletStub
public final void update(java.awt.Graphics g)
update
in class java.awt.Container
public void paint(java.awt.Graphics g)
paint
in class java.awt.Container
public boolean imageUpdate(java.awt.Image img, int flag, int x, int y, int width, int height)
imageUpdate
in interface java.awt.image.ImageObserver
imageUpdate
in class java.awt.Component
protected java.lang.String getDescriptionForState()
protected java.lang.String trimExtensionByCapabilities(java.lang.String file)
file
- string of files to be trimmedprotected void loadJarURLs() throws java.lang.Exception
java.lang.Exception
public void run()
run
in interface java.lang.Runnable
public boolean isMinJREVersionAvailable() throws java.lang.Exception
java.lang.Exception
- a NumberFormatException is thrown if the string is not validprotected boolean compareVersion(java.io.File versionFile, java.lang.String version)
versionFile
- - location to file containing version informationversion
- - String version that needs to be comparedprotected void setLWJGLProperties()
protected java.lang.String getCacheDirectory() throws java.lang.Exception
java.lang.Exception
- if access is deniedprotected java.lang.String getLWJGLCacheDir()
protected java.lang.String readStringFile(java.io.File file)
file
- to be readprotected java.util.HashMap<java.lang.String,java.lang.Long> readHashMapFile(java.io.File file)
file
- the file to readprotected java.lang.Object readObjectFile(java.io.File file) throws java.lang.Exception
file
- the file to readjava.lang.Exception
- if it fails to read object from fileprotected void writeObjectFile(java.io.File file, java.lang.Object object) throws java.lang.Exception
file
- the file to write out toobject
- the contents of the filejava.lang.Exception
- if it fails to write fileprotected void updateClassPath(java.lang.String path) throws java.lang.Exception
path
- location where applet is storedjava.lang.Exception
- if it fails to add classpathprotected void switchApplet() throws java.lang.Exception
java.lang.Exception
protected void getJarInfo(java.io.File dir) throws java.lang.Exception
dir
- - location to read cache file fromjava.lang.Exception
- - if fails to get infomationprotected void downloadJars(java.lang.String path) throws java.lang.Exception
path
- location of the directory to save tojava.lang.Exception
- if download failsprotected java.io.InputStream getJarInputStream(java.lang.String currentFile, java.net.URLConnection urlconnection) throws java.lang.Exception
urlconnection
- connection to get input stream fromjava.lang.Exception
protected void extractLZMA(java.lang.String in, java.lang.String out) throws java.lang.Exception
in
- Input path to pack fileout
- output path to resulting filejava.lang.Exception
- if any errors occurprotected void extractGZip(java.lang.String in, java.lang.String out) throws java.lang.Exception
in
- Input path to pack fileout
- output path to resulting filejava.lang.Exception
- if any errors occurprotected void extractPack(java.lang.String in, java.lang.String out) throws java.lang.Exception
in
- Input path to pack fileout
- output path to resulting filejava.lang.Exception
- if any errors occurprotected void extractJars(java.lang.String path) throws java.lang.Exception
path
- output pathjava.lang.Exception
- if any errors occurprotected void extractNatives(java.lang.String path) throws java.lang.Exception
path
- base folder containing all downloaded jarsjava.lang.Exception
- if it fails to extract filesprotected static boolean certificatesMatch(java.security.cert.Certificate[] certs1, java.security.cert.Certificate[] certs2) throws java.lang.Exception
cert1
- first chain of certificatescert2
- second chain of certificatesjava.lang.Exception
protected static java.security.cert.Certificate[] getCurrentCertificates() throws java.lang.Exception
java.lang.Exception
protected void validateJars(java.lang.String path) throws java.lang.Exception
path
- - where the jars are storedjava.lang.Exception
- if a corrupt jar is foundprotected boolean isZipValid(java.io.File file)
file
- - zip file to testprotected java.awt.Image getImage(java.lang.String s)
s
- location of the imagepublic java.awt.Image getImage(java.net.URL url)
getImage
in class java.applet.Applet
url
- location of the imageprotected java.lang.String getJarName(java.net.URL url)
url
- Get jar file name from this urlprotected java.lang.String getFileName(java.net.URL url)
url
- Get file name from this urlprotected java.awt.Color getColor(java.lang.String param, java.awt.Color defaultColor)
param
- Color to loaddefaultColor
- Default color to use if no color to loadpublic java.lang.String replaceLast(java.lang.String original, java.lang.String target, java.lang.String replacement)
original
- - String to searchtarget
- - substring to findreplacement
- - what to replace target substring withprotected java.lang.String getStringParameter(java.lang.String name, java.lang.String defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected boolean getBooleanParameter(java.lang.String name, boolean defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected int getIntParameter(java.lang.String name, int defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected void fatalErrorOccured(java.lang.String error, java.lang.Exception e)
error
- Error message to printprotected void setState(int state)
new
- state of applet loaderprotected void debug_sleep(long ms)
ms
- milliseconds to sleepprotected void sleep(long ms)
ms
- milliseconds to sleepCopyright © 2002-2009 lwjgl.org. All Rights Reserved.