Class PtolemyApplet

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, ExecutionListener
    Direct Known Subclasses:
    BusContentionApplet, LocalZenoApplet, 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:

    • background: The background color, typically given as a hex number of the form "#rrggbb" where rr gives the red component, gg gives the green component, and bb gives the blue component.
    • controls: This gives a comma-separated list of any subset of the words "buttons", "topParameters", and "directorParameters" (case insensitive), or the word "none". If this parameter is not given, then it is equivalent to giving "buttons", and only the control buttons mentioned above will be displayed. If the parameter is given, and its value is "none", then no controls are placed on the screen. If the word "topParameters" is included in the comma-separated list, then controls for the top-level parameters of the model are placed on the screen, below the buttons. If the word "directorParameters" is included, then controls for the director parameters are also included.
    • modelClass: The fully qualified class name of a Java class that extends NamedObj. This class defines the model.
    • orientation: This can have value "horizontal", "vertical", or "controls_only" (case insensitive). If it is "vertical", then the controls are placed above the visual elements of the Placeable actors. This is the default. If it is "horizontal", then the controls are placed to the left of the visual elements. If it is "controls_only" then no visual elements are placed.
    • autoRun: This can have value "true", or "false". If it is "true", then the model will be run when the applet's start() method is called. If false, then the model will not be run automatically. The default is "true".

    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$
    Author:
    Edward A. Lee
    See Also:
    ModelPane, Placeable, Serialized Form
    Pt.AcceptedRating:
    Yellow (johnr)
    Pt.ProposedRating:
    Green (eal)
    • Nested Class Summary

      • 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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Manager _manager
      The manager, created in the init() method.
      protected boolean _setupOK
      Set this to false if the setup of the model during the init() method fails.
      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 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

      Constructors 
      Constructor Description
      PtolemyApplet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      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 javax.swing.JApplet

        addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
      • Methods inherited from class java.applet.Applet

        getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, isValidateRoot, 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, 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, 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, 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, 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
      • 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.
    • 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

        @Deprecated
        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.