Class AbstractProbeImageSwingJPanel
- java.lang.Object
-
- fr.univ_artois.lgi2a.similar.microkernel.libs.probes.AbstractProbeImageSwingJPanel
-
- All Implemented Interfaces:
IProbe
public abstract class AbstractProbeImageSwingJPanel extends Object implements IProbe
Models a probe where the simulation data are displayed into an image printed in a SwingJPanel
object.- Author:
- Yoann Kubera, Gildas Morvan
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractProbeImageSwingJPanel.MainJPanel
The panel where the simulation is being displayed.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractProbeImageSwingJPanel()
Builds a swing displayer using a transparent background in the drawing area.protected
AbstractProbeImageSwingJPanel(Color backgroundColor)
Builds a swing displayer using a custom background in the drawing area.protected
AbstractProbeImageSwingJPanel(Color backgroundColor, boolean displayOptimization)
Builds a swing displayer using a custom background in the drawing area.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Dimension
computeSimulationImageDimensions(IPublicDynamicStateMap dynamicState, SimulationTimeStamp initialTime)
Computes the dimensions of the image that will display the simulation.void
endObservation()
Ends the observation of a simulation.protected BufferedImage[]
getDoubleBuffer()
JPanel
getSwingView()
Gets the swing panel where the simulation is displayed.void
observeAtFinalTime(SimulationTimeStamp lastTime, ISimulationEngine engine)
Observes the state of the simulation when the final time stamp of the simulation is reached.void
observeAtInitialTimes(SimulationTimeStamp initialTimestamp, ISimulationEngine simulationEngine)
Observes the state of the simulation when the initial time stamp is reached.void
observeAtPartialConsistentTime(SimulationTimeStamp time, ISimulationEngine engine)
Observes the state of the simulation when at least one level is in a consistent state.void
prepareObservation()
Prepares the observation of a simulation.void
reactToAbortion(SimulationTimeStamp time, ISimulationEngine engine)
Reacts to the abortion of a currently running simulation.void
reactToError(String time, Throwable cause)
Reacts to an error thrown by the simulation engine.protected void
swapDoubleBufferAndDisplayImage(SimulationTimeStamp currentTime, IPublicDynamicStateMap dynamicState)
Refreshes the not displayed image of the double buffer with the simulation data defined as arguments of this method, and then performs a double buffer swap to display its content on screen.protected abstract void
updateGraphics(IPublicDynamicStateMap dynamicState, SimulationTimeStamp currentTime, Graphics2D graphics, int imgWidth, int imgHeight)
Updates the contents of a graphics object with the contents of the levels of the simulation.
-
-
-
Constructor Detail
-
AbstractProbeImageSwingJPanel
protected AbstractProbeImageSwingJPanel()
Builds a swing displayer using a transparent background in the drawing area.
-
AbstractProbeImageSwingJPanel
protected AbstractProbeImageSwingJPanel(Color backgroundColor)
Builds a swing displayer using a custom background in the drawing area.- Parameters:
backgroundColor
- A background color used when the drawing area is not filled.null
means that the background remains transparent.
-
AbstractProbeImageSwingJPanel
protected AbstractProbeImageSwingJPanel(Color backgroundColor, boolean displayOptimization)
Builds a swing displayer using a custom background in the drawing area.- Parameters:
backgroundColor
- A background color used when the drawing area is not filled.null
means that the background remains transparent.displayOptimization
- Flag telling if the display of the simulation has to be optimized or not. Iftrue
, then some half-consistent states will be ignored to prevent going over 32 milliseconds between two images updates. Indeed, paradoxically, doing so reduces the overall performances of the display.
-
-
Method Detail
-
getDoubleBuffer
protected BufferedImage[] getDoubleBuffer()
-
getSwingView
public JPanel getSwingView()
Gets the swing panel where the simulation is displayed.- Returns:
- The swing panel where the simulation is displayed.
-
prepareObservation
public void prepareObservation()
Prepares the observation of a simulation.This method is defined to open the streams or the other resources used during the observation of one simulation.
- Specified by:
prepareObservation
in interfaceIProbe
-
observeAtInitialTimes
public void observeAtInitialTimes(SimulationTimeStamp initialTimestamp, ISimulationEngine simulationEngine)
Observes the state of the simulation when the initial time stamp is reached.- Specified by:
observeAtInitialTimes
in interfaceIProbe
- Parameters:
initialTimestamp
- The initial time stamp of the simulation.simulationEngine
- The simulation engine embedding the currently running simulation and the current dynamic state of the various levels of the simulation.
-
updateGraphics
protected abstract void updateGraphics(IPublicDynamicStateMap dynamicState, SimulationTimeStamp currentTime, Graphics2D graphics, int imgWidth, int imgHeight)
Updates the contents of a graphics object with the contents of the levels of the simulation.Usually, the implementation of this method consists in:
-
Clearing the drawing area either with the background color or with a custom color, using
the
Graphics2D.setBackground(Color)
andGraphics.clearRect(int, int, int, int)
methods. -
Printing the data of the simulation contained in the
dynamicState
argument, using the various filling and drawing methods of thegraphics
argument after setting either the drawing color withGraphics.setColor(Color)
or a more complex painting style usingGraphics2D.setPaint(java.awt.Paint)
.
- Parameters:
dynamicState
- The current dynamic state of the simulation.currentTime
- The current time of the simulation.graphics
- The graphical context used to modify the image.imgWidth
- The width of the image where the simulation is painted.imgHeight
- The height of the image where the simulation is painted.
-
Clearing the drawing area either with the background color or with a custom color, using
the
-
computeSimulationImageDimensions
protected abstract Dimension computeSimulationImageDimensions(IPublicDynamicStateMap dynamicState, SimulationTimeStamp initialTime)
Computes the dimensions of the image that will display the simulation.- Parameters:
dynamicState
- The current dynamic state of the simulation.initialTime
- The initial time of the simulation.- Returns:
- The dimensions of the image where the content of the simulation will be displayed.
-
swapDoubleBufferAndDisplayImage
protected void swapDoubleBufferAndDisplayImage(SimulationTimeStamp currentTime, IPublicDynamicStateMap dynamicState)
Refreshes the not displayed image of the double buffer with the simulation data defined as arguments of this method, and then performs a double buffer swap to display its content on screen.- Parameters:
currentTime
- The current time of the simulation.dynamicState
- The dynamic state of the simulation to display on screen.
-
observeAtPartialConsistentTime
public void observeAtPartialConsistentTime(SimulationTimeStamp time, ISimulationEngine engine)
Observes the state of the simulation when at least one level is in a consistent state.- Specified by:
observeAtPartialConsistentTime
in interfaceIProbe
- Parameters:
time
- The time stamp for which at least one level of the simulation is a consistent state.engine
- The simulation engine embedding the currently running simulation and the current dynamic state of the various levels of the simulation.
-
observeAtFinalTime
public void observeAtFinalTime(SimulationTimeStamp lastTime, ISimulationEngine engine)
Observes the state of the simulation when the final time stamp of the simulation is reached.- Specified by:
observeAtFinalTime
in interfaceIProbe
- Parameters:
lastTime
- The final time stamp of the simulation.engine
- The simulation engine embedding the currently running simulation and the current dynamic state of the various levels of the simulation.
-
reactToAbortion
public void reactToAbortion(SimulationTimeStamp time, ISimulationEngine engine)
Reacts to the abortion of a currently running simulation.- Specified by:
reactToAbortion
in interfaceIProbe
- Parameters:
time
- The time stamp reached right after the moment when the abortion was requested.engine
- The simulation engine embedding the aborted simulation and the dynamic state of the various levels of the simulation after abortion.
-
reactToError
public void reactToError(String time, Throwable cause)
Reacts to an error thrown by the simulation engine.- Specified by:
reactToError
in interfaceIProbe
cause
- The cause of the error.
-
endObservation
public void endObservation()
Ends the observation of a simulation.This method is defined to close the streams or the other resources used during the observation of one simulation.
- Specified by:
endObservation
in interfaceIProbe
-
-