ptolemy.actor.gui
Class PtolemyApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by ptolemy.gui.BasicJApplet
                          extended by ptolemy.actor.gui.PtolemyApplet
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, ExecutionListener
Direct Known Subclasses:
MoMLApplet

public class PtolemyApplet
extends BasicJApplet
implements ExecutionListener

This class provides a convenient way to make applets out of Ptolemy II models. It assumes that the model is defined as a Java class that extends NamedObj, with the classname given by the modelClass applet parameter. If that model does not contain a manager, then this class will create one for it.

This class offers a number of alternatives that control the visual appearance of the applet. By default, the applet places on the screen a set of control buttons that can be used to start, stop, pause, and resume the model. Below those buttons, it places the visual elements of any actors in the model that implement the Placeable interface, such as plotters or textual output.

The applet parameters are:

To create a model in a different way, say without a modelClass applet parameter, you may extend this class and override the protected method _createModel(). If you wish to alter the way that the model is represented on the screen, you can extend this class an override the _createView() method. The rendition in this class is an instance of ModelPane.

This class provides a number of methods that might be useful even if its init() or _createModel() methods are not appropriate for a given applet. Specifically, it provides a mechanism for reporting errors and exceptions; and it provide an applet parameter for controlling the background color.

Since:
Ptolemy II 0.3
Version:
$Id: PtolemyApplet.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
ModelPane, Placeable, Serialized Form
Accepted Rating:
Yellow (johnr)
Proposed Rating:
Green (eal)

Nested Class Summary
private  class PtolemyApplet.GoButtonListener
           
private  class PtolemyApplet.StopButtonListener
           
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  javax.swing.JButton _goButton
           
protected  Manager _manager
          The manager, created in the init() method.
private  Manager.State _previousState
           
protected  boolean _setupOK
          Set this to false if the setup of the model during the init() method fails.
private  javax.swing.JButton _stopButton
           
protected  NamedObj _toplevel
          The top-level composite actor, created in the init() method.
protected  Workspace _workspace
          The workspace that the applet is built in.
 
Fields inherited from class ptolemy.gui.BasicJApplet
_background
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
PtolemyApplet()
           
 
Method Summary
protected  NamedObj _createModel(Workspace workspace)
          Create a model.
protected  javax.swing.JPanel _createRunControls(int numberOfButtons)
          Deprecated. Use the control applet parameter.
protected  void _createView()
          Create a ModelPane to control execution of the model and display its results.
protected  void _go()
          Execute the model, if the manager is not currently executing.
protected  void _stop()
          Stop the execution.
 void destroy()
          Cleanup after execution of the model.
 void executionError(Manager manager, java.lang.Throwable throwable)
          Report that an execute error occurred.
 void executionFinished(Manager manager)
          Report that execution of the model has finished.
 java.lang.String getAppletInfo()
          Return a string describing this applet.
 java.lang.String[][] getParameterInfo()
          Describe the applet parameters.
 void init()
          Initialize the applet.
 void managerStateChanged(Manager manager)
          Report that the manager state has changed.
 void start()
          Start execution of the model.
 void stop()
          Stop execution of the model.
 
Methods inherited from class ptolemy.gui.BasicJApplet
_concatStringArrays, _getBackground, _stackTraceToString, report, report, report
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, 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, 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, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, 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, 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, imageUpdate, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_manager

protected Manager _manager
The manager, created in the init() method.


_setupOK

protected boolean _setupOK
Set this to false if the setup of the model during the init() method fails. This prevents the model from executing.


_toplevel

protected NamedObj _toplevel
The top-level composite actor, created in the init() method.


_workspace

protected Workspace _workspace
The workspace that the applet is built in. Each applet has it own workspace.


_goButton

private javax.swing.JButton _goButton

_stopButton

private javax.swing.JButton _stopButton

_previousState

private Manager.State _previousState
Constructor Detail

PtolemyApplet

public PtolemyApplet()
Method Detail

destroy

public void destroy()
Cleanup after execution of the model. This method is called by the browser or appletviewer to inform this applet that it should clean up.

Overrides:
destroy in class java.applet.Applet

executionError

public void executionError(Manager manager,
                           java.lang.Throwable throwable)
Report that an execute error occurred. This is called by the manager.

Specified by:
executionError in interface ExecutionListener
Parameters:
manager - The manager in charge of the execution.
throwable - The throwable that triggered the error.

executionFinished

public void executionFinished(Manager manager)
Report that execution of the model has finished. This is called by the manager.

Specified by:
executionFinished in interface ExecutionListener
Parameters:
manager - The manager in charge of the execution.

getAppletInfo

public java.lang.String getAppletInfo()
Return a string describing this applet.

Overrides:
getAppletInfo in class BasicJApplet
Returns:
A string describing the applet.

getParameterInfo

public java.lang.String[][] getParameterInfo()
Describe the applet parameters.

Overrides:
getParameterInfo in class BasicJApplet
Returns:
An array describing the applet parameters.

init

public void init()
Initialize the applet. This method is called by the browser or applet viewer to inform this applet that it has been loaded into the system. It is always called before the first time that the start() method is called. In this base class, this method creates a new workspace, and instantiates in it the model whose class name is given by the modelClass applet parameter. If that model does not contain a manager, then this method creates one for it.

Overrides:
init in class BasicJApplet

managerStateChanged

public void managerStateChanged(Manager manager)
Report that the manager state has changed. This is called by the manager.

Specified by:
managerStateChanged in interface ExecutionListener
Parameters:
manager - The manager controlling the execution.
See Also:
Manager.getState()

start

public void start()
Start execution of the model. This method is called by the browser or applet viewer to inform this applet that it should start its execution. It is called after the init method and each time the applet is revisited in a Web page. In this base class, this method calls the protected method _go(), which executes the model, unless the noAutoRun parameter has been set. If a derived class does not wish to execute the model each time start() is called, it should override this method with a blank method.

Overrides:
start in class java.applet.Applet

stop

public void stop()
Stop execution of the model. This method is called by the browser or applet viewer to inform this applet that it should stop its execution. It is called when the Web page that contains this applet has been replaced by another page, and also just before the applet is to be destroyed. In this base class, this method calls the stop() method of the manager. If there is no manager, do nothing.

Overrides:
stop in class java.applet.Applet

_createModel

protected NamedObj _createModel(Workspace workspace)
                         throws java.lang.Exception
Create a model. In this base class, we check to see whether the applet has a parameter modelClass, and if so, then we instantiate the class specified in that parameter. If not, then we create an empty instance of NamedObj. It is required that the class specified in the modelClass parameter have a constructor that takes one argument, an instance of Workspace. In either case, if the resulting model does not have a manager, then we give it a manager.

Parameters:
workspace - The workspace in which to create the model.
Returns:
A model.
Throws:
java.lang.Exception - If something goes wrong. This is a broad exception to allow derived classes wide latitude as to which exception to throw.

_createRunControls

protected javax.swing.JPanel _createRunControls(int numberOfButtons)
Deprecated. Use the control applet parameter.

Create run controls in a panel and return that panel. The argument controls how many buttons are created. If its value is greater than zero, then a "Go" button created. If its value is greater than one, then a "Stop" button is also created. Derived classes may override this method to add additional controls, or to create a panel with a different layout.

Parameters:
numberOfButtons - How many buttons to create.
Returns:
The run control panel.

_createView

protected void _createView()
Create a ModelPane to control execution of the model and display its results. Derived classes may override this to do something different.


_go

protected void _go()
            throws IllegalActionException
Execute the model, if the manager is not currently executing. Note that this method is not called if there are button controls on the screen and the user pushes the "Go" button.

Throws:
IllegalActionException - Not thrown in this base class.

_stop

protected void _stop()
Stop the execution.