Class Viewer
java.lang.Object
madkit.kernel.Agent
madkit.simulation.SimuAgent
madkit.kernel.Watcher
madkit.simulation.Viewer
- Direct Known Subclasses:
LineChartDrawer
,Viewer2D
A Viewer is a
Watcher
that is designed to display simulation states on screen.
By default, a viewer agent is automatically granted the role
SimuOrganization.VIEWER_ROLE
in the group SimuOrganization.ENGINE_GROUP
when it is activated. This can be changed by overriding the onActivation()
method.
To this end, it holds a ViewerDefaultGUI
which is used to render the simulation
state through a predefined JavaFX stage. When the viewer agent wants to render the
simulation state, it calls the ViewerDefaultGUI.requestRendering()
method which
triggers the render()
in the JavaFX thread if needed, depending on the state
of the GUI such as the synchronous painting mode.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class madkit.kernel.Agent
Agent.ReturnCode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
display()
When using the default simulation engine setup, this method is automatically called by the scheduler agent when it is time to render the simulation state.<G extends ViewerDefaultGUI>
GgetGUI()
Returns the GUI of this viewer.protected void
This method is called when the agent is activated.protected void
onEnd()
This method is called when the agent is ending.void
On simulation start.abstract void
render()
Renders the simulation state.void
setGUI
(ViewerDefaultGUI gui) Sets the GUI of this viewer.Methods inherited from class madkit.kernel.Watcher
addProbe, getProbes, removeAllProbes, removeProbe, toString
Methods inherited from class madkit.simulation.SimuAgent
createSimuGroup, getCommunity, getEngineGroup, getEnvironment, getLauncher, getModel, getModelGroup, getNextEventDate, getScheduler, getSimuTimer, getViewers, launchAgent, leaveRole, leaveSimuGroup, leaveSimuRole, playRole, prng, requestSimuRole
Methods inherited from class madkit.kernel.Agent
activate, broadcast, broadcastWithRole, broadcastWithRoleWaitForReplies, checkAgentAddress, createGroup, createGroup, createGroup, end, equals, executeThisAgent, executeThisAgent, exitOnKill, getAgentsWithRole, getAgentWithRole, getKernelAddress, getKernelConfig, getLogger, getMailbox, getName, getNetworkID, getOrganization, getReplyTo, handleRequestActionMessage, hashCode, isAlive, killAgent, killAgent, launchAgent, launchAgent, leaveGroup, leaveRole, live, nextMessage, onLive, pause, receiveMessage, reload, reply, replyWithRole, requestRole, requestRole, send, send, sendWaitReply, sendWaitReply, sendWithRole, sendWithRole, sendWithRoleWaitReply, sendWithRoleWaitReply, setupDefaultGUI, waitAnswer, waitAnswer, waitNextMessage, waitNextMessage
-
Constructor Details
-
Viewer
public Viewer()
-
-
Method Details
-
onActivation
protected void onActivation()This method is called when the agent is activated. By default, it requests the roleSimuOrganization.VIEWER_ROLE
in the groupSimuOrganization.ENGINE_GROUP
.- Overrides:
onActivation
in classWatcher
-
display
public void display()When using the default simulation engine setup, this method is automatically called by the scheduler agent when it is time to render the simulation state. It calls theViewerDefaultGUI.requestRendering()
method which triggers therender()
in the JavaFX thread if needed, depending on the state of the GUI such as the synchronous painting mode. -
onEnd
protected void onEnd()This method is called when the agent is ending. By default, it sends aSchedulingMessage
with theSchedulingAction.SHUTDOWN
action to the scheduler agent if no other viewer agent is present in the groupSimuOrganization.ENGINE_GROUP
with the role#VIEWER_ROLE
. -
onSimulationStart
public void onSimulationStart()On simulation start.- Overrides:
onSimulationStart
in classSimuAgent
-
render
public abstract void render()Renders the simulation state. This method is called by the GUI bounded to this agent when it is time to render the simulation state. The rendering is done in the JavaFX thread. -
getGUI
Returns the GUI of this viewer.- Returns:
- the GUI of this viewer
-
setGUI
Sets the GUI of this viewer.- Parameters:
gui
- the GUI to set
-