Package org.evoludo.simulator.views
Class AbstractView
- All Implemented Interfaces:
HasAttachHandlers
,HasHandlers
,EventListener
,HasVisibility
,IsRenderable
,IsWidget
,ProvidesResize
,RequiresResize
,AbstractGraph.Controller
,ChangeListener
,MilestoneListener
- Direct Known Subclasses:
Console
,Distribution
,GenericPop
,Histogram
,Mean
,Phase2D
,S3
public abstract class AbstractView
extends Composite
implements RequiresResize, ProvidesResize, AbstractGraph.Controller, MilestoneListener, ChangeListener
The parent class of all panels that provide graphical representations the
state of the current EvoLudo model.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The export command triggered by the context menu entries.static enum
The available export data types: SVG scalable vector graphics format,svg
PDF portable document format,pdf
(not yet implemented). EPS encapsulated postscript format,eps
(not yet implemented). PNG portable network graphics format,png
STAT_DATA statistics data as comma separated list,csv
TRAJ_DATA trajectory data as comma separated list,csv
(not yet implemented). STATE current state of simulation,plist
Nested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
Nested classes/interfaces inherited from interface ChangeListener
ChangeListener.PendingAction
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected EvoLudoGWT
The reference to the EvoLudo engine that manages the simulation.protected ContextMenu
The field to store the export context submenu.protected ContextMenuItem
The field to store the export submenu trigger.(package private) int
The number of columns of graphs in this view.protected List
<? extends AbstractGraph<?>> The list of graphs that are displayed in this view.(package private) int
The number of rows of graphs in this view.private static boolean
The flag to indicate whether the script for exporting SVG has been injected.(package private) boolean
The flag to indicate whether this view is currently active.(package private) boolean
The flag to indicate whether this view has been loaded.protected Logger
Logger for keeping track of and reporting events and issues.protected static final int
In order to conserve computational resources the minimum time between subsequent GUI updates has to be at leastMIN_MSEC_BETWEEN_UPDATES
milliseconds.(package private) Model
The reference to the model that supplies the data for this graph.protected ContextMenuItem
The field to store the restore context menu.protected double
The timestamp of model at the last update of this view.(package private) Data
The type of data shown in this graph.private boolean
The flag to indicate whether an update is already scheduled.(package private) double
Time of last GUI update(package private) ComplexPanel
The GWT widget that contains the graphical representations of the data.Fields inherited from class UIObject
DEBUG_ID_PREFIX
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractView
(EvoLudoGWT engine, Data type) The constructor for the abstract view. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Activate the view.protected abstract void
Allocate all graphs managed by this view.void
clear()
Clear the view.void
Create the widget that will contain the graphical representations of the data.void
Deactivate the view.protected void
Destroy all graphs in this view and free up resources.void
dispose()
Dispose of view.protected void
export
(AbstractGraph.MyContext2d ctx, int scale) Export each graph in this view.protected void
Export the data of the view.protected StringBuilder
The header for data exports.protected void
Export the mean data.protected void
Export the view as a PNG image.protected void
Export the statistics data.protected void
Export the view as a SVG image.protected void
Export the trajectories.protected AbstractView.ExportType[]
Return the list of export types that are acceptable for _all_ graphs in this view.getGraphAt
(int x, int y) Get the graph at the coordinates(x,y)
.Get the logger for returning progress, problems and messages to user.getMode()
Get the mode of this view.getModel()
Get the type of the model supplying the data visualized on the graph.abstract String
getName()
Get the name of this view.Get the status of this view.getStatus
(boolean force) Get the status of this view.getType()
Get the type of data visualized on the graph.private boolean
Checks if the view supports the export typetype
.boolean
Check if the view has finished layouting its graphs.boolean
Checks if the controller is busy running calculations.boolean
keyDownHandler
(String key) Opportunity for view to implement keyboard shortcut for actions (repeating).boolean
keyUpHandler
(String key) Opportunity for view to implement keyboard shortcut for actions (non repeating).void
Notifies the controller of the completion of the layouting process.boolean
load()
Load the view.void
Called whenever the state of the EvoLudo model changed.void
Called after the EvoLudo model got re-initialized.void
Called after the EvoLudo model was reset.void
Called after a running EvoLudo model stopped because the model converged (or reached an absorbing state).void
Called when EvoLudo model is unloading.void
Called when the state of the EvoLudo module has been restored.void
Called when EvoLudo module is unloading.void
onResize()
void
populateContextMenu
(ContextMenu contextMenu) Opportunity for the controller to add functionality to the context menu (optional implementation).void
reset
(boolean hard) Called when a module has been reset.protected void
scheduleUpdate
(boolean force) Schedule an update of the view.void
setBounds
(int width, int height) Set the bounds of the view to the givenwidth
andheight
.boolean
Set the mode of the model tomode
.void
shift
(int dx, int dy) Default implementation for synchronized shifting of multiple graphs.void
unload()
Unload the view.void
update()
Called when the view needs updating.abstract void
update
(boolean force) Called when the view needs updating.void
zoom
(double zoom, int x, int y) Default implementation for synchronized zooming of multiple graphs.Methods inherited from class Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
Methods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
Methods inherited from class UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface AbstractGraph.Controller
setInitialState
Methods inherited from interface MilestoneListener
modelLoaded, modelRelaxed, modelRunning, modelSettings, moduleLoaded
-
Field Details
-
engine
The reference to the EvoLudo engine that manages the simulation. -
model
Model modelThe reference to the model that supplies the data for this graph. -
type
Data typeThe type of data shown in this graph. -
logger
Logger for keeping track of and reporting events and issues. -
graphs
The list of graphs that are displayed in this view. -
gRows
int gRowsThe number of rows of graphs in this view. -
gCols
int gColsThe number of columns of graphs in this view. -
isActive
boolean isActiveThe flag to indicate whether this view is currently active. -
isLoaded
boolean isLoadedThe flag to indicate whether this view has been loaded. -
timestamp
protected double timestampThe timestamp of model at the last update of this view. -
updatetime
double updatetimeTime of last GUI update -
wrapper
ComplexPanel wrapperThe GWT widget that contains the graphical representations of the data. -
MIN_MSEC_BETWEEN_UPDATES
protected static final int MIN_MSEC_BETWEEN_UPDATESIn order to conserve computational resources the minimum time between subsequent GUI updates has to be at leastMIN_MSEC_BETWEEN_UPDATES
milliseconds. If update request are made more frequently some are request are not honoured and simply dropped.- See Also:
-
updateScheduled
private boolean updateScheduledThe flag to indicate whether an update is already scheduled. Subsequent requests are ignored. -
restoreMenu
The field to store the restore context menu. -
hasSVGjs
private static boolean hasSVGjsThe flag to indicate whether the script for exporting SVG has been injected.
-
-
Constructor Details
-
AbstractView
The constructor for the abstract view.- Parameters:
engine
- the EvoLudo enginetype
- the type of data shown in this view
-
-
Method Details
-
createWidget
public void createWidget()Create the widget that will contain the graphical representations of the data.- Note:
- LayoutPanel would be a nice way to continue the onResize cascade but incompatible with current implementation of context menu and tooltips
-
getName
Get the name of this view. This is used to dynamically build the view selector.- Returns:
- the name of this view
-
load
public boolean load()Load the view. This is called for modules and models that implement this view. This is called early on when initializing the view and is independent of the activation of the view.- Returns:
true
if view had not been loaded- See Also:
-
moduleUnloaded
public void moduleUnloaded()Description copied from interface:MilestoneListener
Called when EvoLudo module is unloading.- Specified by:
moduleUnloaded
in interfaceMilestoneListener
-
modelUnloaded
public void modelUnloaded()Description copied from interface:MilestoneListener
Called when EvoLudo model is unloading.- Specified by:
modelUnloaded
in interfaceMilestoneListener
-
unload
public void unload()Unload the view. This is called when changing the module or model that implement this view. This is independent of the activation of the view. -
dispose
public void dispose()Dispose of view. Deregister listeners and free up resources. -
allocateGraphs
protected abstract void allocateGraphs()Allocate all graphs managed by this view. This is called when loading the view. Once all views are attached to the browser DOM a call to the graph'scalcBounds(int, int)
is triggered throughsetBounds(int, int)
to properly calculate the layout.- See Also:
-
destroyGraphs
protected void destroyGraphs()Destroy all graphs in this view and free up resources. -
getType
Description copied from interface:AbstractGraph.Controller
Get the type of data visualized on the graph.- Specified by:
getType
in interfaceAbstractGraph.Controller
- Returns:
- the data type
-
getModel
Description copied from interface:AbstractGraph.Controller
Get the type of the model supplying the data visualized on the graph.- Specified by:
getModel
in interfaceAbstractGraph.Controller
- Returns:
- the model type
-
getLogger
Description copied from interface:AbstractGraph.Controller
Get the logger for returning progress, problems and messages to user.- Specified by:
getLogger
in interfaceAbstractGraph.Controller
- Returns:
- the logger for messages
-
activate
public void activate()Activate the view. This is called when the view is selected in the view selector. -
deactivate
public void deactivate()Deactivate the view. This is called when another view is selected in the view selector. -
clear
public void clear()Clear the view. -
hasLayout
public boolean hasLayout()Check if the view has finished layouting its graphs. Currently onlyGenericPop
and its graphs require layouting.- Returns:
true
if the view has layout- See Also:
-
layoutComplete
public void layoutComplete()Description copied from interface:AbstractGraph.Controller
Notifies the controller of the completion of the layouting process.- Specified by:
layoutComplete
in interfaceAbstractGraph.Controller
-
getMode
Get the mode of this view. The graphical visualizations can request different modes for running the model. The default mode isMode.DYNAMICS
to generate a time series of the states of the model. Some views may digest data and, for example, show statistics such as fixation probabilities or times, in which case the modeMode.STATISTICS_SAMPLE
orMode.STATISTICS_UPDATE
should be requested.- Returns:
- the mode of this view
- See Also:
-
setMode
Set the mode of the model tomode
. Does nothing if the model does not support the requested mode.- Parameters:
mode
- the mode to set- Returns:
true
if the mode was successfully set
-
getStatus
Get the status of this view. Views that aggregate data may want to provide custom status information. HTML formatting is acceptable.- Returns:
- the status of this view
-
getStatus
Get the status of this view. Views that aggregate data may want to provide custom status information. HTML formatting is acceptable. Some status updates may be expensive to compute and views may decide to ignore thegetStatus
request, except ifforce
istrue
.- Parameters:
force
- whether to force an update of the status- Returns:
- the status of this view
-
moduleRestored
public void moduleRestored()Description copied from interface:MilestoneListener
Called when the state of the EvoLudo module has been restored.- Specified by:
moduleRestored
in interfaceMilestoneListener
-
modelDidReset
public void modelDidReset()Description copied from interface:MilestoneListener
Called after the EvoLudo model was reset.- Specified by:
modelDidReset
in interfaceMilestoneListener
-
reset
public void reset(boolean hard) Called when a module has been reset. All graphs are reset and updated if needed, unlesshard
istrue
.- Parameters:
hard
- the flag to indicate whether to do a hard reset
-
modelDidInit
public void modelDidInit()Description copied from interface:MilestoneListener
Called after the EvoLudo model got re-initialized.- Specified by:
modelDidInit
in interfaceMilestoneListener
-
modelStopped
public void modelStopped()Description copied from interface:MilestoneListener
Called after a running EvoLudo model stopped because the model converged (or reached an absorbing state).- Specified by:
modelStopped
in interfaceMilestoneListener
-
modelChanged
Description copied from interface:ChangeListener
Called whenever the state of the EvoLudo model changed. Process potentially pending requests.Note: the model may process some pending actions directly and without notifying the listeners through
modelChanged(PendingAction)
first. In particular, this applies to pending actions that fire their own notifications, such asRESET
andINIT
that in turn triggermodelReset()
andmodelInit()
, respectively.- Specified by:
modelChanged
in interfaceChangeListener
- Parameters:
action
- pending action that needs to be processed.- See Also:
-
update
public void update()Called when the view needs updating. This gets called when the selected view changed or new data is available from the model.- See Also:
-
update
public abstract void update(boolean force) Called when the view needs updating. This gets called when the selected view changed or new data is available from the model. Views may ignore updating requests unlessforce
istrue
.- Parameters:
force
-true
to force the update
-
isRunning
public boolean isRunning()Description copied from interface:AbstractGraph.Controller
Checks if the controller is busy running calculations.- Specified by:
isRunning
in interfaceAbstractGraph.Controller
- Returns:
true
if calculations are running
-
shift
public void shift(int dx, int dy) Default implementation for synchronized shifting of multiple graphs.- Parameters:
dx
- the shift in x-directiondy
- the shift in y-direction- See Also:
-
zoom
public void zoom(double zoom, int x, int y) Default implementation for synchronized zooming of multiple graphs. The center for zooming is given by the coordinates(x,y)
.- Parameters:
zoom
- the zoom factorx
- the x-coordinatey
- the y-coordinate- See Also:
-
keyDownHandler
Opportunity for view to implement keyboard shortcut for actions (repeating). If the key remains pressed this event is triggered repeatedly.- Parameters:
key
- the code of the pressed key- Returns:
true
if the key was handled- See Also:
-
keyUpHandler
Opportunity for view to implement keyboard shortcut for actions (non repeating). For example to clear the display or export graphics.List of shortcuts provided by all views for the following keys:
S
- Export snapshot of view in the Scalable Vecorized Graphics format,
svg
(if available). P
- Export snapshot of view as a bitmap in the Portable Network Graphic
format,
png
(if available). C
- Export data of model as in the Comma Separated Values format,
csv
(if available). For example, this can be used to export the raw statistical data obtained from fixation probability calculations. F
- Toggle full screen mode of data view without controls (if available).
- Parameters:
key
- the code of the released key- Returns:
true
if the key was handled
-
hasExportType
Checks if the view supports the export typetype
.- Parameters:
type
- the export type to check- Returns:
true
if the view supports the export type
-
onResize
public void onResize()- Specified by:
onResize
in interfaceRequiresResize
-
setBounds
public void setBounds(int width, int height) Set the bounds of the view to the givenwidth
andheight
. This is called when loading the views or changing the size of the GUI.- Parameters:
width
- the width of the viewheight
- the height of the view
-
scheduleUpdate
protected void scheduleUpdate(boolean force) Schedule an update of the view. If an update is already scheduled subsequent requests are ignored.- Parameters:
force
-true
to force the update- See Also:
-
getGraphAt
Get the graph at the coordinates(x,y)
.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the graph at the coordinates
(x,y)
-
populateContextMenu
Description copied from interface:AbstractGraph.Controller
Opportunity for the controller to add functionality to the context menu (optional implementation).- Specified by:
populateContextMenu
in interfaceAbstractGraph.Controller
- Parameters:
contextMenu
- the context menu
-
exportTypes
Return the list of export types that are acceptable for _all_ graphs in this view.- Returns:
- the list of viable export types
-
export
Export the data of the view.- Parameters:
type
- the type of data to export
-
exportPNG
protected void exportPNG()Export the view as a PNG image. -
exportSVG
protected void exportSVG()Export the view as a SVG image. -
export
Export each graph in this view.- Parameters:
ctx
- the graphical context of the canvas to export toscale
- the scaling for the export canvas
-
exportDataHeader
The header for data exports.- Returns:
- the header as a string builder
-
exportStatData
protected void exportStatData()Export the statistics data.Important: Must be overridden by subclasses that return
AbstractView.ExportType.STAT_DATA
among their export data types.- See Also:
-
exportMeanData
protected void exportMeanData()Export the mean data. By default this returns the buffer data as a comma separated list.- See Also:
-
exportTrajData
protected void exportTrajData()Export the trajectories. By default this returns the buffer data as a comma separated list.- See Also:
-