fi.hut.tml.xsmiles.mlfc.jax
Class AppletRunner

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byfi.hut.tml.xsmiles.mlfc.jax.AppletRunner
All Implemented Interfaces:
java.applet.AppletContext, java.applet.AppletStub, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class AppletRunner
extends java.awt.Container
implements java.applet.AppletStub, java.applet.AppletContext

AppletRunner - 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.

Version:
1.1
Author:
DTAI, Incorporated, Juha $Id: AppletRunner.java 5988 2005-03-16 16:12:16Z honkkis $ $Source: /home/cvs/xsmiles/src/xsmiles/fi/hut/tml/xsmiles/mlfc/jax/AppletRunner.java,v $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
AppletRunner(java.applet.Applet applet, java.lang.String cB, java.net.URL docBase, int w, int h, MLFCListener listener)
          Constructor for the main class, given an existing applet object.
 
Method Summary
 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.awt.Dimension getPreferredSize()
          so that this is a perfect component
 java.awt.Dimension getSize()
           
 java.io.InputStream getStream(java.lang.String key)
           
 java.util.Iterator getStreamKeys()
           
 boolean handleEvent(java.awt.Event evt)
          Event handler to catch the Frame (window) close action, and exit the program.
 boolean isActive()
          Returns true if the applet is active.
 void runApplet()
          Starts the crapplet
 void setDimension(java.awt.Dimension d)
           
 void setParams(java.util.Hashtable p)
          A hashtable containing all the parameters, with the name as a key
 void setStream(java.lang.String key, java.io.InputStream stream)
          Creates a new URLStreamHandler instance with the specified protocol.
 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.
 void stop()
           
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getAccessibleContext, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, 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, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AppletRunner

public AppletRunner(java.applet.Applet applet,
                    java.lang.String cB,
                    java.net.URL docBase,
                    int w,
                    int h,
                    MLFCListener listener)
Constructor for the main class, given an existing applet object.

Parameters:
applet - the applet embedded in this AppletContext
Method Detail

runApplet

public void runApplet()
Starts the crapplet


stop

public void stop()

setParams

public void setParams(java.util.Hashtable p)
A hashtable containing all the parameters, with the name as a key


setDimension

public void setDimension(java.awt.Dimension d)

handleEvent

public boolean handleEvent(java.awt.Event evt)
Event handler to catch the Frame (window) close action, and exit the program.

Parameters:
evt - The event that occurred
Returns:
false if the event was not handled by this object.

isActive

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

Specified by:
isActive in interface java.applet.AppletStub
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 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

getPreferredSize

public java.awt.Dimension getPreferredSize()
so that this is a perfect component


getSize

public java.awt.Dimension getSize()

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 AppletRunner

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

setStream

public void setStream(java.lang.String key,
                      java.io.InputStream stream)
               throws java.io.IOException
Creates a new URLStreamHandler instance with the specified protocol.

Specified by:
setStream in interface java.applet.AppletContext
Throws:
java.io.IOException

getStream

public java.io.InputStream getStream(java.lang.String key)
Specified by:
getStream in interface java.applet.AppletContext

getStreamKeys

public java.util.Iterator getStreamKeys()
Specified by:
getStreamKeys in interface java.applet.AppletContext


X-Smiles 1.2