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: * ParagraphRenderBox.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.model;
030:
031: import org.jfree.report.ElementAlignment;
032: import org.jfree.report.layout.model.context.BoxDefinition;
033: import org.jfree.report.layout.style.ParagraphPoolboxStyleSheet;
034: import org.jfree.report.style.ElementStyleKeys;
035: import org.jfree.report.style.StyleSheet;
036: import org.jfree.report.util.InstanceID;
037:
038: /**
039: * Creation-Date: 03.04.2007, 13:38:00
040: *
041: * @author Thomas Morgner
042: */
043: public class ParagraphRenderBox extends BlockRenderBox {
044: private static class LineBoxRenderBox extends BlockRenderBox {
045: protected LineBoxRenderBox(final StyleSheet styleSheet,
046: final Object stateKey) {
047: super (styleSheet, BoxDefinition.EMPTY, stateKey);
048: }
049: }
050:
051: private ParagraphPoolBox pool;
052: private LineBoxRenderBox lineboxContainer;
053: private ElementAlignment textAlignment;
054: private ElementAlignment lastLineAlignment;
055: private long lineBoxAge;
056: private long minorLayoutAge;
057: private int poolSize;
058: private Object rawValue;
059:
060: public ParagraphRenderBox(final StyleSheet styleSheet,
061: final BoxDefinition boxDefinition, final Object stateKey) {
062: super (styleSheet, boxDefinition, stateKey);
063:
064: pool = new ParagraphPoolBox(new ParagraphPoolboxStyleSheet(
065: styleSheet), stateKey);
066: pool.setParent(this );
067:
068: // // yet another helper box. Level 2
069: // lineboxContainer = new LineBoxRenderBox(styleSheet);
070: // lineboxContainer.setParent(this);
071:
072: // level 3 means: Add all lineboxes to the paragraph
073: // This gets auto-generated ..
074: this .textAlignment = (ElementAlignment) styleSheet
075: .getStyleProperty(ElementStyleKeys.ALIGNMENT,
076: ElementAlignment.LEFT);
077: this .lastLineAlignment = textAlignment;
078: }
079:
080: //
081: // public void appyStyle(LayoutContext context, OutputProcessorMetaData metaData)
082: // {
083: // super.appyStyle(context, metaData);
084: // CSSValue alignVal = context.getValue(TextStyleKeys.TEXT_ALIGN);
085: // CSSValue alignLastVal = context.getValue(TextStyleKeys.TEXT_ALIGN_LAST);
086: // this.textAlignment = createAlignment(alignVal);
087: // if (textAlignment == TextAlign.JUSTIFY)
088: // {
089: // this.lastLineAlignment = createAlignment(alignLastVal);
090: // }
091: // else
092: // {
093: // this.lastLineAlignment = textAlignment;
094: // }
095: //
096: // pool.appyStyle(context, metaData);
097: // lineboxContainer.appyStyle(context, metaData);
098: // }
099:
100: /**
101: * Derive creates a disconnected node that shares all the properties of the original node. The derived node will no
102: * longer have any parent, silbling, child or any other relationships with other nodes.
103: *
104: * @return
105: */
106: public RenderNode derive(final boolean deepDerive) {
107: final ParagraphRenderBox box = (ParagraphRenderBox) super
108: .derive(deepDerive);
109: box.pool = (ParagraphPoolBox) pool.derive(deepDerive);
110: box.pool.setParent(box);
111:
112: if (lineboxContainer != null) {
113: box.lineboxContainer = (LineBoxRenderBox) lineboxContainer
114: .derive(deepDerive);
115: box.lineboxContainer.setParent(box);
116: }
117: if (!deepDerive) {
118: box.lineBoxAge = 0;
119: }
120: return box;
121: }
122:
123: /**
124: * Derive creates a disconnected node that shares all the properties of the original node. The derived node will no
125: * longer have any parent, silbling, child or any other relationships with other nodes.
126: *
127: * @return
128: */
129: public RenderNode hibernate() {
130: final ParagraphRenderBox box = (ParagraphRenderBox) super
131: .derive(false);
132: box.setHibernated(true);
133: box.pool = (ParagraphPoolBox) pool.hibernate();
134: box.pool.setParent(box);
135: if (lineboxContainer != null) {
136: box.lineboxContainer = (LineBoxRenderBox) lineboxContainer
137: .hibernate();
138: }
139: box.lineBoxAge = 0;
140: return box;
141: }
142:
143: public final void addChild(final RenderNode child) {
144: pool.addChild(child);
145: }
146:
147: protected void addDirectly(final RenderNode child) {
148: if (child instanceof ParagraphPoolBox) {
149: final ParagraphPoolBox poolBox = (ParagraphPoolBox) child;
150: poolBox.trim();
151: }
152: super .addGeneratedChild(child);
153: }
154:
155: /**
156: * Removes all children.
157: */
158: public final void clear() {
159: pool.clear();
160: if (lineboxContainer != null) {
161: lineboxContainer.clear();
162: }
163: super .clear();
164: lineBoxAge = 0;
165: }
166:
167: public final void clearLayout() {
168: super .clear();
169: minorLayoutAge = 0;
170: //lineBoxAge = 0;
171: }
172:
173: public boolean isAppendable() {
174: return pool.isAppendable();
175: }
176:
177: public boolean isEmpty() {
178: return pool.isEmpty();
179: }
180:
181: public boolean isDiscardable() {
182: return pool.isDiscardable();
183: }
184:
185: public ElementAlignment getLastLineAlignment() {
186: return lastLineAlignment;
187: }
188:
189: public ElementAlignment getTextAlignment() {
190: return textAlignment;
191: }
192:
193: public RenderBox getLineboxContainer() {
194: return lineboxContainer;
195: }
196:
197: public boolean isComplexParagraph() {
198: return lineboxContainer != null;
199: }
200:
201: public RenderBox createLineboxContainer() {
202: if (lineboxContainer == null) {
203: this .lineboxContainer = new LineBoxRenderBox(pool
204: .getStyleSheet(), getStateKey());
205: this .lineboxContainer.setParent(this );
206: }
207: return lineboxContainer;
208: }
209:
210: public ParagraphPoolBox getPool() {
211: return pool;
212: }
213:
214: public long getLineBoxAge() {
215: return lineBoxAge;
216: }
217:
218: public void setLineBoxAge(final long lineBoxAge) {
219: this .lineBoxAge = lineBoxAge;
220: }
221:
222: public long getMinorLayoutAge() {
223: return minorLayoutAge;
224: }
225:
226: public void setMinorLayoutAge(final long minorLayoutAge) {
227: this .minorLayoutAge = minorLayoutAge;
228: }
229:
230: /**
231: * The public-id for the paragraph is the pool-box.
232: *
233: * @return
234: */
235: public InstanceID getInstanceId() {
236: return pool.getInstanceId();
237: }
238:
239: public int getPoolSize() {
240: return poolSize;
241: }
242:
243: public void setPoolSize(final int poolSize) {
244: this .poolSize = poolSize;
245: }
246:
247: public void setRawValue(final Object rawValue) {
248: this .rawValue = rawValue;
249: }
250:
251: public Object getRawValue() {
252: return rawValue;
253: }
254:
255: public void close() {
256: pool.close();
257: super.close();
258: }
259: }
|