1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.awt.Color ; 31 import java.io.IOException ; 32 import java.util.HashMap ; 33 import java.util.List ; 34 import java.util.Map ; 35 36 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 37 import net.sf.jasperreports.engine.JRBox; 38 import net.sf.jasperreports.engine.JRChild; 39 import net.sf.jasperreports.engine.JRElement; 40 import net.sf.jasperreports.engine.JRException; 41 import net.sf.jasperreports.engine.JRExpressionCollector; 42 import net.sf.jasperreports.engine.JRFrame; 43 import net.sf.jasperreports.engine.JRPrintElement; 44 import net.sf.jasperreports.engine.JRStyle; 45 import net.sf.jasperreports.engine.base.JRBaseBox; 46 import net.sf.jasperreports.engine.base.JRBaseElementGroup; 47 import net.sf.jasperreports.engine.util.JRStyleResolver; 48 import net.sf.jasperreports.engine.xml.JRXmlWriter; 49 50 56 public class JRFillFrame extends JRFillElement implements JRFrame 57 { 58 protected final JRFrame parentFrame; 59 60 63 private JRFillFrameElements frameContainer; 64 65 68 private Map bottomTemplateFrames; 69 70 73 private Map topTemplateFrames; 74 75 78 private Map topBottomTemplateFrames; 79 80 83 private boolean first; 84 85 private boolean fillBottomBorder; 86 87 90 private boolean filling; 91 92 public JRFillFrame(JRBaseFiller filler, JRFrame frame, JRFillObjectFactory factory) 93 { 94 super(filler, frame, factory); 95 96 parentFrame = frame; 97 98 frameContainer = new JRFillFrameElements(factory); 99 100 bottomTemplateFrames = new HashMap (); 101 topTemplateFrames = new HashMap (); 102 topBottomTemplateFrames = new HashMap (); 103 104 setShrinkable(true); 105 } 106 107 protected JRFillFrame(JRFillFrame frame, JRFillCloneFactory factory) 108 { 109 super(frame, factory); 110 111 parentFrame = frame.parentFrame; 112 113 frameContainer = new JRFillFrameElements(frame.frameContainer, factory); 114 115 bottomTemplateFrames = frame.bottomTemplateFrames; 116 topTemplateFrames = frame.topTemplateFrames; 117 topBottomTemplateFrames = frame.topBottomTemplateFrames; 118 } 119 120 123 public byte getMode() 124 { 125 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 126 } 127 128 protected void evaluate(byte evaluation) throws JRException 129 { 130 reset(); 131 132 evaluatePrintWhenExpression(evaluation); 133 134 if (isPrintWhenExpressionNull() || isPrintWhenTrue()) 135 { 136 frameContainer.evaluate(evaluation); 137 138 boolean repeating = true; 139 JRFillElement[] elements = (JRFillElement[]) getElements(); 140 for (int i = 0; repeating && i < elements.length; i++) 141 { 142 repeating &= elements[i].isValueRepeating(); 143 } 144 setValueRepeating(repeating); 145 } 146 147 filling = false; 148 } 149 150 protected void rewind() throws JRException 151 { 152 frameContainer.rewind(); 153 154 filling = false; 155 } 156 157 protected boolean prepare(int availableStretchHeight, boolean isOverflow) throws JRException 158 { 159 super.prepare(availableStretchHeight, isOverflow); 160 161 if (!isToPrint()) 162 { 163 return false; 164 } 165 166 first = !isOverflow || !filling; 167 int topPadding = first ? getTopPadding() : 0; 168 int bottomPadding = getBottomPadding(); 169 170 if (availableStretchHeight < getRelativeY() - getY() - getBandBottomY() - topPadding) 171 { 172 setToPrint(false); 173 return true; 174 } 175 176 if (!filling && !isPrintRepeatedValues() && isValueRepeating() && 177 (!isPrintInFirstWholeBand() || !getBand().isFirstWholeOnPageColumn()) && 178 (getPrintWhenGroupChanges() == null || !getBand().isNewGroup(getPrintWhenGroupChanges())) && 179 (!isOverflow || !isPrintWhenDetailOverflows()) 180 ) 181 { 182 setToPrint(false); 183 return false; 184 } 185 186 if (!filling && isOverflow && isAlreadyPrinted()) 188 { 189 if (isPrintWhenDetailOverflows()) 190 { 191 rewind(); 192 setReprinted(true); 193 } 194 else 195 { 196 setToPrint(false); 197 return false; 198 } 199 } 200 201 int stretchHeight = availableStretchHeight - getRelativeY() + getY() + getBandBottomY(); 202 203 frameContainer.initFill(); 204 frameContainer.resetElements(); 205 int frameElemsAvailableHeight = stretchHeight + bottomPadding + getTopPadding() - topPadding; 206 frameContainer.prepareElements(frameElemsAvailableHeight, true); 207 208 boolean willOverflow = frameContainer.willOverflow(); 209 if (willOverflow) 210 { 211 fillBottomBorder = false; 212 setStretchHeight(getHeight() + stretchHeight); 213 } 214 else 215 { 216 int neededStretch = frameContainer.getStretchHeight() - frameContainer.getFirstY() + topPadding + bottomPadding; 217 if (neededStretch <= getHeight() + stretchHeight) 218 { 219 fillBottomBorder = true; 220 setStretchHeight(neededStretch); 221 } 222 else { 224 fillBottomBorder = false; 225 setStretchHeight(getHeight() + stretchHeight); 226 } 227 } 228 229 filling = willOverflow; 230 231 return willOverflow; 232 } 233 234 protected void setStretchHeight(int stretchHeight) 235 { 236 super.setStretchHeight(stretchHeight); 237 238 int topPadding = first ? getTopPadding() : 0; 239 int bottomPadding = fillBottomBorder ? getBottomPadding() : 0; 240 frameContainer.setStretchHeight(stretchHeight + frameContainer.getFirstY() - topPadding - bottomPadding); 241 } 242 243 244 protected void stretchHeightFinal() 245 { 246 frameContainer.stretchElements(); 247 frameContainer.moveBandBottomElements(); 248 frameContainer.removeBlankElements(); 249 250 int topPadding = first ? getTopPadding() : 0; 251 int bottomPadding = fillBottomBorder ? getBottomPadding() : 0; 252 super.setStretchHeight(frameContainer.getStretchHeight() - frameContainer.getFirstY() + topPadding + bottomPadding); 253 } 254 255 256 protected JRPrintElement fill() throws JRException 257 { 258 JRTemplatePrintFrame printFrame = new JRTemplatePrintFrame(getTemplate()); 259 printFrame.setX(getX()); 260 printFrame.setY(getRelativeY()); 261 printFrame.setWidth(getWidth()); 262 263 frameContainer.fillElements(printFrame); 264 265 printFrame.setHeight(getStretchHeight()); 266 267 return printFrame; 268 } 269 270 protected JRTemplateFrame getTemplate() 271 { 272 JRStyle style = getStyle(); 273 274 Map templatesMap; 275 if (first) 276 { 277 if (fillBottomBorder) 278 { 279 templatesMap = templates; 280 } 281 else { 283 templatesMap = bottomTemplateFrames; 284 } 285 } 286 else 287 { 288 if (fillBottomBorder) { 290 templatesMap = topTemplateFrames; 291 } 292 else { 294 templatesMap = topBottomTemplateFrames; 295 } 296 } 297 298 JRTemplateFrame boxTemplate = (JRTemplateFrame) templatesMap.get(style); 299 if (boxTemplate == null) 300 { 301 boxTemplate = new JRTemplateFrame(filler.getJasperPrint().getDefaultStyleProvider(), this); 302 if (first) 303 { 304 if (!fillBottomBorder) { 306 JRBox bottomBox = new JRBaseBox(this, false, false, false, true); 307 boxTemplate.setBox(bottomBox); 308 } 309 } 310 else 311 { 312 if (fillBottomBorder) { 314 JRBox topBox = new JRBaseBox(this, false, false, true, false); 315 boxTemplate.setBox(topBox); 316 } 317 else { 319 JRBox topBottomBox = new JRBaseBox(this, false, false, true, true); 320 boxTemplate.setBox(topBottomBox); 321 } 322 } 323 324 templatesMap.put(style, boxTemplate); 325 } 326 327 return boxTemplate; 328 } 329 330 protected void resolveElement(JRPrintElement element, byte evaluation) 331 { 332 } 334 335 public JRElement[] getElements() 336 { 337 return frameContainer.getElements(); 338 } 339 340 public List getChildren() 341 { 342 return frameContainer.getChildren(); 343 } 344 345 public void collectExpressions(JRExpressionCollector collector) 346 { 347 collector.collect(this); 348 } 349 350 public JRChild getCopy(JRAbstractObjectFactory factory) 351 { 352 return factory.getFrame(this); 353 } 354 355 public void writeXml(JRXmlWriter writer) throws IOException 356 { 357 writer.writeFrame(this); 358 } 359 360 361 public JRElement getElementByKey(String key) 362 { 363 return JRBaseElementGroup.getElementByKey(getElements(), key); 364 } 365 366 public JRCloneable createClone(JRFillCloneFactory factory) 367 { 368 return new JRFillFrame(this, factory); 369 } 370 371 372 375 protected class JRFillFrameElements extends JRFillElementContainer 376 { 377 JRFillFrameElements(JRFillObjectFactory factory) 378 { 379 super(JRFillFrame.this.filler, parentFrame, factory); 380 initElements(); 381 } 382 383 JRFillFrameElements(JRFillFrameElements frameElements, JRFillCloneFactory factory) 384 { 385 super(frameElements, factory); 386 initElements(); 387 } 388 389 protected int getContainerHeight() 390 { 391 return JRFillFrame.this.getHeight() - getTopPadding() - getBottomPadding(); 392 } 393 } 394 395 397 public byte getBorder() 398 { 399 return JRStyleResolver.getBorder(this); 400 } 401 402 public Byte getOwnBorder() 403 { 404 return parentFrame.getOwnBorder(); 405 } 406 407 public void setBorder(byte border) 408 { 409 } 410 411 public Color getBorderColor() 412 { 413 return JRStyleResolver.getBorderColor(this, getForecolor()); 414 } 415 416 public Color getOwnBorderColor() 417 { 418 return parentFrame.getOwnBorderColor(); 419 } 420 421 public void setBorderColor(Color borderColor) 422 { 423 } 424 425 public int getPadding() 426 { 427 return JRStyleResolver.getPadding(this); 428 } 429 430 public Integer getOwnPadding() 431 { 432 return parentFrame.getOwnPadding(); 433 } 434 435 public void setPadding(int padding) 436 { 437 } 438 439 public byte getTopBorder() 440 { 441 return JRStyleResolver.getTopBorder(this); 442 } 443 444 public Byte getOwnTopBorder() 445 { 446 return parentFrame.getOwnTopBorder(); 447 } 448 449 public void setTopBorder(byte topBorder) 450 { 451 } 452 453 public Color getTopBorderColor() 454 { 455 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 456 } 457 458 public Color getOwnTopBorderColor() 459 { 460 return parentFrame.getOwnTopBorderColor(); 461 } 462 463 public void setTopBorderColor(Color topBorderColor) 464 { 465 } 466 467 public int getTopPadding() 468 { 469 return JRStyleResolver.getTopPadding(this); 470 } 471 472 public Integer getOwnTopPadding() 473 { 474 return parentFrame.getOwnTopPadding(); 475 } 476 477 public void setTopPadding(int topPadding) 478 { 479 } 480 481 public byte getLeftBorder() 482 { 483 return JRStyleResolver.getLeftBorder(this); 484 } 485 486 public Byte getOwnLeftBorder() 487 { 488 return parentFrame.getOwnLeftBorder(); 489 } 490 491 public void setLeftBorder(byte leftBorder) 492 { 493 } 494 495 public Color getLeftBorderColor() 496 { 497 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 498 } 499 500 public Color getOwnLeftBorderColor() 501 { 502 return parentFrame.getOwnLeftBorderColor(); 503 } 504 505 public void setLeftBorderColor(Color leftBorderColor) 506 { 507 } 508 509 public int getLeftPadding() 510 { 511 return JRStyleResolver.getLeftPadding(this); 512 } 513 514 public Integer getOwnLeftPadding() 515 { 516 return parentFrame.getOwnLeftPadding(); 517 } 518 519 public void setLeftPadding(int leftPadding) 520 { 521 } 522 523 public byte getBottomBorder() 524 { 525 return JRStyleResolver.getBottomBorder(this); 526 } 527 528 public Byte getOwnBottomBorder() 529 { 530 return parentFrame.getOwnBottomBorder(); 531 } 532 533 public void setBottomBorder(byte bottomBorder) 534 { 535 } 536 537 public Color getBottomBorderColor() 538 { 539 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 540 } 541 542 public Color getOwnBottomBorderColor() 543 { 544 return parentFrame.getOwnBottomBorderColor(); 545 } 546 547 public void setBottomBorderColor(Color bottomBorderColor) 548 { 549 } 550 551 public int getBottomPadding() 552 { 553 return JRStyleResolver.getBottomPadding(this); 554 } 555 556 public Integer getOwnBottomPadding() 557 { 558 return parentFrame.getOwnBottomPadding(); 559 } 560 561 public void setBottomPadding(int bottomPadding) 562 { 563 } 564 565 public byte getRightBorder() 566 { 567 return JRStyleResolver.getRightBorder(this); 568 } 569 570 public Byte getOwnRightBorder() 571 { 572 return parentFrame.getOwnRightBorder(); 573 } 574 575 public void setRightBorder(byte rightBorder) 576 { 577 } 578 579 public Color getRightBorderColor() 580 { 581 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 582 } 583 584 public Color getOwnRightBorderColor() 585 { 586 return parentFrame.getOwnRightBorderColor(); 587 } 588 589 public void setRightBorderColor(Color rightBorderColor) 590 { 591 } 592 593 public int getRightPadding() 594 { 595 return JRStyleResolver.getRightPadding(this); 596 } 597 598 public Integer getOwnRightPadding() 599 { 600 return parentFrame.getOwnRightPadding(); 601 } 602 603 public void setRightPadding(int rightPadding) 604 { 605 } 606 607 public void setBorder(Byte border) 608 { 609 } 610 611 public void setPadding(Integer padding) 612 { 613 } 614 615 public void setTopBorder(Byte topBorder) 616 { 617 } 618 619 public void setTopPadding(Integer topPadding) 620 { 621 } 622 623 public void setLeftBorder(Byte leftBorder) 624 { 625 } 626 627 public void setLeftPadding(Integer leftPadding) 628 { 629 } 630 631 public void setBottomBorder(Byte bottomBorder) 632 { 633 } 634 635 public void setBottomPadding(Integer bottomPadding) 636 { 637 } 638 639 public void setRightBorder(Byte rightBorder) 640 { 641 } 642 643 public void setRightPadding(Integer rightPadding) 644 { 645 } 646 } 647 | Popular Tags |