Top Description Fields Constructors Methods
org.lwjgl.util.applet

public Class AppletLoader

extends Applet
implements Runnable, AppletStub
Class Inheritance
All Implemented Interfaces
java.applet.AppletStub, java.lang.Runnable
Imports
org.lwjgl.LWJGLUtil, java.applet.Applet, .AppletStub, java.awt.BorderLayout, .Color, .EventQueue, .FontMetrics, .Graphics, .Image, .MediaTracker, java.awt.image.ImageObserver, java.io.BufferedInputStream, .File, .FileInputStream, .FileOutputStream, .FilePermission, .IOException, .InputStream, .ObjectInputStream, .ObjectOutputStream, .OutputStream, .PrintWriter, .StringWriter, .Writer, java.lang.reflect.Constructor, .Field, java.net.HttpURLConnection, .JarURLConnection, .SocketPermission, .URL, .URLClassLoader, .URLConnection, java.security.AccessControlException, .AccessController, .AllPermission, .CodeSource, .PermissionCollection, .Permissions, .PrivilegedExceptionAction, java.security.cert.Certificate, java.util.Enumeration, .HashMap, .Iterator, .LinkedList, .Queue, .StringTokenizer, .Vector, java.util.concurrent.ExecutorService, .Executors, .Future, java.util.jar.JarEntry, .JarFile, .JarOutputStream, java.util.zip.CRC32, .CheckedInputStream, .GZIPInputStream, .ZipEntry, .ZipFile

Deprecated

as a consequence of Applet and AppletStub being deprecated. See corresponding docs for further information.

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.

Authors
kappaOne , Brian Matzon Contributors:
  • Arielsan
  • Bobjob
  • Dashiva
  • Dr_evil
  • Elias Naur
  • Kevin Glass
  • Matthias Mann
  • Mickelukas
  • NateS
  • Pelle Johnsen
  • Riven
  • Ruben01
  • Shannon Smith

Field Summary

Modifier and TypeField and 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 volatile 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 volatile int
state

state of applet loader

public static final int
STATE_CHECK_JRE_VERSION

checking version of jre

public static final int
STATE_CHECKING_CACHE

checking for already downloaded files

public static final int
STATE_CHECKING_FOR_UPDATES

checking if any updates are available for cache files

public static final int
STATE_DETERMINING_PACKAGES

determining which packages that are required

public static final int
public static final int
STATE_DOWNLOADING

downloading packages

public static final int
STATE_EXTRACTING_PACKAGES

extracting packages

public static final int
STATE_INIT

initializing

public static final int
STATE_INITIALIZE_REAL_APPLET

initializing real applet

public static final int
STATE_START_REAL_APPLET

stating real applet

public static final int
STATE_SWITCHING_APPLET

switching to real applet

public static final int
STATE_UPDATING_CLASSPATH

updating the classpath

public 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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
appletResize(int
the new requested width for the applet
width
,
int
the new requested height for the applet
height
)

Implements java.applet.AppletStub.appletResize.

Transfers the call of AppletResize from the stub to the lwjglApplet.
protected static boolean

Returns:

true if the certificate chains are the same
certificatesMatch
(Certificate[]
first chain of certificates
certs1
,
Certificate[]
second chain of certificates
certs2
)

Compare two certificate chains to see if they match

protected void
cleanUp()

Clean up resources

protected boolean

Returns:

returns true if the version in file matches specified version
compareVersion
(File
- location to file containing version information
versionFile
,
String
- String version that needs to be compared
version
)

This method will return true if the version stored in the file matches the supplied String version.

protected void
debug_sleep(long
milliseconds to sleep
ms
)

Utility method for sleeping Will only really sleep if debug has been enabled

public void
destroy()

Overrides java.applet.Applet.destroy.

Called by the browser or applet viewer to inform this applet that it is being reclaimed and that it should destroy any resources that it has allocated.
protected void
downloadJars(String
location of the directory to save to
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
Input path to pack file
in
,
String
output path to resulting file
out
)

Extract GZip File

protected void
extractJars(String
output path
path
)

Extract all jars from any lzma/gz/pack files

protected void
extractLZMA(String
Input path to pack file
in
,
String
output path to resulting file
out
)

Extract LZMA File

protected void
extractNatives(String
base folder containing all downloaded jars
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(String
Input path to pack file
in
,
String
output path to resulting file
out
)

Extract Pack File

protected void
fatalErrorOccured(String
Error message to print
error
,
Exception e)

Sets the error message and print debug information

private static String

Returns:

Stacktrace of exception in the form of a string
generateStacktrace
(Exception
Exception to make stacktrace of
exception
)

Generates a stacktrace in the form of a string

public Applet
getApplet()

Deprecated as a consequence of Applet being deprecated.
Retrieves the applet that has been loaded.
protected boolean

Returns:

value of parameter or defaultValue
getBooleanParameter
(String
Name of parameter
name
,
boolean
default value to return if no such parameter
defaultValue
)

Retrieves the boolean value for the parameter

protected String

Returns:

path to applets cache directory
getCacheDirectory
()

This method will return the location of the cache directory.

protected Color

Returns:

Color to use
getColor
(String
Color to load
param
,
Color
Default color to use if no color to load
defaultColor
)

Retrieves the color

protected static Certificate[]

Returns:

- certificate chain of AppletLoader
getCurrentCertificates
()

Returns the current certificate chain of the AppletLoader

protected String

Returns:

string describing the state of the loader
getDescriptionForState
()

protected String

Returns:

file name as string
getFileName
(URL
Get file name from this url
url
)

Get file name portion of URL.

protected Image

Returns:

the Image file
getImage
(String
location of the image
s
)

Get Image from path provided

public Image

Returns:

the Image file
getImage
(URL
location of the image
url
)

Overrides java.applet.Applet.getImage.

Get Image from path provided
protected int

Returns:

value of parameter or defaultValue
getIntParameter
(String
Name of parameter
name
,
int
default value to return if no such parameter
defaultValue
)

Retrieves the int value for the applet

protected void
getJarInfo(File
- location to read cache file from
dir
)

This method will get the files sizes of the files to download.

protected InputStream

Returns:

InputStream or null if not possible
getJarInputStream
(final String currentFile, final URLConnection
connection to get input stream from
urlconnection
)

Retrieves a jar files input stream.

protected String

Returns:

file name as string
getJarName
(URL
Get jar file name from this url
url
)

Get jar name from URL.

protected String

Returns:

path to the lwjgl cache directory
getLWJGLCacheDir
()

Get path to the lwjgl cache directory.

public String[]
getMessages()

Retrieves the current message for the current status.

public int
getStatus()

Retrieves the current status of the AppletLoader and is used by liveconnect when running in headless mode.

protected String

Returns:

value of parameter or defaultValue
getStringParameter
(String
Name of parameter
name
,
String
default value to return if no such parameter
defaultValue
)

Retrieves the String value for the parameter

public boolean
imageUpdate(Image
the image being observed
img
,
int
see imageUpdate for more information
flag
,
int
the x coordinate
x
,
int
the y coordinate
y
,
int
the width
width
,
int
the height
height
)

Overrides java.awt.Component.imageUpdate.

Implements java.awt.image.ImageObserver.imageUpdate.

When an animated gif frame is ready to be drawn the ImageObserver will call this method.
public void
init()

Overrides java.applet.Applet.init.

Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
public boolean

Returns:

returns true if the available version is greater or equal to the minimum version required
isMinJREVersionAvailable
()

When this method is supplied with a JRE version it will compare it to the current JRE version.

protected boolean

Returns:

boolean - runs false if the file is corrupt
isZipValid
(File
- zip file to test
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

public void
paint(Graphics
the specified Graphics window
g
)

Overrides java.awt.Container.paint.

Paints the container.
protected HashMap<String, Long>

Returns:

the hashmap stored in the file or an empty hashmap if it fails
readHashMapFile
(File
the file to read
file
)

read the HashMap from File

protected Object

Returns:

the object contained in the file or null if it fails
readObjectFile
(File
the file to read
file
)

read the object from the File

protected String

Returns:

the String stored in the file or null if it fails
readStringFile
(File
to be read
file
)

read String object from File

public String

Returns:

- return the modified string, if target substring not found return original string
replaceLast
(String
- String to search
original
,
String
- substring to find
target
,
String
- what to replace target substring with
replacement
)

Replaces the last occurrence of the specified target substring with the specified replacement string in a string.

public void
run()

Implements java.lang.Runnable.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
new state of applet loader
state
)

set the state of applet loader

protected void
sleep(long
milliseconds to sleep
ms
)

Utility method for sleeping

public void
start()

Overrides java.applet.Applet.start.

Called by the browser or applet viewer to inform this applet that it should start its execution.
public void
stop()

Overrides java.applet.Applet.stop.

Called by the browser or applet viewer to inform this applet that it should stop its execution.
protected void
switchApplet()

replace the current applet with the lwjgl applet using AppletStub and initialise and start it

protected String

Returns:

trimmed string based on capabilities of client
trimExtensionByCapabilities
(String
string of files to be trimmed
file
)

Trims the passed file string based on the available capabilities

private void
unloadNatives(String
directory where natives are stored
nativePath
)

Unload natives loaded by a different classloader.

public final void
update(Graphics
the specified Graphics window
g
)

Overrides java.awt.Container.update.

Updates the container.
protected void
updateClassPath(final String
location where applet is stored
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
- where the jars are stored
path
)

Check and validate jars which will be loaded into the classloader to make sure that they are not corrupt.

protected void
writeObjectFile(File
the file to write out to
file
,
Object
the contents of the file
object
)

write object to specified File

Inherited from java.applet.Applet:
getAccessibleContextgetAppletContextgetAppletInfogetAudioClipgetAudioClipgetCodeBasegetDocumentBasegetImagegetLocalegetParametergetParameterInfoisActiveisValidateRootnewAudioClipplayplayresizeresizesetStubshowStatus