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 TypeClassDescriptionclassThe export command triggered by the context menu entries.static enumThe available export data types: SVG scalable vector graphics format,svgPDF portable document format,pdf(not yet implemented). EPS encapsulated postscript format,eps(not yet implemented). PNG portable network graphics format,pngSTAT_DATA statistics data as comma separated list,csvTRAJ_DATA trajectory data as comma separated list,csv(not yet implemented). STATE current state of simulation,plistNested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface ChangeListener
ChangeListener.PendingAction -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected EvoLudoGWTThe reference to the EvoLudo engine that manages the simulation.protected ContextMenuThe field to store the export context submenu.protected ContextMenuItemThe field to store the export submenu trigger.(package private) intThe number of columns of graphs in this view.protected List<? extends AbstractGraph<?>> The list of graphs that are displayed in this view.(package private) intThe number of rows of graphs in this view.private static booleanThe flag to indicate whether the script for exporting SVG has been injected.(package private) booleanThe flag to indicate whether this view is currently active.(package private) booleanThe flag to indicate whether this view has been loaded.protected LoggerLogger for keeping track of and reporting events and issues.protected static final intIn order to conserve computational resources the minimum time between subsequent GUI updates has to be at leastMIN_MSEC_BETWEEN_UPDATESmilliseconds.(package private) ModelThe reference to the model that supplies the data for this graph.protected ContextMenuItemThe field to store the restore context menu.protected doubleThe timestamp of model at the last update of this view.(package private) DataThe type of data shown in this graph.private booleanThe flag to indicate whether an update is already scheduled.(package private) doubleTime of last GUI update(package private) ComplexPanelThe 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 TypeMethodDescriptionvoidactivate()Activate the view.protected abstract voidAllocate all graphs managed by this view.voidCreate the widget that will contain the graphical representations of the data.voidDeactivate the view.protected voidDestroy all graphs in this view and free up resources.voiddispose()Dispose of view.protected voidexport(AbstractGraph.MyContext2d ctx, int scale) Export each graph in this view.protected voidExport the data of the view.protected StringBuilderThe header for data exports.protected voidExport the mean data.protected voidExport the view as a PNG image.protected voidExport the statistics data.protected voidExport the view as a SVG image.protected voidExport 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 StringgetName()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 booleanChecks if the view supports the export typetype.booleanCheck if the view has finished layouting its graphs.booleanChecks if the controller is busy running calculations.booleankeyDownHandler(String key) Opportunity for view to implement keyboard shortcut for actions (repeating).booleankeyUpHandler(String key) Opportunity for view to implement keyboard shortcut for actions (non repeating).voidNotifies the controller of the completion of the layouting process.booleanload()Load the view.voidCalled whenever the state of the EvoLudo model changed.voidCalled after the EvoLudo model got re-initialized.voidCalled after the EvoLudo model was reset.voidCalled after a running EvoLudo model stopped because the model converged (or reached an absorbing state).voidCalled when EvoLudo model is unloading.voidCalled when the state of the EvoLudo module has been restored.voidCalled when EvoLudo module is unloading.voidonResize()voidpopulateContextMenu(ContextMenu contextMenu) Opportunity for the controller to add functionality to the context menu (optional implementation).voidreset(boolean hard) Called when a module has been reset.protected voidscheduleUpdate(boolean force) Schedule an update of the view.voidsetBounds(int width, int height) Set the bounds of the view to the givenwidthandheight.booleanSet the mode of the model tomode.voidshift(int dx, int dy) Default implementation for synchronized shifting of multiple graphs.voidunload()Unload the view.voidupdate()Called when the view needs updating.abstract voidupdate(boolean force) Called when the view needs updating.voidzoom(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, setWidgetMethods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEventsMethods 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, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AbstractGraph.Controller
setInitialStateMethods 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_UPDATESmilliseconds. 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:
trueif view had not been loaded- See Also:
-
moduleUnloaded
public void moduleUnloaded()Description copied from interface:MilestoneListenerCalled when EvoLudo module is unloading.- Specified by:
moduleUnloadedin interfaceMilestoneListener
-
modelUnloaded
public void modelUnloaded()Description copied from interface:MilestoneListenerCalled when EvoLudo model is unloading.- Specified by:
modelUnloadedin 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.ControllerGet the type of data visualized on the graph.- Specified by:
getTypein interfaceAbstractGraph.Controller- Returns:
- the data type
-
getModel
Description copied from interface:AbstractGraph.ControllerGet the type of the model supplying the data visualized on the graph.- Specified by:
getModelin interfaceAbstractGraph.Controller- Returns:
- the model type
-
getLogger
Description copied from interface:AbstractGraph.ControllerGet the logger for returning progress, problems and messages to user.- Specified by:
getLoggerin 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. -
hasLayout
public boolean hasLayout()Check if the view has finished layouting its graphs. Currently onlyGenericPopand its graphs require layouting.- Returns:
trueif the view has layout- See Also:
-
layoutComplete
public void layoutComplete()Description copied from interface:AbstractGraph.ControllerNotifies the controller of the completion of the layouting process.- Specified by:
layoutCompletein interfaceAbstractGraph.Controller
-
getMode
Get the mode of this view. The graphical visualizations can request different modes for running the model. The default mode isMode.DYNAMICSto 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_SAMPLEorMode.STATISTICS_UPDATEshould 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:
trueif 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 thegetStatusrequest, except ifforceistrue.- Parameters:
force- whether to force an update of the status- Returns:
- the status of this view
-
moduleRestored
public void moduleRestored()Description copied from interface:MilestoneListenerCalled when the state of the EvoLudo module has been restored.- Specified by:
moduleRestoredin interfaceMilestoneListener
-
modelDidReset
public void modelDidReset()Description copied from interface:MilestoneListenerCalled after the EvoLudo model was reset.- Specified by:
modelDidResetin interfaceMilestoneListener
-
reset
public void reset(boolean hard) Called when a module has been reset. All graphs are reset and updated if needed, unlesshardistrue.- Parameters:
hard- the flag to indicate whether to do a hard reset
-
modelDidInit
public void modelDidInit()Description copied from interface:MilestoneListenerCalled after the EvoLudo model got re-initialized.- Specified by:
modelDidInitin interfaceMilestoneListener
-
modelStopped
public void modelStopped()Description copied from interface:MilestoneListenerCalled after a running EvoLudo model stopped because the model converged (or reached an absorbing state).- Specified by:
modelStoppedin interfaceMilestoneListener
-
modelChanged
Description copied from interface:ChangeListenerCalled 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 asRESETandINITthat in turn triggermodelReset()andmodelInit(), respectively.- Specified by:
modelChangedin 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 unlessforceistrue.- Parameters:
force-trueto force the update
-
isRunning
public boolean isRunning()Description copied from interface:AbstractGraph.ControllerChecks if the controller is busy running calculations.- Specified by:
isRunningin interfaceAbstractGraph.Controller- Returns:
trueif 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:
trueif 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:
trueif the key was handled
-
hasExportType
Checks if the view supports the export typetype.- Parameters:
type- the export type to check- Returns:
trueif the view supports the export type
-
onResize
public void onResize()- Specified by:
onResizein interfaceRequiresResize
-
setBounds
public void setBounds(int width, int height) Set the bounds of the view to the givenwidthandheight. 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-trueto 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.ControllerOpportunity for the controller to add functionality to the context menu (optional implementation).- Specified by:
populateContextMenuin 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_DATAamong 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:
-