Class AbstractView<G extends AbstractGraph<?>>
- Type Parameters:
G- the concrete graph type rendered inside the view
- All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, ProvidesResize, RequiresResize, ChangeListener, LifecycleListener, RunListener, SampleListener
- Direct Known Subclasses:
Console, Distribution, GenericPop, Histogram, Mean, Phase2D, S3
public abstract class AbstractView<G extends AbstractGraph<?>>
extends Composite
implements RequiresResize, ProvidesResize, LifecycleListener, RunListener, SampleListener, 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.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.(package private) StringThe string with view specific options.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
ConstructorsModifierConstructorDescriptionprotectedAbstractView(EvoLudoGWT engine, Data type) The constructor for the abstract view. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activate the view.protected abstract booleanAllocate all graphs managed by this view.voidDeactivate the view.protected voidDestroy all graphs in this view and free up resources.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.(package private) ModegetMode()Get the mode required by 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.booleanisActive()Checks if the controller is busy running calculations.booleanChecks if the controller is busy running calculations.voidNotification 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.voidmouseHitNode(int id, int node) Notifies the controller that the mouse/tap has hit node with indexnodeon the graph with the tagid.voidmouseHitNode(int id, int node, boolean alt) Notifies the controller that the mouse/tap has hit node with indexnodeon the graph with the tagid.booleanOpportunity for view to implement keyboard shortcut for actions (repeating).booleanOpportunity for view to implement keyboard shortcut for actions (non repeating).voidonResize()protected voidonUnload()booleanparse()Parse the arguments provided to this view.voidpopulateContextMenu(ContextMenu contextMenu) Opportunity for the controller to add functionality to the context menu (optional implementation).voidpopulateContextMenuAt(ContextMenu menu, int node) 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.booleansetInitialState(double[] init) Notifies the controller that the user requested setting a new initial configurationinit(optional implementation).voidsetOptions(String options) Set the options string for this view.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, 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 LifecycleListener
modelLoaded, moduleLoadedMethods inherited from interface RunListener
modelRelaxed, modelRunning, modelSettingsMethods inherited from interface SampleListener
modelSample
-
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. -
options
-
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- Note:
- A
LayoutPanelinstead of aFlowPanelwould be a nice way to continue the onResize cascade but incompatible with current implementation of context menu and tooltips
-
-
Method Details
-
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:LifecycleListenerCalled when EvoLudo module is unloading.- Specified by:
moduleUnloadedin interfaceLifecycleListener
-
modelUnloaded
public void modelUnloaded()Description copied from interface:LifecycleListenerCalled when EvoLudo model is unloading.- Specified by:
modelUnloadedin interfaceLifecycleListener
-
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. -
onUnload
-
setOptions
Set the options string for this view.- Parameters:
options- the options string
-
parse
public boolean parse()Parse the arguments provided to this view. The default implementation simply passes the currently configured option string to all graphs.- Returns:
trueif the arguments were successfully parsed
-
allocateGraphs
protected abstract boolean 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.- Returns:
trueif graphs were (re)allocated- See Also:
-
destroyGraphs
protected void destroyGraphs()Destroy all graphs in this view and free up resources. -
getType
-
getModel
Get the type of the model supplying the data visualized on the graph.- Returns:
- the model type
-
getLogger
Get the logger for returning progress, problems and messages to user.- 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. -
getMode
-
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()Notification of the completion of the layouting process. -
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:LifecycleListenerCalled when the state of the EvoLudo module has been restored.- Specified by:
moduleRestoredin interfaceLifecycleListener
-
modelDidReset
public void modelDidReset()Description copied from interface:RunListenerCalled after the EvoLudo model was reset.- Specified by:
modelDidResetin interfaceRunListener
-
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:RunListenerCalled after the EvoLudo model got re-initialized.- Specified by:
modelDidInitin interfaceRunListener
-
modelStopped
public void modelStopped()Description copied from interface:RunListenerCalled after a running EvoLudo model stopped because the model converged (or reached an absorbing state).- Specified by:
modelStoppedin interfaceRunListener
-
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
-
isActive
public boolean isActive()Checks if the controller is busy running calculations.- Returns:
trueif calculations are running
-
isRunning
public boolean isRunning()Checks if the controller is busy running calculations.- Returns:
trueif calculations are running
-
setInitialState
public boolean setInitialState(double[] init) Notifies the controller that the user requested setting a new initial configurationinit(optional implementation).- Parameters:
init- the new initial configuration- Returns:
trueif the request was honoured
-
mouseHitNode
public void mouseHitNode(int id, int node) Notifies the controller that the mouse/tap has hit node with indexnodeon the graph with the tagid.- Parameters:
id- the id of the graphnode- the index of the node that was hit
-
mouseHitNode
public void mouseHitNode(int id, int node, boolean alt) Notifies the controller that the mouse/tap has hit node with indexnodeon the graph with the tagid. The flagaltindicates whether thealt-modifier was pressed (optional implementation).- Parameters:
id- the id of the graphnode- the index of the node that was hitalt-trueif thealt-key was pressed
-
populateContextMenuAt
Opportunity for the controller to add functionality to the context menu (optional implementation). Additional entries should be added tomenu. If the context menu was opened while the mouse was over a node its index isnode. At this point the menu already contains entries that are relevant for all graphs, e.g. fullscreen and export. Override this method to add further, more specialized entries. Finally, the current pane will be asked whether it wants to add further entries (e.g. autoscale axes) (optional implementation).- Parameters:
menu- the context menunode- the index of node- See Also:
-
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:
-
onKeyDown
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:
-
onKeyUp
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
Opportunity for the controller to add functionality to the context menu (optional implementation).- 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.CSV_STATamong 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:
-