|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
org.lwjgl.util.applet.AppletLoader
public class AppletLoader
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.
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 | |
---|---|
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 occured |
protected String[] |
certificateRefusedMessage
error message to display if user refuses to accept certicate |
protected 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 boolean |
fatalError
whether a fatal error occured |
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 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 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 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 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 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 |
cleanUp()
Clean up resources |
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 |
extractPack(String in,
String out)
Extract Pack File |
protected void |
fatalErrorOccured(String error,
Exception e)
Sets the state of the loaded and prints some debug information |
Applet |
getApplet()
Retrieves the applet that has been loaded. |
protected boolean |
getBooleanParameter(String name,
boolean defaultValue)
Retrieves the boolean value for the applet |
protected String |
getCacheDir()
get path to the lwjgl cache directory |
protected Color |
getColor(String param,
Color defaultColor)
Retrieves the color |
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 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. |
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()
|
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> |
readCacheFile(File file)
read the current cache file |
protected float |
readVersionFile(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 |
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 |
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 static void |
validateCertificateChain(Certificate[] ownCerts,
Certificate[] native_certs)
Validates the certificate chain for a single file |
protected void |
writeCacheFile(File file,
HashMap<String,Long> filesLastModified)
write out cache file of applet |
protected void |
writeVersionFile(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, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus |
Methods inherited from class java.awt.Panel |
---|
addNotify |
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 |
---|
public static final int STATE_INIT
public static final int STATE_DETERMINING_PACKAGES
public static final int STATE_CHECKING_CACHE
public static final int STATE_DOWNLOADING
public static final int STATE_EXTRACTING_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 int percentage
protected int currentSizeDownload
protected int totalSizeDownload
protected int currentSizeExtract
protected int totalSizeExtract
protected Image logo
protected Image logoBuffer
protected Image progressbar
protected Image progressbarBuffer
protected Image offscreen
protected boolean painting
protected Color bgColor
protected Color fgColor
protected URL[] urlList
protected ClassLoader classLoader
protected Thread loaderThread
protected Thread animationThread
protected Applet lwjglApplet
protected boolean fatalError
protected boolean debugMode
protected boolean prependHost
protected HashMap<String,Long> filesLastModified
protected int[] fileSizes
protected int nativeJarCount
protected boolean cacheEnabled
protected String subtaskMessage
protected volatile int state
protected boolean lzmaSupported
protected boolean pack200Supported
protected String[] genericErrorMessage
protected boolean certificateRefused
protected String[] certificateRefusedMessage
protected static boolean natives_loaded
Constructor Detail |
---|
public AppletLoader()
Method Detail |
---|
public void init()
init
in class Applet
public void start()
start
in class Applet
public void stop()
stop
in class Applet
public void destroy()
destroy
in class Applet
protected void cleanUp()
public Applet getApplet()
public void appletResize(int width, int height)
appletResize
in interface AppletStub
public final void update(Graphics g)
update
in class Container
public void paint(Graphics g)
paint
in class Container
public boolean imageUpdate(Image img, int flag, int x, int y, int width, int height)
imageUpdate
in interface ImageObserver
imageUpdate
in class Component
protected String getDescriptionForState()
protected String trimExtensionByCapabilities(String file)
file
- string of files to be trimmed
protected void loadJarURLs() throws Exception
Exception
public void run()
run
in interface Runnable
protected void setLWJGLProperties()
protected String getCacheDir()
protected float readVersionFile(File file) throws Exception
file
- the file to read
Exception
- if it fails to read valueprotected void writeVersionFile(File file, float version) throws Exception
file
- the file to write out toversion
- the version of the applet as a float
Exception
- if it fails to write fileprotected HashMap<String,Long> readCacheFile(File file) throws Exception
file
- the file to read
Exception
- if it fails to read hashmapprotected void writeCacheFile(File file, HashMap<String,Long> filesLastModified) throws Exception
file
- the file to write out tofilesLastModified
- the hashmap containing files names and lastModified times
Exception
- if it fails to write fileprotected void updateClassPath(String path) throws Exception
path
- location where applet is stored
Exception
- if it fails to add classpathprotected void switchApplet() throws Exception
Exception
protected void getJarInfo(File dir) throws Exception
dir
- - location to read cache file from
Exception
- - if fails to get infomationprotected void downloadJars(String path) throws Exception
path
- location of the directory to save to
Exception
- if download failsprotected InputStream getJarInputStream(String currentFile, URLConnection urlconnection) throws Exception
urlconnection
- connection to get input stream from
Exception
protected void extractLZMA(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting file
Exception
- if any errors occurprotected void extractGZip(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting file
Exception
- if any errors occurprotected void extractPack(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting file
Exception
- if any errors occurprotected void extractJars(String path) throws Exception
path
- output path
Exception
- if any errors occurprotected void extractNatives(String path) throws Exception
path
- base folder containing all downloaded jars
Exception
- if it fails to extract filesprotected static void validateCertificateChain(Certificate[] ownCerts, Certificate[] native_certs) throws Exception
ownCerts
- Chain of certificates to check againstnative_certs
- Chain of certificates to check
Exception
protected Image getImage(String s)
s
- location of the image
public Image getImage(URL url)
getImage
in class Applet
url
- location of the image
protected String getJarName(URL url)
url
- Get jar file name from this url
protected String getFileName(URL url)
url
- Get file name from this url
protected Color getColor(String param, Color defaultColor)
param
- Color to loaddefaultColor
- Default color to use if no color to load
protected boolean getBooleanParameter(String name, boolean defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameter
protected void fatalErrorOccured(String error, 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 sleep
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |