Class 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 Swing JPanel object.
    Author:
    Yoann Kubera, Gildas Morvan
    • 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. If true, 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

      • 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 interface IProbe
      • 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 interface IProbe
        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:

        1. Clearing the drawing area either with the background color or with a custom color, using the Graphics2D.setBackground(Color) and Graphics.clearRect(int, int, int, int) methods.
        2. Printing the data of the simulation contained in the dynamicState argument, using the various filling and drawing methods of the graphics argument after setting either the drawing color with Graphics.setColor(Color) or a more complex painting style using Graphics2D.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.
      • 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 interface IProbe
        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 interface IProbe
        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 interface IProbe
        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 interface IProbe
        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 interface IProbe