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.fill;
25
26 import java.awt.Color;
27
28 import net.sf.jasperreports.engine.JRException;
29 import net.sf.jasperreports.engine.JRGraphicElement;
30 import net.sf.jasperreports.engine.JRPen;
31 import net.sf.jasperreports.engine.type.FillEnum;
32 import net.sf.jasperreports.engine.util.StyleUtil;
33
34
35 /**
36  * @author Teodor Danciu (teodord@users.sourceforge.net)
37  */

38 public abstract class JRFillGraphicElement extends JRFillElement implements JRGraphicElement
39 {
40
41     protected final JRPen initPen;
42     protected JRPen pen;
43
44     /**
45      *
46      */

47     protected JRFillGraphicElement(
48         JRBaseFiller filler,
49         JRGraphicElement graphicElement, 
50         JRFillObjectFactory factory
51         )
52     {
53         super(filler, graphicElement, factory);
54         
55         initPen = graphicElement.getLinePen().clone(this);
56     }
57
58
59     protected JRFillGraphicElement(
60         JRFillGraphicElement graphicElement, 
61         JRFillCloneFactory factory
62         )
63     {
64         super(graphicElement, factory);
65         
66         initPen = graphicElement.getLinePen().clone(this);
67     }
68
69     
70     @Override
71     protected void evaluateStyle(
72         byte evaluation
73         ) throws JRException
74     {
75         super.evaluateStyle(evaluation);
76
77         pen = null;
78         
79         if (providerStyle != null)
80         {
81             pen = initPen.clone(this);
82             StyleUtil.appendPen(pen, providerStyle.getLinePen());
83         }
84     }
85
86
87     @Override
88     public JRPen getLinePen()
89     {
90         return pen == null ? initPen : pen;
91     }
92
93     @Override
94     public FillEnum getFillValue()
95     {
96         return getStyleResolver().getFillValue(this);
97     }
98
99     @Override
100     public FillEnum getOwnFillValue()
101     {
102         return providerStyle == null || providerStyle.getOwnFillValue() == null ? ((JRGraphicElement)this.parent).getOwnFillValue() : providerStyle.getOwnFillValue();
103     }
104
105     @Override
106     public void setFill(FillEnum fill)
107     {
108         throw new UnsupportedOperationException();
109     }
110     
111
112     @Override
113     public Float getDefaultLineWidth() 
114     {
115         return ((JRGraphicElement)this.parent).getDefaultLineWidth();
116     }
117
118     @Override
119     public Color getDefaultLineColor() 
120     {
121         return getForecolor();
122     }
123     
124
125     @Override
126     public void rewind()
127     {
128     }
129
130
131     @Override
132     protected boolean prepare(
133         int availableHeight,
134         boolean isOverflow
135         ) throws JRException
136     {
137         boolean willOverflow = false;
138
139         super.prepare(availableHeight, isOverflow);
140         
141         if (!this.isToPrint())
142         {
143             return willOverflow;
144         }
145         
146         boolean isToPrint = true;
147         boolean isReprinted = false;
148
149         if (isOverflow && this.isAlreadyPrinted() && !this.isPrintWhenDetailOverflows())
150         {
151             isToPrint = false;
152         }
153
154         if (
155             isToPrint && 
156             this.isPrintWhenExpressionNull() &&
157             !this.isPrintRepeatedValues()
158             )
159         {
160             if (
161                 ( !this.isPrintInFirstWholeBand() || !this.getBand().isFirstWholeOnPageColumn() ) &&
162                 ( this.getPrintWhenGroupChanges() == null || !this.getBand().isNewGroup(this.getPrintWhenGroupChanges()) ) &&
163                 ( !isOverflow || !this.isPrintWhenDetailOverflows() )
164                 )
165             {
166                 isToPrint = false;
167             }
168         }
169
170         if (
171             isToPrint && 
172             availableHeight < this.getRelativeY() + getHeight()
173             )
174         {
175             isToPrint = false;
176             willOverflow = true;
177         }
178         
179         if (
180             isToPrint && 
181             isOverflow && 
182             //(this.isAlreadyPrinted() || !this.isPrintRepeatedValues())
183             (this.isPrintWhenDetailOverflows() && (this.isAlreadyPrinted() || (!this.isAlreadyPrinted() && !this.isPrintRepeatedValues())))
184             )
185         {
186             isReprinted = true;
187         }
188
189         this.setToPrint(isToPrint);
190         this.setReprinted(isReprinted);
191         
192         return willOverflow;
193     }
194     
195     
196 }
197