1 50 51 package com.lowagie.text.pdf; 52 53 import com.lowagie.text.Chunk; 54 import com.lowagie.text.Element; 55 import com.lowagie.text.Image; 56 import com.lowagie.text.Phrase; 57 import com.lowagie.text.Rectangle; 58 import com.lowagie.text.pdf.events.PdfPCellEventForwarder; 59 60 62 63 public class PdfPCell extends Rectangle{ 64 65 private ColumnText column = new ColumnText(null); 66 67 68 private int verticalAlignment = Element.ALIGN_TOP; 69 70 71 private float paddingLeft = 2; 72 73 74 private float paddingRight = 2; 75 76 77 private float paddingTop = 2; 78 79 80 private float paddingBottom = 2; 81 82 83 private float fixedHeight = 0; 84 85 86 private boolean noWrap = false; 87 88 89 private PdfPTable table; 90 91 92 private float minimumHeight; 93 94 95 private int colspan = 1; 96 97 98 private Image image; 99 100 101 private PdfPCellEvent cellEvent; 102 103 104 private boolean useDescender; 105 106 107 private boolean useBorderPadding = false; 108 109 110 111 protected Phrase phrase; 112 113 116 public PdfPCell() { 117 super(0, 0, 0, 0); 118 borderWidth = 0.5f; 119 border = BOX; 120 column.setLeading(0, 1); 121 } 122 123 127 public PdfPCell(Phrase phrase) { 128 super(0, 0, 0, 0); 129 borderWidth = 0.5f; 130 border = BOX; 131 column.addText(this.phrase = phrase); 132 column.setLeading(0, 1); 133 } 134 135 139 public PdfPCell(Image image) { 140 super(0, 0, 0, 0); 141 borderWidth = 0.5f; 142 border = BOX; 143 column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0))); 144 column.setLeading(0, 1); 145 setPadding(0); 146 } 147 148 153 public PdfPCell(Image image, boolean fit) { 154 super(0, 0, 0, 0); 155 if (fit) { 156 borderWidth = 0.5f; 157 border = BOX; 158 this.image = image; 159 column.setLeading(0, 1); 160 setPadding(borderWidth / 2); 161 } 162 else { 163 borderWidth = 0.5f; 164 border = BOX; 165 column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0))); 166 column.setLeading(0, 1); 167 setPadding(0); 168 } 169 } 170 171 176 public PdfPCell(PdfPTable table) { 177 super(0, 0, 0, 0); 178 borderWidth = 0.5f; 179 border = BOX; 180 column.setLeading(0, 1); 181 setPadding(0); 182 this.table = table; 183 table.setWidthPercentage(100); 184 table.setExtendLastRow(true); 185 column.addElement(table); 186 } 187 188 191 public PdfPCell(PdfPCell cell) { 192 super(cell.llx, cell.lly, cell.urx, cell.ury); 193 cloneNonPositionParameters(cell); 194 verticalAlignment = cell.verticalAlignment; 195 paddingLeft = cell.paddingLeft; 196 paddingRight = cell.paddingRight; 197 paddingTop = cell.paddingTop; 198 paddingBottom = cell.paddingBottom; 199 phrase = cell.phrase; 200 fixedHeight = cell.fixedHeight; 201 minimumHeight = cell.minimumHeight; 202 noWrap = cell.noWrap; 203 colspan = cell.colspan; 204 if (cell.table != null) 205 table = new PdfPTable(cell.table); 206 image = Image.getInstance(cell.image); 207 cellEvent = cell.cellEvent; 208 useDescender = cell.useDescender; 209 column = ColumnText.duplicate(cell.column); 210 useBorderPadding = cell.useBorderPadding; 211 rotation = cell.rotation; 212 } 213 214 218 public void addElement(Element element) { 219 if (table != null) { 220 table = null; 221 column.setText(null); 222 } 223 column.addElement(element); 224 } 225 226 229 public Phrase getPhrase() { 230 return phrase; 231 } 232 233 236 public void setPhrase(Phrase phrase) { 237 table = null; 238 image = null; 239 column.setText(this.phrase = phrase); 240 } 241 242 245 public int getHorizontalAlignment() { 246 return column.getAlignment(); 247 } 248 249 253 public void setHorizontalAlignment(int horizontalAlignment) { 254 column.setAlignment(horizontalAlignment); 255 } 256 257 260 public int getVerticalAlignment() { 261 return verticalAlignment; 262 } 263 264 268 public void setVerticalAlignment(int verticalAlignment) { 269 if (table != null) 270 table.setExtendLastRow(verticalAlignment == Element.ALIGN_TOP); 271 this.verticalAlignment = verticalAlignment; 272 } 273 274 278 public float getEffectivePaddingLeft() { 279 return paddingLeft + (isUseBorderPadding() ? (getBorderWidthLeft()/(isUseVariableBorders()?1f:2f)) : 0); 280 } 281 282 285 public float getPaddingLeft() { 286 return paddingLeft; 287 } 288 289 293 public void setPaddingLeft(float paddingLeft) { 294 this.paddingLeft = paddingLeft; 295 } 296 297 301 public float getEffectivePaddingRight() { 302 return paddingRight + (isUseBorderPadding() ? (getBorderWidthRight()/(isUseVariableBorders()?1f:2f)) : 0); 303 } 304 305 309 public float getPaddingRight() { 310 return paddingRight; 311 } 312 313 317 public void setPaddingRight(float paddingRight) { 318 this.paddingRight = paddingRight; 319 } 320 321 325 public float getEffectivePaddingTop() { 326 return paddingTop + (isUseBorderPadding() ? (getBorderWidthTop()/(isUseVariableBorders()?1f:2f)) : 0); 327 } 328 329 333 public float getPaddingTop() { 334 return paddingTop; 335 } 336 337 341 public void setPaddingTop(float paddingTop) { 342 this.paddingTop = paddingTop; 343 } 344 345 349 public float getEffectivePaddingBottom() { 350 return paddingBottom + (isUseBorderPadding() ? (getBorderWidthBottom()/(isUseVariableBorders()?1f:2f)) : 0); 351 } 352 353 357 public float getPaddingBottom() { 358 return paddingBottom; 359 } 360 361 365 public void setPaddingBottom(float paddingBottom) { 366 this.paddingBottom = paddingBottom; 367 } 368 369 373 public void setPadding(float padding) { 374 paddingBottom = padding; 375 paddingTop = padding; 376 paddingLeft = padding; 377 paddingRight = padding; 378 } 379 380 384 public boolean isUseBorderPadding() { 385 return useBorderPadding; 386 } 387 388 392 public void setUseBorderPadding(boolean use) { 393 useBorderPadding = use; 394 } 395 396 403 public void setLeading(float fixedLeading, float multipliedLeading) { 404 column.setLeading(fixedLeading, multipliedLeading); 405 } 406 407 411 public float getLeading() { 412 return column.getLeading(); 413 } 414 415 419 public float getMultipliedLeading() { 420 return column.getMultipliedLeading(); 421 } 422 423 427 public void setIndent(float indent) { 428 column.setIndent(indent); 429 } 430 431 435 public float getIndent() { 436 return column.getIndent(); 437 } 438 439 443 public float getExtraParagraphSpace() { 444 return column.getExtraParagraphSpace(); 445 } 446 447 451 public void setExtraParagraphSpace(float extraParagraphSpace) { 452 column.setExtraParagraphSpace(extraParagraphSpace); 453 } 454 455 459 public float getFixedHeight() { 460 return fixedHeight; 461 } 462 463 467 public void setFixedHeight(float fixedHeight) { 468 this.fixedHeight = fixedHeight; 469 minimumHeight = 0; 470 } 471 472 476 public boolean isNoWrap() { 477 return noWrap; 478 } 479 480 484 public void setNoWrap(boolean noWrap) { 485 this.noWrap = noWrap; 486 } 487 488 492 PdfPTable getTable() { 493 return table; 494 } 495 496 void setTable(PdfPTable table) { 497 this.table = table; 498 column.setText(null); 499 image = null; 500 if (table != null) { 501 table.setExtendLastRow(verticalAlignment == Element.ALIGN_TOP); 502 column.addElement(table); 503 table.setWidthPercentage(100); 504 } 505 } 506 507 510 public float getMinimumHeight() { 511 return minimumHeight; 512 } 513 514 517 public void setMinimumHeight(float minimumHeight) { 518 this.minimumHeight = minimumHeight; 519 fixedHeight = 0; 520 } 521 522 525 public int getColspan() { 526 return colspan; 527 } 528 529 532 public void setColspan(int colspan) { 533 this.colspan = colspan; 534 } 535 536 540 public void setFollowingIndent(float indent) { 541 column.setFollowingIndent(indent); 542 } 543 544 548 public float getFollowingIndent() { 549 return column.getFollowingIndent(); 550 } 551 552 556 public void setRightIndent(float indent) { 557 column.setRightIndent(indent); 558 } 559 560 564 public float getRightIndent() { 565 return column.getRightIndent(); 566 } 567 568 572 public float getSpaceCharRatio() { 573 return column.getSpaceCharRatio(); 574 } 575 576 583 public void setSpaceCharRatio(float spaceCharRatio) { 584 column.setSpaceCharRatio(spaceCharRatio); 585 } 586 587 591 public void setRunDirection(int runDirection) { 592 column.setRunDirection(runDirection); 593 } 594 595 599 public int getRunDirection() { 600 return column.getRunDirection(); 601 } 602 603 607 public Image getImage() { 608 return this.image; 609 } 610 611 615 public void setImage(Image image) { 616 column.setText(null); 617 table = null; 618 this.image = image; 619 } 620 621 625 public PdfPCellEvent getCellEvent() { 626 return this.cellEvent; 627 } 628 629 633 public void setCellEvent(PdfPCellEvent event) { 634 if (event == null) this.cellEvent = null; 635 else if (this.cellEvent == null) this.cellEvent = event; 636 else if (this.cellEvent instanceof PdfPCellEventForwarder) ((PdfPCellEventForwarder)this.cellEvent).addCellEvent(event); 637 else { 638 PdfPCellEventForwarder forward = new PdfPCellEventForwarder(); 639 forward.addCellEvent(this.cellEvent); 640 forward.addCellEvent(event); 641 this.cellEvent = forward; 642 } 643 } 644 645 648 public int getArabicOptions() { 649 return column.getArabicOptions(); 650 } 651 652 656 public void setArabicOptions(int arabicOptions) { 657 column.setArabicOptions(arabicOptions); 658 } 659 660 663 public boolean isUseAscender() { 664 return column.isUseAscender(); 665 } 666 667 671 public void setUseAscender(boolean use) { 672 column.setUseAscender(use); 673 } 674 675 676 680 public boolean isUseDescender() { 681 return this.useDescender; 682 } 683 684 688 public void setUseDescender(boolean useDescender) { 689 this.useDescender = useDescender; 690 } 691 692 696 public ColumnText getColumn() { 697 return column; 698 } 699 700 704 public void setColumn(ColumnText column) { 705 this.column = column; 706 } 707 708 712 private int rotation; 713 714 718 public int getRotation() { 719 return this.rotation; 720 } 721 722 727 public void setRotation(int rotation) { 728 rotation %= 360; 729 if (rotation < 0) 730 rotation += 360; 731 if ((rotation % 90) != 0) 732 throw new IllegalArgumentException ("Rotation must be a multiple of 90."); 733 this.rotation = rotation; 734 } 735 } | Popular Tags |