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: * LogicalPageBox.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.PageDefinition;
032: import org.jfree.report.layout.model.context.BoxDefinition;
033: import org.jfree.report.layout.style.SimpleStyleSheet;
034: import org.jfree.report.util.InstanceID;
035:
036: /**
037: * The logical page is the root-structure of the generated content. This object is a slotted container.
038: *
039: * @author Thomas Morgner
040: */
041: public class LogicalPageBox extends BlockRenderBox {
042:
043: // All breaks along the major-axis.
044: private PageBreakPositionList allVerticalBreaks;
045: private long pageOffset;
046: private long pageEnd;
047:
048: private WatermarkAreaBox watermarkArea;
049: private PageAreaBox headerArea;
050: private PageAreaBox footerArea;
051: private DefaultPageGrid pageGrid;
052: private InstanceID contentAreaId;
053: private String pageName;
054:
055: public LogicalPageBox(final PageDefinition pageDefinition) {
056: super (SimpleStyleSheet.EMPTY_STYLE, BoxDefinition.EMPTY, null);
057: this .headerArea = new PageAreaBox(getStyleSheet(),
058: BoxDefinition.EMPTY);
059: this .headerArea.setName("Logical-Page-Header-Area");
060: this .headerArea.setLogicalPage(this );
061: this .footerArea = new PageAreaBox(getStyleSheet(),
062: BoxDefinition.EMPTY);
063: this .footerArea.setName("Logical-Page-Footer-Area");
064: this .footerArea.setLogicalPage(this );
065:
066: final BoxDefinition boxDefinition = new BoxDefinition();
067: boxDefinition
068: .setPreferredHeight(new RenderLength(100000, true));
069: this .watermarkArea = new WatermarkAreaBox(getStyleSheet(),
070: boxDefinition);
071: this .watermarkArea.setName("Logical-Page-Watermark-Area");
072: this .watermarkArea.setLogicalPage(this );
073:
074: final BlockRenderBox contentArea = new BlockRenderBox(
075: getStyleSheet(), BoxDefinition.EMPTY, null);
076: contentArea.setName("Logical-Page-Content-Area");
077: addChild(contentArea);
078: contentAreaId = contentArea.getInstanceId();
079: this .pageGrid = new DefaultPageGrid(pageDefinition);
080:
081: this .allVerticalBreaks = new PageBreakPositionList(null, 1);
082: }
083:
084: public BlockRenderBox getContentArea() {
085: final BlockRenderBox blockRenderBox = (BlockRenderBox) findNodeById(contentAreaId);
086: if (blockRenderBox == null) {
087: throw new IllegalStateException(
088: "Cloning or deriving must have failed: No content area.");
089: }
090: return blockRenderBox;
091: }
092:
093: public BlockRenderBox getHeaderArea() {
094: return headerArea;
095: }
096:
097: public BlockRenderBox getFooterArea() {
098: return footerArea;
099: }
100:
101: public WatermarkAreaBox getWatermarkArea() {
102: return watermarkArea;
103: }
104:
105: public LogicalPageBox getLogicalPage() {
106: return this ;
107: }
108:
109: public long getPageWidth() {
110: return pageGrid.getMaximumPageWidth();
111: }
112:
113: public PageGrid getPageGrid() {
114: return pageGrid;
115: }
116:
117: public long getPageOffset() {
118: return pageOffset;
119: }
120:
121: public void setPageOffset(final long pageOffset) {
122: this .pageOffset = pageOffset;
123: }
124:
125: public long getPageEnd() {
126: return pageEnd;
127: }
128:
129: public void setPageEnd(final long pageEnd) {
130: this .pageEnd = pageEnd;
131: }
132:
133: public long[] getPhysicalBreaks(final int axis) {
134: if (axis == RenderNode.HORIZONTAL_AXIS) {
135: return pageGrid.getHorizontalBreaks();
136: }
137: return pageGrid.getVerticalBreaks();
138: }
139:
140: public long getPageHeight() {
141: return pageGrid.getMaximumPageHeight();
142: }
143:
144: /**
145: * Derive creates a disconnected node that shares all the properties of the
146: * original node. The derived node will no longer have any parent, silbling,
147: * child or any other relationships with other nodes.
148: *
149: * @return
150: */
151: public RenderNode deriveFrozen(final boolean deepDerive) {
152: final LogicalPageBox box = (LogicalPageBox) super
153: .deriveFrozen(deepDerive);
154: box.headerArea = (PageAreaBox) headerArea
155: .deriveFrozen(deepDerive);
156: box.headerArea.setLogicalPage(box);
157: box.footerArea = (PageAreaBox) footerArea
158: .deriveFrozen(deepDerive);
159: box.footerArea.setLogicalPage(box);
160: box.watermarkArea = (WatermarkAreaBox) watermarkArea
161: .deriveFrozen(deepDerive);
162: box.watermarkArea.setLogicalPage(box);
163: //
164: // box.subFlows.clear();
165: //
166: // for (int i = 0; i < subFlows.size(); i++)
167: // {
168: // NormalFlowRenderBox flowRenderBox = (NormalFlowRenderBox) subFlows.get(i);
169: // box.subFlows.add(flowRenderBox.deriveFrozen(deepDerive));
170: // }
171:
172: return box;
173: }
174:
175: /**
176: * Derive creates a disconnected node that shares all the properties of the
177: * original node. The derived node will no longer have any parent, silbling,
178: * child or any other relationships with other nodes.
179: *
180: * @return
181: */
182: public RenderNode derive(final boolean deepDerive) {
183: final LogicalPageBox box = (LogicalPageBox) super
184: .derive(deepDerive);
185: box.headerArea = (PageAreaBox) headerArea.derive(deepDerive);
186: box.headerArea.setLogicalPage(box);
187: box.footerArea = (PageAreaBox) footerArea.derive(deepDerive);
188: box.footerArea.setLogicalPage(box);
189: box.watermarkArea = (WatermarkAreaBox) watermarkArea
190: .derive(deepDerive);
191: box.watermarkArea.setLogicalPage(box);
192: // box.subFlows.clear();
193: //
194: // for (int i = 0; i < subFlows.size(); i++)
195: // {
196: // NormalFlowRenderBox flowRenderBox = (NormalFlowRenderBox) subFlows.get(i);
197: // box.subFlows.add(flowRenderBox.deriveForAdvance(deepDerive));
198: // }
199:
200: return box;
201: }
202:
203: /**
204: * Derives an hibernation copy. The resulting object should get stripped of
205: * all unnecessary caching information and all objects, which will be
206: * regenerated when the layouting restarts. Size does matter here.
207: *
208: * @return
209: */
210: public RenderNode hibernate() {
211: final LogicalPageBox box = (LogicalPageBox) super .hibernate();
212: box.headerArea = (PageAreaBox) headerArea.hibernate();
213: box.headerArea.setLogicalPage(box);
214: box.footerArea = (PageAreaBox) footerArea.hibernate();
215: box.footerArea.setLogicalPage(box);
216: box.watermarkArea = (WatermarkAreaBox) watermarkArea
217: .hibernate();
218: box.watermarkArea.setLogicalPage(box);
219:
220: // box.subFlows.clear();
221: //
222: // for (int i = 0; i < subFlows.size(); i++)
223: // {
224: // NormalFlowRenderBox flowRenderBox = (NormalFlowRenderBox) subFlows.get(i);
225: // box.subFlows.add(flowRenderBox.hibernate());
226: // }
227:
228: return box;
229: }
230:
231: /**
232: * Clones this node. Be aware that cloning can get you into deep trouble, as
233: * the relations this node has may no longer be valid.
234: *
235: * @return
236: */
237: public Object clone() {
238: try {
239: final LogicalPageBox o = (LogicalPageBox) super .clone();
240: o.pageGrid = (DefaultPageGrid) pageGrid.clone();
241: o.allVerticalBreaks = allVerticalBreaks;
242: return o;
243: } catch (CloneNotSupportedException e) {
244: throw new IllegalStateException(
245: "Cloning *must* be supported.");
246: }
247: }
248:
249: public void setAllVerticalBreaks(
250: final PageBreakPositionList allVerticalBreaks) {
251: this .allVerticalBreaks = allVerticalBreaks;
252: }
253:
254: public PageBreakPositionList getAllVerticalBreaks() {
255: return allVerticalBreaks;
256: }
257:
258: public long computePageEnd() {
259: final long pageOffset = getPageOffset();
260: final PageBreakPositionList allVerticalBreaks = getAllVerticalBreaks();
261: final long lastMasterBreak = allVerticalBreaks
262: .getLastMasterBreak();
263: if (pageOffset == lastMasterBreak) {
264: return getHeight();
265: }
266:
267: return allVerticalBreaks
268: .findNextMajorBreakPosition(pageOffset + 1);
269: }
270:
271: public String getPageName() {
272: return pageName;
273: }
274:
275: public void setPageName(final String pageName) {
276: this.pageName = pageName;
277: }
278: }
|