Class SimulationView3D

All Implemented Interfaces:
edu.cnu.mdi.feedback.IFeedbackProvider, edu.cnu.mdi.sim.ISimulationHost, edu.cnu.mdi.sim.SimulationListener, edu.cnu.mdi.transfer.IFileDropHandler, ActionListener, ComponentListener, FocusListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
AizawaDemoView, KineticsDemoView, LogoDemoView

public abstract class SimulationView3D extends PlainView3D implements edu.cnu.mdi.sim.ISimulationHost, edu.cnu.mdi.sim.SimulationListener
Base class for an MDI 3D view that hosts a SimulationEngine.

This is the 3D analogue of edu.cnu.mdi.sim.ui.SimulationView: the simulation engine remains UI-agnostic, while this view provides the "MDI bridge" for Swing/MDI and triggers repaint/refresh of the 3D panel on engine refresh events.

Layout

PlainView3D installs the 3D panel in BorderLayout.CENTER. This class optionally adds:

  • A control panel in BorderLayout.SOUTH
  • An optional diagnostics/settings component on the right by wrapping the current CENTER component in a JSplitPane

Construction

This class now supports both the legacy Object... keyVals pattern and the cleaner Properties-based pattern. Legacy constructors are retained as compatibility shims.

Threading

All SimulationListener callbacks arrive on the Swing EDT (as guaranteed by SimulationEngine). Therefore onRefresh(SimulationContext) can safely call PlainView3D.refresh().

See Also:
  • Field Details

    • engine

      protected volatile edu.cnu.mdi.sim.SimulationEngine engine
      Hosted engine (never null).
    • controlPanel

      protected final JComponent controlPanel
      Optional control panel component (may be null).
    • diagnostics

      protected final JComponent diagnostics
      Optional diagnostics/settings component (may be null).
    • diagnosticsSplitPane

      protected final JSplitPane diagnosticsSplitPane
      If diagnostics is installed, this is the split pane (else null).
  • Constructor Details

    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, Object... keyVals)
      Construct a simulation 3D view using default engine configuration and including the default control panel.
      Parameters:
      simulation - the simulation to run (non-null)
      keyVals - standard BaseView key-value arguments
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, Properties props)
      Construct a simulation 3D view using default engine configuration and including the default control panel.
      Parameters:
      simulation - the simulation to run (non-null)
      props - view properties
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, Object... keyVals)
      Construct a simulation 3D view with optional inclusion of the default control panel.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds the default control panel at SOUTH
      keyVals - standard BaseView key-value arguments
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, Properties props)
      Construct a simulation 3D view with optional inclusion of the default control panel.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds the default control panel at SOUTH
      props - view properties
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, SimulationView3D.ControlPanelFactory factory, Object... keyVals)
      Construct a simulation 3D view with a caller-provided control panel factory.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds a control panel at SOUTH
      factory - factory used to create the control panel component
      keyVals - standard BaseView key-value arguments
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, SimulationView3D.ControlPanelFactory factory, Properties props)
      Construct a simulation 3D view with a caller-provided control panel factory.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds a control panel at SOUTH
      factory - factory used to create the control panel component
      props - view properties
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, SimulationView3D.ControlPanelFactory controlPanelFactory, boolean includeDiagnostics, SimulationView3D.DiagnosticFactory diagnosticFactory, double initialSplitFraction, Object... keyVals)
      Construct a simulation 3D view with optional control panel and optional diagnostics panel.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds a control panel at SOUTH
      controlPanelFactory - factory used to create the control panel component (may be null if includeControlPanel is false)
      includeDiagnostics - if true, installs a right-side diagnostics component via a split pane
      diagnosticFactory - factory used to create the diagnostics component (required if includeDiagnostics is true)
      initialSplitFraction - fraction of width given to the main (left) component on startup (0..1)
      keyVals - standard BaseView key-value arguments
    • SimulationView3D

      public SimulationView3D(edu.cnu.mdi.sim.Simulation simulation, edu.cnu.mdi.sim.SimulationEngineConfig config, boolean includeControlPanel, SimulationView3D.ControlPanelFactory controlPanelFactory, boolean includeDiagnostics, SimulationView3D.DiagnosticFactory diagnosticFactory, double initialSplitFraction, Properties props)
      Construct a simulation 3D view with optional control panel and optional diagnostics panel.
      Parameters:
      simulation - the simulation to run (non-null)
      config - engine configuration (non-null)
      includeControlPanel - if true, creates and adds a control panel at SOUTH
      controlPanelFactory - factory used to create the control panel component (may be null if includeControlPanel is false)
      includeDiagnostics - if true, installs a right-side diagnostics component via a split pane
      diagnosticFactory - factory used to create the diagnostics component (required if includeDiagnostics is true)
      initialSplitFraction - fraction of width given to the main (left) component on startup (0..1)
      props - view properties
  • Method Details

    • getDiagnosticsComponent

      protected JComponent getDiagnosticsComponent()
      Get the diagnostics/settings component if installed.
      Returns:
      diagnostics/settings component, or null if not installed
    • getSimulationEngine

      public final edu.cnu.mdi.sim.SimulationEngine getSimulationEngine()
      Specified by:
      getSimulationEngine in interface edu.cnu.mdi.sim.ISimulationHost
    • onStateChange

      public void onStateChange(edu.cnu.mdi.sim.SimulationContext ctx, edu.cnu.mdi.sim.SimulationState from, edu.cnu.mdi.sim.SimulationState to, String reason)
      Specified by:
      onStateChange in interface edu.cnu.mdi.sim.SimulationListener
    • onInit

      public void onInit(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onInit in interface edu.cnu.mdi.sim.SimulationListener
    • onReady

      public void onReady(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onReady in interface edu.cnu.mdi.sim.SimulationListener
    • onRun

      public void onRun(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onRun in interface edu.cnu.mdi.sim.SimulationListener
    • onResume

      public void onResume(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onResume in interface edu.cnu.mdi.sim.SimulationListener
    • onPause

      public void onPause(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onPause in interface edu.cnu.mdi.sim.SimulationListener
    • onDone

      public void onDone(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onDone in interface edu.cnu.mdi.sim.SimulationListener
    • onFail

      public void onFail(edu.cnu.mdi.sim.SimulationContext ctx, Throwable error)
      Specified by:
      onFail in interface edu.cnu.mdi.sim.SimulationListener
    • onCancelRequested

      public void onCancelRequested(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onCancelRequested in interface edu.cnu.mdi.sim.SimulationListener
    • onMessage

      public void onMessage(edu.cnu.mdi.sim.SimulationContext ctx, String message)
      Specified by:
      onMessage in interface edu.cnu.mdi.sim.SimulationListener
    • onProgress

      public void onProgress(edu.cnu.mdi.sim.SimulationContext ctx, edu.cnu.mdi.sim.ProgressInfo progress)
      Specified by:
      onProgress in interface edu.cnu.mdi.sim.SimulationListener
    • onRefresh

      public void onRefresh(edu.cnu.mdi.sim.SimulationContext ctx)
      Specified by:
      onRefresh in interface edu.cnu.mdi.sim.SimulationListener
    • onSimulationStateChange

      protected void onSimulationStateChange(edu.cnu.mdi.sim.SimulationContext ctx, edu.cnu.mdi.sim.SimulationState from, edu.cnu.mdi.sim.SimulationState to, String reason)
      Called whenever the simulation transitions between states, after any pending engine reset triggered by requestEngineReset(java.util.function.Supplier<edu.cnu.mdi.sim.Simulation>, java.util.function.Consumer<edu.cnu.mdi.sim.SimulationEngine>, boolean, boolean) has been applied.
      Parameters:
      ctx - simulation context
      from - the state being left
      to - the state being entered
      reason - human-readable reason for the transition, or null
    • onSimulationInit

      protected void onSimulationInit(edu.cnu.mdi.sim.SimulationContext ctx)
      Called once the engine has initialized the simulation.
      Parameters:
      ctx - simulation context
    • onSimulationReady

      protected void onSimulationReady(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when the simulation becomes ready to run.
      Parameters:
      ctx - simulation context
    • onSimulationRun

      protected void onSimulationRun(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when the simulation starts or restarts running.
      Parameters:
      ctx - simulation context
    • onSimulationResume

      protected void onSimulationResume(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when the simulation resumes after being paused.
      Parameters:
      ctx - simulation context
    • onSimulationPause

      protected void onSimulationPause(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when the simulation is paused.
      Parameters:
      ctx - simulation context
    • onSimulationDone

      protected void onSimulationDone(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when the simulation completes normally.
      Parameters:
      ctx - simulation context
    • onSimulationFail

      protected void onSimulationFail(edu.cnu.mdi.sim.SimulationContext ctx, Throwable error)
      Called when the simulation terminates with an error.
      Parameters:
      ctx - simulation context
      error - the exception that caused the failure
    • onSimulationCancelRequested

      protected void onSimulationCancelRequested(edu.cnu.mdi.sim.SimulationContext ctx)
      Called when cancellation of the running simulation has been requested.
      Parameters:
      ctx - simulation context
    • onSimulationMessage

      protected void onSimulationMessage(edu.cnu.mdi.sim.SimulationContext ctx, String message)
      Called when the simulation posts an informational message.
      Parameters:
      ctx - simulation context
      message - message text from the simulation
    • onSimulationProgress

      protected void onSimulationProgress(edu.cnu.mdi.sim.SimulationContext ctx, edu.cnu.mdi.sim.ProgressInfo progress)
      Called when the simulation reports progress.
      Parameters:
      ctx - simulation context
      progress - current progress information
    • onSimulationRefresh

      protected void onSimulationRefresh(edu.cnu.mdi.sim.SimulationContext ctx)
      Called on every engine refresh request, immediately before this class repaints or refreshes the 3D panel in response.
      Parameters:
      ctx - simulation context
    • replaceEngine

      protected final void replaceEngine(edu.cnu.mdi.sim.SimulationEngine newEngine)
      Swap in a new SimulationEngine, unregistering this view as a listener on the old engine and registering it on the new one, and rebinding the control panel if it implements ISimulationControlPanel.

      Must run on the EDT; if called from another thread, it re-dispatches itself via SwingUtilities.invokeLater(Runnable).

      Parameters:
      newEngine - the engine to install; must not be null
    • requestEngineReset

      protected final void requestEngineReset(Supplier<edu.cnu.mdi.sim.Simulation> simSupplier, Consumer<edu.cnu.mdi.sim.SimulationEngine> afterSwap, boolean autoStart, boolean refresh)
      Request an engine reset by supplying a factory for the new simulation. If the current engine is in a safe state, the reset will happen immediately. Otherwise the current engine will be requested to stop, and the reset will happen as soon as the engine reaches a safe state (TERMINATED or FAILED).
      Parameters:
      simSupplier - supplier for the new simulation instance (required)
      afterSwap - optional callback that receives the new engine after it has been swapped in
      autoStart - if true, automatically start the new engine after swapping
      refresh - if true, request a refresh on the new engine after swapping
    • startAndRun

      public final void startAndRun()
      Convenience method to start and run the simulation in one call. This is safe to call from any thread.