Class EvoLudoWeb

All Implemented Interfaces:
EntryPoint, HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsRenderable, IsWidget, CLOProvider

public class EvoLudoWeb extends Composite implements CLOProvider, EntryPoint

EvoLudoWeb

Top-level GUI controller for an EvoLudo laboratory instance running in a GWT environment (browser or ePub). This class implements the primary user interface and coordinates between the GWT widgets, the EvoLudo engine (EvoLudoGWT), and a collection of AbstractView implementations that render model data. It provides lifecycle integration with GWT (EntryPoint, onModuleLoad/onLoad/onUnload), runtime control of the engine (start/stop, init/reset, step/debug), management of command-line options (CLO), keyboard and drag-and-drop handlers, export/import of state, as well as ePub-specific accommodations.

Responsibilities

  • Create and bind the GUI widgets declared in the accompanying UiBinder template.
  • Instantiate and configure the EvoLudoGWT engine and its logger and Console view.
  • Parse and apply command-line options (CLO) to load modules and models, configure views, and restore saved state.
  • Maintain and update a dynamic list of active data views for the running model, showing only the appropriate views for module/model features (2D/3D populations, histograms, statistics, console).
  • Provide keyboard shortcuts and a JS-friendly key listener mechanism (via JSNI) that reliably receives global key events even if GWT's default handlers lose focus.
  • Support drag-and-drop of saved state files, including integrating optional JavaScript zip handling when needed.
  • Handle fullscreen events and resizing, and provide a snapshot-ready signal for automated site capture.
  • Adjust behavior for ePub contexts (inline flow vs standalone page), disabling editing, console, and drag-and-drop where necessary.
  • Expose helper JS entry points to create/insert labs or triggers from external JavaScript (createEvoLudoLab, insertEvoLudoLab, insertEPubEvoLudoLab, createEvoLudoTrigger).

Lifecycle

- onModuleLoad(): scans the DOM for marker elements (evoludo-simulation and evoludo-trigger-html) and replaces them with interactive labs or trigger buttons.
- onLoad(): called when the widget is attached; sets up the engine, logger, console, fullscreen element, and applies any CLO present.
- onUnload(): attempts to gracefully shut down the engine, clear the console and remove global listeners. Care is taken to avoid throwing exceptions during unload to keep GWT module reloads stable.

Command-Line Options (CLO)

The class supplies and consumes CLO options that control initial view and GUI size/fullscreen. It provides an editable CLO field in the UI (unless disabled for ePubs), an Apply button (or Standalone link in ePubs), and a Default button to revert to initial settings. The applyCLO() flow: parse CLO, update engine/module/model, load and size views, restore state if present, and activate/resume execution according to parsed flags (e.g. --run, --snap, --samples).

Views and Display

EvoLudoWeb keeps a DeckLayoutPanel (evoludoDeck) that displays exactly one view at a time, while ViewController manages the available views and selection state. Views are created or reused based on module capabilities and model type. Views are responsible for rendering, while EvoLudoWeb orchestrates loading, sizing, activation, deactivation, and disposal. The Console view is treated specially and may be omitted in restricted ePub modes.

Input Handling and Shortcuts

Global keyboard handling is implemented through KeyHandler to provide reliable shortcuts that control the engine and UI. The controller distinguishes between repeating actions (handled on key down) and non-repeating actions (handled on key up) while JSNI routines install window-level listeners that delegate to the controller. Touch interaction variants are supported for critical controls (Start/Stop, Init/Reset, Settings).

Drag-and-Drop and State Restore

The widget supports drag-and-drop of saved state files. It verifies data transfer validity and, when necessary, injects a JavaScript ZIP handler to decompress archives. Restored state is parsed into a Plist, applied to the engine, and the GUI reconfigured to reflect the restored model and settings.

Logging

Logging is routed through the engine's Logger. EvoLudoWeb installs a custom EvoLogHandler that mirrors important messages to the on-screen Console and to the status line (for warnings/errors). Help text and preformatted blocks are handled carefully to preserve formatting and safe encoding for XML/XHTML contexts and ePubs.

Concurrency and Threading

GWT executes UI work on the browser main thread. EvoLudoWeb schedules deferred actions via the Scheduler where appropriate and ensures that model state changes (start/stop/reset) are requested via the engine's request APIs. No internal multithreading beyond browser event callbacks is used.

Extension Points

  • Views: Implement AbstractView to add new visualizations. EvoLudoWeb will discover and include them based on module interfaces and model type.
  • CLO Providers: EvoLudoWeb implements CLOProvider to contribute GUI related options and to react when the engine parses command-line arguments.
  • FullscreenChangeHandler: the class listens for fullscreen changes to apply styling and sizing changes.

ePub Behaviour

EvoLudoWeb adapts to ePub readers: inline labs in an ePub may have editing, drag-and-drop, and console functionality disabled to accommodate reader restrictions. If the lab is on a standalone ePub page, full interactivity is allowed. Special workarounds are applied for known platform quirks (e.g. Apple Books/touch event handler injection).

Generic reader notes:
  1. button elements do not work in ePub's and hence trigger-'buttons' must be provided as anchor elements.

Apple Books:

  1. challenges for passing information to non-linear page (clo parameters)
    • parameters and hash cleared from url before opening non-linear page
    • non-linear page has no opener, referrer, parent to link to calling document
    • no need to read data-clo of triggers because parameters cannot be reliably transmitted to popup lab; besides, it would be much easier to simply append the data to the URL.
    • localStorage does not reliably work (>=2sec delay is required between setting the local variable and opening EvoLudoLab.xhtml...)
    • changes to localStorage do not fire storage events
    Solution: programmatically create individual XHTML pages for each lab, which includes the correct parameters in the data-clo tag, and link to that page.
  2. need to do something about touch events on desktop...
    • attaching touch handlers to triggers does nothing
    • Apple's TouchEvents.js patch does not play nicely with GWT
    • patch seems to prevent marking/highlighting of text passages. worth verifying and filing bug report with Apple if this is indeed the case?
    Solution: inject script TouchEventsGWT.js for iBooks without touch-events to patch the patch. this could probably be done in a JSNI routine.
  3. events in ePubs:
    • iBooks does not fire 'wheel' or 'scroll' events (i.e. zooming does not work) for labs in the flow of the text; no point in adding them to the canvas(es). however, ok in non-linear labs!
    • key events are sent (at least) to all labs in current chapter (isShowing does not work because it's impossible (?) to determine current page visible...); do not process key events for labs in the flow of the text (except maybe 'Alt'?). however, ok in non-linear labs!
    • check for full screen capabilities causes flicker in iBooks (ugly...); seems to be related to key event handing (never observed for context menu); should be resolved by disabling key handler;
    Solution: for labs in text flow 'wheel', 'key' and 'fullscreen' events disabled ('Alt' still processed, if ePub has 'key-events') but not in standalone labs. As a consequence, labs in text also do not include console (impossible to scroll...).
  4. use different GUI elements in ePub
    • parameters in evoludoCLO text area are not read-only but essentially impossible to enter or edit anything; parameters should be read-only (mark with grey text color or similar); disable 'Apply' button, change 'Default' button to 'Standalone/External' lab opening a non-linear page or redirecting to evoludo.org, respectively (use 'Alt' key).
    Solution: evoludoCLO is read only for labs in text flow. 'Apply' and 'Help' buttons disabled (no console to display help text because of scrolling issues). 'Default' button is repurposed to open standalone lab.
  5. Clicks on button text do work for starting simulations but not for stopping them... clicking on the button next to its text works as expected.

Adobe Digital Editions

  1. non-linear pages are appended to the end, which makes returning to the corresponding text location impossible (somehow a marker should be set to allow using the back button).

Usage

  1. Place a <div class="evoludo-simulation"> in the HTML with an optional data-clo attribute or supply "clo" in the URL. The module will instantiate EvoLudoWeb for each such element during onModuleLoad().
  2. Alternatively, call the exported JavaScript helpers to create or insert labs dynamically.
  3. Interact with the lab through the provided GUI or keyboard shortcuts. Use Apply/Default to manage parameters and use Export/drag-and-drop to save/restore state.

Implementation notes: this class is designed to be a single, self-contained controller per DOM container element. It expects to run within the GWT environment and to co-operate with EvoLudoGWT, the Model/Module abstraction, and various AbstractView subclasses. It uses JSNI for some browser integration and therefore relies on the presence of the window object and typical browser DOM APIs.

See Also:
  • Field Details

    • uiBinder

      private static EvoLudoWeb.EvoLudoWebBinder uiBinder
      GWT magic to create GUI elements (see EvoLudoWeb.ui.xml).
    • updatetime

      protected double updatetime
      Time of last GUI update
    • settingsController

      private SettingsController settingsController
      Controller for ePub specific behaviour and emulation.
    • engine

      EvoLudoGWT engine
      Controller. Manages the interface with the outside world.
    • keyController

      private final KeyHandler keyController
      Helper that centralizes keyboard handling.
    • logger

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

      protected EvoLudoWeb.EvoLogHandler logEvoHandler
      Handler for the log framework to report notifications etc. in EvoLudo's console
    • dragEnterHandler

      HandlerRegistration dragEnterHandler
      Reference to registration of drag'n'drop handlers.
    • dragLeaveHandler

      HandlerRegistration dragLeaveHandler
      Reference to registration of drag'n'drop handlers.
    • elementID

      String elementID
      ID of element in DOM that contains the EvoLudo lab.
    • viewController

      private ViewController viewController
      Controller managing all data views and the evoludoDeck.
    • webListener

      WebListener webListener
      Controller managing Lifecycle, Run, Sample, and Change events.
    • viewConsole

      Console viewConsole
      Console view requires slightly special treatment to ensure results of early feature detection get reported.
    • fsController

      private FSController fsController
      Controller handling fullscreen and --size option.
    • DOM_DATA_CLO

      static final String DOM_DATA_CLO
      Attribute name for command line options in DOM elements.
      See Also:
    • evoludoPanel

      @UiField HTMLPanel evoludoPanel
      Outermost panel containing the EvoLudo GUI.
    • evoludoResize

      Panel implementing the ability to resize the GUI of EvoLudo models (only possible in browser or standalone mode in ePubs).
    • evoludoLayout

      @UiField HeaderPanel evoludoLayout
      Basic layout of EvoLudo model GUI with header (for time display, evoludoTime, and view selector evoludoViews), footer (for delay slider evoludoSlider, control buttons evoludoSettings, evoludoInitReset, evoludoStartStop, evoludoStep and status line evoludoStatus plus possibly parameters evoludoCLOPanel) as well as the main content area (for different canvases, evoludoDeck).
    • evoludoTime

      @UiField Label evoludoTime
      Label to display elapsed generations (time).
    • evoludoViews

      @UiField ListBox evoludoViews
      Selector for all graphical representations to visualize the state of the EvoLudo model.
    • evoludoDeck

      Panel containing all the canvas elements to display the EvoLudo model's data. Only one is shown at any time, selected by evoludoViews.
    • evoludoSlider

      @UiField Slider evoludoSlider
      Slider adjusting the delay between updates.
    • BUTTON_SETTINGS

      static final String BUTTON_SETTINGS
      Label of button to show/hide parameter settings.
      See Also:
    • BUTTON_START

      static final String BUTTON_START
      Label of button to start model.
      See Also:
    • BUTTON_STOP

      static final String BUTTON_STOP
      Label of button to stop model.
      See Also:
    • BUTTON_INIT

      static final String BUTTON_INIT
      Label of button to initialize model.
      See Also:
    • BUTTON_RESET

      static final String BUTTON_RESET
      Label of button to reset model.
      See Also:
    • BUTTON_STEP

      static final String BUTTON_STEP
      Label of button to advance model by one step.
      See Also:
    • BUTTON_DEBUG

      static final String BUTTON_DEBUG
      Label of button to advance model by single microscopic step.
      See Also:
    • BUTTON_SAMPLE

      static final String BUTTON_SAMPLE
      Label of button to collect one statistics sample.
      See Also:
    • BUTTON_PREV

      static final String BUTTON_PREV
      Label of button to reverse on step.
      See Also:
    • BUTTON_HELP

      static final String BUTTON_HELP
      Label of button to show help.
      See Also:
    • evoludoSettings

      @UiField Button evoludoSettings
      'Settings' button
    • evoludoInitReset

      @UiField Button evoludoInitReset
      The 'Init'/'Reset' button
    • showAltTouchTimer

      protected Timer showAltTouchTimer
      On touch devices, the Init button changes to Reset for extended touches. This timer controls the delay before Reset is shown. Any other touch event during this period cancels the timer.
    • evoludoStartStop

      @UiField Button evoludoStartStop
      The 'Start'/'Stop' button
    • evoludoStep

      @UiField Button evoludoStep
      The 'Step' button
    • evoludoCLOPanel

      @UiField FlowPanel evoludoCLOPanel
      Panel containing all elements to change/view parameters. Visibility toggled with the 'Settings' button, evoludoSettings. Initially invisible.
    • evoludoCLO

      @UiField Label evoludoCLO
      The text field containing the command line options for the EvoLudo model. Note, TextArea causes grief with ePubs in Apple Books.
    • evoludoApply

      @UiField Button evoludoApply
      The 'Apply' button ('Standalone' in ePubs)
    • guiState

      Field to store the current state of the GUI while applying a new set of parameters.
    • evoludoDefault

      @UiField Button evoludoDefault
      The 'Default' button
    • evoludoHelp

      @UiField Button evoludoHelp
      The 'Help' button
    • TAG_PRE_OPEN

      static final String TAG_PRE_OPEN
      Opening tag of pre-formatted text.
      See Also:
    • TAG_PRE_CLOSE

      static final String TAG_PRE_CLOSE
      Closing tag of pre-formatted text.
      See Also:
    • evoludoStatus

      @UiField HTML evoludoStatus
      Status line of EvoLudo model GUI.
    • displayStatusThresholdLevel

      private int displayStatusThresholdLevel
      Threshold level for overriding status message.
    • deferStatusThresholdReset

      private boolean deferStatusThresholdReset
      Defer resetting the status threshold until after the loading sequence completes.
    • evoludoOverlay

      @UiField HTML evoludoOverlay
      Overlay for drag'n'drop operations
    • hasZipJs

      private static boolean hasZipJs
      The helper variable to indicate JavaScript for dealing with zip archives has already been loaded.
    • snapmarker

      private DivElement snapmarker
      Marker element to indicate that a snapshot is ready.
      See Also:
  • Constructor Details

    • EvoLudoWeb

      private EvoLudoWeb()
      Note: empty default constructor seems to be required by GWT. Why? At least it does not need to be publicly exposed.
    • EvoLudoWeb

      public EvoLudoWeb(String id, EvoLudoTrigger.LightboxPanel popup)
      Constructor restricted to trigger buttons that create an overlay displaying an EvoLudo lab.
      Parameters:
      id - of trigger element in DOM (unique and automatically generated, onModuleLoad().
      popup - semi-transparent overlay
    • EvoLudoWeb

      public EvoLudoWeb(String id, String clo)
      Main constructor for EvoLudo labs.

      Note:

      • If id==null the default ID elementID is used
      • Attempts to fail gracefully if no element with id exists in DOM or if the HTML5 canvas element is not supported.
      Parameters:
      id - the DOM id of the element containing the lab
      clo - the string with the command line options
  • Method Details

    • onModuleLoad

      public void onModuleLoad()
      Entry point method. Process DOM and add/allocate an EvoLudo lab whenever a <div> element with class="evoludo-simulation" is found. Parameters may be passed to the EvoLudo lab either through the data-clo attribute or as part of the URL as a parameter clo. Similarly, <div> elements with class="evoludo-trigger-html" are converted to buttons that trigger a popup EvoLudo lab. Buttons do not work in ePub's and hence trigger-'buttons' must be provided as anchor elements.
      Specified by:
      onModuleLoad in interface EntryPoint
    • processEvoLudoLabs

      private void processEvoLudoLabs()
      Process DOM and add/allocate an EvoLudo lab whenever a <div> element with class="evoludo-simulation" is found.

      The first lab found is passed any command line options specified in the URL (parameter clo). Any subsequent labs need to specify command line options through the data-clo attribute.

    • addEvoLudoToDOM

      private void addEvoLudoToDOM(Element labElement, String clo)
      Add an EvoLudo lab to the DOM element with the given ID. If the ID is null or empty, a unique ID is generated. If clo is null or empty, the data-clo attribute is read and used to set the command line options for the lab.
      Parameters:
      labElement - the DOM element representing the lab
      clo - the command line options for the lab
    • getCLOFromURL

      private String getCLOFromURL()
      Extract command line options from URL parameter clo.
      Returns:
      the command line options
    • processEvoLudoTriggers

      private void processEvoLudoTriggers()
      Process DOM and replace all <div> elements with class="evoludo-trigger-html" by a button that triggers a popup EvoLudo lab.

      Note: buttons do not work in ePub's and hence trigger-'buttons' must be provided as anchor elements.

    • onLoad

      public void onLoad()

      Called when loading GWT application. The contents of evoludoCLO serve as the command line options. If evoludoCLO is empty, the data-clo attribute of the lab element is checked for command line options.

      Overrides:
      onLoad in class Widget
    • setupEngine

      private void setupEngine()
      Create EvoLudo engine and load modules.
    • resetViewSelection

      public void resetViewSelection()
      Reset the current view selection to the default entry.
    • clearCommandLineOptions

      public void clearCommandLineOptions()
      Clear the command line option field in the GUI.
    • resetStatusThreshold

      public void resetStatusThreshold()
      Restore the default log threshold (display all severities).
    • handleModelDidReset

      public void handleModelDidReset()
      Handle model reset event.
    • setupLogger

      private void setupLogger(EvoLudoGWT engine)
      Retrieve the logger and setup the log handler.
      Parameters:
      engine - the EvoLudo engine
    • setupConsole

      private void setupConsole(Logger logger)
      Setup the EvoLudo console to display log messages.
      Parameters:
      logger - the logger instance
    • onUnload

      public void onUnload()

      Called when unloading GWT application. Housekeeping routine to clean up and free as many resources as possible. For example, ensures that EvoLudo model stops running, removes lab from key listeners, removes drag'n'drop handler, unloads model.

      Important: ensure that no errors/exceptions are thrown here! All errors/exceptions are caught and ignored, which results in incomplete unloading and most likely subsequent re-loading of module will fail. A good indicator is if the info message "Module XYZ unloaded" appears in log.

      Overrides:
      onUnload in class Widget
    • updateGUI

      public void updateGUI()
      Update GUI for running/stopped model.
    • updateStatus

      public void updateStatus()
      Helper method to update status of GUI.
    • updateCounter

      public void updateCounter()
      Helper method to update counter of GUI.
    • onViewChange

      @UiHandler("evoludoViews") public void onViewChange(ChangeEvent event)
      Handler for changes of the view selector (evoludoViews).
      Parameters:
      event - the ChangeEvent that was fired
    • changeViewTo

      protected void changeViewTo(AbstractView<?> newView)
      Change view of EvoLudo model data. This helper method is called when the user selects a new view with the popup list evoludoViews or when a particular view is requested through command line options (see ViewController.getCloView()).
      Parameters:
      newView - new view of model data to display
    • changeViewTo

      protected void changeViewTo(AbstractView<?> newView, boolean force)
      Change view of EvoLudo model data. This helper method is called when the user selects a new view with the popup list evoludoViews or when a particular view is requested through command line options (see ViewController.getCloView()). The view is re-activated if force is true and activation is skipped if the view didn't change and force is false.
      Parameters:
      newView - new view of model data to display
      force - if true the view is re-activated even if it didn't change
    • getActiveViews

      public List<AbstractView<?>> getActiveViews()
      Return the list of all active views.
      Returns:
      the list of all active views (console included)
    • getActiveView

      public AbstractView<?> getActiveView()
      Return the currently active view.
      Returns:
      the active view.
    • getActiveViewIndex

      public int getActiveViewIndex()
      Return the index of the currently active view in the list of active views.
      Returns:
      the index of the active view inside the deck or -1.
    • changeView

      public void changeView(AbstractView<?> view)
      Switches to the provided view.
      Parameters:
      view - the new view to display
    • onSliderClick

      @UiHandler("evoludoSlider") public void onSliderClick(ClickEvent event)
      Slider changed, adjust delay between updates. This event is triggered when clicking or taping on the slider (surprisingly, this does not trigger an InputEvent).
      Parameters:
      event - the ClickEvent that was fired
    • onSliderInput

      @UiHandler("evoludoSlider") public void onSliderInput(InputEvent event)
      Slider changed, adjust delay between updates. This event is triggered when programmatically changing the slider settings, e.g. after processing key events to increase/decrease delay or when sliding the slider with touches or the mouse.
      Parameters:
      event - the InputEvent that was fired
    • onSettingsClick

      @UiHandler("evoludoSettings") public void onSettingsClick(ClickEvent event)
      Toggle visibility of the text field evoludoCLOPanel to view or modify the parameter settings.
      Parameters:
      event - the ClickEvent that was fired
      See Also:
    • onSettingsTouchStart

      @UiHandler("evoludoSettings") public void onSettingsTouchStart(TouchStartEvent event)
      Touch of parameter button started. Suppress default behaviour (prevents magnifying glass and text selection).
      Parameters:
      event - the TouchStartEvent that was fired
    • onSettingsTouchEnd

      @UiHandler("evoludoSettings") public void onSettingsTouchEnd(TouchEndEvent event)
      Toggle visibility of evoludoCLOPanel to view or modify the parameter settings. Touch of Settings-button ended.
      Parameters:
      event - the TouchEndEvent that was fired
      See Also:
    • toggleSettings

      public void toggleSettings()
      Helper method to toggle the visibility of evoludoCLOPanel to view or modify the parameter settings.
    • getCLOElement

      public Element getCLOElement()
      Obtain the DOM element that backs the CLO label for direct manipulation.
      Returns:
      the DOM element that backs the CLO label
    • applyCLOFromField

      public void applyCLOFromField()
      Applies the text currently in the CLO field to the engine.
    • isEPubStandalone

      public boolean isEPubStandalone()
      Check if this lab is displayed as standalone page in ePub.
      Returns:
      true if a standalone
    • isEPub

      public boolean isEPub()
      Check if this lab is running inside an ePub reader.
      Returns:
      true when running inside an ePub reader.
    • isCLOPanelVisible

      public boolean isCLOPanelVisible()
      Check if the CLO settings panel is visible in the GUI.
      Returns:
      true if settings panel visible
    • closePopup

      public boolean closePopup()
      Closes the overlay containing this EvoLudo lab, if any.
      Returns:
      true if lab was closed
    • hasPopup

      public boolean hasPopup()
      Check if this lab owns a popup overlay.
      Returns:
      true if lab shown on overlay
    • getEngine

      public EvoLudoGWT getEngine()
      Return the engine that controls the EvoLudo modules.
      Returns:
      the engine
    • syncDelaySlider

      public void syncDelaySlider()
      Syncs the delay slider with the engine's current delay.
    • onInitResetClick

      @UiHandler("evoludoInitReset") public void onInitResetClick(ClickEvent event)
      Initialize or reset EvoLudo model (action depends on title of button). Button changes to Reset if Alt key is pressed and reverts to Init after it is released.
      Parameters:
      event - the ClickEvent that was fired
    • scheduleAltButtons

      private void scheduleAltButtons(TouchStartEvent event)
      Schedule showing alternate/context buttons after a long touch and prevent default handling.
      Parameters:
      event - the touch event (must not be null)
    • onInitResetTouchStart

      @UiHandler("evoludoInitReset") public void onInitResetTouchStart(TouchStartEvent event)
      Touch of Init button started. Set timer for switching to Reset. Suppress default behaviour (prevents magnifying glass and text selection).
      Parameters:
      event - the TouchStartEvent that was fired
    • onInitResetTouchEnd

      @UiHandler("evoludoInitReset") public void onInitResetTouchEnd(TouchEndEvent event)
      Touch of Init (or Reset) button ended. Take the appropriate action.
      Parameters:
      event - the TouchEndEvent that was fired
    • initReset

      public void initReset()
      Initialize or reset EvoLudo model. If model is running wait until next update is completed to prevent unexpected side effects.
    • onStartStopClick

      @UiHandler("evoludoStartStop") public void onStartStopClick(ClickEvent event)
      Start, Stop button clicked. Start EvoLudo model if not running and stop model if running. Button changes title accordingly.
      Parameters:
      event - the ClickEvent that was fired
    • onStartStopTouchStart

      @UiHandler("evoludoStartStop") public void onStartStopTouchStart(TouchStartEvent event)
      Touch of Start, Stop button started. Suppress default behaviour (prevents magnifying glass and text selection).
      Parameters:
      event - the TouchStartEvent that was fired
    • onStartStopTouchEnd

      @UiHandler("evoludoStartStop") public void onStartStopTouchEnd(TouchEndEvent event)
      Touch of Start, Stop button ended. Start EvoLudo model if not running and stop model if running. Button changes title accordingly.
      Parameters:
      event - the TouchEndEvent that was fired
    • onStepClick

      @UiHandler("evoludoStep") public void onStepClick(ClickEvent event)
      Next button clicked. Advances the EvoLudo model by a single step. If the model is running, this is ignored.
      Parameters:
      event - the ClickEvent that was fired
    • onStepTouchStart

      @UiHandler("evoludoStep") public void onStepTouchStart(TouchStartEvent event)
      Touch of Next button started. Suppress default behaviour (prevents magnifying glass and text selection).
      Parameters:
      event - the TouchStartEvent that was fired
    • onStepTouchEnd

      @UiHandler("evoludoStep") public void onStepTouchEnd(TouchEndEvent event)
      Touch of Next button ended. Advances the EvoLudo model by a single step. If the model is running, this is ignored.
      Parameters:
      event - the TouchEndEvent that was fired
    • prevNextDebug

      private void prevNextDebug()
      Helper method to advance the EvoLudo model by a single step. The label on the button determines the action:
      Step
      advances the model by a single step,
      Prev
      goes back by a single step and
      Debug
      advances the model by a single update.
    • onApplyClick

      @UiHandler("evoludoApply") public void onApplyClick(ClickEvent event)
      Apply command line parameters to EvoLudo model. For EvoLudo labs in the text flow of ePub's parameters cannot be changed and the title of the 'Apply' button is changed to 'Standalone' and opens a separate standalone EvoLudo lab, which permits parameter manipulations.
      Parameters:
      event - the ClickEvent that was fired
    • applyCLO

      public void applyCLO()
      Process and apply the command line arguments stored in evoludoCLO Loads new model (and unloads old one), if necessary, and loads/adjusts the data views as appropriate.
    • configGUI

      private void configGUI()
      Helper method to update the views after the command line options have been applied. Ensures that all views are loaded and the GUI updated.
    • processCLOSnap

      private void processCLOSnap()
      Process the command line options for snap execution, EvoLudoGWT.cloSnap, and start the model accordingly.
    • snapDynamics

      private void snapDynamics(Model activeModel)
      Helper method to process snap for dynamics mode.
      Parameters:
      activeModel - the active model
    • snapSamples

      private void snapSamples(Model activeModel)
      Helper method to process snap for statistics sample mode.
      Parameters:
      activeModel - the active model
    • loadViews

      private void loadViews(boolean resetViews)
      Helper method to update the views after the command line options have been applied. Ensures that all views are loaded, the correct sizes applied and the content reset.

      Note: many views need to know their size to adjust, for exmple, buffer sizes or data storage for statistics. However, only views that have been added to the DOM have valid sizes. For this reason the dimensions of the active view are passed to all other views.

      Parameters:
      resetViews - whether to reset view state after loading
    • revertCLO

      protected void revertCLO()
      CLOParser issues warnings for unknown options but do not throw them away (can be annoying when switching between models).
    • onDefaultClick

      @UiHandler("evoludoDefault") public void onDefaultClick(ClickEvent event)
      Discard current parameter settings and revert to default settings on initial launch of current model. For EvoLudo labs in the text flow of an ePub this button is disabled.
      Parameters:
      event - the ClickEvent that was fired
    • onHelpClick

      @UiHandler("evoludoHelp") public void onHelpClick(ClickEvent event)
      Displays a list and brief description of all parameters in the console, viewConsole, including the default and current settings. For EvoLudo labs in the text flow of an ePub this button is disabled because the console is suppressed because scrolling is prevented by ePub reader.
      Parameters:
      event - the ClickEvent that was fired
    • showHelp

      public void showHelp()
      Show help in the console, viewConsole.
    • displayStatus

      public void displayStatus(String msg)
      Displays a message in the status line of the EvoLudo GUI with the default level Level.INFO.
      Parameters:
      msg - the message to display
    • displayStatus

      public void displayStatus(String msg, int level)
      Displays a message in the status line of the EvoLudo GUI with the severity level. Status messages are only overridden by subsequent messages with the same or higher levels. The threshold level for displaying messages is reset the next time the model is initialized or reset.
      Parameters:
      msg - the message to display
      level - the severity of the message
    • onDragOver

      @UiHandler("evoludoOverlay") public void onDragOver(DragOverEvent doe)
      Handler for drag'n'drop operation entering lab.

      Note: apparently DragOverHandler is required for the DropHandler to work (no actions necessary, though).

      Parameters:
      doe - the DragOverEvent that was fired
    • onDragLeave

      @UiHandler("evoludoOverlay") public void onDragLeave(DragLeaveEvent dle)
      Handler for drag'n'drop operation exiting lab.
      Parameters:
      dle - the DragLeaveEvent that was fired
    • onDrop

      @UiHandler("evoludoOverlay") public void onDrop(DropEvent drop)
      Handler for dropping and restoring saved state.
      Parameters:
      drop - the DropEvent that was fired
    • restoreFromString

      public void restoreFromString(String filename, String content)
      Restore state of EvoLudo model from String content.
      Parameters:
      filename - (only for reference and reporting of success or failure)
      content - encoded state of EvoLudo model
    • loadZipJs

      private static void loadZipJs()
      Ensures ZIP JavaScript is loaded exactly once across all instances. Thread-safe and idempotent.
    • updateKeys

      public void updateKeys()
      The Alt-key toggles the button labels for controlling the EvoLudo lab.
    • snapshotReady

      public void snapshotReady()
      Prepare GUI to create a snapshot. Stops running model, updates GUI (buttons and view) and adds a marker element with ID snapshot-ready to DOM. This is used to control automated snapshots using capture-website.
      See Also:
    • clearSnapshotMarker

      public void clearSnapshotMarker()
      Remove the temporary DOM marker indicating that a snapshot is ready.
    • collectCLO

      public void collectCLO(CLOParser parser)
      Description copied from interface: CLOProvider
      All providers of command line options must implement this method to collect their options.

      Each command line option is (uniquely) identified by it's name (see CLOption.getName()), which corresponds to the long version of the option. If an attempt is made to add an option with a name that already exists, the parser issues a warning and ignores the option. Thus, in general, implementing subclasses should first register their options and call super.collectCLO(CLOParser) at the end such that subclasses are able to override command line options specified in a parental class.

      Override this method in subclasses to add further command line options. Subclasses must make sure that they include a call to super.

      Specified by:
      collectCLO in interface CLOProvider
      Parameters:
      parser - the reference to parser that manages command line options
      See Also:
    • createEvoLudoLab

      public static void createEvoLudoLab(String id, String clo)
      Expose method for creating EvoLudo labs (EvoLudoWeb objects) to javascript
      Parameters:
      id - the ID of element for EvoLudo lab
      clo - command line arguments of model
    • insertEvoLudoLab

      public static void insertEvoLudoLab(Element placeholder, String clo)
      Insert EvoLudo model in DOM by replacing the placeholder element.
      Parameters:
      placeholder - the placeholder element for the EvoLudo lab
      clo - command line arguments of model
    • isShowing

      public boolean isShowing()
      Check if EvoLudo model is visible on screen. This is used to determine which model should receive and process key events.

      Notes:

      1. Does not work in ePub (always returns true; apparently impossible to determine currently visible page through javascript. thus, all labs (at least within chapter) would get key events. this is not only messy but even crashes iBooks when requesting full screen.
      2. If two EvoLudo models are simultaneously visible it is undefined which lab receives the 'keypress'
      3. Popup EvoLudo models acquire all key events by activating their KeyHandler.
      Returns:
      true if lab is visible on screen
    • insertEPubEvoLudoLab

      public static void insertEPubEvoLudoLab(Element placeholder, String url)
      Fighting Apple Books constraints: Insert EvoLudo model in DOM by replacing the placeholder element with an iframe. This allows to load the lab as expected but all interactivity is disabled.
      Parameters:
      placeholder - the placeholder element for the EvoLudo lab
      url - command line arguments of model
    • exportInsertEPubEvoLudoLab

      public static void exportInsertEPubEvoLudoLab()
      JSNI method: expose method for inserting EvoLudo models into ePub to javascript.
    • exportInsertEvoLudoLab

      public static void exportInsertEvoLudoLab()
      JSNI method: expose method for inserting EvoLudo models into HTML to javascript.
    • exportCreateEvoLudoLab

      public static void exportCreateEvoLudoLab()
      JSNI method: create EvoLudo labs directly from javascript.
    • createEvoLudoTrigger

      public static void createEvoLudoTrigger(String id)
      Expose method for creating EvoLudoTriggers to javascript.
      Parameters:
      id - the ID of element for EvoLudo trigger button
    • exportCreateEvoLudoTrigger

      public static void exportCreateEvoLudoTrigger()
      JSNI method: create EvoLudo lab trigger buttons directly from javascript.
    • processEPubSettings

      protected void processEPubSettings()
      Helper method to deal with ePub specifics. If EvoLudo lab is in flow of text then the console is removed (or added if EvoLudo model is on standalone ePub page or in browser), drag'n'drop to restore states and setting of parameters are disabled (or enabled otherwise).
    • updateDropHandlers

      private void updateDropHandlers()
      Update drag-and-drop handlers after UI toggles changed the layout.
    • logFeatures

      void logFeatures()
      Log GWT features and GUI specifics.