03.08.2013 Views

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Custom Applets<br />

<br />

<br />

then the result of execution looks like figure 8.5. The layout is now horizontal, with the controls to the<br />

left of the displays instead of on top, and the director parameters have been made available to the<br />

applet user.<br />

8.3.3 Executing the Model in an Application<br />

A model created as above can also be executed as an application, in addition to running it as a<br />

mode. Any class that extends CompositeActor, the base class for TypedCompositeActor, can be executed<br />

using the CompositeActorApplication class, shown in figure 8.6. The command is simply:<br />

bash-2.05b$ cd $PT<strong>II</strong>/doc/tutorial<br />

bash-2.05b$ java -classpath ../.. \<br />

ptolemy.actor.gui.CompositeActorApplication \<br />

-class doc.tutorial.TutorialApplet1<br />

The result will look like figure 8.5. This ability to use the same class definition in both an applet and an<br />

application is convenient.<br />

8.3.4 Extending PtolemyApplet<br />

Another way to use PtolemyApplet is to define the model as a Java class that extends it and overrides<br />

the protected method _createModel() to create a model and optionally overrides the<br />

_createView() protected method to create a custom display. Extending PtolemyApplet gives the developer<br />

the opportunity to control the look and feel of the applet in as much detail as necessary, including<br />

creating completely customized displays and controls.<br />

In figure 8.7 we define the same applet by extending PtolemyApplet instead of extending Typed-<br />

CompositeActor. This class overrides the _createView() method, which takes a Workspace as an argument<br />

and returns a NamedObj. Note that since we are no longer extending TypedCompositeActor, we<br />

FIGURE 8.5. Result of the model as an application.<br />

Heterogeneous Concurrent Modeling and Design 8-239

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!