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:
027: package com.sun.perseus.model;
028:
029: import com.sun.perseus.j2d.Tile;
030:
031: /**
032: * The <code>RenderingManager</code> class provides support for efficiently
033: * managing rendered areas in ModelNode implementations, such as
034: * AbstractShapeNode.
035: *
036: * @version $Id: RenderingManager.java,v 1.4 2006/06/29 10:47:33 ln156897 Exp $
037: */
038: class RenderingManager {
039: /**
040: * The associated ModelNode, the one for which RenderingManager
041: * tracks regions.
042: */
043: protected ModelNode node;
044:
045: /**
046: * True when the rendering tile needs to be recomputed.
047: */
048: protected boolean rTileDirty = true;
049:
050: /**
051: * The node's current rendering bounds
052: */
053: protected Tile rTile = new Tile();
054:
055: /**
056: * The node's most recent rendered tile.
057: */
058: protected Tile lastRenderedTile = null;
059:
060: /**
061: * A value cached so that we don't reallocate tiles all the time.
062: */
063: protected Tile lrtCache = new Tile();
064:
065: /**
066: * @node the associated <code>ModeNode</code>
067: */
068: protected RenderingManager(final ModelNode node) {
069: this .node = node;
070: }
071:
072: /**
073: * @return the bounding box, in screen coordinate, which encompasses the
074: * node's rendering.
075: */
076: protected Tile getRenderingTile() {
077: if (rTileDirty) {
078: node.computeRenderingTile(rTile);
079: rTileDirty = false;
080: }
081:
082: return rTile;
083: }
084:
085: /**
086: * Marks the rendering as dirty, meaning that the rendering tile cached
087: * value cannot be reused, if any value has been cached.
088: */
089: protected final void dirty() {
090: rTileDirty = true;
091: node.modifyingNodeRendering();
092: }
093:
094: /**
095: * @return the set node's last actual rendering. If this node's
096: * hasRendering method returns false, then this method should return
097: * null.
098: */
099: protected Tile getLastRenderedTile() {
100: return lastRenderedTile;
101: }
102:
103: /**
104: * After calling this method, getLastRendered should always return null.
105: */
106: protected void clearLastRenderedTile() {
107: lastRenderedTile = null;
108: }
109:
110: /**
111: * Should be called by ModelNode implementations when they have just
112: * rendered so that the rendered area is captured in the lastRenderedTile.
113: *
114: * Important: it is the responsibility of the classes using this method
115: * to make sure the rendering tile is not dirty when calling this
116: * method. If the rendering tile is dirty, then the captured value will
117: * not correspond to the actual rendering area.
118: */
119: protected void rendered() {
120: if (lastRenderedTile == null) {
121: lastRenderedTile = lrtCache;
122: }
123: lastRenderedTile.x = rTile.x;
124: lastRenderedTile.y = rTile.y;
125: lastRenderedTile.maxX = rTile.maxX;
126: lastRenderedTile.maxY = rTile.maxY;
127: }
128: }
|