Class AbstractView<G extends AbstractGraph<?>>

Object
UIObject
Widget
Composite
AbstractView<G>
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
  • 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 final List<G 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.
    • options

      String options
      The string with view specific options.
      See Also:
    • 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

      protected 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
      Note:
      A LayoutPanel instead of a FlowPanel would be a nice way to continue the onResize cascade but incompatible with current implementation of context menu and tooltips
  • Method Details

    • 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: LifecycleListener
      Called when EvoLudo module is unloading.
      Specified by:
      moduleUnloaded in interface LifecycleListener
    • modelUnloaded

      public void modelUnloaded()
      Description copied from interface: LifecycleListener
      Called when EvoLudo model is unloading.
      Specified by:
      modelUnloaded in interface LifecycleListener
    • 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

      protected void onUnload()
      Overrides:
      onUnload in class Widget
    • setOptions

      public void setOptions(String options)
      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:
      true if 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's calcBounds(int, int) is triggered through setBounds(int, int) to properly calculate the layout.
      Returns:
      true if graphs were (re)allocated
      See Also:
    • destroyGraphs

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

      public Data getType()
      Get the type of data visualized on the graph.
      Returns:
      the data type
    • getModel

      public Model getModel()
      Get the type of the model supplying the data visualized on the graph.
      Returns:
      the model type
    • getLogger

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

      Mode getMode()
      Get the mode required by this view.
      Returns:
      the mode required by this 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()
      Notification of the completion of the layouting process.
    • 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: LifecycleListener
      Called when the state of the EvoLudo module has been restored.
      Specified by:
      moduleRestored in interface LifecycleListener
    • modelDidReset

      public void modelDidReset()
      Description copied from interface: RunListener
      Called after the EvoLudo model was reset.
      Specified by:
      modelDidReset in interface RunListener
    • 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: RunListener
      Called after the EvoLudo model got re-initialized.
      Specified by:
      modelDidInit in interface RunListener
    • modelStopped

      public void modelStopped()
      Description copied from interface: RunListener
      Called after a running EvoLudo model stopped because the model converged (or reached an absorbing state).
      Specified by:
      modelStopped in interface RunListener
    • 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
    • isActive

      public boolean isActive()
      Checks if the controller is busy running calculations.
      Returns:
      true if calculations are running
    • isRunning

      public boolean isRunning()
      Checks if the controller is busy running calculations.
      Returns:
      true if calculations are running
    • setInitialState

      public boolean setInitialState(double[] init)
      Notifies the controller that the user requested setting a new initial configuration init (optional implementation).
      Parameters:
      init - the new initial configuration
      Returns:
      true if the request was honoured
    • mouseHitNode

      public void mouseHitNode(int id, int node)
      Notifies the controller that the mouse/tap has hit node with index node on the graph with the tag id.
      Parameters:
      id - the id of the graph
      node - 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 index node on the graph with the tag id. The flag alt indicates whether the alt-modifier was pressed (optional implementation).
      Parameters:
      id - the id of the graph
      node - the index of the node that was hit
      alt - true if the alt-key was pressed
    • populateContextMenuAt

      public void populateContextMenuAt(ContextMenu menu, int node)
      Opportunity for the controller to add functionality to the context menu (optional implementation). Additional entries should be added to menu. If the context menu was opened while the mouse was over a node its index is node. 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 menu
      node - 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-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:
    • onKeyDown

      public boolean onKeyDown(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:
    • onKeyUp

      public boolean onKeyUp(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 G 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)
      Opportunity for the controller to add functionality to the context menu (optional implementation).
      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.CSV_STAT 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: