com.levigo.jadice.document.render
Class PageRenderer

java.lang.Object
  extended by com.levigo.jadice.document.render.AbstractPageRenderer
      extended by com.levigo.jadice.document.render.PageRenderer

public class PageRenderer
extends AbstractPageRenderer

Provides the ability to render the contents of a page into any valid Graphics2D. This class may be used to integrate the jadice document platform rendering of a page for example inside components.

Prior to calling render(Graphics2D) a Page has to be set using AbstractPageRenderer.setPage(Page). If no page has been set, the render(Graphics2D) method will throw an IllegalStateException.

To allow no-blocking rendering of pages on the Event Dispatch Thread, this class allows to register a repaint TaskScope to act as callback. It informs the caller that more page contents are available for immediate rendering. Without the registration of a TaskScope all initialization and preparation work will be done in place, which means that the rendering process will run as long as those tasks need to complete.

Very basic example component using the PageRenderer:

class RenderedPage  extends JComponent {
   private final PageRenderer renderer;

  public  RenderedPage() {
    super ();
    renderer =  new PageRenderer() ;

    // registering a task scope to act as repaint callback.
    // The taskCompleted method will enqueue a repaint of the whole component.
    // The taskFailed will report a failure.
   TaskScope<RenderResult>taskScope = new TaskScope<RenderResult>() {
      @Override
      public void taskCompleted(RenderResult result) {
        // calling repaint off-EDTis safe, as this will
        // only enqueue a paint task in the event queue
       repaint();
      }

      @Override
      public void taskFailed(Task<RenderResult>task,Throwable reason) {
        // report the failure
       LOGGER.error("rendering failed", reason);
      }
    };

    renderer.setRepaintScope(taskScope);
  }

  public  Page getPageToRender() {
     return renderer.getPage ();
   }

   public void setPageToRender (Page page) {
    renderer.setPage (page);
    repaint();
  }

   @Override
  public  void paint( Graphics g) {
     Graphics2D g2d = (Graphics2D g;

     try {
       renderer.render(g2d) ;
     catch (JadiceException e ) {
       // something did go wrong while initializing or rendering.
      System.err.println ("Rendering of Page failed");
      e.printStackTrace ();
     }
  }
}

See Also:
render(Graphics2D), AbstractPageRenderer.setPage(Page), TaskScope, setRepaintScope(TaskScope)

Constructor Summary
PageRenderer()
           
 
Method Summary
 TaskScope<RenderResult> getRepaintScope()
          Request the applied TaskScope.
 void render(Graphics2D target)
          Paint a Page.
 void setRepaintScope(TaskScope<RenderResult> scope)
          Supply a TaskScope.
 
Methods inherited from class com.levigo.jadice.document.render.AbstractPageRenderer
getPage, getRenderControls, setPage, setRenderControls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageRenderer

public PageRenderer()
Method Detail

render

public void render(Graphics2D target)
            throws JadiceException
Paint a Page. This method will paint the Page set using AbstractPageRenderer.setPage(Page) or if the Page is null, an IllegalStateException will be thrown.

Specified by:
render in class AbstractPageRenderer
Parameters:
target - the Graphics2D to paint to.
Throws:
IllegalStateException - if page reference is null
JadiceException - will be thrown if the initialization or the rendering of the Page failed.

getRepaintScope

public TaskScope<RenderResult> getRepaintScope()
Request the applied TaskScope.

Returns:
the TaskScope
See Also:
setRepaintScope(TaskScope)

setRepaintScope

public void setRepaintScope(TaskScope<RenderResult> scope)
Supply a TaskScope. It is strongly encouraged to use a TaskScope. Without a TaskScope all initialization and preparation work will be executed on the calling thread. In case of the Event Dispatch Thread, this will force the UI to be unresponsive until the whole process has been completed.

Parameters:
scope - the TaskScope to be used.


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.