1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package com.sun.star.report.pentaho.output.text;
24 
25 import com.sun.star.report.pentaho.styles.LengthCalculator;
26 
27 import org.jfree.layouting.input.style.values.CSSNumericValue;
28 
29 /**
30  * Todo: Document me!
31  *
32  * @author Thomas Morgner
33  * @since 24.03.2007
34  */
35 public class PageContext
36 {
37 
38     public static final int KEEP_TOGETHER_OFF = 0;
39     public static final int KEEP_TOGETHER_GROUP = 1;
40     public static final int KEEP_TOGETHER_FIRST_DETAIL = 2;
41     private PageContext parent;
42     private String header;
43     private CSSNumericValue headerHeight;
44     private String footer;
45     private CSSNumericValue footerHeight;
46     private int keepTogether;
47     private Integer columnCount = null;
48     private boolean sectionOpen;
49 
PageContext()50     public PageContext()
51     {
52         this(null);
53     }
54 
PageContext(final PageContext parent)55     public PageContext(final PageContext parent)
56     {
57         this.parent = parent;
58         if (parent != null)
59         {
60             this.keepTogether = parent.getKeepTogether();
61         }
62     }
63 
getActiveColumns()64     public int getActiveColumns()
65     {
66         PageContext pc = this;
67         while (pc != null)
68         {
69             // TODO: IS this code correct? Why not columnCount = pc.getColumnCount(); ?
70             if (columnCount != null)
71             {
72                 return columnCount;
73             }
74             pc = pc.getParent();
75         }
76         return 1;
77     }
78 
setColumnCount(final Integer columnCount)79     public void setColumnCount(final Integer columnCount)
80     {
81         this.columnCount = columnCount;
82     }
83 
getColumnCount()84     public Integer getColumnCount()
85     {
86         return columnCount;
87     }
88 
getHeader()89     public String getHeader()
90     {
91         return header;
92     }
93 
setHeader(final String header, final CSSNumericValue height)94     public void setHeader(final String header, final CSSNumericValue height)
95     {
96         this.header = header;
97         this.headerHeight = height;
98     }
99 
getFooter()100     public String getFooter()
101     {
102         return footer;
103     }
104 
getHeaderHeight()105     public CSSNumericValue getHeaderHeight()
106     {
107         return headerHeight;
108     }
109 
getFooterHeight()110     public CSSNumericValue getFooterHeight()
111     {
112         return footerHeight;
113     }
114 
setFooter(final String footer, final CSSNumericValue height)115     public void setFooter(final String footer, final CSSNumericValue height)
116     {
117         this.footer = footer;
118         this.footerHeight = height;
119     }
120 
getKeepTogether()121     public int getKeepTogether()
122     {
123         return keepTogether;
124     }
125 
setKeepTogether(final int keepTogether)126     public void setKeepTogether(final int keepTogether)
127     {
128         this.keepTogether = keepTogether;
129     }
130 
getParent()131     public PageContext getParent()
132     {
133         return parent;
134     }
135 
getAllFooterSize()136     public CSSNumericValue getAllFooterSize()
137     {
138         if (parent == null)
139         {
140             return footerHeight;
141         }
142 
143         final LengthCalculator lnc = new LengthCalculator();
144         PageContext pc = this;
145         while (pc != null)
146         {
147             lnc.add(pc.getFooterHeight());
148             pc = pc.getParent();
149         }
150         return lnc.getResult();
151     }
152 
getAllHeaderSize()153     public CSSNumericValue getAllHeaderSize()
154     {
155         if (parent == null)
156         {
157             return headerHeight;
158         }
159 
160         final LengthCalculator lnc = new LengthCalculator();
161         PageContext pc = this;
162         while (pc != null)
163         {
164             lnc.add(pc.getHeaderHeight());
165             pc = pc.getParent();
166         }
167         return lnc.getResult();
168     }
169 
getPageFooterContent()170     public String getPageFooterContent()
171     {
172         if (parent == null)
173         {
174             return getFooter();
175         }
176 
177         final StringBuffer b = new StringBuffer();
178 
179         PageContext pc = this;
180         while (pc != null)
181         {
182             final String footer_ = pc.getFooter();
183             if (footer_ != null)
184             {
185                 b.append(footer_);
186             }
187             pc = pc.getParent();
188         }
189 
190         if (b.length() != 0)
191         {
192             return b.toString();
193         }
194         return null;
195     }
196 
getPageHeaderContent()197     public String getPageHeaderContent()
198     {
199         if (parent == null)
200         {
201             return getHeader();
202         }
203 
204         final StringBuffer b = new StringBuffer();
205         b.append(parent.getPageHeaderContent());
206         b.append(getHeader());
207 
208         if (b.length() != 0)
209         {
210             return b.toString();
211         }
212         return null;
213     }
214 
isSectionOpen()215     public boolean isSectionOpen()
216     {
217         return sectionOpen;
218     }
219 
setSectionOpen(final boolean sectionOpen)220     public void setSectionOpen(final boolean sectionOpen)
221     {
222         this.sectionOpen = sectionOpen;
223     }
224 }
225