|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fr.emn.reactiveinput.AbstractDevice
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 |
protected java.util.Vector ins
protected java.util.Vector outs
protected int currIndex
Constructor Detail |
public AbstractDevice(java.lang.String name)
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 |
protected final void insertAt(int index)
protected final void insertAtEnd()
protected final void insertBefore(Slot s)
protected final int getIndex(Slot s)
protected final In addIn(java.lang.String name, int type)
protected final In addIn(java.lang.String name, int type, boolean obligatory)
protected final Out addOut(java.lang.String name, int type)
public void close()
close
in interface Device
public Device copy()
Subclass this method if you want to provide another strategy.
copy
in interface Device
public void doDisable()
public void doEnable()
public java.lang.String getError()
getError
in interface Device
public DeviceInfo getInfo()
getInfo
in interface Device
public final In[] getIns()
Device
getIns
in interface Device
public final java.lang.String getName()
getName
in interface Device
public final Out[] getOuts()
Device
getOuts
in interface Device
public java.lang.String[] getProperties()
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.
getProperties
in interface Device
public boolean hasExternalInput()
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.
hasExternalInput
in interface Device
public boolean hasExternalOutput()
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.
hasExternalOutput
in interface Device
public void init()
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.
init
in interface Processor
Processor.init()
public boolean isCopiable()
Subclass this method and return false if your device is a singleton.
isCopiable
in interface Device
public final boolean isEnabled()
public boolean isOpenable()
By default, returns true if all obligatory input slots are valid. Subclass this method to add more conditions.
isOpenable
in interface Device
public Processor open(OpenContext context)
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.
open
in interface Device
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.
Processor
,
Device.open()
public final void setEnabled(boolean enabled)
setEnabled
in interface Device
public void setInfo(DeviceInfo info)
public void setInfo(java.lang.String description, java.lang.String help)
public final void setLastError(java.lang.String error)
protected void setName(java.lang.String name)
public void update()
Subclass init() and update() methods if you want the device to process the data itself. Otherwise, subclass getProcessor() method to use extern processors.
update
in interface Processor
Processor.update()
protected void finalize()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |