AnyLogic AnyLogic
Expand
Font size
  • java.lang.Object
    • com.anylogic.engine.gui.ExperimentHost
All Implemented Interfaces:
IExperimentHost

@AnyLogicInternalAPI
public class ExperimentHost
extends java.lang.Object
implements IExperimentHost
This class is internal and shouldn't be called by user.
it may be removed/renamed in future.
Author:
AnyLogic North America, LLC https://anylogic.com

Nested Class Summary

Nested classes/interfaces inherited from interface com.anylogic.engine.gui.IExperimentHost

IExperimentHost.IValue

Constructor Summary

Constructors 
ExperimentHost​(Experiment<?> experiment)  
ExperimentHost​(java.lang.String experimentClassName)
Deprecated.
Constructor Description

Method Summary

All Methods Instance Methods Concrete Methods 
void addInspect​(double x, double y, Presentable p, java.lang.String name)
Creates an inspect window at a particular location for an element of a Presentable object.
java.lang.Object callFunction​(java.lang.String pathtofunction, IExperimentHost.IValue... args)  
void close()
This method returns immediately and performs the following actions in a separate thread: stops experiment if it is not stopped, destroys the model and closes experiment window (only if model is started in the application mode)
void copyToClipboard​(java.lang.String text)
Copies the given text to the system clipboard
Due to the security policy of the browser, the actual copying may be preceded by a prompt.
void executeCommand​(java.lang.String cmd, java.lang.String parameters)  
void executeUserAction​(long svgId, java.lang.String value)  
LaunchConfiguration getConfiguration()  
Experiment<?> getExperiment()
Returns the experiment associated with this host.
Experiment.State getExperimentState()  
SVGFrameProducer getFrameProducer()  
long getNextFrameNumber()  
Presentable getPresentable()
Returns the current top-level object (Agent or Experiment), whose presentation is displayed.
double getProgress()  
AnimationPacket getUpdate​(boolean fullFrame)  
java.lang.Object getValue​(java.lang.String pathtofield)  
boolean isRunControlEnabled()
Tests if Run, Pause, and Stop buttons on the model toolbar are enabled.
boolean isSpeedControlEnabled()
Tests if the model execution speed control buttons on the model toolbar are enabled.
boolean isZoomAndPanningEnabled()
Tests if zoom & panning from the GUI is enabled.
void launch​(boolean startServer, boolean startExperiment)
Creates and optionally runs experiment, starts frame collection
void loadSnapshot​(java.lang.String fileName, java.lang.Runnable successfulCallback, java.util.function.Consumer<java.lang.Throwable> errorCallback)
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running.

When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and agents), therefore, it is recommended not to keep references to model objects after this method call
Usage example:
void navigateHome()
Navigates presentation home, i.e. moves the presentation coordinate origin (0,0) to the top left corner of the window, and sets zoom to match the initial frame.
void navigateTo​(ViewArea viewarea)
Shows the given view area in the model animation panel
void onAgentDestroyed_xjal​(Agent ao)
A callback called by the engine when an agent is being destroyed.
void openWebSite​(java.lang.String url)
Opens web page with the given URL in the browser
void postExperimentSettings()  
void removeInspect​(Presentable p, java.lang.String name)
Removes the inspect window for the given element
void saveSnapshot​(java.lang.String fileName, java.lang.Runnable successfulCallback, java.util.function.Consumer<java.lang.Throwable> errorCallback)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
Usage example:
void setCenter​(double centerx, double centery)
Centers the animation view to the given x and y (in the model coordinates)
void setDeveloperPanelEnabled​(boolean debugPanelEnabled)
Enables or disables the developer panel.
void setDeveloperPanelVisibleOnStart​(boolean debugPanelVisibleOnStart)
Shows (if enabled) the developer panel when the model window is shown.
void setMaxFPS​(double maxFPS)
Sets the new maximum FPS to be used by the SVGFrameCollector.
void setPresentable​(Presentable presentable)
Sets a new top-level object (Agent or Experiment) to be displayed and navigates to its home point.
void setRunControlEnabled​(boolean runControlEnabled)
Enables or disables Run, Pause, and Stop buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
void setSendConsoleItems​(boolean yes)  
void setSpeed​(double speed)  
void setSpeedControlEnabled​(boolean speedControlEnabled)
Enables or disables the model execution speed control buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
void setValue​(java.lang.String pathtofield, IExperimentHost.IValue value)  
void setZoomAndPanningEnabled​(boolean yes)
Enables or disables zoom & panning initiated from the GUI (button. mouse, or keyboard).
void showErrorDialog​(java.lang.String text, java.lang.String title)
Shows a standard error dialog box with the given text.
void showErrorInModelDialog​(java.lang.String text, java.lang.String title)
Shows a standard 'error in model logic' dialog box with the given text.
void showMessageDialog​(java.lang.String text)
Shows a standard message dialog box with the given text.
void zoomIn​(double coefficient)
Zooms in the animation view by the given amount
void zoomOut​(double coefficient)
Zooms out the animation view by the given amount
Modifier and Type Method Description

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.gui.IExperimentHost

launch, loadSnapshot, saveSnapshot

Constructor Detail

ExperimentHost

@AnyLogicInternalAPI
public ExperimentHost​(Experiment<?> experiment)

ExperimentHost

@Deprecated
@AnyLogicInternalAPI
public ExperimentHost​(java.lang.String experimentClassName)
Deprecated.

Method Detail

setPresentable

public void setPresentable​(Presentable presentable)
Description copied from interface: IExperimentHost
Sets a new top-level object (Agent or Experiment) to be displayed and navigates to its home point.
Specified by:
setPresentable in interface IExperimentHost
Parameters:
presentable - the new top-level object to be displayed

getPresentable

public Presentable getPresentable()
Description copied from interface: IExperimentHost
Returns the current top-level object (Agent or Experiment), whose presentation is displayed.
Specified by:
getPresentable in interface IExperimentHost
Returns:
the current top-level object being displayed, or null

getExperiment

public Experiment<?> getExperiment()
Description copied from interface: IExperimentHost
Returns the experiment associated with this host.
Specified by:
getExperiment in interface IExperimentHost
Returns:
the experiment associated with this host
public void navigateHome()
Description copied from interface: IExperimentHost
Navigates presentation home, i.e. moves the presentation coordinate origin (0,0) to the top left corner of the window, and sets zoom to match the initial frame.
Specified by:
navigateHome in interface IExperimentHost
@AnyLogicInternalAPI
public void navigateTo​(ViewArea viewarea)
Description copied from interface: IExperimentHost
Shows the given view area in the model animation panel
Specified by:
navigateTo in interface IExperimentHost
Parameters:
viewarea - the view area to show

zoomIn

public void zoomIn​(double coefficient)
Description copied from interface: IExperimentHost
Zooms in the animation view by the given amount
Specified by:
zoomIn in interface IExperimentHost
Parameters:
coefficient - how much to zoom in, positive number. E.g. 2.0 will result in 2x scaling compared to the current view

zoomOut

public void zoomOut​(double coefficient)
Description copied from interface: IExperimentHost
Zooms out the animation view by the given amount
Specified by:
zoomOut in interface IExperimentHost
Parameters:
coefficient - how much to zoom out, positive number. E.g. 2.0 will result in 0.5x scaling compared to the current view

setCenter

public void setCenter​(double centerx,
                      double centery)
Description copied from interface: IExperimentHost
Centers the animation view to the given x and y (in the model coordinates)
Specified by:
setCenter in interface IExperimentHost
Parameters:
centerx - the x to be centered
centery - the y to be centered

setZoomAndPanningEnabled

public void setZoomAndPanningEnabled​(boolean yes)
Description copied from interface: IExperimentHost
Enables or disables zoom & panning initiated from the GUI (button. mouse, or keyboard).
Specified by:
setZoomAndPanningEnabled in interface IExperimentHost
Parameters:
yes - if true, zoom & panning should be enabled, if false - disabled

isZoomAndPanningEnabled

public boolean isZoomAndPanningEnabled()
Description copied from interface: IExperimentHost
Tests if zoom & panning from the GUI is enabled.
Specified by:
isZoomAndPanningEnabled in interface IExperimentHost
Returns:
true if zoom & panning are enabled, false if not.

setDeveloperPanelEnabled

public void setDeveloperPanelEnabled​(boolean debugPanelEnabled)
Description copied from interface: IExperimentHost
Enables or disables the developer panel.
Specified by:
setDeveloperPanelEnabled in interface IExperimentHost
Parameters:
debugPanelEnabled - if false, there will be no button to show the developer panel

setDeveloperPanelVisibleOnStart

public void setDeveloperPanelVisibleOnStart​(boolean debugPanelVisibleOnStart)
Description copied from interface: IExperimentHost
Shows (if enabled) the developer panel when the model window is shown.
Specified by:
setDeveloperPanelVisibleOnStart in interface IExperimentHost
Parameters:
debugPanelVisibleOnStart - if true, the panel will be visible from the beginning, and may be later hidden by pressing the special button.

setRunControlEnabled

public void setRunControlEnabled​(boolean runControlEnabled)
Description copied from interface: IExperimentHost
Enables or disables Run, Pause, and Stop buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
Specified by:
setRunControlEnabled in interface IExperimentHost
Parameters:
runControlEnabled - if false, those buttons will be disabled

isRunControlEnabled

public boolean isRunControlEnabled()
Description copied from interface: IExperimentHost
Tests if Run, Pause, and Stop buttons on the model toolbar are enabled.
Specified by:
isRunControlEnabled in interface IExperimentHost
Returns:
true if they are enabled, false if not.

setSpeedControlEnabled

public void setSpeedControlEnabled​(boolean speedControlEnabled)
Description copied from interface: IExperimentHost
Enables or disables the model execution speed control buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
Specified by:
setSpeedControlEnabled in interface IExperimentHost
Parameters:
speedControlEnabled - if false, those buttons will be disabled

isSpeedControlEnabled

public boolean isSpeedControlEnabled()
Description copied from interface: IExperimentHost
Tests if the model execution speed control buttons on the model toolbar are enabled.
Specified by:
isSpeedControlEnabled in interface IExperimentHost
Returns:
true if they are enabled, false if not.

addInspect

public void addInspect​(double x,
                       double y,
                       Presentable p,
                       java.lang.String name)
Description copied from interface: IExperimentHost
Creates an inspect window at a particular location for an element of a Presentable object. If there is another inspect with the same Presentable and same element name, it is brought to front and a new inspect is not created. The initial size of the window is adjusted to fit the initial contents.
Specified by:
addInspect in interface IExperimentHost
Parameters:
x - the x coordinate in the presentable object system
y - the y coordinate in the presentable object system
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

removeInspect

public void removeInspect​(Presentable p,
                          java.lang.String name)
Description copied from interface: IExperimentHost
Removes the inspect window for the given element
Specified by:
removeInspect in interface IExperimentHost
Parameters:
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

showMessageDialog

public void showMessageDialog​(java.lang.String text)
Description copied from interface: IExperimentHost
Shows a standard message dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Specified by:
showMessageDialog in interface IExperimentHost
Parameters:
text - the text to display

showErrorDialog

public void showErrorDialog​(java.lang.String text,
                            java.lang.String title)
Description copied from interface: IExperimentHost
Shows a standard error dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Specified by:
showErrorDialog in interface IExperimentHost
Parameters:
text - the text to display
title - title of the dialog window

showErrorInModelDialog

public void showErrorInModelDialog​(java.lang.String text,
                                   java.lang.String title)
Description copied from interface: IExperimentHost
Shows a standard 'error in model logic' dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Specified by:
showErrorInModelDialog in interface IExperimentHost
Parameters:
text - the text to display
title - title of the dialog window

openWebSite

public void openWebSite​(java.lang.String url)
Description copied from interface: IExperimentHost
Opens web page with the given URL in the browser
Specified by:
openWebSite in interface IExperimentHost
Parameters:
url - the url to open

copyToClipboard

public void copyToClipboard​(java.lang.String text)
Description copied from interface: IExperimentHost
Copies the given text to the system clipboard
Due to the security policy of the browser, the actual copying may be preceded by a prompt.
Specified by:
copyToClipboard in interface IExperimentHost
Parameters:
text - the text to copy

saveSnapshot

public void saveSnapshot​(java.lang.String fileName,
                         java.lang.Runnable successfulCallback,
                         java.util.function.Consumer<java.lang.Throwable> errorCallback)
Description copied from interface: IExperimentHost
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
Usage example:
 getExperimentHost().saveSnapshot(
                "file.als",
                () -> traceln("Saved!"),
                e -> {
                        traceln("Error!");
                        e.printStackTrace();
                }
 );
 

This method is only available in the AnyLogic Professional
Specified by:
saveSnapshot in interface IExperimentHost
Parameters:
fileName - the name of snapshot file
successfulCallback - called when snapshot is successfully saved
errorCallback - called in case of any error

loadSnapshot

public void loadSnapshot​(java.lang.String fileName,
                         java.lang.Runnable successfulCallback,
                         java.util.function.Consumer<java.lang.Throwable> errorCallback)
Description copied from interface: IExperimentHost
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running.

When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and agents), therefore, it is recommended not to keep references to model objects after this method call
Usage example:
 getExperimentHost().loadSnapshot(
                "file.als",
                () -> {
                        traceln("Loaded!");
                        getExperimentHost().setPresentable(
                                getExperiment().getEngine().getRoot()
                        );
                        getExperiment().run();
                },
                e -> {
                        traceln("Error!");
                        e.printStackTrace();
                }
 );
 

This method is only available in the AnyLogic Professional
Specified by:
loadSnapshot in interface IExperimentHost
Parameters:
fileName - the name of snapshot file

close

public void close()
Description copied from interface: IExperimentHost
This method returns immediately and performs the following actions in a separate thread:
  • stops experiment if it is not stopped,
  • destroys the model and
  • closes experiment window (only if model is started in the application mode)
Specified by:
close in interface IExperimentHost

launch

@AnyLogicInternalAPI
public void launch​(boolean startServer,
                   boolean startExperiment)
Description copied from interface: IExperimentHost
Creates and optionally runs experiment, starts frame collection
Specified by:
launch in interface IExperimentHost
Parameters:
startServer - TODO

getConfiguration

@AnyLogicInternalAPI
public LaunchConfiguration getConfiguration()
Specified by:
getConfiguration in interface IExperimentHost

getUpdate

@AnyLogicInternalAPI
public AnimationPacket getUpdate​(boolean fullFrame)
Specified by:
getUpdate in interface IExperimentHost

getNextFrameNumber

@AnyLogicInternalAPI
public long getNextFrameNumber()
Specified by:
getNextFrameNumber in interface IExperimentHost

executeUserAction

@AnyLogicInternalAPI
public void executeUserAction​(long svgId,
                              java.lang.String value)
Specified by:
executeUserAction in interface IExperimentHost

executeCommand

@AnyLogicInternalAPI
public void executeCommand​(java.lang.String cmd,
                           java.lang.String parameters)
Specified by:
executeCommand in interface IExperimentHost

getExperimentState

@AnyLogicInternalAPI
public Experiment.State getExperimentState()
Specified by:
getExperimentState in interface IExperimentHost

setValue

@AnyLogicInternalAPI
public void setValue​(java.lang.String pathtofield,
                     IExperimentHost.IValue value)
Specified by:
setValue in interface IExperimentHost

getValue

@AnyLogicInternalAPI
public java.lang.Object getValue​(java.lang.String pathtofield)
Specified by:
getValue in interface IExperimentHost

callFunction

public java.lang.Object callFunction​(java.lang.String pathtofunction,
                                     IExperimentHost.IValue... args)
Specified by:
callFunction in interface IExperimentHost

getProgress

@AnyLogicInternalAPI
public double getProgress()
Specified by:
getProgress in interface IExperimentHost

setSpeed

@AnyLogicInternalAPI
public void setSpeed​(double speed)
Specified by:
setSpeed in interface IExperimentHost

setMaxFPS

@AnyLogicInternalAPI
public void setMaxFPS​(double maxFPS)
Sets the new maximum FPS to be used by the SVGFrameCollector. The actual FPS of the packets sent can be lower than that, as the SVGFrameCollector may adjust FPS to keep the number of frames per packet in certain bounds, see SVGFrameCollector.adjustFPS().
Specified by:
setMaxFPS in interface IExperimentHost
Parameters:
maxFPS - the new FPS suggested by the frontend

setSendConsoleItems

@AnyLogicInternalAPI
public void setSendConsoleItems​(boolean yes)
Specified by:
setSendConsoleItems in interface IExperimentHost

postExperimentSettings

@AnyLogicInternalAPI
public void postExperimentSettings()
Specified by:
postExperimentSettings in interface IExperimentHost

onAgentDestroyed_xjal

@AnyLogicInternalAPI
public void onAgentDestroyed_xjal​(Agent ao)
Description copied from interface: IExperimentHost
A callback called by the engine when an agent is being destroyed. If that agent is currently displayed by the presentation, display experiment.
Specified by:
onAgentDestroyed_xjal in interface IExperimentHost
Parameters:
ao - the agent being destroyed

getFrameProducer

public SVGFrameProducer getFrameProducer()
How can we improve this article?