ptolemy.actor.lib.gui
Class SliderSource

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.actor.lib.Source
                              extended by ptolemy.actor.lib.gui.SliderSource
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.event.ChangeListener, Actor, Executable, FiringsRecordable, Placeable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class SliderSource
extends Source
implements javax.swing.event.ChangeListener, Placeable

The output of this actor is controlled by a slider in the run window. The range of the output is specified by two parameters, minimum and maximum. The type of these parameters and the output is integer.

Since:
Ptolemy II 2.0
Version:
$Id: SliderSource.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Xiaojun Liu, Gang Zhou
See Also:
Serialized Form
Accepted Rating:
Red (liuxj)
Proposed Rating:
Red (liuxj)

Nested Class Summary
static class SliderSource.SliderFrame
          The frame for the slider.
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  java.awt.Container _container
           
private  javax.swing.JFrame _frame
           
private  IntToken _outputVal
           
private  javax.swing.JPanel _panel
          The JPanel that contains the slider.
 Parameter majorTickSpacing
          The major tick spacing of the slider.
 Parameter maximum
          The maximum value of the slider.
 Parameter minimum
          The minimum value of the slider.
 Parameter minorTickSpacing
          The minor tick spacing of the slider.
 javax.swing.JSlider slider
          The slider that controls the output of this actor.
 StringAttribute title
          The title to put on top.
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
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
SliderSource(CompositeEntity container, java.lang.String name)
          Construct an actor with an input multiport of type GENERAL.
 
Method Summary
private  void _remove()
          Remove the display from the current container, if there is one.
 void attributeChanged(Attribute attribute)
          If the specified attribute is minimum or maximum, then set the range of the slider.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Output the value of the slider recorded when prefire() is last called.
 java.awt.Color getBackground()
          Return the background.
 void initialize()
          Create a slider on the screen, if necessary.
 void place(java.awt.Container container)
          Specify the container in which the slider should be displayed.
 boolean prefire()
          Record the current value of the slider.
 void setBackground(java.awt.Color background)
          Set the background color of the panel that contains the slider.
 void setContainer(CompositeEntity container)
          Override the base class to remove the display from its graphical container if the argument is null.
 void stateChanged(javax.swing.event.ChangeEvent e)
          The value of the slider changed, record the new value.
 
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, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate, wrapup
 
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, 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, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
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

slider

public javax.swing.JSlider slider
The slider that controls the output of this actor.


minimum

public Parameter minimum
The minimum value of the slider. The value must be an integer. The default value is -10.


maximum

public Parameter maximum
The maximum value of the slider. The value must be an integer. The default value is 10.


majorTickSpacing

public Parameter majorTickSpacing
The major tick spacing of the slider. The value must be an integer. The default value is 10.


minorTickSpacing

public Parameter minorTickSpacing
The minor tick spacing of the slider. The value must be an integer. The default value is 1.


title

public StringAttribute title
The title to put on top.


_panel

private javax.swing.JPanel _panel
The JPanel that contains the slider.


_container

private java.awt.Container _container

_outputVal

private IntToken _outputVal

_frame

private javax.swing.JFrame _frame
Constructor Detail

SliderSource

public SliderSource(CompositeEntity container,
                    java.lang.String name)
             throws IllegalActionException,
                    NameDuplicationException
Construct an actor with an input multiport of type GENERAL.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an entity with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the specified attribute is minimum or maximum, then set the range of the slider.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified range for the slider is invalid.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the slider public variable to null.

Overrides:
clone in class AtomicActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Output the value of the slider recorded when prefire() is last called.

Specified by:
fire in interface Executable
Overrides:
fire in class Source
Throws:
IllegalActionException - Not thrown in this base class.

getBackground

public java.awt.Color getBackground()
Return the background.

Returns:
The background color.
See Also:
setBackground(Color)

initialize

public void initialize()
                throws IllegalActionException
Create a slider on the screen, if necessary. If a graphical container has not been specified, place the slider into its own frame. Otherwise, place it in the specified container.

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

place

public void place(java.awt.Container container)
Specify the container in which the slider should be displayed. An instance of JSlider will be added to that container. This method needs to be called before the first call to initialize(). Otherwise, an instance of JSlider will be placed in its own frame. The slider is also placed in its own frame if this method is called with a null argument. The background of the slider is set equal to that of the container (unless it is null).

Specified by:
place in interface Placeable
Parameters:
container - The container into which to place the slider.

prefire

public boolean prefire()
                throws IllegalActionException
Record the current value of the slider. This value is output in the subsequent firings of this actor.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Source
Returns:
True, unless the trigger input is connected and has no input.
Throws:
IllegalActionException - If checking the trigger for a token throws it or if the super class throws it.

setBackground

public void setBackground(java.awt.Color background)
Set the background color of the panel that contains the slider.

Parameters:
background - The background color.
See Also:
getBackground()

setContainer

public void setContainer(CompositeEntity container)
                  throws IllegalActionException,
                         NameDuplicationException
Override the base class to remove the display from its graphical container if the argument is null.

Overrides:
setContainer in class AtomicActor
Parameters:
container - The proposed container.
Throws:
IllegalActionException - If the base class throws it.
NameDuplicationException - If the base class throws it.
See Also:
ComponentEntity.getContainer()

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
The value of the slider changed, record the new value.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

_remove

private void _remove()
Remove the display from the current container, if there is one.