1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
|
/*
* $Id: Cell.java,v 1.105 2005/05/11 11:48:55 blowagie Exp $
* $Name: $
*
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
package com.lowagie.text;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import com.lowagie.text.markup.MarkupParser;
import com.lowagie.text.pdf.PdfPCell;
/**
* A <CODE>Cell</CODE> is a <CODE>Rectangle</CODE> containing other
* <CODE>Element</CODE>s.
* <P>
* A <CODE>Cell</CODE> must be added to a <CODE>Table</CODE>.
* The <CODE>Table</CODE> will place the <CODE>Cell</CODE> in
* a <CODE>Row</CODE>.
* <P>
* Example:
* <BLOCKQUOTE><PRE>
* Table table = new Table(3);
* table.setBorderWidth(1);
* table.setBorderColor(new Color(0, 0, 255));
* table.setCellpadding(5);
* table.setCellspacing(5);
* <STRONG>Cell cell = new Cell("header");</STRONG>
* <STRONG>cell.setHeader(true);</STRONG>
* <STRONG>cell.setColspan(3);</STRONG>
* table.addCell(cell);
* <STRONG>cell = new Cell("example cell with colspan 1 and rowspan 2");</STRONG>
* <STRONG>cell.setRowspan(2);</STRONG>
* <STRONG>cell.setBorderColor(new Color(255, 0, 0));</STRONG>
* table.addCell(cell);
* table.addCell("1.1");
* table.addCell("2.1");
* table.addCell("1.2");
* table.addCell("2.2");
* </PRE></BLOCKQUOTE>
*
* @see Rectangle
* @see Element
* @see Table
* @see Row
*/
public class Cell extends Rectangle implements TextElementArray {
// static final membervariable
// This accessor replaces the dangerous static member DUMMY_CELL
/**
* Get dummy cell used when merging inner tables.
* @return a cell with colspan 3 and no border
*/
public static Cell getDummyCell() {
Cell cell = new Cell(true);
cell.setColspan(3);
cell.setBorder(NO_BORDER);
return cell;
}
// membervariables
/** This is the <CODE>ArrayList</CODE> of <CODE>Element</CODE>s. */
protected ArrayList arrayList = null;
/** This is the horizontal alignment. */
protected int horizontalAlignment = Element.ALIGN_UNDEFINED;
/** This is the vertical alignment. */
protected int verticalAlignment = Element.ALIGN_UNDEFINED;
/** This is the vertical alignment. */
protected String width;
/** This is the colspan. */
protected int colspan = 1;
/** This is the rowspan. */
protected int rowspan = 1;
/** This is the leading. */
float leading = Float.NaN;
/** Is this <CODE>Cell</CODE> a header? */
protected boolean header;
/** Indicates that the largest ascender height should be used to determine the
* height of the first line. Note that this only has an effect when rendered
* to PDF. Setting this to true can help with vertical alignment problems. */
protected boolean useAscender = false;
/** Indicates that the largest descender height should be added to the height of
* the last line (so characters like y don't dip into the border). Note that
* this only has an effect when rendered to PDF. */
protected boolean useDescender = false;
/**
* Adjusts the cell contents to compensate for border widths. Note that
* this only has an effect when rendered to PDF.
*/
protected boolean useBorderPadding;
// constructors
/**
* Constructs an empty <CODE>Cell</CODE>.
*/
public Cell() {
// creates a Rectangle with BY DEFAULT a border of 0.5
super(0, 0, 0, 0);
setBorder(UNDEFINED);
setBorderWidth(0.5f);
// initializes the arraylist and adds an element
arrayList = new ArrayList();
}
/**
* Constructs an empty <CODE>Cell</CODE> (for internal use only).
*
* @param dummy a dummy value
*/
public Cell(boolean dummy) {
this();
arrayList.add(new Paragraph(0));
}
/**
* Constructs a <CODE>Cell</CODE> with a certain content.
* <P>
* The <CODE>String</CODE> will be converted into a <CODE>Paragraph</CODE>.
*
* @param content a <CODE>String</CODE>
*/
public Cell(String content) {
// creates a Rectangle with BY DEFAULT a border of 0.5
super(0, 0, 0, 0);
setBorder(UNDEFINED);
setBorderWidth(0.5f);
// initializes the arraylist and adds an element
arrayList = new ArrayList();
try {
addElement(new Paragraph(content));
}
catch(BadElementException bee) {
}
}
/**
* Constructs a <CODE>Cell</CODE> with a certain <CODE>Element</CODE>.
* <P>
* if the element is a <CODE>ListItem</CODE>, <CODE>Row</CODE> or
* <CODE>Cell</CODE>, an exception will be thrown.
*
* @param element the element
* @throws BadElementException when the creator was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
*/
public Cell(Element element) throws BadElementException {
// creates a Rectangle with BY DEFAULT a border of 0.5
super(0, 0, 0, 0);
setBorder(UNDEFINED);
setBorderWidth(0.5f);
// Update by Benoit WIART <b.wiart@proxiad.com>
if(element instanceof Phrase) {
Phrase p = (Phrase)element;
leading = p.leading();
}
// initializes the arraylist and adds an element
arrayList = new ArrayList();
addElement(element);
}
/**
* Returns a <CODE>Cell</CODE> that has been constructed taking in account
* the value of some <VAR>attributes</VAR>.
*
* @param attributes Some attributes
*/
public Cell(Properties attributes) {
this();
String value;
if ((value = (String)attributes.remove(ElementTags.HORIZONTALALIGN)) != null) {
setHorizontalAlignment(value);
}
if ((value = (String)attributes.remove(ElementTags.VERTICALALIGN)) != null) {
setVerticalAlignment(value);
}
if ((value = (String)attributes.remove(ElementTags.WIDTH)) != null) {
setWidth(value);
}
if ((value = (String)attributes.remove(ElementTags.COLSPAN)) != null) {
setColspan(Integer.parseInt(value));
}
if ((value = (String)attributes.remove(ElementTags.ROWSPAN)) != null) {
setRowspan(Integer.parseInt(value));
}
if ((value = (String)attributes.remove(ElementTags.LEADING)) != null) {
setLeading(Float.valueOf(value + "f").floatValue());
}
if ((value = (String)attributes.remove(ElementTags.HEADER)) != null) {
setHeader(new Boolean(value).booleanValue());
}
if ((value = (String)attributes.remove(ElementTags.NOWRAP)) != null) {
setNoWrap(new Boolean(value).booleanValue());
}
if ((value = (String)attributes.remove(ElementTags.BORDERWIDTH)) != null) {
setBorderWidth(Float.valueOf(value + "f").floatValue());
}
int border = 0;
if ((value = (String)attributes.remove(ElementTags.LEFT)) != null) {
if (new Boolean(value).booleanValue()) border |= Rectangle.LEFT;
}
if ((value = (String)attributes.remove(ElementTags.RIGHT)) != null) {
if (new Boolean(value).booleanValue()) border |= Rectangle.RIGHT;
}
if ((value = (String)attributes.remove(ElementTags.TOP)) != null) {
if (new Boolean(value).booleanValue()) border |= Rectangle.TOP;
}
if ((value = (String)attributes.remove(ElementTags.BOTTOM)) != null) {
if (new Boolean(value).booleanValue()) border |= Rectangle.BOTTOM;
}
setBorder(border);
String r = (String)attributes.remove(ElementTags.RED);
String g = (String)attributes.remove(ElementTags.GREEN);
String b = (String)attributes.remove(ElementTags.BLUE);
if (r != null || g != null || b != null) {
int red = 0;
int green = 0;
int blue = 0;
if (r != null) red = Integer.parseInt(r);
if (g != null) green = Integer.parseInt(g);
if (b != null) blue = Integer.parseInt(b);
setBorderColor(new Color(red, green, blue));
}
else if ((value = (String)attributes.remove(ElementTags.BORDERCOLOR)) != null) {
setBorderColor(MarkupParser.decodeColor(value));
}
r = (String)attributes.remove(ElementTags.BGRED);
g = (String)attributes.remove(ElementTags.BGGREEN);
b = (String)attributes.remove(ElementTags.BGBLUE);
if (r != null || g != null || b != null) {
int red = 0;
int green = 0;
int blue = 0;
if (r != null) red = Integer.parseInt(r);
if (g != null) green = Integer.parseInt(g);
if (b != null) blue = Integer.parseInt(b);
setBackgroundColor(new Color(red, green, blue));
}
else if ((value = (String)attributes.remove(ElementTags.BACKGROUNDCOLOR)) != null) {
setBackgroundColor(MarkupParser.decodeColor(value));
}
if ((value = (String)attributes.remove(ElementTags.GRAYFILL)) != null) {
setGrayFill(Float.valueOf(value + "f").floatValue());
}
if (attributes.size() > 0) setMarkupAttributes(attributes);
}
// implementation of the Element-methods
/**
* Processes the element by adding it (or the different parts) to an
* <CODE>ElementListener</CODE>.
*
* @param listener an <CODE>ElementListener</CODE>
* @return <CODE>true</CODE> if the element was processed successfully
*/
public boolean process(ElementListener listener) {
try {
return listener.add(this);
}
catch(DocumentException de) {
return false;
}
}
/**
* Gets the type of the text element.
*
* @return a type
*/
public int type() {
return Element.CELL;
}
/**
* Gets all the chunks in this element.
*
* @return an <CODE>ArrayList</CODE>
*/
public ArrayList getChunks() {
ArrayList tmp = new ArrayList();
for (Iterator i = arrayList.iterator(); i.hasNext(); ) {
tmp.addAll(((Element) i.next()).getChunks());
}
return tmp;
}
// methods to set the membervariables
/**
* Adds an element to this <CODE>Cell</CODE>.
* <P>
* Remark: you can't add <CODE>ListItem</CODE>s, <CODE>Row</CODE>s, <CODE>Cell</CODE>s,
* <CODE>JPEG</CODE>s, <CODE>GIF</CODE>s or <CODE>PNG</CODE>s to a <CODE>Cell</CODE>.
*
* @param element The <CODE>Element</CODE> to add
* @throws BadElementException if the method was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
*/
public void addElement(Element element) throws BadElementException {
if (isTable()) {
Table table = (Table) arrayList.get(0);
Cell tmp = new Cell(element);
tmp.setBorder(NO_BORDER);
tmp.setColspan(table.columns());
table.addCell(tmp);
return;
}
switch(element.type()) {
case Element.LISTITEM:
case Element.ROW:
case Element.CELL:
throw new BadElementException("You can't add listitems, rows or cells to a cell.");
case Element.LIST:
if (Float.isNaN(leading)) {
leading = ((List) element).leading();
}
if (((List) element).size() == 0) return;
arrayList.add(element);
return;
case Element.ANCHOR:
case Element.PARAGRAPH:
case Element.PHRASE:
if (Float.isNaN(leading)) {
leading = ((Phrase) element).leading();
}
if (((Phrase) element).isEmpty()) return;
arrayList.add(element);
return;
case Element.CHUNK:
if (((Chunk) element).isEmpty()) return;
arrayList.add(element);
return;
case Element.TABLE:
Table table = new Table(3);
float[] widths = new float[3];
widths[1] = ((Table)element).widthPercentage();
switch(((Table)element).alignment()) {
case Element.ALIGN_LEFT:
widths[0] = 0f;
widths[2] = 100f - widths[1];
break;
case Element.ALIGN_CENTER:
widths[0] = (100f - widths[1]) / 2f;
widths[2] = widths[0];
break;
case Element.ALIGN_RIGHT:
widths[0] = 100f - widths[1];
widths[2] = 0f;
}
table.setWidths(widths);
Cell tmp;
if (arrayList.size() == 0) {
table.addCell(getDummyCell());
}
else {
tmp = new Cell();
tmp.setBorder(NO_BORDER);
tmp.setColspan(3);
for (Iterator i = arrayList.iterator(); i.hasNext(); ) {
tmp.add((Element) i.next());
}
table.addCell(tmp);
}
tmp = new Cell();
tmp.setBorder(NO_BORDER);
table.addCell(tmp);
table.insertTable((Table)element);
table.addCell(tmp);
table.addCell(getDummyCell());
clear();
arrayList.add(table);
return;
default:
arrayList.add(element);
}
}
/**
* Add an <CODE>Object</CODE> to this cell.
*
* @param o the object to add
* @return always <CODE>true</CODE>
*/
public boolean add(Object o) {
try {
this.addElement((Element) o);
return true;
}
catch(ClassCastException cce) {
throw new ClassCastException("You can only add objects that implement the Element interface.");
}
catch(BadElementException bee) {
throw new ClassCastException(bee.getMessage());
}
}
/**
* Sets the leading.
*
* @param value the new value
*/
public void setLeading(float value) {
leading = value;
}
/**
* Sets the horizontal alignment.
*
* @param value the new value
*/
public void setHorizontalAlignment(int value) {
horizontalAlignment = value;
}
/**
* Sets the alignment of this cell.
*
* @param alignment the new alignment as a <CODE>String</CODE>
*/
public void setHorizontalAlignment(String alignment) {
if (ElementTags.ALIGN_CENTER.equalsIgnoreCase(alignment)) {
this.horizontalAlignment = Element.ALIGN_CENTER;
return;
}
if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(alignment)) {
this.horizontalAlignment = Element.ALIGN_RIGHT;
return;
}
if (ElementTags.ALIGN_JUSTIFIED.equalsIgnoreCase(alignment)) {
this.horizontalAlignment = Element.ALIGN_JUSTIFIED;
return;
}
if (ElementTags.ALIGN_JUSTIFIED_ALL.equalsIgnoreCase(alignment)) {
this.horizontalAlignment = Element.ALIGN_JUSTIFIED_ALL;
return;
}
this.horizontalAlignment = Element.ALIGN_LEFT;
}
/**
* Sets the vertical alignment.
*
* @param value the new value
*/
public void setVerticalAlignment(int value) {
verticalAlignment = value;
}
/**
* Sets the alignment of this paragraph.
*
* @param alignment the new alignment as a <CODE>String</CODE>
*/
public void setVerticalAlignment(String alignment) {
if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(alignment)) {
this.verticalAlignment = Element.ALIGN_MIDDLE;
return;
}
if (ElementTags.ALIGN_BOTTOM.equalsIgnoreCase(alignment)) {
this.verticalAlignment = Element.ALIGN_BOTTOM;
return;
}
if (ElementTags.ALIGN_BASELINE.equalsIgnoreCase(alignment)) {
this.verticalAlignment = Element.ALIGN_BASELINE;
return;
}
this.verticalAlignment = Element.ALIGN_TOP;
}
/**
* Sets the width.
*
* @param value the new value
*/
public void setWidth(String value) {
width = value;
}
/**
* Sets the colspan.
*
* @param value the new value
*/
public void setColspan(int value) {
colspan = value;
}
/**
* Sets the rowspan.
*
* @param value the new value
*/
public void setRowspan(int value) {
rowspan = value;
}
/**
* Sets header.
*
* @param value the new value
*/
public void setHeader(boolean value) {
header = value;
}
/**
* Set nowrap.
*
* @param value the new value
*/
public void setNoWrap(boolean value) {
maxLines = 1;
}
// methods to retrieve information
/**
* Gets the number of <CODE>Element</CODE>s in the Cell.
*
* @return a <CODE>size</CODE>.
*/
public int size() {
return arrayList.size();
}
/**
* Checks if the <CODE>Cell</CODE> is empty.
*
* @return <CODE>false</CODE> if there are non-empty <CODE>Element</CODE>s in the <CODE>Cell</CODE>.
*/
public boolean isEmpty() {
switch(size()) {
case 0:
return true;
case 1:
Element element = (Element) arrayList.get(0);
switch (element.type()) {
case Element.CHUNK:
return ((Chunk) element).isEmpty();
case Element.ANCHOR:
case Element.PHRASE:
case Element.PARAGRAPH:
return ((Phrase) element).isEmpty();
case Element.LIST:
return ((List) element).size() == 0;
}
return false;
default:
return false;
}
}
/**
* Makes sure there is at least 1 object in the Cell.
*
* Otherwise it might not be shown in the table.
*/
void fill() {
if (size() == 0) arrayList.add(new Paragraph(0));
}
/**
* Checks if the <CODE>Cell</CODE> is empty.
*
* @return <CODE>false</CODE> if there are non-empty <CODE>Element</CODE>s in the <CODE>Cell</CODE>.
*/
public boolean isTable() {
return (size() == 1) && (((Element)arrayList.get(0)).type() == Element.TABLE);
}
/**
* Gets an iterator of <CODE>Element</CODE>s.
*
* @return an <CODE>Iterator</CODE>.
*/
public Iterator getElements() {
return arrayList.iterator();
}
/**
* Gets the horizontal alignment.
*
* @return a value
*/
public int horizontalAlignment() {
return horizontalAlignment;
}
/**
* Gets the vertical alignment.
*
* @return a value
*/
public int verticalAlignment() {
return verticalAlignment;
}
/**
* Gets the width.
*
* @return a value
*/
public String cellWidth() {
return width;
}
/**
* Gets the colspan.
*
* @return a value
*/
public int colspan() {
return colspan;
}
/**
* Gets the rowspan.
*
* @return a value
*/
public int rowspan() {
return rowspan;
}
/**
* Gets the leading.
*
* @return a value
*/
public float leading() {
if (Float.isNaN(leading)) {
return 16;
}
return leading;
}
/**
* Is this <CODE>Cell</CODE> a header?
*
* @return a value
*/
public boolean header() {
return header;
}
/**
* Get nowrap.
*
* @return a value
*/
public boolean noWrap() {
return maxLines == 1;
}
/**
* Clears all the <CODE>Element</CODE>s of this <CODE>Cell</CODE>.
*/
public void clear() {
arrayList.clear();
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @return NA
*/
public float top() {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @return NA
*/
public float bottom() {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @return NA
*/
public float left() {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @return NA
*/
public float right() {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param margin
* @return NA
*/
public float top(int margin) {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param margin
* @return NA
*/
public float bottom(int margin) {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param margin
* @return NA
*/
public float left(int margin) {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param margin NA
* @return NA
*/
public float right(int margin) {
throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param value NA
*/
public void setTop(int value) {
throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param value NA
*/
public void setBottom(int value) {
throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param value NA
*/
public void setLeft(int value) {
throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
}
/**
* This method throws an <CODE>UnsupportedOperationException</CODE>.
* @param value NA
*/
public void setRight(int value) {
throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
}
/**
* Checks if a given tag corresponds with this object.
*
* @param tag the given tag
* @return true if the tag corresponds
*/
public static boolean isTag(String tag) {
return ElementTags.CELL.equals(tag);
}
/** Does this <CODE>Cell</CODE> force a group change? */
protected boolean groupChange = true;
/**
* Does this <CODE>Cell</CODE> force a group change?
*
* @return a value
*/
public boolean getGroupChange() {
return groupChange;
}
/**
* Sets group change.
*
* @param value the new value
*/
public void setGroupChange(boolean value) {
groupChange = value;
}
/**
* Getter for {@link #maxLines}
* @return the maxLines value
*/
public int getMaxLines() {
return maxLines;
}
/**
* Setter for {@link #maxLines}
* @param value the maximum number of lines
*/
public void setMaxLines(int value) {
maxLines = value;
}
/**
* Maximum number of lines allowed in the cell.
* The default value of this property is not to limit the maximum number of lines
* (contributed by dperezcar@fcc.es)
*/
protected int maxLines = Integer.MAX_VALUE;
/**Setter for {@link #showTruncation}
* @param value Can be null for avoiding marking the truncation.*/
public void setShowTruncation(String value) {
showTruncation = value;
}
/**
* Getter for {@link #showTruncation}
* @return the showTruncation value
*/
public String getShowTruncation() {
return showTruncation;
}
/**
* If a truncation happens due to the {@link #maxLines} property, then this text will
* be added to indicate a truncation has happened.
* Default value is null, and means avoiding marking the truncation.
* A useful value of this property could be e.g. "..."
* (contributed by dperezcar@fcc.es)
*/
String showTruncation;
/**
* Sets the value of {@link #useAscender}.
* @param use use ascender height if true
*/
public void setUseAscender(boolean use) {
useAscender = use;
}
/**
* Gets the value of {@link #useAscender}
* @return useAscender
*/
public boolean isUseAscender() {
return useAscender;
}
/**
* Sets the value of {@link #useDescender}.
* @param use use descender height if true
*/
public void setUseDescender(boolean use) {
useDescender = use;
}
/**
* gets the value of {@link #useDescender }
* @return useDescender
*/
public boolean isUseDescender() {
return useDescender;
}
/**
* Sets the value of {@link #useBorderPadding}.
* @param use adjust layour for borders if true
*/
public void setUseBorderPadding(boolean use) {
useBorderPadding = use;
}
/**
* Gets the value of {@link #useBorderPadding}.
* @return useBorderPadding
*/
public boolean isUseBorderPadding() {
return useBorderPadding;
}
/**
* Creates a PdfPCell based on this Cell object.
* @return a PdfPCell
* @throws BadElementException
*/
public PdfPCell createPdfPCell() throws BadElementException {
if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
PdfPCell cell = new PdfPCell();
cell.setVerticalAlignment(verticalAlignment);
cell.setHorizontalAlignment(horizontalAlignment);
cell.setColspan(colspan);
cell.setUseBorderPadding(useBorderPadding);
cell.setUseDescender(useDescender);
cell.setLeading(leading(), 0);
cell.cloneNonPositionParameters(this);
cell.setNoWrap(noWrap());
for (Iterator i = getElements(); i.hasNext(); ) {
cell.addElement((Element)i.next());
}
return cell;
}
}
|