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
  • Field Details

    • engine

      protected EvoLudoGWT engine
      The reference to the EvoLudo engine that manages the simulation.
    • model

      Model model
      The reference to the model that supplies the data for this graph.
    • type

      Data type
      The type of data shown in this graph.
    • logger

      protected Logger logger
      Logger for keeping track of and reporting events and issues.
    • graphs

      protected List<? extends AbstractGraph<?>> graphs
      The list of graphs that are displayed in this view.
    • gRows

      int gRows
      The number of rows of graphs in this view.
    • gCols

      int gCols
      The number of columns of graphs in this view.
    • isActive

      boolean isActive
      The flag to indicate whether this view is currently active.
    • isLoaded

      boolean isLoaded
      The flag to indicate whether this view has been loaded.
    • timestamp

      protected double timestamp
      The timestamp of model at the last update of this view.
    • updatetime

      double updatetime
      Time of last GUI update
    • wrapper

      ComplexPanel wrapper
      The GWT widget that contains the graphical representations of the data.
    • MIN_MSEC_BETWEEN_UPDATES

      protected static final int MIN_MSEC_BETWEEN_UPDATES
      In order to conserve computational resources the minimum time between subsequent GUI updates has to be at least MIN_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 updateScheduled
      The flag to indicate whether an update is already scheduled. Subsequent requests are ignored.
    • restoreMenu

      protected ContextMenuItem restoreMenu
      The field to store the restore context menu.
    • exportSubmenuTrigger

      protected ContextMenuItem exportSubmenuTrigger
      The field to store the export submenu trigger.
    • exportSubmenu

      protected ContextMenu exportSubmenu
      The field to store the export context submenu.
    • hasSVGjs

      private static boolean hasSVGjs
      The flag to indicate whether the script for exporting SVG has been injected.
  • Constructor Details

    • AbstractView

      public AbstractView(EvoLudoGWT engine, Data type)
      The constructor for the abstract view.
      Parameters:
      engine - the EvoLudo engine
      type - 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

      public abstract String 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 interface MilestoneListener
    • modelUnloaded

      public void modelUnloaded()
      Description copied from interface: MilestoneListener
      Called when EvoLudo model is unloading.
      Specified by:
      modelUnloaded in interface MilestoneListener
    • 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's calcBounds(int, int) is triggered through setBounds(int, int) to properly calculate the layout.
      See Also:
    • destroyGraphs

      protected void destroyGraphs()
      Destroy all graphs in this view and free up resources.
    • getType

      public Data getType()
      Description copied from interface: AbstractGraph.Controller
      Get the type of data visualized on the graph.
      Specified by:
      getType in interface AbstractGraph.Controller
      Returns:
      the data type
    • getModel

      public Model getModel()
      Description copied from interface: AbstractGraph.Controller
      Get the type of the model supplying the data visualized on the graph.
      Specified by:
      getModel in interface AbstractGraph.Controller
      Returns:
      the model type
    • getLogger

      public Logger getLogger()
      Description copied from interface: AbstractGraph.Controller
      Get the logger for returning progress, problems and messages to user.
      Specified by:
      getLogger in interface AbstractGraph.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 only GenericPop 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 interface AbstractGraph.Controller
    • getMode

      public Mode getMode()
      Get the mode of this view. The graphical visualizations can request different modes for running the model. The default mode is Mode.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 mode Mode.STATISTICS_SAMPLE or Mode.STATISTICS_UPDATE should be requested.
      Returns:
      the mode of this view
      See Also:
    • setMode

      public boolean setMode(Mode mode)
      Set the mode of the model to mode. 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

      public String 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

      public String getStatus(boolean force)
      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 the getStatus request, except if force is true.
      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 interface MilestoneListener
    • modelDidReset

      public void modelDidReset()
      Description copied from interface: MilestoneListener
      Called after the EvoLudo model was reset.
      Specified by:
      modelDidReset in interface MilestoneListener
    • reset

      public void reset(boolean hard)
      Called when a module has been reset. All graphs are reset and updated if needed, unless hard is true.
      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 interface MilestoneListener
    • 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 interface MilestoneListener
    • modelChanged

      public void modelChanged(ChangeListener.PendingAction action)
      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 as RESET and INIT that in turn trigger modelReset() and modelInit(), respectively.

      Specified by:
      modelChanged in interface ChangeListener
      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 unless force is true.
      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 interface AbstractGraph.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-direction
      dy - 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 factor
      x - the x-coordinate
      y - the y-coordinate
      See Also:
    • keyDownHandler

      public boolean keyDownHandler(String key)
      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

      public boolean keyUpHandler(String key)
      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

      private boolean hasExportType(AbstractView.ExportType type)
      Checks if the view supports the export type type.
      Parameters:
      type - the export type to check
      Returns:
      true if the view supports the export type
    • onResize

      public void onResize()
      Specified by:
      onResize in interface RequiresResize
    • setBounds

      public void setBounds(int width, int height)
      Set the bounds of the view to the given width and height. This is called when loading the views or changing the size of the GUI.
      Parameters:
      width - the width of the view
      height - 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

      public AbstractGraph<?> getGraphAt(int x, int y)
      Get the graph at the coordinates (x,y).
      Parameters:
      x - the x-coordinate
      y - the y-coordinate
      Returns:
      the graph at the coordinates (x,y)
    • populateContextMenu

      public void populateContextMenu(ContextMenu contextMenu)
      Description copied from interface: AbstractGraph.Controller
      Opportunity for the controller to add functionality to the context menu (optional implementation).
      Specified by:
      populateContextMenu in interface AbstractGraph.Controller
      Parameters:
      contextMenu - the context menu
    • exportTypes

      protected AbstractView.ExportType[] exportTypes()
      Return the list of export types that are acceptable for _all_ graphs in this view.
      Returns:
      the list of viable export types
    • export

      protected void export(AbstractView.ExportType type)
      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

      protected void export(AbstractGraph.MyContext2d ctx, int scale)
      Export each graph in this view.
      Parameters:
      ctx - the graphical context of the canvas to export to
      scale - the scaling for the export canvas
    • exportDataHeader

      protected StringBuilder 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: