Class MapCanvasAWT.Renderer

Enclosing class:
Map­Canvas­AWT

protected abstract static class MapCanvasAWT.Renderer extends MapCanvas.Renderer
A snapshot of Map­Canvas­AWT state to paint as an image. The snapshot is created in JavaFX thread by the Map­Canvas­AWT​.create­Renderer() 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 Map­Canvas­AWT property from a method invoked in background thread (render() and paint(Graphics2D)). It may access Map­Canvas­AWT properties from the commit(Map­Canvas) 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 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 Map­Canvas​.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 Volatile­Image content is invalidated in the middle of rendering process. This method should not access any Map­Canvas 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 Map­Canvas​.floating­Pane 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 Map­Canvas­AWT​.Renderer instance; the current instance will not be reused.

      The default implementation does nothing and returns true.

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