# Class MapCanvasAWT.Renderer

Object
MapCanvas.Renderer
Renderer

Enclosing class:
  `MapCanvasAWT`

protected abstract static class MapCanvasAWT.Renderer extends MapCanvas.Renderer
A snapshot of `MapCanvasAWT` state to paint as an image. The snapshot is created in JavaFX thread by the `MapCanvasAWT​.createRenderer()` method, then the rendering process is executed in a background thread. Methods are invoked in the following order:

Methods invoked during a map rendering process
Method | Thread | Remarks
--- | --- | ---
`MapCanvas.createRenderer()` | JavaFX thread | Collects all needed information.
`render()` | Background thread | Computes what can be done in advance.
`paint(Graphics2D)` | Background thread | Holds a `Graphics2D`.
`commit(MapCanvas)` | JavaFX thread | Saves data to cache for reuse.

This class should not access any `MapCanvasAWT` property from a method invoked in background thread (`render()` and `paint(Graphics2D)`). It may access `MapCanvasAWT` properties from the `commit(MapCanvas)` method.

Since:
  1.1

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Renderer()`
  Creates a new renderer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `commit(MapCanvas canvas)`
  Invoked in JavaFX thread after successful `paint(Graphics2D)` completion.
  `protected abstract void`
  `paint(Graphics2D gr)`
  Invoked after `render()` for doing the actual map painting.
  `protected void`
  `render()`
  Invoked in a background thread before `paint(Graphics2D)`.

  ### Methods inherited from class MapCanvas.Renderer

  `getHeight, getWidth`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Renderer

    protected Renderer()
    Creates a new renderer. The width and height are initially zero; they will get a non-zero values before `paint(Graphics2D)` is invoked.

- ## Method Details

  - ### render

    protected void render() throws Exception
    Invoked in a background thread before `paint(Graphics2D)`. Subclasses can override this method if some rendering steps do not need `Graphics2D` handler. Doing work in advance allow to hold the `Graphics2D` handler for a shorter time.

    The default implementation does nothing.

    Specified by:
      `render` in class `MapCanvas​.Renderer`
    Throws:
      `Exception` - if an error occurred while preparing data.

  - ### paint

    protected abstract void paint(Graphics2D gr)
    Invoked after `render()` for doing the actual map painting. This method is invoked in a background thread, potentially many times if `VolatileImage` content is invalidated in the middle of rendering process. This method should not access any `MapCanvas` property; if some canvas properties are needed, they should have been copied at construction time.
    Parameters:
      `gr` - the Java2D handler to use for rendering the map.

  - ### commit

    protected boolean commit(MapCanvas canvas)
    Invoked in JavaFX thread after successful `paint(Graphics2D)` completion. This method can update the `MapCanvas​.floatingPane` children with the nodes (images, shaped, etc.) created by `render()`. If this method detects that data has changed during the time `Renderer` was working in background, then this method can return `true` for requesting a new repaint. In such case that repaint will use a new `MapCanvasAWT​.Renderer` instance; the current instance will not be reused.

    The default implementation does nothing and returns `true`.

    Specified by:
      `commit` in class `MapCanvas​.Renderer`
    Parameters:
      `canvas` - the canvas where drawing has been done. It will be a `MapCanvasAWT` instance.
    Returns:
      `true` on success, or `false` if the rendering should be redone (for example because a change has been detected in the data).