jaron.components
Class Signal

java.lang.Object
  extended by jaron.components.Signal
All Implemented Interfaces:
SignalListener, java.util.EventListener
Direct Known Subclasses:
Axis, RadioButton, Servo, TwoWaySwitch

public class Signal
extends java.lang.Object
implements SignalListener

The Signal class contains a single double value (signal) and implements an EventListener mechanism that allows its registered listeners to be informed if the signal's value has changes. By implementing the SignalListener interface it can also receive signal change events from other signals.

Since:
1.0
Version:
1.2
Author:
jarontec gmail com

Constructor Summary
Signal()
          Creates a Signal object that contains a single double value and implements the EventListener mechanism.
Signal(double value)
          Creates a Signal object that contains a single double value and implements the EventListener mechanism.
 
Method Summary
 void addSignalListener(SignalListener listener)
          Adds the listener to the EventListener mechanism.
 double getBandwidth()
          Returns the signal's bandwidth which is the high value minus the low value.
 double getHigh()
          Returns the high value of the signal's bandwidth.
 double getLow()
          Returns the low value of the signal's bandwidth.
 double getValue()
          Returns the current value of the signal.
 void removeSignalListener(SignalListener listener)
          Removes the listener from the EventListener mechanism.
 void setBandwidth(double low, double high)
          Sets the low and the high values of the signal.
 void setHigh(double value)
          Sets the high value of the signal's bandwidth.
 void setLow(double value)
          Sets the low value of the signal's bandwidth.
 void setValue(double value)
          Sets the signal's value.
 void signalChanged(SignalEvent event)
          Notifies the listener about a signal change event that occurred in the EventListener mechanism.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Signal

public Signal(double value)
Creates a Signal object that contains a single double value and implements the EventListener mechanism. By default the signal's low value is set to -1 and high value is 1.

Parameters:
value - a default value for the signal

Signal

public Signal()
Creates a Signal object that contains a single double value and implements the EventListener mechanism. By default the signal's value is 0, its low value is set to -1 and the high value is 1.

Method Detail

addSignalListener

public void addSignalListener(SignalListener listener)
Adds the listener to the EventListener mechanism. So whenever the value of the signal changes, the listener will be informed.

Parameters:
listener - the listener to be added

getBandwidth

public double getBandwidth()
Returns the signal's bandwidth which is the high value minus the low value. By default the bandwidth is 2.

Returns:
a double representing the signal's current bandwidth

getHigh

public double getHigh()
Returns the high value of the signal's bandwidth. By default this value is set to +1.

Returns:
the current high signal value

getLow

public double getLow()
Returns the low value of the signal's bandwidth. By default this value is set to -1.

Returns:
the current low signal value

getValue

public double getValue()
Returns the current value of the signal.

Returns:
the current signal value

setBandwidth

public void setBandwidth(double low,
                         double high)
Sets the low and the high values of the signal. This is equal to calling setLow and setHigh.

Parameters:
low - the low end of the bandwidth
high - the high end of the bandwidth

setHigh

public void setHigh(double value)
Sets the high value of the signal's bandwidth.

Parameters:
value - the signal's new high value

setLow

public void setLow(double value)
Sets the low value of the signal's bandwidth.

Parameters:
value - the signal's new low value

setValue

public void setValue(double value)
Description copied from interface: SignalListener
Sets the signal's value. This method is used by an event notifier that notifies all its listeners about a change of the signal value.
The method can also be used outside the EventListener mechanism to set the signal's value.

Specified by:
setValue in interface SignalListener
Parameters:
value - the notifier's signal value that has changed or just the new signal value

signalChanged

public void signalChanged(SignalEvent event)
Description copied from interface: SignalListener
Notifies the listener about a signal change event that occurred in the EventListener mechanism.

Specified by:
signalChanged in interface SignalListener
Parameters:
event - the event that occurred

removeSignalListener

public void removeSignalListener(SignalListener listener)
Removes the listener from the EventListener mechanism. So in the future the listener won't get informed about signal value changes anymore.

Parameters:
listener - the listener to be removed