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: * IterateStructuralProcessStep.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:
039: /**
040: * Iterates over the document tree using the display-role of the current node
041: * as selector. Usually all structural processing steps use this iteration
042: * strategy.
043: *
044: * @author Thomas Morgner
045: */
046: public abstract class IterateStructuralProcessStep {
047: protected IterateStructuralProcessStep() {
048: }
049:
050: protected final void startProcessing(final RenderNode node) {
051: if (node instanceof CanvasRenderBox) {
052: final CanvasRenderBox box = (CanvasRenderBox) node;
053: if (startCanvasBox(box)) {
054: processBoxChilds(box);
055: }
056: finishCanvasBox(box);
057: } else if (node instanceof InlineRenderBox) {
058: final InlineRenderBox box = (InlineRenderBox) node;
059: if (startInlineBox(box)) {
060: processBoxChilds(box);
061: }
062: finishInlineBox(box);
063: } else if (node instanceof ParagraphRenderBox) {
064: final ParagraphRenderBox box = (ParagraphRenderBox) node;
065: if (startBlockBox(box)) {
066: processParagraphChilds(box);
067: }
068: finishBlockBox(box);
069: } else if (node instanceof LogicalPageBox) {
070: final LogicalPageBox box = (LogicalPageBox) node;
071: if (startBlockBox(box)) {
072: startProcessing(box.getWatermarkArea());
073: startProcessing(box.getHeaderArea());
074: processBoxChilds(box);
075: startProcessing(box.getFooterArea());
076: }
077: finishBlockBox(box);
078: } else if (node instanceof BlockRenderBox) {
079: final BlockRenderBox box = (BlockRenderBox) node;
080: if (startBlockBox(box)) {
081: processBoxChilds(box);
082: }
083: finishBlockBox(box);
084: } else if (node instanceof RenderBox) {
085: final RenderBox box = (RenderBox) node;
086: if (startOtherBox(box)) {
087: processBoxChilds(box);
088: }
089: finishOtherBox(box);
090: } else {
091: processOtherNode(node);
092: }
093: }
094:
095: protected void finishCanvasBox(final CanvasRenderBox box) {
096:
097: }
098:
099: protected boolean startCanvasBox(final CanvasRenderBox box) {
100: return true;
101: }
102:
103: protected void processParagraphChilds(final ParagraphRenderBox box) {
104: processBoxChilds(box.getPool());
105: }
106:
107: protected final void processBoxChilds(final RenderBox box) {
108: RenderNode node = box.getFirstChild();
109: while (node != null) {
110: startProcessing(node);
111: node = node.getNext();
112: }
113: }
114:
115: protected void processOtherNode(final RenderNode node) {
116: }
117:
118: protected boolean startBlockBox(final BlockRenderBox box) {
119: return true;
120: }
121:
122: protected void finishBlockBox(final BlockRenderBox box) {
123: }
124:
125: protected boolean startInlineBox(final InlineRenderBox box) {
126: return true;
127: }
128:
129: protected void finishInlineBox(final InlineRenderBox box) {
130: }
131:
132: protected boolean startOtherBox(final RenderBox box) {
133: return true;
134: }
135:
136: protected void finishOtherBox(final RenderBox box) {
137: }
138: }
|