1 /*
2 * JasperReports - Free Java Reporting Library.
3 * Copyright (C) 2001 - 2019 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.component;
25
26 /**
27 * A result of a {@link FillComponent#prepare(int) component fill preparation}.
28 *
29 * @author Lucian Chirita (lucianc@users.sourceforge.net)
30 */
31 public class FillPrepareResult
32 {
33
34 /**
35 * A result that indicates that the component will not print and does not
36 * require a band overflow.
37 *
38 * <p>
39 * This result would be used when the component does not intend to include
40 * any print element in the generated report.
41 */
42 public static final FillPrepareResult NO_PRINT_NO_OVERFLOW = new FillPrepareResult(false, 0, false);
43
44 /**
45 * A result that indicates that the component will print, but will not
46 * stretch vertically.
47 *
48 * <p>
49 * This would be used when the component will produce a print element that
50 * fits the space allocated at design time for the component element.
51 */
52 public static final FillPrepareResult PRINT_NO_STRETCH = new FillPrepareResult(true, 0, false);
53
54 /**
55 * Returns a result that indicates that the component will not print
56 * (at the current position in the generated report), but requires
57 * an overflow so that it can print on a new column/page.
58 *
59 * @param stretchHeight the height that is consumed by the component;
60 * usually this would be the same as the <code>availableHeight</code>
61 * argument passed to {@link FillComponent#prepare(int)}
62 * @return a result as described above
63 */
64 public static FillPrepareResult noPrintOverflow(int stretchHeight)
65 {
66 return new FillPrepareResult(false, stretchHeight, true);
67 }
68
69 /**
70 * Returns a result which indicates that the component will print at the
71 * current position, and optionally consume more vertical space
72 * and/or require a band overflow.
73 *
74 * @param stretchHeight the stretched height of the component
75 * @param overflow whether a band overflow is required so that the
76 * component would continue printing on a new column/page
77 * @return a result that the component will print with the specified
78 * stretch height and overflow flag
79 */
80 public static FillPrepareResult printStretch(int stretchHeight, boolean overflow)
81 {
82 return new FillPrepareResult(true, stretchHeight, overflow);
83 }
84
85 private final boolean toPrint;
86 private final boolean overflow;
87 private final int stretchHeight;
88
89 /**
90 * Creates a fill preparation result.
91 *
92 * @param toPrint indicates whether the component will produce a print
93 * element at the current position in the generated report
94 * @param stretchHeight the amount of vertical space consumed
95 * by the component
96 * @param overflow indicates whether a band overflow is required in order
97 * to continue the component fill on a new column/page
98 */
99 public FillPrepareResult(boolean toPrint,
100 int stretchHeight, boolean overflow)
101 {
102 this.stretchHeight = stretchHeight;
103 this.toPrint = toPrint;
104 this.overflow = overflow;
105 }
106
107 /**
108 * Returns whether the component will produce a print element at the current
109 * position in the generated report.
110 *
111 * @return whether the component will print
112 */
113 public boolean isToPrint()
114 {
115 return toPrint;
116 }
117
118 /**
119 * Returns whether a band overflow is required in order to continue the
120 * component fill on a new column/page.
121 *
122 * @return whether a band overflow is required
123 */
124 public boolean willOverflow()
125 {
126 return overflow;
127 }
128
129 /**
130 * Returns the amount of vertical space consumed by the component.
131 *
132 * @return the amount of vertical space consumed by the component
133 */
134 public int getStretchHeight()
135 {
136 return stretchHeight;
137 }
138
139 public FillPrepareResult addStretch(int delta)
140 {
141 return new FillPrepareResult(toPrint, stretchHeight + delta, overflow);
142 }
143
144 }
145