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:
Additionally the following parameters can be supplied to tweak the behaviour of the AppletLoader.
Applet.AccessibleApplet
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Container.AccessibleAWTContainer
Panel.AccessibleAWTPanel
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 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 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
|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor | Description |
---|---|
AppletLoader() |
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 |
extractPack(String in,
String out) |
Extract Pack File
|
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
|
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
|
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getLocale, getParameter, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus
getAppletContext, getCodeBase, getDocumentBase, getParameter, isActive
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
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
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 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 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 boolean headless
protected boolean headlessWaiting
protected String[] headlessMessage
protected int concurrentLookupThreads
protected boolean fatalError
protected boolean certificateRefused
protected boolean minimumJreNotFound
protected String[] genericErrorMessage
protected String[] certificateRefusedMessage
protected String[] minimumJREMessage
protected String[] errorMessage
protected static boolean natives_loaded
protected void cleanUp()
public Applet getApplet()
public int getStatus()
public String[] getMessages()
public void appletResize(int width, int height)
appletResize
in interface AppletStub
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 trimmedprotected void loadJarURLs() throws Exception
Exception
public void run()
public boolean isMinJREVersionAvailable() throws Exception
Exception
- a NumberFormatException is thrown if the string is not validprotected boolean compareVersion(File versionFile, String version)
versionFile
- - location to file containing version informationversion
- - String version that needs to be comparedprotected void setLWJGLProperties()
protected String getCacheDirectory() throws Exception
Exception
- if access is deniedprotected String getLWJGLCacheDir()
protected String readStringFile(File file)
file
- to be readprotected HashMap<String,Long> readHashMapFile(File file)
file
- the file to readprotected Object readObjectFile(File file) throws Exception
file
- the file to readException
- if it fails to read object from fileprotected void writeObjectFile(File file, Object object) throws Exception
file
- the file to write out toobject
- the contents of the fileException
- if it fails to write fileprotected void updateClassPath(String path) throws Exception
path
- location where applet is storedException
- if it fails to add classpathprotected void switchApplet() throws Exception
Exception
protected void getJarInfo(File dir) throws Exception
dir
- - location to read cache file fromException
- - if fails to get infomationprotected void downloadJars(String path) throws Exception
path
- location of the directory to save toException
- if download failsprotected InputStream getJarInputStream(String currentFile, URLConnection urlconnection) throws Exception
urlconnection
- connection to get input stream fromException
protected void extractLZMA(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting fileException
- if any errors occurprotected void extractGZip(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting fileException
- if any errors occurprotected void extractPack(String in, String out) throws Exception
in
- Input path to pack fileout
- output path to resulting fileException
- if any errors occurprotected void extractJars(String path) throws Exception
path
- output pathException
- if any errors occurprotected void extractNatives(String path) throws Exception
path
- base folder containing all downloaded jarsException
- if it fails to extract filesprotected static boolean certificatesMatch(Certificate[] certs1, Certificate[] certs2) throws Exception
certs1
- first chain of certificatescerts2
- second chain of certificatesException
protected static Certificate[] getCurrentCertificates() throws Exception
Exception
protected void validateJars(String path) throws Exception
path
- - where the jars are storedException
- if a corrupt jar is foundprotected boolean isZipValid(File file)
file
- - zip file to testprotected Image getImage(String s)
s
- location of the imageprotected String getJarName(URL url)
url
- Get jar file name from this urlprotected String getFileName(URL url)
url
- Get file name from this urlprotected Color getColor(String param, Color defaultColor)
param
- Color to loaddefaultColor
- Default color to use if no color to loadpublic String replaceLast(String original, String target, String replacement)
original
- - String to searchtarget
- - substring to findreplacement
- - what to replace target substring withprotected String getStringParameter(String name, String defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected boolean getBooleanParameter(String name, boolean defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected int getIntParameter(String name, int defaultValue)
name
- Name of parameterdefaultValue
- default value to return if no such parameterprotected void fatalErrorOccured(String error, Exception e)
error
- Error message to printprotected void setState(int state)
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.