Package madkit.simulation.viewer
Class SwingViewer
java.lang.Object
madkit.kernel.AbstractAgent
madkit.kernel.Watcher
madkit.simulation.viewer.SwingViewer
- All Implemented Interfaces:
Comparable<AbstractAgent>
A very basic simulation viewer agent. This class defines a panel for the
simulation rendering and two modes of rendering: Synchronous and
asynchronous. The synchronous mode ensures that each simulation frame is
displayed. That means that the scheduler will wait the end of the rendering
activity to proceed to the next activator, waiting for the swing thread to
ends. this is not the case with the asynchronous mode so that the whole
simulation process goes faster because some simulation states will not be
displayed. An
observe
method is already defined and is intended
to be called by scheduler agents to trigger the rendering. This class could
be thus extended to reuse the rendering call mechanism which is defined in
here.- Since:
- MaDKit 5.0.0.17
- Version:
- 1.1
- Author:
- Fabien Michel
-
Nested Class Summary
Nested classes/interfaces inherited from class madkit.kernel.AbstractAgent
AbstractAgent.ReturnCode, AbstractAgent.State
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new agent with a default panel for rendering purposes -
Method Summary
Modifier and TypeMethodDescriptionReturns a menu which could be used in any viewer GUI.getFrame()
By default, get the default frame provided by MaDKit insetupFrame(AgentFrame)
and set usingsetupFrame(AgentFrame)
.Returns the viewer's toolbar.boolean
boolean
Tells if the rendering should be done synchronously or asynchronously with respect to simulation steps.protected void
observe()
Intended to be invoked by a scheduler's activator for triggering the rendering.protected abstract void
Override this method to do the rendering in the agent's panel.void
setDisplayPane
(JComponent displayPane) Could be used to define a customized panel instead of the default panevoid
setRendering
(boolean activated) Enable or disable the rendering activityvoid
setRenderingInterval
(int interval) Set the number of states between display updates.void
setSynchronousPainting
(boolean synchronousPainting) Set the rendering mode to synchronous or asynchronous.void
setupFrame
(AgentFrame frame) Provides a default implementation that assigns the default panel to the default frameMethods inherited from class madkit.kernel.Watcher
activate, addProbe, allProbes, getProbes, removeAllProbes, removeProbe, toString
Methods inherited from class madkit.kernel.AbstractAgent
broadcastMessage, broadcastMessageWithRole, bucketModeCreateGroup, bucketModeRequestRole, checkAgentAddress, compareTo, createGroup, createGroup, createGroup, createGroupIfAbsent, createGroupIfAbsent, createGroupIfAbsent, createGUIOnStartUp, destroyCommunity, destroyGroup, destroyRole, end, executeThisAgent, executeThisAgent, executeThisAgent, getAgentAddressIn, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getDistantAgentWithRole, getExistingCommunities, getExistingGroups, getExistingRoles, getKernelAddress, getLastReceivedMessage, getLastReceivedMessage, getLogger, getMadkitConfig, getMadkitProperty, getMadkitProperty, getMyGroups, getMyRoles, getName, getNetworkID, getNextEventDate, getOrganizationSnapShot, getReplyTo, getServerInfo, getSimpleNetworkID, getSimulationTime, getState, hasGUI, hashCode, hasRole, isAlive, isCommunity, isGroup, isKernelOnline, isMadkitPropertyTrue, isMessageBoxEmpty, isRole, killAgent, killAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchNode, launchXmlAgents, leaveGroup, leaveRole, nextMessage, nextMessage, nextMessages, proceedEnumMessage, purgeMailbox, receiveMessage, reload, requestRole, requestRole, sendMessage, sendMessage, sendMessageWithRole, sendMessageWithRole, sendReply, sendReplyWithRole, setLogLevel, setMadkitProperty, setMadkitProperty, setName
-
Constructor Details
-
SwingViewer
public SwingViewer()Creates a new agent with a default panel for rendering purposes
-
-
Method Details
-
isRendering
public boolean isRendering()- Returns:
true
if the rendering activity is activated.
-
setRendering
public void setRendering(boolean activated) Enable or disable the rendering activity -
getDisplayPane
- Returns:
- the current panel which is used for display
-
setDisplayPane
Could be used to define a customized panel instead of the default pane- Parameters:
displayPane
- the displayPane to set
-
observe
protected void observe()Intended to be invoked by a scheduler's activator for triggering the rendering. This method activate the rendering either synchronously or asynchronously depending onisSynchronousPainting()
. -
render
Override this method to do the rendering in the agent's panel. This method is automatically called when theobserve
method is triggered by a Scheduler- Parameters:
g
-
-
isSynchronousPainting
public boolean isSynchronousPainting()Tells if the rendering should be done synchronously or asynchronously with respect to simulation steps.- Returns:
- the synchronousPainting
-
setSynchronousPainting
public void setSynchronousPainting(boolean synchronousPainting) Set the rendering mode to synchronous or asynchronous. Synchronous painting is done for each time step and the simulation does not advance until all the rendering is done for a step: The simulation is slower but more smoothly rendered, making the visualization of the simulation dynamics more precise. In asynchronous mode, the rendering is done in parallel with the simulation steps and thus only display snapshot of the simulation's state:- Parameters:
synchronousPainting
- the synchronousPainting mode to set
-
setupFrame
Provides a default implementation that assigns the default panel to the default frame- Overrides:
setupFrame
in classAbstractAgent
- Parameters:
frame
- the default frame which has been created by MaDKit for this agent.- See Also:
-
getDisplayMenu
Returns a menu which could be used in any viewer GUI.- Returns:
- a menu controlling the viewer's options
-
getFrame
By default, get the default frame provided by MaDKit insetupFrame(AgentFrame)
and set usingsetupFrame(AgentFrame)
. It can be anyJFrame
ifsetupFrame(AgentFrame)
has been overridden.- Returns:
- the working frame
-
getSynchroPaintingAction
-
setRenderingInterval
public void setRenderingInterval(int interval) Set the number of states between display updates. If set to 1, every simulation states will be displayed- Parameters:
interval
- an int > 0
-
getToolBar
Returns the viewer's toolbar.- Returns:
- a toolBar controlling the viewer's actions
-