Fields Summary |
---|
public final Object | lockThe object used as a lock to synchronize access
to the paint surface. |
protected boolean | canvasConsumedThis flag should be used by the consumer of the offscreen
buffer to let the SimpleCanvasManager know when the updated
offscreen has been consumed. |
protected com.sun.perseus.j2d.RenderGraphics | rgThe RenderGraphics which this
SimpleCanvasManager keeps up to date
with its associated model changes. |
protected DocumentNode | documentNodeModel which this SimpleCanvasManager renders to
the associated RenderGraphics |
protected CanvasUpdateListener | canvasUpdateListenerListens to canvas updates |
protected boolean | needRepaintControls whether a repaint is needed or not |
protected com.sun.perseus.j2d.RGB | clearPaintThe color used to clear the canvas. |
protected DirtyAreaManager | dirtyAreaManagerDirty area manager. May be null. |
protected boolean | isOffWhen off, no updates are made to the rendering surface. |
Methods Summary |
---|
public void | consume()Should be called by the SimpleCanvasManager user to notify the
SimpleCanvasManager when an update to the canvas has been consumed.
synchronized (lock) {
canvasConsumed = true;
lock.notifyAll();
}
|
protected void | fullPaint()Utility method used to do a full repaint. This method should be called
from the update thread only.
synchronized (lock) {
if (DirtyAreaManager.ON) {
dirtyAreaManager.refresh(documentNode, rg, clearPaint);
} else {
rg.setRenderingTile(null);
rg.setFill(clearPaint);
rg.setTransform(null);
rg.setFillOpacity(1);
rg.fillRect(0, 0, documentNode.getWidth(),
documentNode.getHeight(), 0, 0);
documentNode.paint(rg);
}
canvasConsumed = false;
}
canvasUpdateListener.updateComplete(this);
|
public com.sun.perseus.j2d.RenderGraphics | getRenderGraphics()
return rg;
|
public boolean | isOff()
return isOff;
|
public void | loadBegun(ModelNode node)Invoked when the input node has started loading
|
public void | loadComplete(ModelNode node)Invoked when the input node has finished loading.
// Do nothing.
|
public void | loadStarting(DocumentNode documentNode, java.io.InputStream is)Invoked when the document starts loading
|
public void | loadingFailed(DocumentNode documentNode, java.lang.Exception error)Invoked when a document error happened before finishing loading.
// Do nothing.
|
public void | modifiedNode(ModelNode node)Invoked when a node modification completed.
if (!needRepaint
&&
(node.hasNodeRendering()
||
node.hasDescendants())) {
needRepaint = true;
}
|
public void | modifyingNode(ModelNode node)Invoked when a node is about to be modified. This will
be used in the future to track dirty areas.
if ((node.hasNodeRendering() || node.hasDescendants())
&& (node.canRenderState == 0)) {
needRepaint = true;
}
|
public void | modifyingNodeRendering(ModelNode node)Invoked when a node's rendering is about to be modified
// Note that this is redundant with the the check done in
// DirtyAreaManager. However, this is needed because DirtyAreaManager
// is sometimes used stand-alone (e.g. from ScalableGraphics).
// Having the call in the if statement makes the check redundant only
// when evaluating to true.
if (DirtyAreaManager.ON) {
dirtyAreaManager.modifyingNodeRendering(node);
}
|
public void | nodeInserted(ModelNode node)Invoked when a node has been inserted into the tree
if (DirtyAreaManager.ON) {
dirtyAreaManager.nodeInserted(node);
}
needRepaint = true;
|
public void | runnableInvoked(com.sun.perseus.util.RunnableQueue rq, java.lang.Runnable r)Called when the given Runnable has just been invoked and
has returned.
if (!isOff) {
updateCanvas();
}
|
public void | setClearPaint(com.sun.perseus.j2d.RGB clearPaint)Sets the paint used to clear the canvas.
if (clearPaint == null) {
throw new NullPointerException();
}
this.clearPaint = clearPaint;
needRepaint = true;
|
public void | setRenderGraphics(com.sun.perseus.j2d.RenderGraphics rg)
if (rg == null) {
throw new IllegalArgumentException();
}
synchronized (lock) {
this.rg = rg;
// Repaint the documentNode into the new graphics
needRepaint = true;
// The new buffer has not been painted and has not been
// consumed.
canvasConsumed = false;
}
|
public void | textInserted(ModelNode node)Invoked when a string has been appended, during a load
phase. This is only used when parsing a document and is
used in support of progressive download, like the other
loadXXX methods.
|
public void | turnOff()Turns off any rendering updates.
isOff = true;
|
public void | turnOn()Turns rendering updates on.
isOff = false;
|
public void | updateCanvas()Utility method used to update the canvas appropriately
depending on what is needed.
During the loading phase, while we do progressive
rendering, the canvas will only redraw nodes in the
progressiveNodes list, unless a repaint has been
requested.
Important Note: this method should only be called from
the update thread, i.e., the thread that also manages
the model node tree.
if (needRepaint) {
if (canvasConsumed) {
fullPaint();
needRepaint = false;
} else {
// There is a request to update the canvas
// (likely after a Runnable was invoked),
// but the last update was not consumed.
// If there is a Runnable in the RunnableQueue,
// we just skip this rendering update. Otherwise,
// schedule a fake Runnable to force a later repaint.
if (documentNode.getUpdateQueue().getSize() == 0) {
documentNode.getUpdateQueue()
.preemptLater(new Runnable() {
public void run() {
}
}, this);
}
}
}
|