Source Code Cross Referenced for Cell.java in  » PDF » pdf-itext » com » lowagie » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » pdf itext » com.lowagie.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $Id: Cell.java 2752 2007-05-15 14:58:33Z blowagie $
0003:         * $Name$
0004:         *
0005:         * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
0006:         *
0007:         * The contents of this file are subject to the Mozilla Public License Version 1.1
0008:         * (the "License"); you may not use this file except in compliance with the License.
0009:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0010:         *
0011:         * Software distributed under the License is distributed on an "AS IS" basis,
0012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0013:         * for the specific language governing rights and limitations under the License.
0014:         *
0015:         * The Original Code is 'iText, a free JAVA-PDF library'.
0016:         *
0017:         * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
0018:         * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
0019:         * All Rights Reserved.
0020:         * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
0021:         * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
0022:         *
0023:         * Contributor(s): all the names of the contributors are added in the source code
0024:         * where applicable.
0025:         *
0026:         * Alternatively, the contents of this file may be used under the terms of the
0027:         * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
0028:         * provisions of LGPL are applicable instead of those above.  If you wish to
0029:         * allow use of your version of this file only under the terms of the LGPL
0030:         * License and not to allow others to use your version of this file under
0031:         * the MPL, indicate your decision by deleting the provisions above and
0032:         * replace them with the notice and other provisions required by the LGPL.
0033:         * If you do not delete the provisions above, a recipient may use your version
0034:         * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
0035:         *
0036:         * This library is free software; you can redistribute it and/or modify it
0037:         * under the terms of the MPL as stated above or under the terms of the GNU
0038:         * Library General Public License as published by the Free Software Foundation;
0039:         * either version 2 of the License, or any later version.
0040:         *
0041:         * This library is distributed in the hope that it will be useful, but WITHOUT
0042:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
0043:         * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
0044:         * details.
0045:         *
0046:         * If you didn't download this code from the following link, you should check if
0047:         * you aren't using an obsolete version:
0048:         * http://www.lowagie.com/iText/
0049:         */
0050:
0051:        package com.lowagie.text;
0052:
0053:        import java.util.ArrayList;
0054:        import java.util.Iterator;
0055:
0056:        import com.lowagie.text.pdf.PdfPCell;
0057:
0058:        /**
0059:         * A <CODE>Cell</CODE> is a <CODE>Rectangle</CODE> containing other
0060:         * <CODE>Element</CODE>s.
0061:         * <P>
0062:         * A <CODE>Cell</CODE> must be added to a <CODE>Table</CODE>.
0063:         * The <CODE>Table</CODE> will place the <CODE>Cell</CODE> in
0064:         * a <CODE>Row</CODE>.
0065:         * <P>
0066:         * Example:
0067:         * <BLOCKQUOTE><PRE>
0068:         * Table table = new Table(3);
0069:         * table.setBorderWidth(1);
0070:         * table.setBorderColor(new Color(0, 0, 255));
0071:         * table.setCellpadding(5);
0072:         * table.setCellspacing(5);
0073:         * <STRONG>Cell cell = new Cell("header");</STRONG>
0074:         * <STRONG>cell.setHeader(true);</STRONG>
0075:         * <STRONG>cell.setColspan(3);</STRONG>
0076:         * table.addCell(cell);
0077:         * <STRONG>cell = new Cell("example cell with colspan 1 and rowspan 2");</STRONG>
0078:         * <STRONG>cell.setRowspan(2);</STRONG>
0079:         * <STRONG>cell.setBorderColor(new Color(255, 0, 0));</STRONG>
0080:         * table.addCell(cell);
0081:         * table.addCell("1.1");
0082:         * table.addCell("2.1");
0083:         * table.addCell("1.2");
0084:         * table.addCell("2.2");
0085:         * </PRE></BLOCKQUOTE>
0086:         *
0087:         * @see		Rectangle
0088:         * @see		Element
0089:         * @see		Table
0090:         * @see		Row
0091:         */
0092:
0093:        public class Cell extends Rectangle implements  TextElementArray {
0094:
0095:            // membervariables
0096:
0097:            /**
0098:             * The <CODE>ArrayList</CODE> of <CODE>Element</CODE>s
0099:             * that are part of the content of the Cell.
0100:             */
0101:            protected ArrayList arrayList = null;
0102:
0103:            /** The horizontal alignment of the cell content. */
0104:            protected int horizontalAlignment = Element.ALIGN_UNDEFINED;
0105:
0106:            /** The vertical alignment of the cell content. */
0107:            protected int verticalAlignment = Element.ALIGN_UNDEFINED;
0108:
0109:            /**
0110:             * The width of the cell as a String.
0111:             * It can be an absolute value "100" or a percentage "20%".
0112:             */
0113:            protected float width;
0114:            protected boolean percentage = false;
0115:
0116:            /** The colspan of the cell. */
0117:            protected int colspan = 1;
0118:
0119:            /** The rowspan of the cell. */
0120:            protected int rowspan = 1;
0121:
0122:            /** The leading of the content inside the cell. */
0123:            float leading = Float.NaN;
0124:
0125:            /** Is this <CODE>Cell</CODE> a header? */
0126:            protected boolean header;
0127:
0128:            /**
0129:             * Maximum number of lines allowed in the cell.  
0130:             * The default value of this property is not to limit the maximum number of lines
0131:             * (contributed by dperezcar@fcc.es)
0132:             */
0133:            protected int maxLines = Integer.MAX_VALUE;
0134:
0135:            /**
0136:             * If a truncation happens due to the {@link #maxLines} property, then this text will 
0137:             * be added to indicate a truncation has happened.
0138:             * Default value is null, and means avoiding marking the truncation.  
0139:             * A useful value of this property could be e.g. "..."
0140:             * (contributed by dperezcar@fcc.es)
0141:             */
0142:            String showTruncation;
0143:
0144:            /**
0145:             * Indicates that the largest ascender height should be used to determine the
0146:             * height of the first line.  Note that this only has an effect when rendered
0147:             * to PDF.  Setting this to true can help with vertical alignment problems.
0148:             */
0149:            protected boolean useAscender = false;
0150:
0151:            /**
0152:             * Indicates that the largest descender height should be added to the height of
0153:             * the last line (so characters like y don't dip into the border).   Note that
0154:             * this only has an effect when rendered to PDF.
0155:             */
0156:            protected boolean useDescender = false;
0157:
0158:            /**
0159:             * Adjusts the cell contents to compensate for border widths.  Note that
0160:             * this only has an effect when rendered to PDF.
0161:             */
0162:            protected boolean useBorderPadding;
0163:
0164:            /** Does this <CODE>Cell</CODE> force a group change? */
0165:            protected boolean groupChange = true;
0166:
0167:            // constructors
0168:
0169:            /** Constructs an empty <CODE>Cell</CODE>. */
0170:            public Cell() {
0171:                // creates a Rectangle with BY DEFAULT a border of 0.5
0172:                super (0, 0, 0, 0);
0173:                setBorder(UNDEFINED);
0174:                setBorderWidth(0.5f);
0175:                // initializes the arraylist
0176:                arrayList = new ArrayList();
0177:            }
0178:
0179:            /**
0180:             * Constructs an empty <CODE>Cell</CODE> (for internal use only).
0181:             *
0182:             * @param   dummy   a dummy value
0183:             */
0184:            public Cell(boolean dummy) {
0185:                this ();
0186:                arrayList.add(new Paragraph(0));
0187:            }
0188:
0189:            /**
0190:             * Constructs a <CODE>Cell</CODE> with a certain content.<p>
0191:             * The <CODE>String</CODE> will be converted into a <CODE>Paragraph</CODE>.
0192:             * @param	content		a <CODE>String</CODE>
0193:             */
0194:            public Cell(String content) {
0195:                this ();
0196:                try {
0197:                    addElement(new Paragraph(content));
0198:                } catch (BadElementException bee) {
0199:                }
0200:            }
0201:
0202:            /**
0203:             * Constructs a <CODE>Cell</CODE> with a certain <CODE>Element</CODE>.<p>
0204:             * if the element is a <CODE>ListItem</CODE>, <CODE>Row</CODE> or
0205:             * <CODE>Cell</CODE>, an exception will be thrown.
0206:             *
0207:             * @param	element		the element
0208:             * @throws	BadElementException when the creator was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
0209:             */
0210:            public Cell(Element element) throws BadElementException {
0211:                this ();
0212:                if (element instanceof  Phrase) {
0213:                    setLeading(((Phrase) element).getLeading());
0214:                }
0215:                addElement(element);
0216:            }
0217:
0218:            // implementation of the Element-methods
0219:
0220:            /**
0221:             * Processes the element by adding it (or the different parts) to an
0222:             * <CODE>ElementListener</CODE>.
0223:             *
0224:             * @param	listener	an <CODE>ElementListener</CODE>
0225:             * @return	<CODE>true</CODE> if the element was processed successfully
0226:             */
0227:            public boolean process(ElementListener listener) {
0228:                try {
0229:                    return listener.add(this );
0230:                } catch (DocumentException de) {
0231:                    return false;
0232:                }
0233:            }
0234:
0235:            /**
0236:             * Gets the type of the text element.
0237:             *
0238:             * @return	a type
0239:             */
0240:            public int type() {
0241:                return Element.CELL;
0242:            }
0243:
0244:            /**
0245:             * Gets all the chunks in this element.
0246:             *
0247:             * @return	an <CODE>ArrayList</CODE>
0248:             */
0249:            public ArrayList getChunks() {
0250:                ArrayList tmp = new ArrayList();
0251:                for (Iterator i = arrayList.iterator(); i.hasNext();) {
0252:                    tmp.addAll(((Element) i.next()).getChunks());
0253:                }
0254:                return tmp;
0255:            }
0256:
0257:            // Getters and setters
0258:
0259:            /**
0260:             * Gets the horizontal alignment.
0261:             *
0262:             * @return	a value
0263:             */
0264:            public int getHorizontalAlignment() {
0265:                return horizontalAlignment;
0266:            }
0267:
0268:            /**
0269:             * Sets the horizontal alignment.
0270:             * @param	value	the new value
0271:             */
0272:            public void setHorizontalAlignment(int value) {
0273:                horizontalAlignment = value;
0274:            }
0275:
0276:            /**
0277:             * Sets the alignment of this cell.
0278:             * This methods allows you to set the alignment as a String.
0279:             * @param	alignment		the new alignment as a <CODE>String</CODE>
0280:             */
0281:            public void setHorizontalAlignment(String alignment) {
0282:                setHorizontalAlignment(ElementTags.alignmentValue(alignment));
0283:            }
0284:
0285:            /**
0286:             * Gets the vertical alignment.
0287:             * @return	a value
0288:             */
0289:            public int getVerticalAlignment() {
0290:                return verticalAlignment;
0291:            }
0292:
0293:            /**
0294:             * Sets the vertical alignment.
0295:             * @param	value	the new value
0296:             */
0297:            public void setVerticalAlignment(int value) {
0298:                verticalAlignment = value;
0299:            }
0300:
0301:            /**
0302:             * Sets the alignment of this paragraph.
0303:             *
0304:             * @param	alignment		the new alignment as a <CODE>String</CODE>
0305:             */
0306:            public void setVerticalAlignment(String alignment) {
0307:                setVerticalAlignment(ElementTags.alignmentValue(alignment));
0308:            }
0309:
0310:            /**
0311:             * Sets the width.
0312:             *
0313:             * @param	value	the new value
0314:             */
0315:            public void setWidth(float value) {
0316:                this .width = value;
0317:            }
0318:
0319:            /**
0320:             * Sets the width.
0321:             * It can be an absolute value "100" or a percentage "20%"
0322:             *
0323:             * @param	value	the new value
0324:             */
0325:            public void setWidth(String value) {
0326:                if (value.endsWith("%")) {
0327:                    value = value.substring(0, value.length() - 1);
0328:                    percentage = true;
0329:                }
0330:                width = Integer.parseInt(value);
0331:            }
0332:
0333:            /**
0334:             * Gets the width.
0335:             */
0336:            public float getWidth() {
0337:                return width;
0338:            }
0339:
0340:            /**
0341:             * Gets the width as a String.
0342:             *
0343:             * @return	a value
0344:             */
0345:            public String getWidthAsString() {
0346:                String w = String.valueOf(width);
0347:                if (w.endsWith(".0"))
0348:                    w = w.substring(0, w.length() - 2);
0349:                if (percentage)
0350:                    w += "%";
0351:                return w;
0352:            }
0353:
0354:            /**
0355:             * Sets the colspan.
0356:             *
0357:             * @param	value	the new value
0358:             */
0359:            public void setColspan(int value) {
0360:                colspan = value;
0361:            }
0362:
0363:            /**
0364:             * Gets the colspan.
0365:             * @return	a value
0366:             */
0367:            public int getColspan() {
0368:                return colspan;
0369:            }
0370:
0371:            /**
0372:             * Sets the rowspan.
0373:             *
0374:             * @param	value	the new value
0375:             */
0376:            public void setRowspan(int value) {
0377:                rowspan = value;
0378:            }
0379:
0380:            /**
0381:             * Gets the rowspan.
0382:             * @return	a value
0383:             */
0384:            public int getRowspan() {
0385:                return rowspan;
0386:            }
0387:
0388:            /**
0389:             * Sets the leading.
0390:             *
0391:             * @param	value	the new value
0392:             */
0393:            public void setLeading(float value) {
0394:                leading = value;
0395:            }
0396:
0397:            /**
0398:             * Gets the leading.
0399:             *
0400:             * @return	a value
0401:             */
0402:            public float getLeading() {
0403:                if (Float.isNaN(leading)) {
0404:                    return 16;
0405:                }
0406:                return leading;
0407:            }
0408:
0409:            /**
0410:             * Sets header.
0411:             *
0412:             * @param	value	the new value
0413:             */
0414:            public void setHeader(boolean value) {
0415:                header = value;
0416:            }
0417:
0418:            /**
0419:             * Is this <CODE>Cell</CODE> a header?
0420:             *
0421:             * @return	a value
0422:             */
0423:            public boolean isHeader() {
0424:                return header;
0425:            }
0426:
0427:            /**
0428:             * Setter for {@link #maxLines}
0429:             * @param value the maximum number of lines
0430:             */
0431:            public void setMaxLines(int value) {
0432:                maxLines = value;
0433:            }
0434:
0435:            /**
0436:             * Getter for {@link #maxLines}
0437:             * @return the maxLines value
0438:             */
0439:            public int getMaxLines() {
0440:                return maxLines;
0441:            }
0442:
0443:            /**
0444:             * Setter for {@link #showTruncation}
0445:             * @param value	Can be null for avoiding marking the truncation.
0446:             */
0447:            public void setShowTruncation(String value) {
0448:                showTruncation = value;
0449:            }
0450:
0451:            /**
0452:             * Getter for {@link #showTruncation}
0453:             * @return the showTruncation value
0454:             */
0455:            public String getShowTruncation() {
0456:                return showTruncation;
0457:            }
0458:
0459:            /**
0460:             * Sets the value of {@link #useAscender}.
0461:             * @param use use ascender height if true
0462:             */
0463:            public void setUseAscender(boolean use) {
0464:                useAscender = use;
0465:            }
0466:
0467:            /**
0468:             * Gets the value of {@link #useAscender}
0469:             * @return useAscender
0470:             */
0471:            public boolean isUseAscender() {
0472:                return useAscender;
0473:            }
0474:
0475:            /**
0476:             * Sets the value of {@link #useDescender}.
0477:             * @param use use descender height if true
0478:             */
0479:            public void setUseDescender(boolean use) {
0480:                useDescender = use;
0481:            }
0482:
0483:            /**
0484:             * gets the value of {@link #useDescender }
0485:             * @return useDescender
0486:             */
0487:            public boolean isUseDescender() {
0488:                return useDescender;
0489:            }
0490:
0491:            /**
0492:             * Sets the value of {@link #useBorderPadding}.
0493:             * @param use adjust layour for borders if true
0494:             */
0495:            public void setUseBorderPadding(boolean use) {
0496:                useBorderPadding = use;
0497:            }
0498:
0499:            /**
0500:             * Gets the value of {@link #useBorderPadding}.
0501:             * @return useBorderPadding
0502:             */
0503:            public boolean isUseBorderPadding() {
0504:                return useBorderPadding;
0505:            }
0506:
0507:            /**
0508:             * Does this <CODE>Cell</CODE> force a group change?
0509:             *
0510:             * @return	a value
0511:             */
0512:            public boolean getGroupChange() {
0513:                return groupChange;
0514:            }
0515:
0516:            /**
0517:             * Sets group change.
0518:             *
0519:             * @param	value	the new value
0520:             */
0521:            public void setGroupChange(boolean value) {
0522:                groupChange = value;
0523:            }
0524:
0525:            // arraylist stuff
0526:
0527:            /**
0528:             * Gets the number of <CODE>Element</CODE>s in the Cell.
0529:             *
0530:             * @return	a <CODE>size</CODE>.
0531:             */
0532:            public int size() {
0533:                return arrayList.size();
0534:            }
0535:
0536:            /**
0537:             * Gets an iterator of <CODE>Element</CODE>s.
0538:             *
0539:             * @return	an <CODE>Iterator</CODE>.
0540:             */
0541:            public Iterator getElements() {
0542:                return arrayList.iterator();
0543:            }
0544:
0545:            /**
0546:             * Clears all the <CODE>Element</CODE>s of this <CODE>Cell</CODE>.
0547:             */
0548:            public void clear() {
0549:                arrayList.clear();
0550:            }
0551:
0552:            /**
0553:             * Checks if the <CODE>Cell</CODE> is empty.
0554:             *
0555:             * @return	<CODE>false</CODE> if there are non-empty <CODE>Element</CODE>s in the <CODE>Cell</CODE>.
0556:             */
0557:            public boolean isEmpty() {
0558:                switch (size()) {
0559:                case 0:
0560:                    return true;
0561:                case 1:
0562:                    Element element = (Element) arrayList.get(0);
0563:                    switch (element.type()) {
0564:                    case Element.CHUNK:
0565:                        return ((Chunk) element).isEmpty();
0566:                    case Element.ANCHOR:
0567:                    case Element.PHRASE:
0568:                    case Element.PARAGRAPH:
0569:                        return ((Phrase) element).isEmpty();
0570:                    case Element.LIST:
0571:                        return ((List) element).isEmpty();
0572:                    }
0573:                    return false;
0574:                default:
0575:                    return false;
0576:                }
0577:            }
0578:
0579:            /**
0580:             * Makes sure there is at least 1 object in the Cell.
0581:             *
0582:             * Otherwise it might not be shown in the table.
0583:             */
0584:            void fill() {
0585:                if (size() == 0)
0586:                    arrayList.add(new Paragraph(0));
0587:            }
0588:
0589:            /**
0590:             * Checks if this <CODE>Cell</CODE> is a placeholder for a (nested) table.
0591:             *
0592:             * @return	true if the only element in this cell is a table
0593:             */
0594:            public boolean isTable() {
0595:                return (size() == 1)
0596:                        && (((Element) arrayList.get(0)).type() == Element.TABLE);
0597:            }
0598:
0599:            /**
0600:             * Adds an element to this <CODE>Cell</CODE>.
0601:             * <P>
0602:             * Remark: you can't add <CODE>ListItem</CODE>s, <CODE>Row</CODE>s, <CODE>Cell</CODE>s,
0603:             * <CODE>JPEG</CODE>s, <CODE>GIF</CODE>s or <CODE>PNG</CODE>s to a <CODE>Cell</CODE>.
0604:             *
0605:             * @param element The <CODE>Element</CODE> to add
0606:             * @throws BadElementException if the method was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
0607:             */
0608:            public void addElement(Element element) throws BadElementException {
0609:                if (isTable()) {
0610:                    Table table = (Table) arrayList.get(0);
0611:                    Cell tmp = new Cell(element);
0612:                    tmp.setBorder(NO_BORDER);
0613:                    tmp.setColspan(table.getColumns());
0614:                    table.addCell(tmp);
0615:                    return;
0616:                }
0617:                switch (element.type()) {
0618:                case Element.LISTITEM:
0619:                case Element.ROW:
0620:                case Element.CELL:
0621:                    throw new BadElementException(
0622:                            "You can't add listitems, rows or cells to a cell.");
0623:                case Element.LIST:
0624:                    List list = (List) element;
0625:                    if (Float.isNaN(leading)) {
0626:                        setLeading(list.getTotalLeading());
0627:                    }
0628:                    if (list.isEmpty())
0629:                        return;
0630:                    arrayList.add(element);
0631:                    return;
0632:                case Element.ANCHOR:
0633:                case Element.PARAGRAPH:
0634:                case Element.PHRASE:
0635:                    Phrase p = (Phrase) element;
0636:                    if (Float.isNaN(leading)) {
0637:                        setLeading(p.getLeading());
0638:                    }
0639:                    if (p.isEmpty())
0640:                        return;
0641:                    arrayList.add(element);
0642:                    return;
0643:                case Element.CHUNK:
0644:                    if (((Chunk) element).isEmpty())
0645:                        return;
0646:                    arrayList.add(element);
0647:                    return;
0648:                case Element.TABLE:
0649:                    Table table = new Table(3);
0650:                    float[] widths = new float[3];
0651:                    widths[1] = ((Table) element).getWidth();
0652:                    switch (((Table) element).getAlignment()) {
0653:                    case Element.ALIGN_LEFT:
0654:                        widths[0] = 0f;
0655:                        widths[2] = 100f - widths[1];
0656:                        break;
0657:                    case Element.ALIGN_CENTER:
0658:                        widths[0] = (100f - widths[1]) / 2f;
0659:                        widths[2] = widths[0];
0660:                        break;
0661:                    case Element.ALIGN_RIGHT:
0662:                        widths[0] = 100f - widths[1];
0663:                        widths[2] = 0f;
0664:                    }
0665:                    table.setWidths(widths);
0666:                    Cell tmp;
0667:                    if (arrayList.isEmpty()) {
0668:                        table.addCell(getDummyCell());
0669:                    } else {
0670:                        tmp = new Cell();
0671:                        tmp.setBorder(NO_BORDER);
0672:                        tmp.setColspan(3);
0673:                        for (Iterator i = arrayList.iterator(); i.hasNext();) {
0674:                            tmp.add(i.next());
0675:                        }
0676:                        table.addCell(tmp);
0677:                    }
0678:                    tmp = new Cell();
0679:                    tmp.setBorder(NO_BORDER);
0680:                    table.addCell(tmp);
0681:                    table.insertTable((Table) element);
0682:                    tmp = new Cell();
0683:                    tmp.setBorder(NO_BORDER);
0684:                    table.addCell(tmp);
0685:                    table.addCell(getDummyCell());
0686:                    clear();
0687:                    arrayList.add(table);
0688:                    return;
0689:                default:
0690:                    arrayList.add(element);
0691:                }
0692:            }
0693:
0694:            /**
0695:             * Add an <CODE>Object</CODE> to this cell.
0696:             *
0697:             * @param o the object to add
0698:             * @return always <CODE>true</CODE>
0699:             */
0700:            public boolean add(Object o) {
0701:                try {
0702:                    this .addElement((Element) o);
0703:                    return true;
0704:                } catch (ClassCastException cce) {
0705:                    throw new ClassCastException(
0706:                            "You can only add objects that implement the Element interface.");
0707:                } catch (BadElementException bee) {
0708:                    throw new ClassCastException(bee.getMessage());
0709:                }
0710:            }
0711:
0712:            // helper methods
0713:
0714:            /**
0715:             * Get dummy cell used when merging inner tables. 
0716:             * @return a cell with colspan 3 and no border
0717:             */
0718:            private static Cell getDummyCell() {
0719:                Cell cell = new Cell(true);
0720:                cell.setColspan(3);
0721:                cell.setBorder(NO_BORDER);
0722:                return cell;
0723:            }
0724:
0725:            /**
0726:             * Creates a PdfPCell based on this Cell object.
0727:             * @return a PdfPCell
0728:             * @throws BadElementException
0729:             */
0730:            public PdfPCell createPdfPCell() throws BadElementException {
0731:                if (rowspan > 1)
0732:                    throw new BadElementException(
0733:                            "PdfPCells can't have a rowspan > 1");
0734:                if (isTable())
0735:                    return new PdfPCell(((Table) arrayList.get(0))
0736:                            .createPdfPTable());
0737:                PdfPCell cell = new PdfPCell();
0738:                cell.setVerticalAlignment(verticalAlignment);
0739:                cell.setHorizontalAlignment(horizontalAlignment);
0740:                cell.setColspan(colspan);
0741:                cell.setUseBorderPadding(useBorderPadding);
0742:                cell.setUseDescender(useDescender);
0743:                cell.setLeading(getLeading(), 0);
0744:                cell.cloneNonPositionParameters(this );
0745:                cell.setNoWrap(getMaxLines() == 1);
0746:                for (Iterator i = getElements(); i.hasNext();) {
0747:                    Element e = (Element) i.next();
0748:                    if (e.type() == Element.PHRASE
0749:                            || e.type() == Element.PARAGRAPH) {
0750:                        Paragraph p = new Paragraph((Phrase) e);
0751:                        p.setAlignment(horizontalAlignment);
0752:                        e = p;
0753:                    }
0754:                    cell.addElement(e);
0755:                }
0756:                return cell;
0757:            }
0758:
0759:            // unsupported Rectangle methods
0760:
0761:            /**
0762:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0763:             * @return NA
0764:             * @deprecated Use {@link #getTop()} instead
0765:             */
0766:            public float top() {
0767:                return getTop();
0768:            }
0769:
0770:            /**
0771:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0772:             * @return NA
0773:             */
0774:            public float getTop() {
0775:                throw new UnsupportedOperationException(
0776:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0777:            }
0778:
0779:            /**
0780:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0781:             * @return NA
0782:             * @deprecated Use {@link #getBottom()} instead
0783:             */
0784:            public float bottom() {
0785:                return getBottom();
0786:            }
0787:
0788:            /**
0789:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0790:             * @return NA
0791:             */
0792:            public float getBottom() {
0793:                throw new UnsupportedOperationException(
0794:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0795:            }
0796:
0797:            /**
0798:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0799:             * @return NA
0800:             * @deprecated Use {@link #getLeft()} instead
0801:             */
0802:            public float left() {
0803:                return getLeft();
0804:            }
0805:
0806:            /**
0807:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0808:             * @return NA
0809:             */
0810:            public float getLeft() {
0811:                throw new UnsupportedOperationException(
0812:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0813:            }
0814:
0815:            /**
0816:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0817:             * @return NA
0818:             * @deprecated Use {@link #getRight()} instead
0819:             */
0820:            public float right() {
0821:                return getRight();
0822:            }
0823:
0824:            /**
0825:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0826:             * @return NA
0827:             */
0828:            public float getRight() {
0829:                throw new UnsupportedOperationException(
0830:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0831:            }
0832:
0833:            /**
0834:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0835:             * @param margin
0836:             * @return NA
0837:             */
0838:            public float top(int margin) {
0839:                throw new UnsupportedOperationException(
0840:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0841:            }
0842:
0843:            /**
0844:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0845:             * @param margin
0846:             * @return NA
0847:             */
0848:            public float bottom(int margin) {
0849:                throw new UnsupportedOperationException(
0850:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0851:            }
0852:
0853:            /**
0854:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0855:             * @param margin
0856:             * @return NA
0857:             */
0858:            public float left(int margin) {
0859:                throw new UnsupportedOperationException(
0860:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0861:            }
0862:
0863:            /**
0864:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0865:             * @param margin NA
0866:             * @return NA
0867:             */
0868:            public float right(int margin) {
0869:                throw new UnsupportedOperationException(
0870:                        "Dimensions of a Cell can't be calculated. See the FAQ.");
0871:            }
0872:
0873:            /**
0874:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0875:             * @param value NA
0876:             */
0877:            public void setTop(int value) {
0878:                throw new UnsupportedOperationException(
0879:                        "Dimensions of a Cell are attributed automagically. See the FAQ.");
0880:            }
0881:
0882:            /**
0883:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0884:             * @param value NA
0885:             */
0886:            public void setBottom(int value) {
0887:                throw new UnsupportedOperationException(
0888:                        "Dimensions of a Cell are attributed automagically. See the FAQ.");
0889:            }
0890:
0891:            /**
0892:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0893:             * @param value NA
0894:             */
0895:            public void setLeft(int value) {
0896:                throw new UnsupportedOperationException(
0897:                        "Dimensions of a Cell are attributed automagically. See the FAQ.");
0898:            }
0899:
0900:            /**
0901:             * This method throws an <CODE>UnsupportedOperationException</CODE>.
0902:             * @param value NA
0903:             */
0904:            public void setRight(int value) {
0905:                throw new UnsupportedOperationException(
0906:                        "Dimensions of a Cell are attributed automagically. See the FAQ.");
0907:            }
0908:
0909:            // deprecated stuff
0910:
0911:            /**
0912:             * Returns a <CODE>Cell</CODE> that has been constructed taking in account
0913:             * the value of some <VAR>attributes</VAR>.
0914:             *
0915:             * @param	attributes		Some attributes
0916:             * @deprecated use ElementFactory.getCell(attributes)
0917:             */
0918:            public Cell(java.util.Properties attributes) {
0919:                this ();
0920:                Cell tmp = com.lowagie.text.factories.ElementFactory
0921:                        .getCell(attributes);
0922:                this .cloneNonPositionParameters(tmp);
0923:                this .setHorizontalAlignment(tmp.getHorizontalAlignment());
0924:                this .setVerticalAlignment(tmp.getVerticalAlignment());
0925:                this .setWidth(tmp.getWidth());
0926:                this .setColspan(tmp.getColspan());
0927:                this .setRowspan(tmp.getRowspan());
0928:                this .setLeading(tmp.getLeading());
0929:                this .setHeader(tmp.isHeader());
0930:                this .setMaxLines(tmp.getMaxLines());
0931:            }
0932:
0933:            /**
0934:             * Gets the horizontal alignment.
0935:             * @return	a value
0936:             * @deprecated Use {@link #getHorizontalAlignment()} instead
0937:             */
0938:            public int horizontalAlignment() {
0939:                return getHorizontalAlignment();
0940:            }
0941:
0942:            /**
0943:             * Gets the vertical alignment.
0944:             * @return	a value
0945:             * @deprecated Use {@link #getVerticalAlignment()} instead
0946:             */
0947:            public int verticalAlignment() {
0948:                return getVerticalAlignment();
0949:            }
0950:
0951:            /**
0952:             * Gets the width.
0953:             *
0954:             * @return	a value
0955:             * @deprecated Use {@link #getWidthAsString()} instead
0956:             */
0957:            public String cellWidth() {
0958:                return getWidthAsString();
0959:            }
0960:
0961:            /**
0962:             * Gets the colspan.
0963:             * @return	a value
0964:             * @deprecated Use {@link #getColspan()} instead
0965:             */
0966:            public int colspan() {
0967:                return getColspan();
0968:            }
0969:
0970:            /**
0971:             * Gets the rowspan.
0972:             * @return	a value
0973:             * @deprecated Use {@link #getRowspan()} instead
0974:             */
0975:            public int rowspan() {
0976:                return getRowspan();
0977:            }
0978:
0979:            /**
0980:             * Gets the leading.
0981:             *
0982:             * @return	a value
0983:             * @deprecated Use {@link #getLeading()} instead
0984:             */
0985:            public float leading() {
0986:                return getLeading();
0987:            }
0988:
0989:            /**
0990:             * Is this <CODE>Cell</CODE> a header?
0991:             *
0992:             * @return	a value
0993:             * @deprecated Use {@link #isHeader()} instead
0994:             */
0995:            public boolean header() {
0996:                return isHeader();
0997:            }
0998:
0999:            /**
1000:             * Set nowrap.
1001:             *
1002:             * @param	value	the new value
1003:             * @deprecated Use setMaxLines(1) instead
1004:             */
1005:            public void setNoWrap(boolean value) {
1006:                if (value)
1007:                    maxLines = 1;
1008:                else
1009:                    maxLines = Integer.MAX_VALUE;
1010:            }
1011:
1012:            /**
1013:             * Get nowrap.
1014:             *
1015:             * @return	a value
1016:             * @deprecated Use getMaxLines() == 1 instead
1017:             */
1018:            public boolean noWrap() {
1019:                return maxLines == 1;
1020:            }
1021:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.