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: * IterateVisualProcessStep.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 tree of nodes and classifies nodes by their Display-Model.
041: * The Display-Model of nodes is either 'Block' or 'Inline'. All steps dealing
042: * with element placement commonly use this strategy.
043: *
044: *
045: * @author Thomas Morgner
046: */
047: public abstract class IterateVisualProcessStep {
048: protected IterateVisualProcessStep() {
049: }
050:
051: protected final void startProcessing(final RenderNode node) {
052: final RenderBox parent = node.getParent();
053: if (parent == null || parent instanceof BlockRenderBox) {
054: processBlockLevelChild(node);
055: } else if (parent instanceof CanvasRenderBox) {
056: processCanvasLevelChild(node);
057: } else if (parent instanceof InlineRenderBox) {
058: processInlineLevelChild(node);
059: } else {
060: processOtherLevelChild(node);
061: }
062: }
063:
064: protected void processOtherLevelChild(final RenderNode node) {
065: // we do not even handle that one. Other level elements are
066: // always non-visual!
067: }
068:
069: protected void processInlineLevelNode(final RenderNode node) {
070: }
071:
072: protected boolean startInlineLevelBox(final RenderBox box) {
073: return true;
074: }
075:
076: protected void finishInlineLevelBox(final RenderBox box) {
077: }
078:
079: protected void processInlineLevelChild(final RenderNode node) {
080: if (node instanceof ParagraphRenderBox) {
081: final ParagraphRenderBox box = (ParagraphRenderBox) node;
082: if (startInlineLevelBox(box)) {
083: processParagraphChilds(box);
084: }
085: finishInlineLevelBox(box);
086: } else if (node instanceof RenderBox) {
087: final RenderBox box = (RenderBox) node;
088: if (startInlineLevelBox(box)) {
089: processBoxChilds(box);
090: }
091: finishInlineLevelBox(box);
092: } else {
093: processInlineLevelNode(node);
094: }
095: }
096:
097: protected void processCanvasLevelNode(final RenderNode node) {
098: }
099:
100: protected boolean startCanvasLevelBox(final RenderBox box) {
101: return true;
102: }
103:
104: protected void finishCanvasLevelBox(final RenderBox box) {
105: }
106:
107: protected final void processCanvasLevelChild(final RenderNode node) {
108: if (node instanceof ParagraphRenderBox) {
109: final ParagraphRenderBox box = (ParagraphRenderBox) node;
110: if (startCanvasLevelBox(box)) {
111: processParagraphChilds(box);
112: }
113: finishCanvasLevelBox(box);
114: } else if (node instanceof RenderBox) {
115: final RenderBox box = (RenderBox) node;
116: if (startCanvasLevelBox(box)) {
117: processBoxChilds(box);
118: }
119: finishCanvasLevelBox(box);
120: } else {
121: processCanvasLevelNode(node);
122: }
123: }
124:
125: protected void processBlockLevelNode(final RenderNode node) {
126: }
127:
128: protected boolean startBlockLevelBox(final RenderBox box) {
129: return true;
130: }
131:
132: protected void finishBlockLevelBox(final RenderBox box) {
133: }
134:
135: protected final void processBlockLevelChild(final RenderNode node) {
136: if (node instanceof LogicalPageBox) {
137: final LogicalPageBox box = (LogicalPageBox) node;
138: if (startBlockLevelBox(box)) {
139: startProcessing(box.getWatermarkArea());
140: startProcessing(box.getHeaderArea());
141: processBoxChilds(box);
142: startProcessing(box.getFooterArea());
143: }
144: finishBlockLevelBox(box);
145: } else if (node instanceof ParagraphRenderBox) {
146: final ParagraphRenderBox box = (ParagraphRenderBox) node;
147: if (startBlockLevelBox(box)) {
148: processParagraphChilds(box);
149: }
150: finishBlockLevelBox(box);
151: } else if (node instanceof RenderBox) {
152: final RenderBox box = (RenderBox) node;
153: if (startBlockLevelBox(box)) {
154: processBoxChilds(box);
155: }
156: finishBlockLevelBox(box);
157: } else {
158: processBlockLevelNode(node);
159: }
160: }
161:
162: protected abstract void processParagraphChilds(
163: final ParagraphRenderBox box);
164:
165: protected final void processBoxChilds(final RenderBox box) {
166: RenderNode node = box.getFirstChild();
167: while (node != null) {
168: startProcessing(node);
169: node = node.getNext();
170: }
171: }
172: }
|