simtools.data
Class DataSourceAnimator

java.lang.Object
  extended by simtools.data.ValueProvider
      extended by simtools.data.DataSource
          extended by simtools.data.DynamicDataSource
              extended by simtools.data.DataSourceAnimator
All Implemented Interfaces:
DataSourceListener
Direct Known Subclasses:
DataSourceAnimator

public class DataSourceAnimator
extends DynamicDataSource
implements DataSourceListener

This class adds dynamical features to a DataSource. This is useful to replay time series, for example. It will use the underlying source to provide the values, and has its own API to control how to advance the index : step by step, or with a timer. Note: All APIs from superclasses are redirected. So, this wrapper should really be transparent.

Author:
Nicolas Brodu

Field Summary
protected  boolean autoStop
           
protected  boolean finished
           
static java.lang.String MARKER
           
protected  long period
           
protected  DataSource target
           
protected  java.util.Timer timer
           
 
Fields inherited from class simtools.data.DynamicDataSource
autoRegister, cachedByte, cachedDouble, cachedFloat, cachedInteger, cachedLong, cachedObject, cachedShort, currentByte, currentDouble, currentFloat, currentInteger, currentLong, currentObject, currentShort, hasValue, info, kind, lastIndex, maxByte, maxDouble, maxFloat, maxInteger, maxLong, maxObject, maxShort, minByte, minDouble, minFloat, minInteger, minLong, minObject, minShort
 
Fields inherited from class simtools.data.DataSource
endNotificationListeners, listeners, sortedOrder
 
Fields inherited from class simtools.data.ValueProvider
ByteProvider, DoubleProvider, FloatProvider, IntegerProvider, LongProvider, ObjectProvider, ShortProvider
 
Constructor Summary
DataSourceAnimator(DataSource ds)
           
DataSourceAnimator(DataSource ds, int delay)
           
DataSourceAnimator(DataSource ds, int delay, long period)
           
 
Method Summary
 void DataSourceIndexRangeChanged(DataSource ds, long startIndex, long lastIndex)
          Called when the range of valid index changed
 void DataSourceInfoChanged(DataSource ds, DataInfo newInfo)
          Called when the information about the data source changed
 void DataSourceOrderChanged(DataSource ds, int newOrder)
          If defined, called when the order of the source changed.
 void DataSourceReplaced(DataSource oldData, DataSource newData)
          Called when a data source is replaced by another one
 void DataSourceValueChanged(DataSource ds, long minIndex, long maxIndex)
          Called when at least a value changed in the data source.
 void DataSourceValueRangeChanged(DataSource ds)
          Called when the range of possible values changed, if defined.
 long getPeriod()
           
 boolean isAutoStop()
           
 boolean isFinished()
           
 boolean isRunning()
           
 void reset()
          Resets the source.
 void setAutoStop(boolean autoStop)
           
 void setPeriod(long period)
          Sets a period for cyclic execution
 int sortedOrder()
          Check if the values are sorted or not.
 void start()
          Starts to update the values with the previously set period.
 void start(long period)
          Starts to update the values with the given period.
 void step()
          Increase current index
 void stop()
          Stop to update the values.
 java.lang.Class valueClass()
          Returns the more specialized superclass of all objects returned by this provider.
 
Methods inherited from class simtools.data.DynamicDataSource
bufferize, changeInfo, computeLastIndex, computeMinMax, computeStartIndex, getByteMax, getByteMin, getDoubleMax, getDoubleMin, getFloatMax, getFloatMin, getInformation, getIntegerMax, getIntegerMin, getKind, getLastIndex, getLongMax, getLongMin, getMax, getMin, getShortMax, getShortMin, getStartIndex, getValue, isAutoRegister, isComparable, registerNewValue, setAutoRegister, setByteValue, setDoubleValue, setFloatValue, setIntegerValue, setLongValue, setObjectValue, setShortValue
 
Methods inherited from class simtools.data.DataSource
addEndNotificationListener, addListener, computeMax, computeMin, computeSortedOrder, createEmptyDataSource, equals, getAuxiliarySources, getChoiceFormat, getDataSourceInformationClass, getSortedOrder, getSourceDependencies, isAuxiliary, isComparable, isCompound, notifyEndNotificationListeners, notifyListenersForDataReplaced, notifyListenersForDataReplaced, notifyListenersForIndexRangeChange, notifyListenersForInfoChange, notifyListenersForOrderChange, notifyListenersForValueChange, notifyListenersForValueRangeChange, removeEndNotificationListener, removeListener, setSlice, updateSortedOrder
 
Methods inherited from class simtools.data.ValueProvider
getByteValue, getDoubleValue, getFloatValue, getIntegerValue, getLongValue, getObjectValue, getShortValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MARKER

public static final java.lang.String MARKER
See Also:
Constant Field Values

target

protected DataSource target

period

protected long period

timer

protected java.util.Timer timer

finished

protected boolean finished

autoStop

protected boolean autoStop
Constructor Detail

DataSourceAnimator

public DataSourceAnimator(DataSource ds)

DataSourceAnimator

public DataSourceAnimator(DataSource ds,
                          int delay)

DataSourceAnimator

public DataSourceAnimator(DataSource ds,
                          int delay,
                          long period)
Method Detail

isFinished

public boolean isFinished()
Returns:
true iff the underlying data source has no more values

step

public void step()
          throws DataException
Increase current index

Throws:
DataException

getPeriod

public long getPeriod()
Returns:
The current period, in milliseconds

setPeriod

public void setPeriod(long period)
Sets a period for cyclic execution

Parameters:
period, - in milliseconds

isRunning

public boolean isRunning()
Returns:
true is the values are beeing updated cyclically.

start

public void start(long period)
Starts to update the values with the given period.


start

public void start()
Starts to update the values with the previously set period. Default is 1 second.


stop

public void stop()
Stop to update the values. This method is automatically called when there is no more data in the underlying data source, if this option is chosen.


reset

public void reset()
Resets the source. Next call to step will show the first source element.


isAutoStop

public boolean isAutoStop()
Returns:
Returns the autoStop.

setAutoStop

public void setAutoStop(boolean autoStop)
Parameters:
autoStop - The autoStop to set.

DataSourceValueChanged

public void DataSourceValueChanged(DataSource ds,
                                   long minIndex,
                                   long maxIndex)
Description copied from interface: DataSourceListener
Called when at least a value changed in the data source. The listener shall then get the values in the given range again, if it is interested by the values in that range.

Specified by:
DataSourceValueChanged in interface DataSourceListener
Parameters:
ds - The data source that changed
minIndex - Lower bound of the range where values changed
maxIndex - Higher bound of the range where values changed

DataSourceIndexRangeChanged

public void DataSourceIndexRangeChanged(DataSource ds,
                                        long startIndex,
                                        long lastIndex)
Description copied from interface: DataSourceListener
Called when the range of valid index changed

Specified by:
DataSourceIndexRangeChanged in interface DataSourceListener
Parameters:
ds - The data source that changed
startIndex - The new start Index
lastIndex - The new last index

DataSourceInfoChanged

public void DataSourceInfoChanged(DataSource ds,
                                  DataInfo newInfo)
Description copied from interface: DataSourceListener
Called when the information about the data source changed

Specified by:
DataSourceInfoChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceValueRangeChanged

public void DataSourceValueRangeChanged(DataSource ds)
Description copied from interface: DataSourceListener
Called when the range of possible values changed, if defined.

Specified by:
DataSourceValueRangeChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceOrderChanged

public void DataSourceOrderChanged(DataSource ds,
                                   int newOrder)
Description copied from interface: DataSourceListener
If defined, called when the order of the source changed. See the sortedOrder() in the Datasource class for more information.

Specified by:
DataSourceOrderChanged in interface DataSourceListener
Parameters:
ds - The data source that changed

DataSourceReplaced

public void DataSourceReplaced(DataSource oldData,
                               DataSource newData)
Description copied from interface: DataSourceListener
Called when a data source is replaced by another one

Specified by:
DataSourceReplaced in interface DataSourceListener

sortedOrder

public int sortedOrder()
Description copied from class: DataSource
Check if the values are sorted or not. This is usefull to optimize some computations (curves drawing for instance)

Overrides:
sortedOrder in class DataSource
Returns:
0 if the values are not sorted, 1 if the values are sorted in ascending order and -1 if the values are sorted in descending order

valueClass

public java.lang.Class valueClass()
Description copied from class: ValueProvider
Returns the more specialized superclass of all objects returned by this provider. Returns Object by default in the base implementation, subclass should specialize if possible.

Overrides:
valueClass in class DynamicDataSource