ptolemy.domains.gr.lib
Class ViewScreen2D

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.domains.gr.kernel.GRActor
                              extended by ptolemy.domains.gr.kernel.GRActor2D
                                  extended by ptolemy.domains.gr.lib.ViewScreen2D
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Placeable, Initializable, TypedActor, ViewScreenInterface, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class ViewScreen2D
extends GRActor2D
implements Placeable, ViewScreenInterface

A sink actor that renders a two-dimensional scene into a display screen. All mouse and keyboard events within the viewscreen are handled by a ViewScreen2DListener.

Since:
Ptolemy II 4.0
Version:
$Id: ViewScreen2D.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer, Ismael M. Sarmiento
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (ismael)

Nested Class Summary
 class ViewScreen2D.ViewScreen2DListener
          Listen for Layer, LayerMotion and Key events.
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  JCanvas _canvas
           
private  java.awt.Container _container
           
private  BasicFigure _crosshairX
           
private  BasicFigure _crosshairY
           
private  ViewScreen2D.ViewScreen2DListener _eventHandler
           
private  EventLayer _eventLayer
           
private  javax.swing.JFrame _frame
           
private  FigureLayer _layer
           
private  java.awt.geom.Point2D.Double _origin
           
private  boolean _originRelocatable
           
private  OverlayLayer _overlayLayer
           
private  Figure _selectedFigure
           
 ColorAttribute backgroundColor
          The red, green, blue, and alpha components of the background color of the viewscreen.
 Parameter horizontalPixels
          The horizontal resolution of the display screen.
 Parameter lowerRightX
          The x coordinate of the canvas point visible in the lower right corner of the display screen.
 Parameter lowerRightY
          The y coordinate of the canvas point visible in the lower right corner of the display screen.
 Parameter rotatable
          Boolean variable that determines if the user is allowed to rotate the scene.
 Parameter scalable
          Boolean variable that determines if the user is allowed to scale the scene.
 TypedIOPort sceneGraphIn
          The input scene graph.
 Parameter showAxes
          Boolean variable that determines if the axes crosshairs are shown This parameter should contain a BooleanToken.
 Parameter translatable
          Boolean variable that determines if the user is allowed to translate the scene.
 Parameter upperLeftX
          The x coordinate of the canvas point visible in the upper left corner of the display screen.
 Parameter upperLeftY
          The y coordinate of the canvas point visible in the upper left corner of the display screen.
 Parameter verticalPixels
          The vertical resolution of the display screen.
 
Fields inherited from class ptolemy.domains.gr.kernel.GRActor2D
_viewScreen
 
Fields inherited from class ptolemy.domains.gr.kernel.GRActor
_allowAttributeChanges, _isSceneGraphInitialized
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
ViewScreen2D(CompositeEntity container, java.lang.String name)
          Construct a ViewScreen2D in the given container with the given name.
 
Method Summary
protected  void _addChild(Figure figure)
          Add a figure to the figure layer and set its interactor.
protected  void _createViewScreen2D()
          Create the view screen component.
protected  int _getHorizontalPixels()
          Return the horizontal pixels by reading the horizontalPixels parameter.
protected  int _getVerticalPixels()
          Return the vertical pixels by reading the verticalPixels parameter.
protected  boolean _isRotatable()
          Return the value of the rotatable parameter.
protected  boolean _isScalable()
          Return the value of the scalable parameter.
protected  boolean _isTranslatable()
          Return the value of the translatable parameter.
protected  void _makeSceneGraphConnection()
          Set up the scene graph connections of this actor.
 void fire()
          Repaint the canvas.
 JCanvas getCanvas()
          Return the Diva canvas used by this view screen.
 BasicFigure getCrosshairX()
          Return the horizontal component of the crosshair which marks the origin.
 BasicFigure getCrosshairY()
          Return the vertical component of the crosshair which marks the origin.
 java.awt.geom.Point2D.Double getOrigin()
          Return the location of the origin of the viewscreen.
 Figure getSelectedFigure()
          Return the figure currently selected in the viewscreen.
 void initialize()
          Initialize the execution.
 void place(java.awt.Container container)
          Set the container that this actor should display data in.
 void setSelectedFigure(Figure figure)
          Update the state of this object to reflect which figure is currently selected in the viewscreen.
 void wrapup()
          Wrap up an execution.
 
Methods inherited from class ptolemy.domains.gr.kernel.GRActor2D
_setViewScreen
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

backgroundColor

public ColorAttribute backgroundColor
The red, green, blue, and alpha components of the background color of the viewscreen. This parameter must contain an array of double values. The default value is {1.0, 1.0, 1.0, 1.0}, corresponding to opaque white.


sceneGraphIn

public TypedIOPort sceneGraphIn
The input scene graph.


horizontalPixels

public Parameter horizontalPixels
The horizontal resolution of the display screen. This parameter should contain a IntToken. The default value of this parameter is the IntToken 400.


rotatable

public Parameter rotatable
Boolean variable that determines if the user is allowed to rotate the scene. This parameter should contain a BooleanToken. The default value of this parameter is BooleanToken true.


scalable

public Parameter scalable
Boolean variable that determines if the user is allowed to scale the scene. This parameter should contain a BooleanToken. The default value of this parameter is BooleanToken false.


showAxes

public Parameter showAxes
Boolean variable that determines if the axes crosshairs are shown This parameter should contain a BooleanToken. The default value of this parameter is BooleanToken true.


translatable

public Parameter translatable
Boolean variable that determines if the user is allowed to translate the scene. This parameter should contain a BooleanToken. The default value of this parameter is BooleanToken false.


verticalPixels

public Parameter verticalPixels
The vertical resolution of the display screen. This parameter should contain a IntToken. The default value of this parameter is IntToken 400.


upperLeftX

public Parameter upperLeftX
The x coordinate of the canvas point visible in the upper left corner of the display screen.


upperLeftY

public Parameter upperLeftY
The y coordinate of the canvas point visible in the upper left corner of the display screen.


lowerRightX

public Parameter lowerRightX
The x coordinate of the canvas point visible in the lower right corner of the display screen.


lowerRightY

public Parameter lowerRightY
The y coordinate of the canvas point visible in the lower right corner of the display screen.


_canvas

private JCanvas _canvas

_container

private java.awt.Container _container

_crosshairX

private BasicFigure _crosshairX

_crosshairY

private BasicFigure _crosshairY

_eventHandler

private ViewScreen2D.ViewScreen2DListener _eventHandler

_eventLayer

private EventLayer _eventLayer

_frame

private javax.swing.JFrame _frame

_layer

private FigureLayer _layer

_origin

private java.awt.geom.Point2D.Double _origin

_originRelocatable

private boolean _originRelocatable

_overlayLayer

private OverlayLayer _overlayLayer

_selectedFigure

private Figure _selectedFigure
Constructor Detail

ViewScreen2D

public ViewScreen2D(CompositeEntity container,
                    java.lang.String name)
             throws IllegalActionException,
                    NameDuplicationException
Construct a ViewScreen2D in the given container with the given name. If the container argument is null, a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - Container of the director.
name - Name of this ViewScreen2D.
Throws:
IllegalActionException - If this actor is not compatible with the specified container.
NameDuplicationException - If the container not a CompositeActor and the name collides with an entity in the container.
Method Detail

fire

public void fire()
          throws IllegalActionException
Repaint the canvas.

Specified by:
fire in interface Executable
Overrides:
fire in class GRActor
Throws:
IllegalActionException - If an error occurs during the scene graph initialization.

getCanvas

public JCanvas getCanvas()
Return the Diva canvas used by this view screen.

Returns:
The Diva canvas.

getCrosshairX

public BasicFigure getCrosshairX()
Return the horizontal component of the crosshair which marks the origin.

Returns:
The horizontal component of the crosshair which marks the origin.

getCrosshairY

public BasicFigure getCrosshairY()
Return the vertical component of the crosshair which marks the origin.

Returns:
The vertical component of the crosshair which marks the origin.

getOrigin

public java.awt.geom.Point2D.Double getOrigin()
Return the location of the origin of the viewscreen.

Returns:
The origin of the viewscreen.

getSelectedFigure

public Figure getSelectedFigure()
Return the figure currently selected in the viewscreen.

Returns:
The figure currently selected in the viewscreen.
See Also:
setSelectedFigure(Figure figure)

initialize

public void initialize()
                throws IllegalActionException
Initialize the execution. Create the ViewScreen2D frame if it hasn't been set using the place() method.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class GRActor
Throws:
IllegalActionException - If the base class throws it.

place

public void place(java.awt.Container container)
Set the container that this actor should display data in. If place is not called, then the actor will create its own frame for display.

Specified by:
place in interface Placeable
Parameters:
container - The container in which to place the object, or null to specify that there is no current container.

setSelectedFigure

public void setSelectedFigure(Figure figure)
Update the state of this object to reflect which figure is currently selected in the viewscreen.

Parameters:
figure - The figure currently selected.
See Also:
getSelectedFigure()

wrapup

public void wrapup()
            throws IllegalActionException
Wrap up an execution.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class GRActor
Throws:
IllegalActionException - If the base class throws it.

_addChild

protected void _addChild(Figure figure)
                  throws IllegalActionException
Add a figure to the figure layer and set its interactor.

Parameters:
figure - The figure that is to be added.
Throws:
IllegalActionException - Always thrown for this base class.

_createViewScreen2D

protected void _createViewScreen2D()
                            throws IllegalActionException
Create the view screen component. If place() was called with a container, then use the container. Otherwise, create a new frame and use that.

Throws:
IllegalActionException - If there is a problem reading a parameter.

_getHorizontalPixels

protected int _getHorizontalPixels()
                            throws IllegalActionException
Return the horizontal pixels by reading the horizontalPixels parameter.

Returns:
the horizontal pixels.
Throws:
IllegalActionException - If thrown while reading the parameter.

_getVerticalPixels

protected int _getVerticalPixels()
                          throws IllegalActionException
Return the vertical pixels by reading the verticalPixels parameter.

Returns:
the vertical pixels.
Throws:
IllegalActionException - If thrown while reading the parameter.

_isRotatable

protected boolean _isRotatable()
                        throws IllegalActionException
Return the value of the rotatable parameter.

Returns:
The value of the rotatable parameter.
Throws:
IllegalActionException - If thrown while reading the parameter.

_isScalable

protected boolean _isScalable()
                       throws IllegalActionException
Return the value of the scalable parameter.

Returns:
The value of the scalable parameter.
Throws:
IllegalActionException - If thrown while reading the parameter.

_isTranslatable

protected boolean _isTranslatable()
                           throws IllegalActionException
Return the value of the translatable parameter.

Returns:
The value of the tranlatable parameter.
Throws:
IllegalActionException - If thrown while reading the parameter.

_makeSceneGraphConnection

protected void _makeSceneGraphConnection()
                                  throws IllegalActionException
Set up the scene graph connections of this actor.

Specified by:
_makeSceneGraphConnection in class GRActor
Throws:
IllegalActionException - Always thrown for this base class.