001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package com.sun.perseus.model;
027:
028: import com.sun.perseus.j2d.PaintTarget;
029: import com.sun.perseus.j2d.RenderGraphics;
030:
031: import com.sun.perseus.j2d.Box;
032: import com.sun.perseus.j2d.Tile;
033: import com.sun.perseus.j2d.Transform;
034:
035: import org.w3c.dom.svg.SVGRect;
036:
037: /**
038: * An <code>AbstractRenderingNodeProxy</code> delegates its rendering to a
039: * proxied <code>AbstractRenderingNode</code> and also has its own rendering
040: * manager.
041: *
042: * @version $Id: AbstractRenderingNodeProxy.java,v 1.4 2006/06/29 10:47:29 ln156897 Exp $
043: */
044: public class AbstractRenderingNodeProxy extends
045: CompositeGraphicsNodeProxy {
046: /**
047: * Used to track the node's rendering area and the rendered areas.
048: */
049: protected RenderingManager renderingManager;
050:
051: /**
052: * @param proxiedNode <tt>AbstractRenderingNode</tt> to proxy
053: */
054: protected AbstractRenderingNodeProxy(
055: final AbstractRenderingNode proxiedNode) {
056: super (proxiedNode);
057: if (DirtyAreaManager.ON) {
058: renderingManager = new RenderingManager(this );
059: }
060: }
061:
062: /**
063: * Clears the text layouts, if any exist. This is typically
064: * called when the font selection has changed and nodes such
065: * as <code>Text</code> should recompute their layouts.
066: * This should recursively call clearLayouts on children
067: * node or expanded content, if any.
068: */
069: protected void clearLayouts() {
070: }
071:
072: /**
073: * @return the tight bounding box in current user coordinate
074: * space.
075: */
076: public SVGRect getBBox() {
077: return addNodeBBox(null, null);
078: }
079:
080: /**
081: * @param bbox the bounding box to which this node's bounding box should be
082: * appended. That bounding box is in the target coordinate space. It
083: * may be null, in which case this node should create a new one.
084: * @param t the transform to apply from the node's coordinate space to the
085: * target coordinate space. May be null for the identity
086: * transform.
087: * @return the node's bounding box in the target coordinate space.
088: */
089: Box addBBox(Box bbox, final Transform t) {
090: return addNodeBBox(bbox, t);
091: }
092:
093: /**
094: * @param bbox the bounding box to which this node's bounding box should be
095: * appended. That bounding box is in the target coordinate space. It
096: * may be null, in which case this node should create a new one.
097: * @param t the transform from the node coordinate system to the coordinate
098: * system into which the bounds should be computed.
099: * @return the bounding box of this node, in the target coordinate space,
100: */
101: Box addNodeBBox(final Box bbox, final Transform t) {
102: return proxied.addNodeBBox(bbox, t);
103: }
104:
105: /**
106: * Computes this node's rendering tile.
107: *
108: * @param tile the Tile instance whose bounds should be set.
109: * @return the device space rendering tile.
110: */
111: protected final void computeRenderingTile(final Tile tile) {
112: ((AbstractRenderingNode) proxied).computeRenderingTile(tile,
113: txf, this );
114: }
115:
116: /**
117: * Should be called whenever this node's rendering becomes dirty.
118: */
119: final void renderingDirty() {
120: if (DirtyAreaManager.ON) {
121: renderingManager.dirty();
122: }
123: }
124:
125: /**
126: * Recomputes the transform cache, if one exists.
127: *
128: * @param parentTransform the Transform applied to this node's parent.
129: */
130: protected void recomputeTransformState(
131: final Transform parentTransform) {
132: super .recomputeTransformState(parentTransform);
133: renderingDirty();
134: }
135:
136: /**
137: * Modifies the node proxied by this proxy.
138: *
139: * @param newProxied this node's new proxied node
140: */
141: protected void setProxied(final ElementNode newProxied) {
142: if (this .proxied == newProxied) {
143: return;
144: }
145:
146: super .setProxied(newProxied);
147: renderingDirty();
148: }
149:
150: /**
151: * An <code>AbstractNodeRendering</code> has something to render.
152: *
153: * @return true
154: */
155: public boolean hasNodeRendering() {
156: return true;
157: }
158:
159: /**
160: * Paints this node into the input <code>RenderGraphics</code>.
161: *
162: * @param rg the <tt>RenderGraphics</tt> where the node should paint itself
163: */
164: public void paint(final RenderGraphics rg) {
165: if (canRenderState != 0) {
166: return;
167: }
168:
169: if (DirtyAreaManager.ON) {
170: Tile primitiveTile = getRenderingTile();
171: if (primitiveTile == null
172: || rg.getRenderingTile().isHit(primitiveTile)) {
173: // rg.setPrimitiveTile(primitiveTile);
174: ((AbstractRenderingNode) proxied).paintRendered(rg,
175: this , this , txf);
176:
177: // nodeRendered is called seperately from paintRendered
178: // because paintRendered is used in different contexts,
179: // for example by proxy nodes to render, using their
180: // proxied node's paintRendered method.
181: nodeRendered();
182: }
183: } else {
184: ((AbstractRenderingNode) proxied).paintRendered(rg, this ,
185: this , txf);
186: }
187: }
188:
189: /**
190: * Simply notifies the RenderingManager.
191: */
192: protected void nodeRendered() {
193: if (DirtyAreaManager.ON) {
194: renderingManager.rendered();
195: }
196: }
197:
198: /**
199: * Proxied nodes should call this method when they are being modified.
200: */
201: public void modifyingProxied() {
202: super .modifyingProxied();
203: renderingDirty();
204: }
205:
206: /**
207: * @return the bounding box, in screen coordinate, which encompasses the
208: * node's rendering.
209: */
210: protected final Tile getRenderingTile() {
211: return renderingManager.getRenderingTile();
212: }
213:
214: /**
215: * @return the tile which encompasses the node's last actual rendering.
216: */
217: protected Tile getLastRenderedTile() {
218: return renderingManager.getLastRenderedTile();
219: }
220:
221: /**
222: * After calling this method, getLastRenderedTile should always return null.
223: */
224: protected void clearLastRenderedTile() {
225: renderingManager.clearLastRenderedTile();
226: }
227:
228: /**
229: * To be overriddent by derived classes, such as TimedElementNode,
230: * if they need to do special operations when hooked into the
231: * document tree.
232: */
233: void nodeHookedInDocumentTree() {
234: renderingDirty();
235: }
236:
237: /**
238: * To be overriddent by derived classes, such as TimedElementNode,
239: * if they need to do special operations when unhooked from the
240: * document tree.
241: */
242: void nodeUnhookedFromDocumentTree() {
243: renderingDirty();
244: }
245:
246: /**
247: * @param newDisplay the new computed display value
248: */
249: public void setDisplay(final boolean newDisplay) {
250: super .setDisplay(newDisplay);
251:
252: renderingDirty();
253: }
254:
255: /**
256: * @param newVisibility the new computed visibility property.
257: */
258: public void setVisibility(final boolean newVisibility) {
259: super.setVisibility(newVisibility);
260:
261: renderingDirty();
262: }
263:
264: }
|