de.jaetzold.art.platform
Class BaseSensorPeer

java.lang.Object
  |
  +--de.jaetzold.art.platform.BaseSensorPeer
All Implemented Interfaces:
SensorPeer
Direct Known Subclasses:
AWTRobotInterface.TextFieldSensorPeer, ForwardingSensorPeer, Mindstorms.RCXRawSensorPeer

public abstract class BaseSensorPeer
extends Object
implements SensorPeer

Base class for easier implementation of the interface SensorPeer. The only thing really required is to implement the method getValue(). Maybe the properties connected, precision and deliversFloatingPoint need an implementation too to produce correct results.

For a more efficient update()-method it is advisable to assign a de.jaetzold.Queue to eventQueue. This queue then may hold instances of SensorEvents and must be emptied regularly by some thread which passes the events in the queue to the method processEvent(SensorEvent).

For a more efficient handling of Events it is advisable to implement enable/disableEvent(SensorEventDescriptor).


Field Summary
protected  PropertyChangeSupport changes
           
protected  Queue eventQueue
          If this is non-null events generated by update() are posted there.
 
Constructor Summary
BaseSensorPeer()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          The SensorEvents get deliverd to all registered PropertyChangeListeners.
 void disableEvent(SensorEventDescriptor eventDescriptor)
          Disable delivering the Events described by the given SensorEventDescriptor.
 void enableEvent(SensorEventDescriptor eventDescriptor)
          Enable delivering the Events described by the given SensorEventDescriptor.
 boolean getDeliversFloatingPoint()
          Returns true.
 int getIntValue()
          Calls (int)getValue().
 double getPrecision()
          Returns 0.
 boolean isConnected()
          Returns true.
 void processEvent(SensorEvent event)
          Deliver the given SensorEvent to all Listeners.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove the specified listener.
 void update()
          Generate and deliver a SensorEvent for the current sensors state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jaetzold.art.platform.SensorPeer
getValue
 

Field Detail

changes

protected PropertyChangeSupport changes

eventQueue

protected Queue eventQueue
If this is non-null events generated by update() are posted there. Otherwise they get delivered by some Thread controlled by the implementation of update().
Constructor Detail

BaseSensorPeer

public BaseSensorPeer()
Method Detail

getIntValue

public int getIntValue()
Calls (int)getValue().
See Also:
SensorPeer.getValue()

isConnected

public boolean isConnected()
Returns true.
Specified by:
isConnected in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
RobotInterface.isConnected()

getDeliversFloatingPoint

public boolean getDeliversFloatingPoint()
Returns true.
Specified by:
getDeliversFloatingPoint in interface SensorPeer

getPrecision

public double getPrecision()
Returns 0.
Specified by:
getPrecision in interface SensorPeer

enableEvent

public void enableEvent(SensorEventDescriptor eventDescriptor)
Description copied from interface: SensorPeer
Enable delivering the Events described by the given SensorEventDescriptor. Not fully used. Implementors may enable more than the descibed Events an this is pretty much "all" in the current implementations.
Specified by:
enableEvent in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
SensorEventDescriptor

disableEvent

public void disableEvent(SensorEventDescriptor eventDescriptor)
Description copied from interface: SensorPeer
Disable delivering the Events described by the given SensorEventDescriptor. Not fully used. Implementors may disable less than the descibed Events an this is pretty much "none" in the current implementations.
Specified by:
disableEvent in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
SensorEventDescriptor

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Description copied from interface: SensorPeer
The SensorEvents get deliverd to all registered PropertyChangeListeners. The PropertyChangeEvent has the SensorEvent as it's new value and the last SensorEvent as the old value. The property name used for this is value. This mechanism in the SensorPeer is not really used for anything else right now but may be in future releases.
Specified by:
addPropertyChangeListener in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
Sensor.addPropertyChangeListener(PropertyChangeListener), SensorPeer.processEvent(SensorEvent)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Description copied from interface: SensorPeer
Remove the specified listener.
Specified by:
removePropertyChangeListener in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
SensorPeer.addPropertyChangeListener(PropertyChangeListener)

update

public void update()
Description copied from interface: SensorPeer
Generate and deliver a SensorEvent for the current sensors state.
Specified by:
update in interface SensorPeer

processEvent

public void processEvent(SensorEvent event)
Description copied from interface: SensorPeer
Deliver the given SensorEvent to all Listeners. Maybe update internal cache of the value.
Specified by:
processEvent in interface SensorPeer
Following copied from interface: de.jaetzold.art.platform.SensorPeer
See Also:
SensorPeer.addPropertyChangeListener(PropertyChangeListener)