com.xj.anylogic.engine.presentation
Class Presentation

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.Presentation
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public final class Presentation
extends java.lang.Object
implements java.awt.event.ActionListener

This class creates AnyLogic GUI and controls the model execution in GUI applications and applets. The presentation has a panel, a toolbar and a status bar. The presentation can be created in three modes: application, applet and component. In application mode the Presentation creates JFrame and puts its components there. In applet mode Presentation embeds its components into a given JApplet. In component mode the Presentation assumes that an externally created container takes care of embedding and laying out the presentation components.
After creating an instance of Presentation you need to call its start() method.
The GUI is highly customizable: you can control what sections of the toolbar and the status bar are visible.

Author:
XJ Technologies Company Ltd. www.anylogic.com

Field Summary
static int MODE_APPLET
           
static int MODE_APPLICATION
           
static int MODE_COMPONENT
           
 
Constructor Summary
Presentation(Experiment<?> ex, int mode, java.awt.Container container)
          Creates a Presentation (AnyLogic model GUI components) for a given experiment in a given mode: MODE_APPLICATION, MODE_APPLET, or MODE_COMPONENT.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          A method of ActionListener interface.
 void addSnapshotEventListener(SnapshotEventListener listener)
          Registers listener for snapshot events, this listener is notified about changes performed by saveSnapshot(String) and loadSnapshot(String) methods
Does nothing if the given listener has already been added
 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)
 javax.swing.JApplet getApplet()
          In applet mode returns the applet, otherwise returns null.
 java.awt.Container getContainer()
          Returns frame, applet, or other container of the presentation GUI.
 Experiment<?> getExperiment()
          Returns the experiment associated with this presentation.
 javax.swing.JFrame getFrame()
          In application mode returns the frame, otherwise returns null.
 int getMode()
          Returns the mode of the presentation: MODE_APPLICATION, MODE_APPLET, or MODE_COMPONENT.
 Panel getPanel()
          Returns the panel - the area where the model active objects draw themselves.
 StatusBar getStatusBar()
          Returns the status bar of AnyLogic GUI application or applet.
 ToolBar getToolBar()
          Returns the tool bar of AnyLogic GUI application or applet.
 boolean isFullScreen()
          Returns true if the frame mode is full screen, false if it is normal.
 boolean isMaximized()
          Returns true if the model window is maximized, false otherwise
 boolean isPanningEnabled()
          Tests if mouse panning is enabled.
 boolean isZoomEnabled()
          Tests if zoom from the GUI is enabled.
 void loadSnapshot(java.lang.String fileName)
          Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
 void onActiveObjectDestroyed(ActiveObject ao)
          A callback called by the engine when an active object is being destroyed.
 void openWebSite(java.lang.String url)
          Opens web page with the given URL in the browser
 void refresh()
          Refreshes all presentation components (tool bar, status bar and the panel).
 void removeSnapshotEventListener(SnapshotEventListener listener)
          Unregisters listener for snapshot events (which was previously registered using addSnapshotEventListener(SnapshotEventListener) method)
Does nothing if the given listener has already been removed
 void saveSnapshot(java.lang.String fileName)
          Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
 void setConfirmWindowClose(boolean confirm)
          Configures the presentation window to show confirmation dialog when user tries to close the model window.
 void setFullScreen(boolean full)
          In application mode, sets the full screen or normal.
 void setMaximized(boolean maximized)
          In application mode, sets the window state to maximized or normal.
 void setPanelSize(int width, int height)
          In application mode, sets the size of the frame so that the frame's inner panel dimensions are exactly width by height pixels.
 void setPanningEnabled(boolean yes)
          Enables or disables panning with mouse right+drag, but does not affect programmatic changes of offsets that are always possible.
 void setPresentable(Presentable p)
          Sets the presentable object to be displayed by the presentation panel.
 void setZoomEnabled(boolean yes)
          Enables or disables zoom initiated from the GUI (button. mouse, or keyboard), but does not affect programmatic changes of zoom that are always possible.
 void showErrorDialog(java.lang.String text, java.lang.String title)
          Shows a standard error dialog box with the given text.
 void showMessageDialog(java.lang.String text)
          Shows a standard message dialog box with the given text.
 void start()
          Starts the GUI, subject to mode: in application mode initializes and shows frame; in application and applet mode lays out the toolbar, panel and the status bar.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_APPLICATION

public static final int MODE_APPLICATION
See Also:
Constant Field Values

MODE_APPLET

public static final int MODE_APPLET
See Also:
Constant Field Values

MODE_COMPONENT

public static final int MODE_COMPONENT
See Also:
Constant Field Values
Constructor Detail

Presentation

public Presentation(Experiment<?> ex,
                    int mode,
                    java.awt.Container container)
Creates a Presentation (AnyLogic model GUI components) for a given experiment in a given mode: MODE_APPLICATION, MODE_APPLET, or MODE_COMPONENT.

Parameters:
ex - the experiment
mode - the mode
container - the applet in applet mode, the external container in component mode, or null
Method Detail

start

public void start()
Starts the GUI, subject to mode: in application mode initializes and shows frame; in application and applet mode lays out the toolbar, panel and the status bar. Starts the components. Must be called after creation.


close

public void close()
This method returns immediately and performs the following actions in a separate thread:


getMode

public int getMode()
Returns the mode of the presentation: MODE_APPLICATION, MODE_APPLET, or MODE_COMPONENT.

Returns:
the mode of the presentation

getPanel

public Panel getPanel()
Returns the panel - the area where the model active objects draw themselves.

Returns:
the presentation panel

getStatusBar

public StatusBar getStatusBar()
Returns the status bar of AnyLogic GUI application or applet.

Returns:
the status bar

getToolBar

public ToolBar getToolBar()
Returns the tool bar of AnyLogic GUI application or applet.

Returns:
the tool bar

getContainer

public java.awt.Container getContainer()
Returns frame, applet, or other container of the presentation GUI.

Returns:
frame, applet, or other container of the presentation GUI

getFrame

public javax.swing.JFrame getFrame()
In application mode returns the frame, otherwise returns null.

Returns:
the frame or null

getApplet

public javax.swing.JApplet getApplet()
In applet mode returns the applet, otherwise returns null.

Returns:
the applet or null

setPresentable

public void setPresentable(Presentable p)
Sets the presentable object to be displayed by the presentation panel. Should be called when a different object should be displayed or when the current (active) object is destroyed.


onActiveObjectDestroyed

public void onActiveObjectDestroyed(ActiveObject ao)
A callback called by the engine when an active object is being destroyed. If that active object is currently displayed by the presentation, display experiment.

Parameters:
ao - the active object being destroyed

getExperiment

public Experiment<?> getExperiment()
Returns the experiment associated with this presentation.

Returns:
the experiment associated with this presentation

isFullScreen

public boolean isFullScreen()
Returns true if the frame mode is full screen, false if it is normal.

Returns:
true in full screen mode, false in normal

setPanelSize

public void setPanelSize(int width,
                         int height)
In application mode, sets the size of the frame so that the frame's inner panel dimensions are exactly width by height pixels. The frame itself will be larger as it includes header, tool bar, status bar, and border. In other modes has no effect.

Parameters:
width - the width of the panel in pixels
height - the height of the panel in pixels

showMessageDialog

public void showMessageDialog(java.lang.String text)
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)

Parameters:
text - the text to display

showErrorDialog

public void showErrorDialog(java.lang.String text,
                            java.lang.String title)
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)

Parameters:
text - the text to display

setZoomEnabled

public void setZoomEnabled(boolean yes)
Enables or disables zoom initiated from the GUI (button. mouse, or keyboard), but does not affect programmatic changes of zoom that are always possible.

Parameters:
yes - if true, zoom is enabled, if false - disabled

isZoomEnabled

public boolean isZoomEnabled()
Tests if zoom from the GUI is enabled.

Returns:
true if zoom is enabled, false if not.

setPanningEnabled

public void setPanningEnabled(boolean yes)
Enables or disables panning with mouse right+drag, but does not affect programmatic changes of offsets that are always possible.

Parameters:
yes - if true, panning is enabled, if false - disabled

isPanningEnabled

public boolean isPanningEnabled()
Tests if mouse panning is enabled.

Returns:
true if panning is enabled, false if not.

refresh

public void refresh()
Refreshes all presentation components (tool bar, status bar and the panel).


addSnapshotEventListener

public void addSnapshotEventListener(SnapshotEventListener listener)
Registers listener for snapshot events, this listener is notified about changes performed by saveSnapshot(String) and loadSnapshot(String) methods
Does nothing if the given listener has already been added

Parameters:
listener - the listener of snapshot events

removeSnapshotEventListener

public void removeSnapshotEventListener(SnapshotEventListener listener)
Unregisters listener for snapshot events (which was previously registered using addSnapshotEventListener(SnapshotEventListener) method)
Does nothing if the given listener has already been removed

Parameters:
listener - the listener of snapshot events

saveSnapshot

public void saveSnapshot(java.lang.String fileName)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing. If you need custom error processing, please use special callback method of listener
Notifies all listeners registered via addSnapshotEventListener(SnapshotEventListener)

This method is only available in the AnyLogic Professional

Parameters:
fileName - the name of snapshot file

loadSnapshot

public void loadSnapshot(java.lang.String fileName)
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. If you need custom error processing, please use special callback method of listener
Notifies all listeners registered via addSnapshotEventListener(SnapshotEventListener)
When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and active objects), therefore, it is recommended not to keep references to model objects after this method call

This method is only available in the AnyLogic Professional

Parameters:
fileName - the name of snapshot file

setFullScreen

public void setFullScreen(boolean full)
In application mode, sets the full screen or normal. Has no effect in other modes

Parameters:
full - if true - go full screen, otherwise restore normal mode

setMaximized

public void setMaximized(boolean maximized)
In application mode, sets the window state to maximized or normal. Has no effect in other modes

Parameters:
maximized - if true - the window will be maximized, otherwise - restored to the normal size

setConfirmWindowClose

public void setConfirmWindowClose(boolean confirm)
Configures the presentation window to show confirmation dialog when user tries to close the model window.
This option may be useful for long running experiments (which may collect some data and save it by user's request) - for not to lose unsaved data.
Confirmation is turned off by default.

Parameters:
confirm - true enables close confirmation, false disables

isMaximized

public boolean isMaximized()
Returns true if the model window is maximized, false otherwise

Returns:
true if the model window is maximized

openWebSite

public void openWebSite(java.lang.String url)
Opens web page with the given URL in the browser

Parameters:
url - the url to open

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
A method of ActionListener interface. Reacts to button and menu actions.

Specified by:
actionPerformed in interface java.awt.event.ActionListener


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.