fr.emn.reactiveinput
Class AbstractDevice

java.lang.Object
  extended byfr.emn.reactiveinput.AbstractDevice
All Implemented Interfaces:
Device, Processor
Direct Known Subclasses:
AbstractMutableDevice, DAddShape, DAnd, DAWTKeyboard, DBrush, DColorConv, DCompare, DConvertFromScreen, DDirectMouse, DGaming, DGestureCommand, DInDraw, DInstanceOf, DJComponent, DJScrollBar, DJText, DJzPick, DLowPass, DMidiIn, DMidiOut, DMidiSynth, DNot, DOr, DQuikWrite, DRound, DSerializer, DSpeechCommand, DSpeechSynth, DSwCommand, DSwFocus, DSwGhost, DSwPick, DTick, DTime, DTool, DTransition, DXInput, DZCanvas, DZNode, MissingDevice

public abstract class AbstractDevice
extends java.lang.Object
implements Device, Processor

An abstract device you can use to create your own devices.


Field Summary
protected  int currIndex
           
protected  java.util.Vector ins
           
protected  java.util.Vector outs
           
 
Fields inherited from interface fr.emn.reactiveinput.Device
AUTO_PROPERTIES
 
Constructor Summary
AbstractDevice(java.lang.String name)
          AbstractDevice's constructor.
 
Method Summary
protected  In addIn(java.lang.String name, int type)
          Adds an inSlot to the device (obligatory=false).
protected  In addIn(java.lang.String name, int type, boolean obligatory)
          Adds an inSlot to the device.
protected  Out addOut(java.lang.String name, int type)
          Adds an outSlot to the device.
 void close()
          Add closing code here if needed.
 Device copy()
          Is isCopiable() returns true, copies the device by calling DeviceUtilities.defaultCopy().
 void doDisable()
          Add device disabling code here (does nothing by default).
 void doEnable()
          Add device enabling code here (does nothing by default).
protected  void finalize()
           
 java.lang.String getError()
          Subclass this method to return the current error message (FAILED state).
protected  int getIndex(Slot s)
           
 DeviceInfo getInfo()
          Returns null by default.
 In[] getIns()
          Returns the device's input slots.
 java.lang.String getName()
          getName method comment.
 Out[] getOuts()
          Returns the device's output slots.
 java.lang.String[] getProperties()
          Returns Device.AUTO_PROPERTIES: to add properties to the device, you just have to add appropriate "type value getProp()" and "void setProp(type value)" accessor methods.
 boolean hasExternalInput()
          Specifies whether this device has external (implicit) input or not.
 boolean hasExternalOutput()
          Specifies whether this device has external (implicit) output or not.
 void init()
          Initializes device's output values.
protected  void insertAt(int index)
          Insert next slots before the specified index
protected  void insertAtEnd()
          Add next slots at the end (default)
protected  void insertBefore(Slot s)
          Insert next slots before the specified slot.
 boolean isCopiable()
          Returns true by default.
 boolean isEnabled()
           
 boolean isOpenable()
          Returns true if the device can be opened.
 Processor open(OpenContext context)
          Subclass this method if you want to specialize data processing, or if you want to perform some initializations before running the device.
 void setEnabled(boolean enabled)
          setEnabled method comment.
 void setInfo(DeviceInfo info)
          Returns null by default.
 void setInfo(java.lang.String description, java.lang.String help)
           
 void setLastError(java.lang.String error)
           
protected  void setName(java.lang.String name)
           
 void update()
          Updates device's output values.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ins

protected java.util.Vector ins

outs

protected java.util.Vector outs

currIndex

protected int currIndex
Constructor Detail

AbstractDevice

public AbstractDevice(java.lang.String name)
AbstractDevice's constructor. Call this constructor in your device's constructor.

When created, the device is implicitely in this state: status = STATUS_CLOSED; enabled = true;

In this constructor, you may :

- Create input and/or output slots.

Method Detail

insertAt

protected final void insertAt(int index)
Insert next slots before the specified index


insertAtEnd

protected final void insertAtEnd()
Add next slots at the end (default)


insertBefore

protected final void insertBefore(Slot s)
Insert next slots before the specified slot.


getIndex

protected final int getIndex(Slot s)

addIn

protected final In addIn(java.lang.String name,
                         int type)
Adds an inSlot to the device (obligatory=false).


addIn

protected final In addIn(java.lang.String name,
                         int type,
                         boolean obligatory)
Adds an inSlot to the device.


addOut

protected final Out addOut(java.lang.String name,
                           int type)
Adds an outSlot to the device.


close

public void close()
Add closing code here if needed.

Specified by:
close in interface Device

copy

public Device copy()
Is isCopiable() returns true, copies the device by calling DeviceUtilities.defaultCopy(). Returns null if isCopiable() returns false.

Subclass this method if you want to provide another strategy.

Specified by:
copy in interface Device

doDisable

public void doDisable()
Add device disabling code here (does nothing by default).


doEnable

public void doEnable()
Add device enabling code here (does nothing by default).


getError

public java.lang.String getError()
Subclass this method to return the current error message (FAILED state). By default, returns the last error set by setLastError() method.

Specified by:
getError in interface Device

getInfo

public DeviceInfo getInfo()
Returns null by default.

Specified by:
getInfo in interface Device

getIns

public final In[] getIns()
Description copied from interface: Device
Returns the device's input slots.

Specified by:
getIns in interface Device

getName

public final java.lang.String getName()
getName method comment.

Specified by:
getName in interface Device

getOuts

public final Out[] getOuts()
Description copied from interface: Device
Returns the device's output slots.

Specified by:
getOuts in interface Device

getProperties

public java.lang.String[] getProperties()
Returns Device.AUTO_PROPERTIES: to add properties to the device, you just have to add appropriate "type value getProp()" and "void setProp(type value)" accessor methods.

Subclass this method and declare all properties if you do not want some accessors to be visible as properties, or if you want them to appear in a given order in properties dialog box.

Specified by:
getProperties in interface Device

hasExternalInput

public boolean hasExternalInput()
Specifies whether this device has external (implicit) input or not. Returns false by default.

Return false if the device is deterministic from the data & time points of view, i.e. if its output production only depend on the explicit input history (input slots) and device's initial configuration. This is the case of most of the processing devices.

Return true if output values not only depend on the values of input slots, or if output production takes undefined time. Examples of devices with external input are input peripherals and asynchronous devices.

This method is used by the reactive machine to determine if this device is triggered by its input slots, or if it must be triggered continuously (i.e. each tick). This method can also be used by the editor for the device's graphical representation.

Specified by:
hasExternalInput in interface Device

hasExternalOutput

public boolean hasExternalOutput()
Specifies whether this device has external (implicit) output or not. Returns false by default.

Return false if the device has no border effects. Most of input and processing devices are in this case.

Return true if the device has border effects, such as graphical feedback, or control of some external value. Examples of devices with external output are application-interfacing devices and all user feedback devices.

This method can be used by the editor for the device's graphical representation. However there is at now no clear definition of what is external output.

Specified by:
hasExternalOutput in interface Device

init

public void init()
Initializes device's output values.

Subclass init() and update() methods if you want the device to process the data itself. Otherwise, subclass getProcessor() method to use extern processors. By default, this method calls update(). Subclass this method if you'd like to make a specific initialization routine.

Specified by:
init in interface Processor
See Also:
Processor.init()

isCopiable

public boolean isCopiable()
Returns true by default.

Subclass this method and return false if your device is a singleton.

Specified by:
isCopiable in interface Device

isEnabled

public final boolean isEnabled()

isOpenable

public boolean isOpenable()
Returns true if the device can be opened.

By default, returns true if all obligatory input slots are valid. Subclass this method to add more conditions.

Specified by:
isOpenable in interface Device

open

public Processor open(OpenContext context)
Subclass this method if you want to specialize data processing, or if you want to perform some initializations before running the device.

By default, open() does nothing and returns the device itself as the Processor (or null if it is not openable): AbstractDevice implements both Device and Processor interfaces, so that you can add processing code directly into the device.

If you want to add specialization features, subclass this method to return a specific processor implementation depending on your device configuration.

Example :

public Processor getProcessor() { if (super.open() == null) return null; // Select the right processor if (in2.isValid()) { return new twoParamProcessor(in1, in2, out); else return new oneParamProcessor(in1, out); }

In this method, you may also perform all necessary pre-running initialization. If initialization fails, return null even if isOpenable() returns true.

In all cases, return null if isOpenable() returns false.

Specified by:
open in interface Device
Returns:
a Processor if the device is openable and has been successfully open, null otherwise.

OPEN CONTEXT:

Some devices may need a context to open. For example, devices that display themselves on a swing window will need a JFrame as context. Context is handled by OpenContext class.

See Also:
Processor, Device.open()

setEnabled

public final void setEnabled(boolean enabled)
setEnabled method comment.

Specified by:
setEnabled in interface Device

setInfo

public void setInfo(DeviceInfo info)
Returns null by default.


setInfo

public void setInfo(java.lang.String description,
                    java.lang.String help)

setLastError

public final void setLastError(java.lang.String error)

setName

protected void setName(java.lang.String name)

update

public void update()
Updates device's output values.

Subclass init() and update() methods if you want the device to process the data itself. Otherwise, subclass getProcessor() method to use extern processors.

Specified by:
update in interface Processor
See Also:
Processor.update()

finalize

protected void finalize()