Class MapCanvas.Renderer

Object
Renderer
Direct Known Subclasses:
Map­Canvas­AWT​.Renderer
Enclosing class:
Map­Canvas

protected abstract static class MapCanvas.Renderer extends Object
A snapshot of Map­Canvas state to render as a map, together with rendering code. This class is instantiated and used as below:
  1. Map­Canvas invokes Map­Canvas​.create­Renderer() in the JavaFX thread. That method shall take a snapshot of every information needed for performing the rendering in a background thread.
  2. Map­Canvas invokes render() in a background thread. That method creates or updates the nodes to show in the canvas but without reading or writing any canvas property; that method should use only the snapshot taken in step 1.
  3. Map­Canvas invokes commit(Map­Canvas) in the JavaFX thread. The nodes prepared at step 2 can be transferred to Map­Canvas​.floating­Pane in that method.
Since:
1.1
  • Constructor Details

    • Renderer

      protected Renderer()
      Creates a new renderer. The width and height are initially zero; they will get a non-zero values before render() is invoked.
  • Method Details

    • getWidth

      public int getWidth()
      Returns the width (number of columns) of the view, in pixels.
      Returns:
      number of pixels to render horizontally.
    • getHeight

      public int getHeight()
      Returns the height (number of rows) of the view, in pixels.
      Returns:
      number of pixels to render vertically.
    • render

      protected abstract void render() throws Exception
      Invoked in a background thread for rendering the map. This method should not access any Map­Canvas property; if some canvas properties are needed, they should have been copied at construction time.
      Throws:
      Exception - if an error occurred while preparing data or rendering them.
    • commit

      protected abstract boolean commit(MapCanvas canvas)
      Invoked in JavaFX thread after render() completion. This method can update the Map­Canvas​.floating­Pane children with the nodes (images, shaped, etc.) created by render().
      Parameters:
      canvas - the canvas where drawing has been done.
      Returns:
      true on success, or false if the rendering should be redone (for example because a change has been detected in the data).