com.sas.util
Class AppletHost

com.sas.util.AppletHost
All Implemented Interfaces:
java.applet.AppletContext, java.applet.AppletStub, java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class AppletHost
implements java.applet.AppletStub, java.applet.AppletContext, java.awt.event.ActionListener

AppletHost - implements AppletContext and AppletStub to allow any applet to easily run as an application. The only thing it can't do is access URL's. Applet parameters are entered on the command line with name as one word and value as the next.

See Also:
Serialized Form

Field Summary
protected  java.util.Vector applets
           
protected  int initial_height
           
protected  int initial_width
           
protected  java.util.Hashtable params
           
protected  java.awt.Button startButton
           
protected  java.awt.TextField status
           
protected  java.awt.Button stopButton
           
 
Constructor Summary
AppletHost(java.applet.Applet applet, int default_width, int default_height, java.lang.String[] args)
          Constructor for the main class, given an existing applet object and a default frame (window) width and height.
AppletHost(java.applet.Applet applet, java.lang.String[] args)
          Constructor for the main class, given an existing applet object.
AppletHost(java.lang.String[] args)
          Constructor for the main class, from the command line arguments.
AppletHost(java.lang.String appletClassName, int default_width, int default_height, java.lang.String[] args)
          Constructor for the main class, given a name of an applet object and a default frame (window) width and height.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
           
 void appletResize(int width, int height)
          Called when the applet wants to be resized.
 java.applet.Applet getApplet(java.lang.String name)
          Gets an applet by name.
 java.applet.AppletContext getAppletContext()
          Gets a handler to the applet's context.
 java.util.Enumeration getApplets()
          Enumerates the applets in this context.
 java.applet.AudioClip getAudioClip(java.net.URL url)
          Gets an audio clip.
 java.net.URL getCodeBase()
          Gets the codebase URL.
 java.net.URL getDocumentBase()
          Gets the document URL.
 java.awt.Image getImage(java.net.URL url)
          Gets an image.
 java.lang.String getParameter(java.lang.String name)
          Gets a parameter of the applet.
 java.io.InputStream getStream(java.lang.String key)
          Returns the stream to which specified key is associated within this applet context.
 java.util.Iterator getStreamKeys()
          Finds all the keys of the streams in this applet context.
 boolean isActive()
          Returns true if the applet is active.
static void main(java.lang.String[] args)
          Entry point into the standalone program.
 void parseArgs(java.lang.String[] args, int startidx)
          Parse the command line arguments.
 void processWindowEvent(java.awt.event.WindowEvent evt)
           
 void setStream(java.lang.String key, java.io.InputStream stream)
          Associates the specified stream with the specified key in this applet context.
 void showDocument(java.net.URL url)
          Shows a new document.
 void showDocument(java.net.URL url, java.lang.String target)
          Show a new document in a target window or frame.
 void showStatus(java.lang.String text)
          Show a status string in the status area (the Text object at the bottom of the window.
 

Field Detail

status

protected java.awt.TextField status

startButton

protected java.awt.Button startButton

stopButton

protected java.awt.Button stopButton

params

protected java.util.Hashtable params

applets

protected java.util.Vector applets

initial_width

protected int initial_width

initial_height

protected int initial_height
Constructor Detail

AppletHost

public AppletHost(java.applet.Applet applet,
                  java.lang.String[] args)
Constructor for the main class, given an existing applet object.

Parameters:
applet - the applet embedded in this AppletContext
args - the command line arguments. Contains possibly height and width, and any applet parameters

AppletHost

public AppletHost(java.applet.Applet applet,
                  int default_width,
                  int default_height,
                  java.lang.String[] args)
Constructor for the main class, given an existing applet object and a default frame (window) width and height.

Parameters:
applet - the applet embedded in this AppletContext
default_width - the default width of the window
default_height - the default width of the window
args - the command line arguments. Contains possibly height and width, and any applet parameters

AppletHost

public AppletHost(java.lang.String appletClassName,
                  int default_width,
                  int default_height,
                  java.lang.String[] args)
Constructor for the main class, given a name of an applet object and a default frame (window) width and height.

Parameters:
appletClassName - the applet embedded in this AppletContext
default_width - the default width of the window
default_height - the default width of the window
args - the command line arguments. Contains possibly height and width, and any applet parameters

AppletHost

public AppletHost(java.lang.String[] args)
Constructor for the main class, from the command line arguments.

Parameters:
args - the command line arguments. Contains the name of the applet class, possibly height and width, and any applet parameters.
Method Detail

main

public static void main(java.lang.String[] args)
Entry point into the standalone program.

Parameters:
args - the command line arguments

parseArgs

public void parseArgs(java.lang.String[] args,
                      int startidx)
Parse the command line arguments. Get the initial width and height of the window if specified (-width [value] -height [value]), and the applet parameters (name value pairs, or name=value).

Parameters:
args - the command line arguments. Contains possibly height and width, and any applet parameters
startidx - index in the args array at which to start parsing

processWindowEvent

public void processWindowEvent(java.awt.event.WindowEvent evt)
Overrides:
processWindowEvent in class java.awt.Window

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

isActive

public boolean isActive()
Returns true if the applet is active.

Specified by:
isActive in interface java.applet.AppletStub
Overrides:
isActive in class java.awt.Window
Returns:
always true

getDocumentBase

public java.net.URL getDocumentBase()
Gets the document URL.

Specified by:
getDocumentBase in interface java.applet.AppletStub
Returns:
a "file:" URL for the current directory

getCodeBase

public final java.net.URL getCodeBase()
Gets the codebase URL.

Specified by:
getCodeBase in interface java.applet.AppletStub
Returns:
in this case, the same value as getDocumentBase()

getParameter

public final java.lang.String getParameter(java.lang.String name)
Gets a parameter of the applet.

Specified by:
getParameter in interface java.applet.AppletStub
Parameters:
name - the name of the parameter
Returns:
the value, or null if not defined

getAppletContext

public final java.applet.AppletContext getAppletContext()
Gets a handler to the applet's context.

Specified by:
getAppletContext in interface java.applet.AppletStub
Returns:
this object

appletResize

public void appletResize(int width,
                         int height)
Called when the applet wants to be resized. This causes the Frame (window) to be resized to accomodate the new Applet size.

Specified by:
appletResize in interface java.applet.AppletStub
Parameters:
width - the new width of the applet
height - the new height of the applet

getAudioClip

public final java.applet.AudioClip getAudioClip(java.net.URL url)
Gets an audio clip. (There doesn't seem to be a "Toolkit" for audio clips in my JDK, so this always returns null. You could implement this differently, returning a dummy AudioClip object for which the class could be defined at the bottom of this file.)

Specified by:
getAudioClip in interface java.applet.AppletContext
Parameters:
url - URL of the AudioClip to load
Returns:
the AudioClip object if it exists (in our case, this is always null

getImage

public final java.awt.Image getImage(java.net.URL url)
Gets an image. This usually involves downloading it over the net. However, the environment may decide to cache images. This method takes an array of URLs, each of which will be tried until the image is found.

Specified by:
getImage in interface java.applet.AppletContext
Parameters:
url - URL of the Image to load
Returns:
the Image object

getApplet

public final java.applet.Applet getApplet(java.lang.String name)
Gets an applet by name.

Specified by:
getApplet in interface java.applet.AppletContext
Parameters:
name - the name of the applet
Returns:
null if the applet does not exist, and it never does since we never name the applet.

getApplets

public final java.util.Enumeration getApplets()
Enumerates the applets in this context. Only applets that are accessible will be returned. This list always includes the applet itself.

Specified by:
getApplets in interface java.applet.AppletContext
Returns:
the Enumeration -- contains ONLY the applet created with this DummyAppletContext

showDocument

public void showDocument(java.net.URL url)
Shows a new document. This may be ignored by the applet context (and in our case, it is, but we'll show the user, in the status area, that the document was requested and WOULD be loaded if in a browser).

Specified by:
showDocument in interface java.applet.AppletContext
Parameters:
url - URL to load

showDocument

public void showDocument(java.net.URL url,
                         java.lang.String target)
Show a new document in a target window or frame. This may be ignored by the applet context. (Again, it is ignored, but we'll show the request information to the user in the status area.) This method accepts the target strings: _self show in current frame _parent show in parent frame _top show in top-most frame _blank show in new unnamed top-level window show in new top-level window named

Specified by:
showDocument in interface java.applet.AppletContext
Parameters:
url - URL to load
target - the target string

showStatus

public void showStatus(java.lang.String text)
Show a status string in the status area (the Text object at the bottom of the window.

Specified by:
showStatus in interface java.applet.AppletContext
Parameters:
text - the text to display

getStream

public java.io.InputStream getStream(java.lang.String key)
Returns the stream to which specified key is associated within this applet context.

Specified by:
getStream in interface java.applet.AppletContext

getStreamKeys

public java.util.Iterator getStreamKeys()
Finds all the keys of the streams in this applet context.

Specified by:
getStreamKeys in interface java.applet.AppletContext

setStream

public void setStream(java.lang.String key,
                      java.io.InputStream stream)
Associates the specified stream with the specified key in this applet context.

Specified by:
setStream in interface java.applet.AppletContext



Copyright © 2009 SAS Institute Inc. All Rights Reserved.