001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ApplyPageShiftValuesStep.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.process;
030:
031: import org.jfree.report.layout.model.BlockRenderBox;
032: import org.jfree.report.layout.model.CanvasRenderBox;
033: import org.jfree.report.layout.model.InlineRenderBox;
034: import org.jfree.report.layout.model.LogicalPageBox;
035: import org.jfree.report.layout.model.ParagraphRenderBox;
036: import org.jfree.report.layout.model.RenderBox;
037: import org.jfree.report.layout.model.RenderNode;
038: import org.jfree.report.util.InstanceID;
039:
040: /**
041: * This processing step applies the cache shift to all nodes.
042: *
043: * Paginated and processed boxes are based on shifted nodes that have been created/shifted by the PaginationStep.
044: * The cached values of the nodes that come after these finished nodes are now invalid, as the cache-positions
045: * have been stored *before* the pagination shift was applied.
046: *
047: * Instead of simply invalidating the caches (which would be expensive), we patch the caches of these nodes and
048: * shift them downwards so that the cache and the recomputation results will be in sync.
049: *
050: * Without this correction (or the equivalent cache-invalidation), we would encounter lost content, as the
051: * finished node and the cached content would overlap.
052: *
053: * @author Thomas Morgner
054: */
055: public final class ApplyPageShiftValuesStep extends
056: IterateStructuralProcessStep {
057: private long shift;
058: private InstanceID triggerId;
059: private boolean found;
060:
061: public ApplyPageShiftValuesStep() {
062: }
063:
064: public void compute(final LogicalPageBox logicalPageBox,
065: final long shift, final InstanceID triggerId) {
066: this .shift = shift;
067: this .triggerId = triggerId;
068: this .found = false;
069: startProcessing(logicalPageBox);
070: }
071:
072: public boolean startCanvasBox(final CanvasRenderBox box) {
073: if (found == false && box.getInstanceId() == triggerId) {
074: found = true;
075: CacheBoxShifter.extendHeight(box.getParent(), shift);
076: }
077: if (found) {
078: box.shiftCached(shift);
079: }
080: return true;
081: }
082:
083: protected boolean startBlockBox(final BlockRenderBox box) {
084: if (found == false && box.getInstanceId() == triggerId) {
085: found = true;
086: CacheBoxShifter.extendHeight(box.getParent(), shift);
087: }
088: if (found) {
089: box.shiftCached(shift);
090: }
091: return true;
092: }
093:
094: protected boolean startInlineBox(final InlineRenderBox box) {
095: if (found == false && box.getInstanceId() == triggerId) {
096: found = true;
097: CacheBoxShifter.extendHeight(box.getParent(), shift);
098: }
099: if (found) {
100: box.shiftCached(shift);
101: }
102: return true;
103: }
104:
105: protected void processOtherNode(final RenderNode node) {
106: if (found == false && node.getInstanceId() == triggerId) {
107: found = true;
108: CacheBoxShifter.extendHeight(node.getParent(), shift);
109: }
110: if (found) {
111: node.shiftCached(shift);
112: }
113: // do something
114: }
115:
116: protected boolean startOtherBox(final RenderBox box) {
117: if (found == false && box.getInstanceId() == triggerId) {
118: found = true;
119: CacheBoxShifter.extendHeight(box.getParent(), shift);
120: }
121: if (found) {
122: box.shiftCached(shift);
123: }
124: return true;
125: }
126:
127: protected void processParagraphChilds(final ParagraphRenderBox box) {
128: processBoxChilds(box);
129: }
130: }
|