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: * ModelPrinter.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout;
030:
031: import org.jfree.report.layout.model.FinishedRenderNode;
032: import org.jfree.report.layout.model.LogicalPageBox;
033: import org.jfree.report.layout.model.ParagraphRenderBox;
034: import org.jfree.report.layout.model.RenderBox;
035: import org.jfree.report.layout.model.RenderNode;
036: import org.jfree.report.layout.model.RenderableText;
037: import org.jfree.util.Log;
038:
039: /**
040: * Creation-Date: Jan 9, 2007, 2:22:59 PM
041: *
042: * @author Thomas Morgner
043: */
044: public class ModelPrinter {
045: private static final boolean PRINT_LINEBOX_CONTENTS = false;
046:
047: private ModelPrinter() {
048: }
049:
050: public static void printParents(RenderNode node) {
051: while (node != null) {
052: final StringBuffer b = new StringBuffer();
053: b.append(node.getClass().getName());
054: b.append('[');
055: //b.append(Integer.toHexString(System.identityHashCode(node)));
056: b.append(']');
057: Log.debug(b);
058: node = node.getParent();
059: }
060: }
061:
062: public static void print(final RenderBox box) {
063: printBox(box, 0);
064: }
065:
066: public static void printBox(final RenderBox box, final int level) {
067: StringBuffer b = new StringBuffer();
068: for (int i = 0; i < level; i++) {
069: b.append(" ");
070: }
071: b.append(box.getClass().getName());
072: b.append('[');
073: //b.append(Integer.toHexString(System.identityHashCode(box)));
074: b.append(';');
075: b.append(box.getName());
076: b.append(']');
077: b.append("={stateKey=");
078: b.append(box.getStateKey());
079: b.append(", x=");
080: b.append(box.getX());
081: b.append(", y=");
082: b.append(box.getY());
083: b.append(", width=");
084: b.append(box.getWidth());
085: b.append(", height=");
086: b.append(box.getHeight());
087: b.append(", computed-x=");
088: b.append(box.getComputedX());
089: b.append(", computed-width=");
090: b.append(box.getComputedWidth());
091: b.append(", cached-x=");
092: b.append(box.getCachedX());
093: b.append(", cached-y=");
094: b.append(box.getCachedY());
095: b.append(", cached-width=");
096: b.append(box.getCachedWidth());
097: b.append(", cached-height=");
098: b.append(box.getCachedHeight());
099: b.append('}');
100: Log.debug(b.toString());
101:
102: b = new StringBuffer();
103: for (int i = 0; i < level; i++) {
104: b.append(" ");
105: }
106: b.append("- boxDefinition=");
107: b.append(box.getBoxDefinition());
108: Log.debug(b.toString());
109: b = new StringBuffer();
110: for (int i = 0; i < level; i++) {
111: b.append(" ");
112: }
113: b.append("- nodeLayoutProperties=");
114: b.append(box.getNodeLayoutProperties());
115: Log.debug(b.toString());
116: b = new StringBuffer();
117: for (int i = 0; i < level; i++) {
118: b.append(" ");
119: }
120: b.append("- staticBoxLayoutProperties=");
121: b.append(box.getStaticBoxLayoutProperties());
122: Log.debug(b.toString());
123:
124: if (box instanceof LogicalPageBox) {
125: final LogicalPageBox pageBox = (LogicalPageBox) box;
126: b = new StringBuffer();
127: for (int i = 0; i < level; i++) {
128: b.append(" ");
129: }
130: b.append("- PageBox={PageOffset=");
131: b.append(pageBox.getPageOffset());
132: b.append(", PageHeight=");
133: b.append(pageBox.getPageHeight());
134: b.append(", PageEnd=");
135: b.append(pageBox.getPageEnd());
136: b.append('}');
137: Log.debug(b.toString());
138: }
139:
140: if (box.isOpen()) {
141: b = new StringBuffer();
142: for (int i = 0; i < level; i++) {
143: b.append(" ");
144: }
145: b.append("- WARNING: THIS BOX IS STILL OPEN");
146: Log.debug(b.toString());
147: }
148:
149: if (box.isFinished()) {
150: b = new StringBuffer();
151: for (int i = 0; i < level; i++) {
152: b.append(" ");
153: }
154: b.append("- INFO: THIS BOX IS FINISHED");
155: Log.debug(b.toString());
156: }
157: if (box.isCommited()) {
158: b = new StringBuffer();
159: for (int i = 0; i < level; i++) {
160: b.append(" ");
161: }
162: b.append("- INFO: THIS BOX IS COMMITED");
163: Log.debug(b.toString());
164: }
165:
166: b = new StringBuffer();
167: for (int i = 0; i < level; i++) {
168: b.append(" ");
169: }
170: Log.debug(b.toString());
171:
172: if (box instanceof ParagraphRenderBox) {
173: if (PRINT_LINEBOX_CONTENTS) {
174: final ParagraphRenderBox paraBox = (ParagraphRenderBox) box;
175: if (paraBox.isComplexParagraph()) {
176: Log
177: .debug("---------------- START PARAGRAPH LINEBOX CONTAINER -------------------------------------");
178: printBox(paraBox.getLineboxContainer(), level + 1);
179: Log
180: .debug("---------------- FINISH PARAGRAPH LINEBOX CONTAINER -------------------------------------");
181: }
182: }
183: }
184:
185: if (box instanceof LogicalPageBox) {
186: final LogicalPageBox lbox = (LogicalPageBox) box;
187: printBox(lbox.getHeaderArea(), level + 1);
188: printBox(lbox.getWatermarkArea(), level + 1);
189: }
190: printChilds(box, level);
191: if (box instanceof LogicalPageBox) {
192: final LogicalPageBox lbox = (LogicalPageBox) box;
193: printBox(lbox.getFooterArea(), level + 1);
194: }
195: }
196:
197: private static void printChilds(final RenderBox box, final int level) {
198: RenderNode childs = box.getFirstChild();
199: while (childs != null) {
200: if (childs instanceof RenderBox) {
201: printBox((RenderBox) childs, level + 1);
202: } else if (childs instanceof RenderableText) {
203: printText((RenderableText) childs, level + 1);
204: } else {
205: printNode(childs, level + 1);
206: }
207: childs = childs.getNext();
208: }
209: }
210:
211: private static void printNode(final RenderNode node, final int level) {
212: StringBuffer b = new StringBuffer();
213: for (int i = 0; i < level; i++) {
214: b.append(" ");
215: }
216: b.append(node.getClass().getName());
217: b.append('[');
218: //b.append(Integer.toHexString(System.identityHashCode(node)));
219: b.append(']');
220: b.append("={x=");
221: b.append(node.getX());
222: b.append(", y=");
223: b.append(node.getY());
224: b.append(", width=");
225: b.append(node.getWidth());
226: b.append(", height=");
227: b.append(node.getHeight());
228: b.append(", computed-x=");
229: b.append(node.getComputedX());
230: b.append(", computed-width=");
231: b.append(node.getComputedWidth());
232:
233: if (node instanceof FinishedRenderNode) {
234: final FinishedRenderNode fn = (FinishedRenderNode) node;
235: b.append(", layouted-width=");
236: b.append(fn.getLayoutedWidth());
237: b.append(", layouted-height=");
238: b.append(fn.getLayoutedHeight());
239: }
240: b.append('}');
241: Log.debug(b.toString());
242:
243: b = new StringBuffer();
244: for (int i = 0; i < level; i++) {
245: b.append(" ");
246: }
247: b.append("- nodeLayoutProperties=");
248: b.append(node.getNodeLayoutProperties());
249: Log.debug(b.toString());
250: }
251:
252: private static void printText(final RenderableText text,
253: final int level) {
254: StringBuffer b = new StringBuffer();
255: for (int i = 0; i < level; i++) {
256: b.append(" ");
257: }
258: b.append("Text");
259: b.append('[');
260: //b.append(Integer.toHexString(System.identityHashCode(text)));
261: b.append(']');
262: b.append("={x=");
263: b.append(text.getX());
264: b.append(", y=");
265: b.append(text.getY());
266: b.append(", width=");
267: b.append(text.getWidth());
268: b.append(", height=");
269: b.append(text.getHeight());
270: b.append(", computed-x=");
271: b.append(text.getComputedX());
272: b.append(", computed-width=");
273: b.append(text.getComputedWidth());
274: b.append(", text='");
275: b.append(text.getRawText());
276: b.append("'}");
277: Log.debug(b.toString());
278:
279: b = new StringBuffer();
280: for (int i = 0; i < level; i++) {
281: b.append(" ");
282: }
283: b.append("- nodeLayoutProperties=");
284: b.append(text.getNodeLayoutProperties());
285: Log.debug(b.toString());
286: }
287:
288: }
|