|
||||||||||
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 |
---|
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 |
cacheEnabled
whether to use caching system, only download files that have changed |
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 boolean |
fatalError
whether a fatal error occured |
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 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 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_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 |
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(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 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.lang.String |
getCacheDir()
get path to the lwjgl cache directory |
protected java.awt.Color |
getColor(java.lang.String param,
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 |
java.awt.Image |
getImage(java.net.URL url)
Get Image from path provided |
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. |
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()
|
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> |
readCacheFile(java.io.File file)
read the current cache file |
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 |
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 static void |
validateCertificateChain(java.security.cert.Certificate[] ownCerts,
java.security.cert.Certificate[] native_certs)
Validates the certificate chain for a single file |
protected void |
writeCacheFile(java.io.File file,
java.util.HashMap<java.lang.String,java.lang.Long> filesLastModified)
write out cache file of applet |
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, 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, 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 |
---|
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 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 fatalError
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 java.lang.String[] genericErrorMessage
protected boolean certificateRefused
protected java.lang.String[] certificateRefusedMessage
protected static boolean natives_loaded
Constructor Detail |
---|
public AppletLoader()
Method Detail |
---|
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 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 trimmed
protected void loadJarURLs() throws java.lang.Exception
java.lang.Exception
public void run()
run
in interface java.lang.Runnable
protected void setLWJGLProperties()
protected java.lang.String getCacheDir()
protected float readVersionFile(java.io.File file) throws java.lang.Exception
file
- the file to read
java.lang.Exception
- if it fails to read valueprotected void writeVersionFile(java.io.File file, float version) throws java.lang.Exception
file
- the file to write out toversion
- the version of the applet as a float
java.lang.Exception
- if it fails to write fileprotected java.util.HashMap<java.lang.String,java.lang.Long> readCacheFile(java.io.File file) throws java.lang.Exception
file
- the file to read
java.lang.Exception
- if it fails to read hashmapprotected void writeCacheFile(java.io.File file, java.util.HashMap<java.lang.String,java.lang.Long> filesLastModified) throws java.lang.Exception
file
- the file to write out tofilesLastModified
- the hashmap containing files names and lastModified times
java.lang.Exception
- if it fails to write fileprotected void updateClassPath(java.lang.String path) throws java.lang.Exception
path
- location where applet is stored
java.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 from
java.lang.Exception
- - if fails to get infomationprotected void downloadJars(java.lang.String path) throws java.lang.Exception
path
- location of the directory to save to
java.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 from
java.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 file
java.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 file
java.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 file
java.lang.Exception
- if any errors occurprotected void extractJars(java.lang.String path) throws java.lang.Exception
path
- output path
java.lang.Exception
- if any errors occurprotected void extractNatives(java.lang.String path) throws java.lang.Exception
path
- base folder containing all downloaded jars
java.lang.Exception
- if it fails to extract filesprotected static void validateCertificateChain(java.security.cert.Certificate[] ownCerts, java.security.cert.Certificate[] native_certs) throws java.lang.Exception
ownCerts
- Chain of certificates to check againstnative_certs
- Chain of certificates to check
java.lang.Exception
protected java.awt.Image getImage(java.lang.String s)
s
- location of the image
public java.awt.Image getImage(java.net.URL url)
getImage
in class java.applet.Applet
url
- location of the image
protected java.lang.String getJarName(java.net.URL url)
url
- Get jar file name from this url
protected java.lang.String getFileName(java.net.URL url)
url
- Get file name from this url
protected java.awt.Color getColor(java.lang.String param, java.awt.Color defaultColor)
param
- Color to loaddefaultColor
- Default color to use if no color to load
protected boolean getBooleanParameter(java.lang.String name, boolean defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameter
protected 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 sleep
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |