Package org.lwjgl.util.applet

# Class AppletLoader

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
org.lwjgl.util.applet.AppletLoader

All Implemented Interfaces:
  `AppletStub`, `ImageObserver`, `MenuContainer`, `Serializable`, `Runnable`, `Accessible`

public class AppletLoader extends Applet implements Runnable, 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:

- al_main - [String] Full package and class the applet to instantiate and display when loaded.
- al_jars - [String] Comma separated list of jars to download.

- al_windows - [String] Jar containing native files for windows.
- al_linux - [String] Jar containing native files for linux.
- al_mac - [String] Jar containing native files for mac.
- al_solaris - [String] Jar containing native files for solaris.
- al_freebsd - [String] Jar containing native files for freebsd.
- al_openbsd - [String] Jar containing native files for openbsd.

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

- al_cache - [boolean] Whether to use cache system. Default: true.
- al_version - [int or float] Version of deployment. If this is specified, the jars will be cached and reused if the version matches. If version doesn't match all of the files are reloaded.
- al_debug - [boolean] Whether to enable debug mode. Default: false.
- al_min_jre - [String] Specify the minimum jre version that the applet requires, should be in format like 1.6.0_24 or a subset like 1.6 Default: 1.5.
- al_prepend_host - [boolean] Whether to limit caching to this domain, disable if your applet is hosted on multiple domains and needs to share the cache. Default: true.
- al_lookup_threads - [int] Specify the number of concurrent threads to use to get file information before downloading. Default: 1.

- al_windows64 - [String] If specified it will be used instead of al_windows on 64bit windows systems.
- al_windows32 - [String] If specified it will be used instead of al_windows on 32bit windows systems.
- al_linux64 - [String] If specified it will be used instead of al_linux on 64bit linux systems.
- al_linux32 - [String] If specified it will be used instead of al_linux on 32bit linux systems.
- al_mac32 - [String] If specified it will be used instead of al_mac on 64bit mac systems.
- al_mac64 - [String] If specified it will be used instead of al_mac on 32bit mac systems.
- al_macppc - [String] If specified it will be used instead of al_mac on PPC mac systems.

- boxbgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as background. Default: #ffffff.
- boxfgcolor - [String] any String AWT color ("red", "blue", etc), RGB (0-255) or hex formated color (#RRGGBB) to use as foreground. Default: #000000.

- al_logo - [String Path of of the logo resource to paint while loading.Default: "appletlogo.gif".
- al_progressbar - [String] Path of the progressbar resource to paint on top of the logo, width clipped by percentage.Default: "appletprogress.gif".

- lwjgl_arguments -
[String] used to pass LWJGL parameters to LWJGL e.g. ("-Dorg.lwjgl.input.Mouse.allowNegativeMouseCoords=true -Dorg.lwjgl.util.Debug=true").

Version:
  $Revision$ $Id$ Contributors:
  - Arielsan
  - Bobjob
  - Dashiva
  - Dr_evil
  - Elias Naur
  - Kevin Glass
  - Matthias Mann
  - Mickelukas
  - NateS
  - Pelle Johnsen
  - Riven
  - Ruben01
  - Shannon Smith
Author:
  kappaOne invalid input: '<'one.kappa@gmail.com>, Brian Matzon invalid input: '<'brian@matzon.dk>
See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class java.applet.Applet

`Applet.AccessibleApplet`

## Nested classes/interfaces inherited from class java.awt.Panel

`Panel.AccessibleAWTPanel`

## Nested classes/interfaces inherited from class java.awt.Container

`Container.AccessibleAWTContainer`

## Nested classes/interfaces inherited from class java.awt.Component

`Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Thread`
`animationThread`
animation thread that renders our load screen while loading
`protected 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 String[]`
`certificateRefusedMessage`
error message to display if user refuses to accept certificate
`protected 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 String[]`
`errorMessage`
fatal error message to display
`protected boolean`
`fatalError`
whether a fatal error occurred
`protected Color`
`fgColor`
color to write foreground in
`protected int[]`
`fileSizes`
Sizes of files to download
`protected HashMap<String,Long>`
`filesLastModified`
Used to store file names with lastModified time
`protected String[]`
`genericErrorMessage`
generic error message to display on error
`protected boolean`
`headless`
whether to run in headless mode
`protected 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 Thread`
`loaderThread`
actual thread that does the loading
`protected Image`
`logo`
logo to be shown while loading
`protected Image`
`logoBuffer`
logo to be shown while loading
`protected Applet`
`lwjglApplet`
applet to load after all downloads are complete
`protected boolean`
`lzmaSupported`
whether lzma is supported
`protected 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 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 Image`
`progressbar`
progressbar to render while loading
`protected Image`
`progressbarBuffer`
progressbar to render while loading
`protected int`
`state`
state of applet loader
`static final int`
`STATE_CHECK_JRE_VERSION`
checking version of jre
`static final int`
`STATE_CHECKING_CACHE`
checking for already downloaded files
`static final int`
`STATE_CHECKING_FOR_UPDATES`
checking if any updates are available for cache files
`static final int`
`STATE_DETERMINING_PACKAGES`
determining which packages that are required
`static final int`
`STATE_DONE`
done
`static final int`
`STATE_DOWNLOADING`
downloading packages
`static final int`
`STATE_EXTRACTING_PACKAGES`
extracting packages
`static final int`
`STATE_INIT`
initializing
`static final int`
`STATE_INITIALIZE_REAL_APPLET`
initializing real applet
`static final int`
`STATE_START_REAL_APPLET`
stating real applet
`static final int`
`STATE_SWITCHING_APPLET`
switching to real applet
`static final int`
`STATE_UPDATING_CLASSPATH`
updating the classpath
`static final int`
`STATE_VALIDATING_PACKAGES`
validating packages
`protected 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 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

Constructors
Constructor
Description
`AppletLoader()`

## Method Summary

Modifier and Type
Method
Description
`void`
`appletResize(int width, int height)`
Transfers the call of AppletResize from the stub to the lwjglApplet.
`protected static boolean`
`certificatesMatch(Certificate[] certs1, Certificate[] certs2)`
Compare two certificate chains to see if they match
`protected void`
`cleanUp()`
Clean up resources
`protected boolean`
`compareVersion(File versionFile, 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(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(String in, String out)`
Extract GZip File
`protected void`
`extractJars(String path)`
Extract all jars from any lzma/gz/pack files
`protected void`
`extractLZMA(String in, String out)`
Extract LZMA File
`protected void`
`extractNatives(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`
`fatalErrorOccured(String error, Exception e)`
Sets the error message and print debug information
`Applet`
`getApplet()`
Retrieves the applet that has been loaded.
`protected boolean`
`getBooleanParameter(String name, boolean defaultValue)`
Retrieves the boolean value for the parameter
`protected String`
`getCacheDirectory()`
This method will return the location of the cache directory.
`protected Color`
`getColor(String param, Color defaultColor)`
Retrieves the color
`protected static Certificate[]`
`getCurrentCertificates()`
Returns the current certificate chain of the AppletLoader
`protected String`
`getDescriptionForState()`
`protected String`
`getFileName(URL url)`
Get file name portion of URL.
`protected Image`
`getImage(String s)`
Get Image from path provided
`Image`
`getImage(URL url)`
Get Image from path provided
`protected int`
`getIntParameter(String name, int defaultValue)`
Retrieves the int value for the applet
`protected void`
`getJarInfo(File dir)`
This method will get the files sizes of the files to download.
`protected InputStream`
`getJarInputStream(String currentFile, URLConnection urlconnection)`
Retrieves a jar files input stream.
`protected String`
`getJarName(URL url)`
Get jar name from URL.
`protected String`
`getLWJGLCacheDir()`
Get path to the lwjgl cache directory.
`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 String`
`getStringParameter(String name, String defaultValue)`
Retrieves the String value for the parameter
`boolean`
`imageUpdate(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(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(Graphics g)`
`protected HashMap<String,Long>`
`readHashMapFile(File file)`
read the HashMap from File
`protected Object`
`readObjectFile(File file)`
read the object from the File
`protected String`
`readStringFile(File file)`
read String object from File
`String`
`replaceLast(String original, String target, 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 String`
`trimExtensionByCapabilities(String file)`
Trims the passed file string based on the available capabilities
`final void`
`update(Graphics g)`
`protected void`
`updateClassPath(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(String path)`
Check and validate jars which will be loaded into the classloader to make sure that they are not corrupt.
`protected void`
`writeObjectFile(File file, Object object)`
write object to specified File

### Methods inherited from class java.applet.Applet

`getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getLocale, getParameter, getParameterInfo, isActive, isValidateRoot, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, 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 Details

### STATE_INIT

public static final int STATE_INIT
initializing

See Also:
  - Constant Field Values

### STATE_CHECK_JRE_VERSION

public static final int STATE_CHECK_JRE_VERSION
checking version of jre

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_CHECKING_FOR_UPDATES

public static final int STATE_CHECKING_FOR_UPDATES
checking if any updates are available for cache 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_VALIDATING_PACKAGES

public static final int STATE_VALIDATING_PACKAGES
validating 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 volatile int percentage
used to calculate length of progress bar

### totalDownloadSize

protected int totalDownloadSize
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 Image logo
logo to be shown while loading

### logoBuffer

protected Image logoBuffer
logo to be shown while loading

### progressbar

protected Image progressbar
progressbar to render while loading

### progressbarBuffer

protected Image progressbarBuffer
progressbar to render while loading

### offscreen

protected Image offscreen
offscreen image used

### painting

protected boolean painting
set to true while painting is done

### bgColor

protected Color bgColor
background color of applet

### fgColor

protected Color fgColor
color to write foreground in

### urlList

protected URL[] urlList
urls of the jars to download

### classLoader

protected ClassLoader classLoader
classLoader used to add downloaded jars to the classpath

### loaderThread

protected Thread loaderThread
actual thread that does the loading

### animationThread

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

### lwjglApplet

protected Applet lwjglApplet
applet to load after all downloads are complete

### debugMode

protected boolean debugMode
whether we're running in debug mode

### prependHost

protected boolean prependHost
whether to prepend host to cache path

### filesLastModified

protected HashMap<String,Long> filesLastModified
Used to store file names with lastModified time

### fileSizes

protected int[] fileSizes
Sizes of files to download

### nativeJarCount

protected int nativeJarCount
Number of native jars

### cacheEnabled

protected boolean cacheEnabled
whether to use caching system, only download files that have changed

### subtaskMessage

protected String subtaskMessage
String to display as a subtask

### state

protected volatile int state
state of applet loader

### lzmaSupported

protected boolean lzmaSupported
whether lzma is supported

### pack200Supported

protected boolean pack200Supported
whether pack200 is supported

### headless

protected boolean headless
whether to run in headless mode

### headlessWaiting

protected boolean headlessWaiting
whether to switch applets in headless mode or wait longer

### headlessMessage

protected String[] headlessMessage
messages to be passed via liveconnect in headless mode

### concurrentLookupThreads

protected int concurrentLookupThreads
threads to use when fetching information of files to be downloaded

### fatalError

protected boolean fatalError
whether a fatal error occurred

### certificateRefused

protected boolean certificateRefused
whether a certificate refused error occurred

### minimumJreNotFound

protected boolean minimumJreNotFound
whether the minimum required JRE version is not found

### genericErrorMessage

protected String[] genericErrorMessage
generic error message to display on error

### certificateRefusedMessage

protected String[] certificateRefusedMessage
error message to display if user refuses to accept certificate

### minimumJREMessage

protected String[] minimumJREMessage
error message to display if minimum JRE version is not met

### errorMessage

protected String[] errorMessage
fatal error message to display

### natives_loaded

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

## Constructor Details

### AppletLoader

public AppletLoader()

## Method Details

### init

public void init()

Overrides:
  `init` in class `Applet`

### start

public void start()

Overrides:
  `start` in class `Applet`

### stop

public void stop()

Overrides:
  `stop` in class `Applet`

### destroy

public void destroy()

Overrides:
  `destroy` in class `Applet`

### cleanUp

protected void cleanUp()
Clean up resources

### getApplet

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

### getStatus

public int getStatus()
Retrieves the current status of the AppletLoader and is used by liveconnect when running in headless mode. This method will return the current progress of the AppletLoader as a value from 0-100. In the case of a fatal error it will return -1. If the certificate is refused it will return -2. If the minimum jre requirement is not met will return -3. When method returns 100 the AppletLoader will sleep until the method is called again. When called again it will switch to the LWJGL Applet. This is a useful trigger to start the LWJGL applet when needed.

### getMessages

public String[] getMessages()
Retrieves the current message for the current status. Used by liveconnect when running in headless mode.

### appletResize

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

Specified by:
  `appletResize` in interface `AppletStub`

### update

public final void update(Graphics g)

Overrides:
  `update` in class `Container`

### paint

public void paint(Graphics g)

Overrides:
  `paint` in class `Container`

### imageUpdate

public boolean imageUpdate(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. The Image frame is copied into a buffer, which is then drawn. This is done to prevent image tearing on gif animations.

Specified by:
  `imageUpdate` in interface `ImageObserver`
Overrides:
  `imageUpdate` in class `Component`

### getDescriptionForState

protected String getDescriptionForState()

Returns:
  string describing the state of the loader

### trimExtensionByCapabilities

protected String trimExtensionByCapabilities(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 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:
  `Exception`

### run

public 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

Specified by:
  `run` in interface `Runnable`

### isMinJREVersionAvailable

public boolean isMinJREVersionAvailable() throws Exception
When this method is supplied with a JRE version it will compare it to the current JRE version. minimum requried JRE version is set using al_min_jre parameter, if not this is not set then the value will default to version 1.5 The minimumVersion should follow a structure such as x.x.x_x Example values would include 1.6.0_10 or a subset like 1.6.0 or 1.6

Returns:
  returns true if the available version is greater or equal to the minimum version required
Throws:
  `Exception` - a NumberFormatException is thrown if the string is not valid

### compareVersion

protected boolean compareVersion(File versionFile, String version)
This method will return true if the version stored in the file matches the supplied String version.

Parameters:
  `versionFile` - - location to file containing version information
  `version` - - String version that needs to be compared
Returns:
  returns true if the version in file matches specified version

### setLWJGLProperties

protected void setLWJGLProperties()
Parses the java_arguments list and sets lwjgl specific properties accordingly, before the launch.

### getCacheDirectory

protected String getCacheDirectory() throws Exception
This method will return the location of the cache directory. All the applet files will be downloaded and stored here. A folder will be created inside the LWJGL cache directory from the al_title parameter. This folder will also be prepended by the host name of the codebase to avoid conflict with same named applets on other hosts.

Returns:
  path to applets cache directory
Throws:
  `Exception` - if access is denied

### getLWJGLCacheDir

protected String getLWJGLCacheDir()
Get path to the lwjgl cache directory. This location will be where the OS keeps temporary files.

Returns:
  path to the lwjgl cache directory

### readStringFile

protected String readStringFile(File file)
read String object from File

Parameters:
  `file` - to be read
Returns:
  the String stored in the file or null if it fails

### readHashMapFile

protected HashMap<String,Long> readHashMapFile(File file)
read the HashMap from File

Parameters:
  `file` - the file to read
Returns:
  the hashmap stored in the file or an empty hashmap if it fails

### readObjectFile

protected Object readObjectFile(File file) throws Exception
read the object from the File

Parameters:
  `file` - the file to read
Returns:
  the object contained in the file or null if it fails
Throws:
  `Exception` - if it fails to read object from file

### writeObjectFile

protected void writeObjectFile(File file, Object object) throws Exception
write object to specified File

Parameters:
  `file` - the file to write out to
  `object` - the contents of the file
Throws:
  `Exception` - if it fails to write file

### updateClassPath

protected void updateClassPath(String path) throws 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:
  `Exception` - if it fails to add classpath

### switchApplet

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

Throws:
  `Exception`

### getJarInfo

protected void getJarInfo(File dir) throws Exception
This method will get the files sizes of the files to download. It wil further get the lastModified time of files and save it in a hashmap, if cache is enabled it will mark those files that have not changed since last download to not redownloaded.

Parameters:
  `dir` - - location to read cache file from
Throws:
  `Exception` - - if fails to get infomation

### downloadJars

protected void downloadJars(String path) throws 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:
  `Exception` - if download fails

### getJarInputStream

protected InputStream getJarInputStream(String currentFile, URLConnection urlconnection) throws 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:
  `Exception`

### extractLZMA

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

Parameters:
  `in` - Input path to pack file
  `out` - output path to resulting file
Throws:
  `Exception` - if any errors occur

### extractGZip

protected void extractGZip(String in, String out) throws Exception
Extract GZip File

Parameters:
  `in` - Input path to pack file
  `out` - output path to resulting file
Throws:
  `Exception` - if any errors occur

### extractJars

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

Parameters:
  `path` - output path
Throws:
  `Exception` - if any errors occur

### extractNatives

protected void extractNatives(String path) throws 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:
  `Exception` - if it fails to extract files

### certificatesMatch

protected static boolean certificatesMatch(Certificate[] certs1, Certificate[] certs2) throws Exception
Compare two certificate chains to see if they match

Parameters:
  `certs1` - first chain of certificates
  `certs2` - second chain of certificates
Returns:
  true if the certificate chains are the same
Throws:
  `Exception`

### getCurrentCertificates

protected static Certificate[] getCurrentCertificates() throws Exception
Returns the current certificate chain of the AppletLoader

Returns:
  - certificate chain of AppletLoader
Throws:
  `Exception`

### validateJars

protected void validateJars(String path) throws Exception
Check and validate jars which will be loaded into the classloader to make sure that they are not corrupt. This ensures corrupt files are never marked as successful downloadeds by the cache system.

Parameters:
  `path` - - where the jars are stored
Throws:
  `Exception` - if a corrupt jar is found

### isZipValid

protected boolean isZipValid(File file)
This method will check if a zip file is valid by running through it and checking for any corruption and CRC failures

Parameters:
  `file` - - zip file to test
Returns:
  boolean - runs false if the file is corrupt

### getImage

protected Image getImage(String s)
Get Image from path provided

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

### getImage

public Image getImage(URL url)
Get Image from path provided

Overrides:
  `getImage` in class `Applet`
Parameters:
  `url` - location of the image
Returns:
  the Image file

### getJarName

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

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

### getFileName

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

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

### getColor

protected Color getColor(String param, Color defaultColor)
Retrieves the color

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

### replaceLast

public String replaceLast(String original, String target, String replacement)
Replaces the last occurrence of the specified target substring with the specified replacement string in a string.

Parameters:
  `original` - - String to search
  `target` - - substring to find
  `replacement` - - what to replace target substring with
Returns:
  - return the modified string, if target substring not found return original string

### getStringParameter

protected String getStringParameter(String name, String defaultValue)
Retrieves the String value for the parameter

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

### getBooleanParameter

protected boolean getBooleanParameter(String name, boolean defaultValue)
Retrieves the boolean value for the parameter

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

### getIntParameter

protected int getIntParameter(String name, int defaultValue)
Retrieves the int 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(String error, Exception e)
Sets the error message and print debug information

Parameters:
  `error` - Error message to print

### setState

protected void setState(int state)
set the state of applet loader

Parameters:
  `state` - new state of applet loader

### 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