public class PageGraphicsRenderer extends AbstractRenderer
Graphics2D
. This
class may be used to integrate the jadice document platform rendering of a page for example
inside components.
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 PageGraphicsRenderer
:
class
RenderedPage
extends
JComponent{
private final
PageGraphicsRenderer renderer;
public
RenderedPage (Page page) {
super();
renderer =
new
PageGraphicsRenderer(page);
// 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-EDT is 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);
}
@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();
}
}
}
render(Graphics2D)
,
TaskScope
,
setRepaintScope(TaskScope)
graphicsContextRenderer
Constructor and Description |
---|
PageGraphicsRenderer(Page page)
Creates an instance of this class.
|
Modifier and Type | Method and Description |
---|---|
Page |
getPage()
Returns the page to be rendered.
|
TaskScope<RenderResult> |
getRepaintScope()
Returns the applied
TaskScope . |
void |
render(Graphics2D target)
Renders a
Page . |
void |
setRepaintScope(TaskScope<RenderResult> scope)
Defines a
TaskScope for the rendering process. |
getRenderControls, setRenderControls
public PageGraphicsRenderer(Page page)
page
- The page to be rendered into the Graphics2D
.public void render(Graphics2D target) throws JadiceException
render
in class AbstractRenderer
target
- the Graphics2D
to paint to.JadiceException
- will be thrown if the initialization or the rendering of the Page
failed.public TaskScope<RenderResult> getRepaintScope()
TaskScope
. A TaskScope
should be used if initialization and
preparation work for the rendering can and should be done on a thread other the calling thread.
In this case the rendering result will be finished in an unspecified time in the future. If no
TaskScope
is defined, the rendering happens on the calling thread. By default the
TaskScope
is null
.TaskScope
, may be null
if the rendering process should happen on
the calling thread.setRepaintScope(TaskScope)
public void setRepaintScope(TaskScope<RenderResult> scope)
TaskScope
for the rendering process. The effect of setting a TaskScope
is described in the javadoc of getRepaintScope()
.
It is strongly encouraged to use a TaskScope
for instances of this class. 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.
scope
- the TaskScope
to be used or null
getRepaintScope()
Copyright © 2024 levigo holding gmbh. All rights reserved.