public class TLcdSimulator extends Object
TLcdSimulator
is the class that is responsible for the timing of the simulation:
it produces the correct simulation time at each simulation step. Associated with a
TLcdSimulator
are:
The simulator model
is responsible for providing the
TLcdSimulator
with the ILcdModel
objects holding the domain data to be simulated,
and for putting these data in the state corresponding to a given simulation time.
The layer factories are used by the TLcdSimulator to create layers for the views, for each of the different simulation models.
TLcdSimulator
can be used in two different modes:
time-steps
as fast as it can.You can choose between the two modes with the setUseTimeStep(boolean)
method.
Modifier and Type | Field and Description |
---|---|
static int |
ENDED
The Status when ended.
|
static int |
PAUSING
The Status when pausing.
|
static int |
RUNNING
The Status when running.
|
static int |
STOPPED
The Status when stopped.
|
Constructor and Description |
---|
TLcdSimulator()
Creates a new
TLcdSimulator |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener l)
Register a listener for the PropertyChange event.
|
void |
addView(ILcdView aView)
Adds the given view as one of the views of this simulator and properly initializes it with the
necessary simulation layers.
|
protected long |
currentTime()
Returns the difference in milliseconds between some fixed but arbitrary time, and the
current wall-clock time.
|
Date |
getBeginDate()
Return the begin date of the simulation.
|
Date |
getDate()
Return the current date of the simulation.
|
int |
getDelayBetweenUpdateMs()
Returns the minimal delay between updates in milliseconds.
|
Date |
getEndDate()
Return the end date of the simulation.
|
ILcdGXYLayerFactory |
getGXYLayerFactory()
Return the
ILcdGXYLayerFactory to create the simulation layer(s) for the GXY
views. |
ILcdGXYView[] |
getGXYView()
Returns an array of
ILcdGXYView on which the simulation is shown. |
Collection<ILcdLayer> |
getLayers()
Returns a collection of all the
ILcdLayer used in this simulator. |
ILspLayerFactory |
getLspLayerFactory()
Return the
ILspLayerFactory to create the simulation layer(s) for a Lightspeed
view. |
ILspView[] |
getLspView()
Returns an array of
ILspView on which the simulation is shown. |
int |
getMaxCPUUsage()
Returns the maximum percentage of CPU to be used by the simulation.
|
ILcdGXYLayer[][] |
getSimulationGXYLayers()
Returns a two-dimensional array of
ILcdGXYLayer . |
ILspLayer[][] |
getSimulationLspLayers()
Returns a two-dimensional array of
ILspLayer . |
ILcdSimulatorModel |
getSimulatorModel()
Return the
ILcdSimulatorModel that is simulated by this simulator. |
int |
getStatus()
Returns the status of the simulator.
|
String |
getStatusAsString()
Return the status of the simulator as a String.
|
double |
getTimeFactor()
Returns the time factor, this is the factor by which simulation is accelerated with respect to
real time.
|
long |
getTimeStep()
Returns the time step in milliseconds.
|
int |
getUpdatesPerSecond()
Returns the current update rate.
|
boolean |
isManageNumberOfCachedBackgroundLayers()
Determines whether the simulator manages the number of cached background layers of the views to
which it is linked.
|
boolean |
isPauseOnMousePressed()
Returns whether the simulation is suspended while the mouse is pressed.
|
boolean |
isPlayInLoop()
Returns whether this simulator plays the simulation in a loop.
|
boolean |
isTimerTraceOn()
Returns true if time tracing is active, false otherwise.
|
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the standard Java logging
framework directly.
|
boolean |
isUseSameGXYLayer()
Returns whether the same simulation layer can be used in different GXY views, or each GXY view
has to have its own layer.
|
boolean |
isUseTimeStep()
Returns true if using time steps, false otherwise.
|
void |
pause()
Pause the simulator
|
void |
removePropertyChangeListener(PropertyChangeListener l)
Remove a listener for the PropertyChange event.
|
void |
removeView(ILcdView aView)
Removes the given view from this simulator's views
|
void |
run()
Start the simulator
|
void |
setDate(Date newDate)
Sets the date associated with this simulator to the given date
|
void |
setDelayBetweenUpdateMs(int aDelayBetweenUpdateMs)
Set the minimal delay in milliseconds between two simulation updates.
|
void |
setGXYLayerFactory(ILcdGXYLayerFactory aGXYLayerFactory)
Set the
ILcdGXYLayerFactory to create the simulation layer(s) for the GXY views. |
void |
setGXYView(ILcdGXYView[] aGXYView)
Set an array of
ILcdGXYView on which the simulation is shown. |
void |
setLspLayerFactory(ILspLayerFactory aLayerFactory)
Set the
ILspLayerFactory to create the simulation layer(s) for a Lightspeed view. |
void |
setLspView(ILspView[] aLspView)
Set an array of
ILspView on which the simulation is shown. |
void |
setManageNumberOfCachedBackgroundLayers(boolean aManageNumberOfCachedBackgroundLayers)
Enables or disables number of cached background layer management.
|
void |
setMaxCPUUsage(int aMaxCPUUsage)
Set the maximum percentage of CPU to be used by the simulation.
|
void |
setPauseOnMousePressed(boolean aPauseOnMousePressed)
Set whether to suspend the simulation when the mouse is pressed on one of the simulation
views.
|
void |
setPlayInLoop(boolean aPlayInLoop)
Sets whether this simulator should play the simulation in a loop.
|
void |
setSimulatorModel(ILcdSimulatorModel aSimulatorModel)
Set the
ILcdSimulatorModel to be simulated by this
simulator. |
void |
setTimeFactor(double aTimeFactor)
Sets the time factor, this is the factor by which simulation is accelerated with respect to real
time.
|
void |
setTimerTraceOn(boolean aTimerTraceOn)
Set time tracing to aTimerTraceOn.
|
void |
setTimeStep(long aTimeStep)
Sets the time step to use expressed in milliseconds.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the standard Java logging
framework directly.
|
void |
setUseSameGXYLayer(boolean aUseSameGXYLayer)
Set whether the same simulation layer can be used in different GXY views, or each GXY view has
to have its own layer.
|
void |
setUseTimeStep(boolean aUseTimeStep)
Set whether to use a time-step simulation.
|
void |
stop()
Stop the simulator.
|
public static final int STOPPED
public static final int RUNNING
public static final int PAUSING
public static final int ENDED
public void addView(ILcdView aView)
Adds the given view as one of the views of this simulator and properly initializes it with the necessary simulation layers.
Currently only instances of ILcdGXYView
and ILspView
are accepted.
Other implementations are ignored.
aView
- the view to be added to the views of this simulatorpublic void removeView(ILcdView aView)
aView
- the view that needs to be removed from this simulator's viewspublic ILcdSimulatorModel getSimulatorModel()
ILcdSimulatorModel
that is simulated by this simulator.ILcdSimulatorModel
that is simulated by this simulator.setSimulatorModel(ILcdSimulatorModel)
public void setSimulatorModel(ILcdSimulatorModel aSimulatorModel)
ILcdSimulatorModel
to be simulated by this
simulator. The date information associated with the simulator is replaced
with the date information associated with the simulator model. The
simulator's date and the simulation's begin date and end date are set to
the date, begin date, and end date of the simulator model.aSimulatorModel
- The ILcdSimulatorModel
to be simulated by this
simulator.getSimulatorModel()
public int getStatus()
public String getStatusAsString()
getStatus()
public int getMaxCPUUsage()
setMaxCPUUsage(int)
public void setMaxCPUUsage(int aMaxCPUUsage)
aMaxCPUUsage
- A value between 1 and 100.getMaxCPUUsage()
public boolean isPauseOnMousePressed()
setPauseOnMousePressed(boolean)
public void setPauseOnMousePressed(boolean aPauseOnMousePressed)
Set whether to suspend the simulation when the mouse is pressed on one of the simulation views.
When the mouse is released, the simulation will continue as if the simulation had not been paused: the simulation time will jump to catch up the time lost between the press and release of the mouse.
By default, this feature is enabled.
Note: This feature does not work with Lightspeed views
aPauseOnMousePressed
- When true, the simulation will be suspended while the mouse is
being pressed.isPauseOnMousePressed()
public double getTimeFactor()
setTimeFactor(double)
public void setTimeFactor(double aTimeFactor)
aTimeFactor
- The time factor to be set.getTimeFactor()
public boolean isPlayInLoop()
public void setPlayInLoop(boolean aPlayInLoop)
aPlayInLoop
- whether the simulator should play the simulation in a loop.public boolean isTimerTraceOn()
setTimerTraceOn(boolean)
public void setTimerTraceOn(boolean aTimerTraceOn)
Set time tracing to aTimerTraceOn. When timer tracing is turned on, all timer related log messages are recorded.
To see the log output, you also have to enable tracing for this class. You can do that for example by using a logging configuration file. If you're using the default Java logging this code snippet can be used as well:
simulator.setTimerTraceOn( true );
Logger logger = Logger.getLogger( TLcdSimulator.class.getName() );
logger.setLevel( Level.ALL );
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel( Level.ALL );
logger.addHandler( handler );
This property is meant for debugging purposes. As such, no property change events are fired when it changes.
aTimerTraceOn
- The value to be set for time tracing.isTimerTraceOn()
public int getUpdatesPerSecond()
public int getDelayBetweenUpdateMs()
setDelayBetweenUpdateMs(int)
public void setDelayBetweenUpdateMs(int aDelayBetweenUpdateMs)
MaxCPUUsage
. This property can be used to limit the
maximum frame rate. If this property is for example set to 50 milliseconds, the theoretical
maximum frame rate is 1000/50 = 20. In practice it will be somewhat lower because refreshing
the view takes some time as well.aDelayBetweenUpdateMs
- The delay in milliseconds between two simulation updates.getDelayBetweenUpdateMs()
public boolean isUseTimeStep()
setUseTimeStep(boolean)
,
getTimeStep()
public void setUseTimeStep(boolean aUseTimeStep)
getTimeStep()
) returns a value > 0), the simulator will not perform a
simulation that has a relation with the real elapsed time. Instead it will give an animation at
successive time step as fast as it can. By default, this feature is disabledaUseTimeStep
- The value to be set for time-stepping.isUseTimeStep()
,
setTimeStep(long)
public long getTimeStep()
setTimeStep(long)
public void setTimeStep(long aTimeStep)
Sets the time step to use expressed in milliseconds. The default time step is 0.
This property is only relevant when this simulator works in
time-step
mode.
aTimeStep
- The time step in milliseconds.getTimeStep()
,
setUseTimeStep(boolean)
public void addPropertyChangeListener(PropertyChangeListener l)
l
- The listener to register.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener l)
l
- The listener to remove.addPropertyChangeListener(PropertyChangeListener)
protected long currentTime()
Returns the difference in milliseconds between some fixed but arbitrary time, and the
current wall-clock time. For example System.nanoTime()/1e6
can be used.
Overriding this method can be useful to synchronize the simulator with an external clock, for example from an audio or a video stream.
public Date getDate()
setDate(java.util.Date)
public void setDate(Date newDate)
newDate
- the new date for this simulatorpublic Date getBeginDate()
public Date getEndDate()
public void run()
public void stop()
public void pause()
public ILcdGXYView[] getGXYView()
ILcdGXYView
on which the simulation is shown.ILcdGXYView
on which the simulation is shown.setGXYView(ILcdGXYView[])
public void setGXYView(ILcdGXYView[] aGXYView)
ILcdGXYView
on which the simulation is shown.aGXYView
- An array of ILcdGXYView
on which the simulation is shown.getGXYView()
public ILspView[] getLspView()
ILspView
on which the simulation is shown.ILspView
on which the simulation is shown.public void setLspView(ILspView[] aLspView)
ILspView
on which the simulation is shown.aLspView
- An array of ILspView
on which the simulation is shown.getLspView()
public ILcdGXYLayerFactory getGXYLayerFactory()
ILcdGXYLayerFactory
to create the simulation layer(s) for the GXY
views.ILcdGXYLayerFactory
to create the simulation layer(s) for the GXY
views.setGXYLayerFactory(com.luciad.view.gxy.ILcdGXYLayerFactory)
public void setGXYLayerFactory(ILcdGXYLayerFactory aGXYLayerFactory)
ILcdGXYLayerFactory
to create the simulation layer(s) for the GXY views.aGXYLayerFactory
- The ILcdGXYLayerFactory
to create the simulation layer(s)
for the GXY views.getGXYLayerFactory()
public ILspLayerFactory getLspLayerFactory()
ILspLayerFactory
to create the simulation layer(s) for a Lightspeed
view.ILspLayerFactory
to create the simulation layer(s) for a Lightspeed
view.setLspLayerFactory(com.luciad.view.lightspeed.layer.ILspLayerFactory)
public void setLspLayerFactory(ILspLayerFactory aLayerFactory)
ILspLayerFactory
to create the simulation layer(s) for a Lightspeed view.aLayerFactory
- The ILspLayerFactory
to create the simulation layer(s) for a
Lightspeed view.getLspLayerFactory()
public Collection<ILcdLayer> getLayers()
ILcdLayer
used in this simulator.
The returned collection can not be modified.ILcdLayer
used in this simulator. The
returned collection can not be modified.public ILcdGXYLayer[][] getSimulationGXYLayers()
ILcdGXYLayer
. The first dimension corresponds
to the different ILcdGXYView
of this simulator. The second dimension corresponds
to the different simulation layers per view.
The simulation layers are automatically generated when an ILcdSimulatorModel
along
with one or multiple views is set to this simulator.
Each view should have the same number of layers, one for each track model that is contained in
the ILcdSimulatorModel
and should have the same order as the track models array
that can be obtained by calling ILcdSimulatorModel#getTrackModels()
.
Based on whether this simulator is configured to share layers between views (see
#setUseSameGXYLayer
) a layer for a specific track model will be shared across
multiple GXY views.ILcdGXYLayer
. The first dimension corresponds
to the different ILcdGXYView
of this simulator. The second dimension
corresponds to the different simulation layers per view.public ILspLayer[][] getSimulationLspLayers()
ILspLayer
. The first dimension corresponds
to the different ILspView
of this simulator. The second dimension corresponds
to the different simulation layers per view.
The simulation layers are automatically generated when an ILcdSimulatorModel
along
with one or multiple views is set to this simulator.
Each view should have the same number of layers, one for each track model that is contained in
the ILcdSimulatorModel
and should have the same order as the track models array
that can be obtained by calling ILcdSimulatorModel#getTrackModels()
.ILspLayer
. The first dimension corresponds
to the different ILspView
of this simulator. The second dimension
corresponds to the different simulation layers per view.public void setUseSameGXYLayer(boolean aUseSameGXYLayer)
aUseSameGXYLayer
- If true a single layer is shared among all GXY simulation views,
if false a separate simulation layer is created for each
GXY simulation view.isUseSameGXYLayer()
public boolean isUseSameGXYLayer()
setUseSameGXYLayer(boolean)
public boolean isManageNumberOfCachedBackgroundLayers()
setManageNumberOfCachedBackgroundLayers(boolean)
,
ILcdGXYView.setNumberOfCachedBackgroundLayers(int)
public void setManageNumberOfCachedBackgroundLayers(boolean aManageNumberOfCachedBackgroundLayers)
aManageNumberOfCachedBackgroundLayers
- true to enable background layer management; false to disable itisManageNumberOfCachedBackgroundLayers()
public boolean isTraceOn()
true
if tracing is enabled for this class.public void setTraceOn(boolean aTraceOn)
true
or
false
as argument automatically turns off tracing for all other class instances
for which setTraceOn
has not been called. If the argument is false
then only the informative, warning and error log messages are recorded.aTraceOn
- if true then all log messages are recorded for this instance. If false, then
only the informative, warning and error log messages are recorded.