lejos.robotics.objectdetection
Class FeatureDetectorAdapter

java.lang.Object
  extended by lejos.robotics.objectdetection.FeatureDetectorAdapter
All Implemented Interfaces:
FeatureDetector
Direct Known Subclasses:
RangeFeatureDetector, TouchFeatureDetector

public abstract class FeatureDetectorAdapter
extends java.lang.Object
implements FeatureDetector

An adapter to make it easier to implement FeatureDetector classes. The scan() method is the only method which must be implemented by the actual class.

Author:
BB

Constructor Summary
FeatureDetectorAdapter(int delay)
           
 
Method Summary
 void addListener(FeatureListener l)
          Adds a listener to the FeatureDetector.
 void enableDetection(boolean enable)
          Enable or disable detection of objects.
 int getDelay()
          The minimum delay between notification of readings from the feature detector.
 boolean isEnabled()
          Indicates if automatic scanning mode and listener notification is currently enabled.
protected  void notifyListeners(Feature feature)
           
abstract  Feature scan()
          Performs a single scan for an object and returns the results.
 void setDelay(int delay)
          Sets the minimum delay between readings from the feature detector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FeatureDetectorAdapter

public FeatureDetectorAdapter(int delay)
Method Detail

addListener

public void addListener(FeatureListener l)
Description copied from interface: FeatureDetector
Adds a listener to the FeatureDetector. The FeatureListener will be notified when objects are detected.

Specified by:
addListener in interface FeatureDetector
Parameters:
l - The FeatureListener that is notified every time a feature is detected.

enableDetection

public void enableDetection(boolean enable)
Description copied from interface: FeatureDetector
Enable or disable detection of objects.

Specified by:
enableDetection in interface FeatureDetector
Parameters:
enable - true enables detection and notifications, false disables this class until it is enabled again.

isEnabled

public boolean isEnabled()
Description copied from interface: FeatureDetector
Indicates if automatic scanning mode and listener notification is currently enabled. (true by default)

Specified by:
isEnabled in interface FeatureDetector
Returns:
true if enabled, false if not

getDelay

public int getDelay()
Description copied from interface: FeatureDetector
The minimum delay between notification of readings from the feature detector. If no objects are detected, no notification will occur. Some sensors, such as touch sensors, check the sensor more frequently than other sensors, such as range sensors.

Specified by:
getDelay in interface FeatureDetector
Returns:
The delay between sensor readings.

setDelay

public void setDelay(int delay)
Description copied from interface: FeatureDetector
Sets the minimum delay between readings from the feature detector. The notification thread will notify FeatureListener objects every delay milliseconds, unless it takes longer to retrieve readings from the sensor.

Specified by:
setDelay in interface FeatureDetector
Parameters:
delay - The FeatureDetector will return one new set of readings every delay milliseconds.

notifyListeners

protected void notifyListeners(Feature feature)

scan

public abstract Feature scan()
Description copied from interface: FeatureDetector

Performs a single scan for an object and returns the results. If an object is not detected, this method returns null.

Warning: Make sure to check for a null object before trying to read data from the returned Feature object, otherwise your code will throw a null pointer exception.

Specified by:
scan in interface FeatureDetector
Returns:
A feature it has detected. null if nothing found.