1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Map ; 33 import java.util.Set ; 34 35 import net.sf.jasperreports.engine.JRBand; 36 import net.sf.jasperreports.engine.JRElement; 37 import net.sf.jasperreports.engine.JRException; 38 import net.sf.jasperreports.engine.JRExpression; 39 import net.sf.jasperreports.engine.JRGroup; 40 import net.sf.jasperreports.engine.JRSubreport; 41 import net.sf.jasperreports.engine.JRSubreportReturnValue; 42 43 44 48 public class JRFillBand extends JRFillElementContainer implements JRBand 49 { 50 51 52 55 private JRBand parent = null; 56 57 private boolean isPrintWhenTrue = true; 58 59 62 private boolean isNewPageColumn = false; 63 private boolean isFirstWholeOnPageColumn = false; 64 private Map isNewGroupMap = new HashMap (); 65 66 private Set nowEvaluationTimes; 67 68 71 protected JRFillBand( 72 JRBaseFiller filler, 73 JRBand band, 74 JRFillObjectFactory factory 75 ) 76 { 77 super(filler, band, factory); 78 79 parent = band; 80 81 if (deepElements.length > 0) 82 { 83 for(int i = 0; i < deepElements.length; i++) 84 { 85 deepElements[i].setBand(this); 86 } 87 } 88 89 initElements(); 90 91 initConditionalStyles(); 92 93 nowEvaluationTimes = new HashSet (); 94 } 95 96 97 100 protected void setNewPageColumn(boolean isNew) 101 { 102 this.isNewPageColumn = isNew; 103 } 104 105 106 109 protected boolean isNewPageColumn() 110 { 111 return isNewPageColumn; 112 } 113 114 115 120 protected boolean isFirstWholeOnPageColumn() 121 { 122 return isFirstWholeOnPageColumn; 123 } 124 125 126 129 protected void setNewGroup(JRGroup group, boolean isNew) 130 { 131 isNewGroupMap.put(group, isNew ? Boolean.TRUE : Boolean.FALSE); 132 } 133 134 135 138 protected boolean isNewGroup(JRGroup group) 139 { 140 Boolean value = (Boolean )isNewGroupMap.get(group); 141 142 if (value == null) 143 { 144 value = Boolean.FALSE; 145 } 146 147 return value.booleanValue(); 148 } 149 150 151 154 public int getHeight() 155 { 156 return (parent != null ? parent.getHeight() : 0); 157 } 158 159 162 public boolean isSplitAllowed() 163 { 164 return parent.isSplitAllowed(); 165 } 166 167 170 public void setSplitAllowed(boolean isSplitAllowed) 171 { 172 } 173 174 177 public JRExpression getPrintWhenExpression() 178 { 179 return (parent != null ? parent.getPrintWhenExpression() : null); 180 } 181 182 185 protected boolean isPrintWhenExpressionNull() 186 { 187 return (getPrintWhenExpression() == null); 188 } 189 190 193 protected boolean isPrintWhenTrue() 194 { 195 return isPrintWhenTrue; 196 } 197 198 201 protected void setPrintWhenTrue(boolean isPrintWhenTrue) 202 { 203 this.isPrintWhenTrue = isPrintWhenTrue; 204 } 205 206 209 protected boolean isToPrint() 210 { 211 return 212 (isPrintWhenExpressionNull() || 213 (!isPrintWhenExpressionNull() && 214 isPrintWhenTrue())); 215 } 216 217 218 221 protected void evaluatePrintWhenExpression( 222 byte evaluation 223 ) throws JRException 224 { 225 boolean isPrintTrue = false; 226 227 JRExpression expression = getPrintWhenExpression(); 228 if (expression != null) 229 { 230 Boolean printWhenExpressionValue = (Boolean )filler.evaluateExpression(expression, evaluation); 231 if (printWhenExpressionValue == null) 232 { 233 isPrintTrue = false; 234 } 235 else 236 { 237 isPrintTrue = printWhenExpressionValue.booleanValue(); 238 } 239 } 240 241 setPrintWhenTrue(isPrintTrue); 242 } 243 244 245 246 249 protected JRPrintBand refill( 250 int availableStretchHeight 251 ) throws JRException 252 { 253 rewind(); 254 255 return fill(availableStretchHeight); 256 } 257 258 259 262 protected JRPrintBand fill() throws JRException 263 { 264 return fill(0, false); 265 } 266 267 268 271 protected JRPrintBand fill( 272 int availableStretchHeight 273 ) throws JRException 274 { 275 return fill(availableStretchHeight, true); 276 } 277 278 279 282 protected JRPrintBand fill( 283 int availableStretchHeight, 284 boolean isOverflowAllowed 285 ) throws JRException 286 { 287 filler.fillContext.ensureMasterPageAvailable(); 288 289 if ( 290 Thread.currentThread().isInterrupted() 291 || filler.isInterrupted() 292 ) 293 { 294 filler.setInterrupted(true); 296 297 throw new JRFillInterruptedException(); 298 } 299 300 filler.setBandOverFlowAllowed(isOverflowAllowed); 301 302 initFill(); 303 304 if (isNewPageColumn && !isOverflow) 305 { 306 isFirstWholeOnPageColumn = true; 307 } 308 309 resetElements(); 310 311 prepareElements(availableStretchHeight, isOverflowAllowed); 312 313 stretchElements(); 314 315 moveBandBottomElements(); 316 317 removeBlankElements(); 318 319 isFirstWholeOnPageColumn = isNewPageColumn && isOverflow; 320 isNewPageColumn = false; 321 isNewGroupMap = new HashMap (); 322 323 JRPrintBand printBand = new JRPrintBand(); 324 fillElements(printBand); 325 326 return printBand; 327 } 328 329 330 protected int getContainerHeight() 331 { 332 return getHeight(); 333 } 334 335 336 protected boolean isVariableUsedInSubreportReturns(String variableName) 337 { 338 boolean used = false; 339 JRElement[] bandElements = getElements(); 340 if (bandElements != null) 341 { 342 elementsLoop: 343 for (int i = 0; i < bandElements.length; i++) 344 { 345 JRElement element = bandElements[i]; 346 if (element instanceof JRSubreport) 347 { 348 JRSubreport subreport = (JRSubreport) element; 349 JRSubreportReturnValue[] returnValues = subreport.getReturnValues(); 350 if (returnValues != null) 351 { 352 for (int j = 0; j < returnValues.length; j++) 353 { 354 JRSubreportReturnValue returnValue = returnValues[j]; 355 if (returnValue.getToVariable().equals(variableName)) 356 { 357 used = true; 358 break elementsLoop; 359 } 360 } 361 } 362 } 363 } 364 } 365 366 return used; 367 } 368 369 370 protected void addNowEvaluationTime(JREvaluationTime evaluationTime) 371 { 372 nowEvaluationTimes.add(evaluationTime); 373 } 374 375 376 protected void addNowEvaluationTimes(JREvaluationTime[] evaluationTimes) 377 { 378 for (int i = 0; i < evaluationTimes.length; i++) 379 { 380 nowEvaluationTimes.add(evaluationTimes[i]); 381 } 382 } 383 384 385 protected boolean isNowEvaluationTime(JREvaluationTime evaluationTime) 386 { 387 return nowEvaluationTimes.contains(evaluationTime); 388 } 389 390 391 protected int getId() 392 { 393 return System.identityHashCode(this); 394 } 395 396 397 protected void evaluate(byte evaluation) throws JRException 398 { 399 evaluateConditionalStyles(evaluation); 400 super.evaluate(evaluation); 401 } 402 403 } 404 | Popular Tags |