PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jasperreports/src/net/sf/jasperreports/engine/base/JRBaseGroup.java

https://gitlab.com/samuel-davis/JasperReports-OSGI
Java | 344 lines | 228 code | 58 blank | 58 comment | 9 complexity | e17cfa86390d6df249897a342a5113e7 MD5 | raw file
  1. /*
  2. * JasperReports - Free Java Reporting Library.
  3. * Copyright (C) 2001 - 2016 TIBCO Software Inc. All rights reserved.
  4. * http://www.jaspersoft.com
  5. *
  6. * Unless you have purchased a commercial license agreement from Jaspersoft,
  7. * the following license terms apply:
  8. *
  9. * This program is part of JasperReports.
  10. *
  11. * JasperReports is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * JasperReports is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package net.sf.jasperreports.engine.base;
  25. import java.io.IOException;
  26. import java.io.ObjectInputStream;
  27. import java.io.Serializable;
  28. import net.sf.jasperreports.engine.JRBand;
  29. import net.sf.jasperreports.engine.JRConstants;
  30. import net.sf.jasperreports.engine.JRExpression;
  31. import net.sf.jasperreports.engine.JRGroup;
  32. import net.sf.jasperreports.engine.JRRuntimeException;
  33. import net.sf.jasperreports.engine.JRSection;
  34. import net.sf.jasperreports.engine.JRVariable;
  35. import net.sf.jasperreports.engine.design.events.JRChangeEventsSupport;
  36. import net.sf.jasperreports.engine.design.events.JRPropertyChangeSupport;
  37. import net.sf.jasperreports.engine.type.FooterPositionEnum;
  38. import net.sf.jasperreports.engine.util.JRCloneUtils;
  39. /**
  40. * @author Teodor Danciu (teodord@users.sourceforge.net)
  41. */
  42. public class JRBaseGroup implements JRGroup, Serializable, JRChangeEventsSupport
  43. {
  44. /**
  45. *
  46. */
  47. private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
  48. public static final String PROPERTY_MIN_HEIGHT_TO_START_NEW_PAGE = "minHeightToStartNewPage";
  49. public static final String PROPERTY_FOOTER_POSITION = "footerPosition";
  50. public static final String PROPERTY_KEEP_TOGETHER = "keepTogether";
  51. public static final String PROPERTY_RESET_PAGE_NUMBER = "isResetPageNumber";
  52. public static final String PROPERTY_REPRINT_HEADER_ON_EACH_PAGE = "isReprintHeaderOnEachPage";
  53. public static final String PROPERTY_START_NEW_COLUMN = "isStartNewColumn";
  54. public static final String PROPERTY_START_NEW_PAGE = "isStartNewPage";
  55. /**
  56. *
  57. */
  58. protected String name;
  59. protected boolean isStartNewColumn;
  60. protected boolean isStartNewPage;
  61. protected boolean isResetPageNumber;
  62. protected boolean isReprintHeaderOnEachPage;
  63. protected int minHeightToStartNewPage;
  64. protected FooterPositionEnum footerPositionValue = FooterPositionEnum.NORMAL;
  65. protected boolean keepTogether;
  66. /**
  67. *
  68. */
  69. protected JRExpression expression;
  70. protected JRSection groupHeaderSection;
  71. protected JRSection groupFooterSection;
  72. protected JRVariable countVariable;
  73. /**
  74. *
  75. */
  76. protected JRBaseGroup()
  77. {
  78. }
  79. /**
  80. *
  81. */
  82. protected JRBaseGroup(JRGroup group, JRBaseObjectFactory factory)
  83. {
  84. factory.put(group, this);
  85. name = group.getName();
  86. isStartNewColumn = group.isStartNewColumn();
  87. isStartNewPage = group.isStartNewPage();
  88. isResetPageNumber = group.isResetPageNumber();
  89. isReprintHeaderOnEachPage = group.isReprintHeaderOnEachPage();
  90. minHeightToStartNewPage = group.getMinHeightToStartNewPage();
  91. footerPositionValue = group.getFooterPositionValue();
  92. keepTogether = group.isKeepTogether();
  93. expression = factory.getExpression(group.getExpression());
  94. groupHeaderSection = factory.getSection(group.getGroupHeaderSection());
  95. groupFooterSection = factory.getSection(group.getGroupFooterSection());
  96. countVariable = factory.getVariable(group.getCountVariable());
  97. }
  98. @Override
  99. public String getName()
  100. {
  101. return this.name;
  102. }
  103. @Override
  104. public boolean isStartNewColumn()
  105. {
  106. return this.isStartNewColumn;
  107. }
  108. @Override
  109. public void setStartNewColumn(boolean isStart)
  110. {
  111. boolean old = this.isStartNewColumn;
  112. this.isStartNewColumn = isStart;
  113. getEventSupport().firePropertyChange(PROPERTY_START_NEW_COLUMN, old, this.isStartNewColumn);
  114. }
  115. @Override
  116. public boolean isStartNewPage()
  117. {
  118. return this.isStartNewPage;
  119. }
  120. @Override
  121. public void setStartNewPage(boolean isStart)
  122. {
  123. boolean old = this.isStartNewPage;
  124. this.isStartNewPage = isStart;
  125. getEventSupport().firePropertyChange(PROPERTY_START_NEW_PAGE, old, this.isStartNewPage);
  126. }
  127. @Override
  128. public boolean isResetPageNumber()
  129. {
  130. return this.isResetPageNumber;
  131. }
  132. @Override
  133. public void setResetPageNumber(boolean isReset)
  134. {
  135. boolean old = this.isResetPageNumber;
  136. this.isResetPageNumber = isReset;
  137. getEventSupport().firePropertyChange(PROPERTY_RESET_PAGE_NUMBER, old, this.isResetPageNumber);
  138. }
  139. @Override
  140. public boolean isReprintHeaderOnEachPage()
  141. {
  142. return this.isReprintHeaderOnEachPage;
  143. }
  144. @Override
  145. public void setReprintHeaderOnEachPage(boolean isReprint)
  146. {
  147. boolean old = this.isReprintHeaderOnEachPage;
  148. this.isReprintHeaderOnEachPage = isReprint;
  149. getEventSupport().firePropertyChange(PROPERTY_REPRINT_HEADER_ON_EACH_PAGE, old, this.isReprintHeaderOnEachPage);
  150. }
  151. @Override
  152. public int getMinHeightToStartNewPage()
  153. {
  154. return this.minHeightToStartNewPage;
  155. }
  156. @Override
  157. public void setMinHeightToStartNewPage(int minHeight)
  158. {
  159. int old = this.minHeightToStartNewPage;
  160. this.minHeightToStartNewPage = minHeight;
  161. getEventSupport().firePropertyChange(PROPERTY_MIN_HEIGHT_TO_START_NEW_PAGE, old, this.minHeightToStartNewPage);
  162. }
  163. @Override
  164. public FooterPositionEnum getFooterPositionValue()
  165. {
  166. return this.footerPositionValue;
  167. }
  168. @Override
  169. public void setFooterPosition(FooterPositionEnum footerPositionValue)
  170. {
  171. FooterPositionEnum old = this.footerPositionValue;
  172. this.footerPositionValue = footerPositionValue;
  173. getEventSupport().firePropertyChange(PROPERTY_FOOTER_POSITION, old, this.footerPositionValue);
  174. }
  175. @Override
  176. public boolean isKeepTogether()
  177. {
  178. return this.keepTogether;
  179. }
  180. @Override
  181. public void setKeepTogether(boolean keepTogether)
  182. {
  183. boolean old = this.keepTogether;
  184. this.keepTogether = keepTogether;
  185. getEventSupport().firePropertyChange(PROPERTY_KEEP_TOGETHER, old, this.keepTogether);
  186. }
  187. @Override
  188. public JRExpression getExpression()
  189. {
  190. return this.expression;
  191. }
  192. @Override
  193. public JRSection getGroupHeaderSection()
  194. {
  195. return this.groupHeaderSection;
  196. }
  197. @Override
  198. public JRSection getGroupFooterSection()
  199. {
  200. return this.groupFooterSection;
  201. }
  202. @Override
  203. public JRVariable getCountVariable()
  204. {
  205. return this.countVariable;
  206. }
  207. @Override
  208. public Object clone()
  209. {
  210. JRBaseGroup clone = null;
  211. try
  212. {
  213. clone = (JRBaseGroup)super.clone();
  214. }
  215. catch (CloneNotSupportedException e)
  216. {
  217. throw new JRRuntimeException(e);
  218. }
  219. clone.expression = JRCloneUtils.nullSafeClone(expression);
  220. clone.groupHeader = JRCloneUtils.nullSafeClone(groupHeader);
  221. clone.groupFooter = JRCloneUtils.nullSafeClone(groupFooter);
  222. clone.countVariable = JRCloneUtils.nullSafeClone(countVariable);
  223. clone.eventSupport = null;
  224. return clone;
  225. }
  226. private transient JRPropertyChangeSupport eventSupport;
  227. @Override
  228. public JRPropertyChangeSupport getEventSupport()
  229. {
  230. synchronized (this)
  231. {
  232. if (eventSupport == null)
  233. {
  234. eventSupport = new JRPropertyChangeSupport(this);
  235. }
  236. }
  237. return eventSupport;
  238. }
  239. /*
  240. * These fields are only for serialization backward compatibility.
  241. */
  242. private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
  243. /**
  244. * @deprecated
  245. */
  246. private byte footerPosition;
  247. /**
  248. * @deprecated
  249. */
  250. private JRBand groupHeader;
  251. /**
  252. * @deprecated
  253. */
  254. private JRBand groupFooter;
  255. @SuppressWarnings("deprecation")
  256. private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
  257. {
  258. in.defaultReadObject();
  259. if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_7_2)
  260. {
  261. if (footerPosition == 0)
  262. {
  263. // stream class didn't have footerPosition, use default.
  264. // ideally we should have used PSEUDO_SERIAL_VERSION_UID to
  265. // detect this case, but there was no PSEUDO_SERIAL_VERSION_UID
  266. // when footerPosition was introduced
  267. footerPositionValue = FooterPositionEnum.NORMAL;
  268. }
  269. else
  270. {
  271. // convert stream byte value to enum
  272. footerPositionValue = FooterPositionEnum.getByValue(footerPosition);
  273. }
  274. }
  275. if (groupHeader != null)
  276. {
  277. groupHeaderSection = new JRBaseSection(groupHeader);
  278. groupHeader = null;
  279. }
  280. if (groupFooter != null)
  281. {
  282. groupFooterSection = new JRBaseSection(groupFooter);
  283. groupFooter = null;
  284. }
  285. }
  286. }