Source Code Cross Referenced for Chunk.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) 


001:        /*
002:         * $Id: Chunk.java 2896 2007-08-28 08:09:13Z blowagie $
003:         * $Name$
004:         *
005:         * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
006:         *
007:         * The contents of this file are subject to the Mozilla Public License Version 1.1
008:         * (the "License"); you may not use this file except in compliance with the License.
009:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010:         *
011:         * Software distributed under the License is distributed on an "AS IS" basis,
012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013:         * for the specific language governing rights and limitations under the License.
014:         *
015:         * The Original Code is 'iText, a free JAVA-PDF library'.
016:         *
017:         * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018:         * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019:         * All Rights Reserved.
020:         * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021:         * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022:         *
023:         * Contributor(s): all the names of the contributors are added in the source code
024:         * where applicable.
025:         *
026:         * Alternatively, the contents of this file may be used under the terms of the
027:         * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028:         * provisions of LGPL are applicable instead of those above.  If you wish to
029:         * allow use of your version of this file only under the terms of the LGPL
030:         * License and not to allow others to use your version of this file under
031:         * the MPL, indicate your decision by deleting the provisions above and
032:         * replace them with the notice and other provisions required by the LGPL.
033:         * If you do not delete the provisions above, a recipient may use your version
034:         * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035:         *
036:         * This library is free software; you can redistribute it and/or modify it
037:         * under the terms of the MPL as stated above or under the terms of the GNU
038:         * Library General Public License as published by the Free Software Foundation;
039:         * either version 2 of the License, or any later version.
040:         *
041:         * This library is distributed in the hope that it will be useful, but WITHOUT
042:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043:         * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044:         * details.
045:         *
046:         * If you didn't download this code from the following link, you should check if
047:         * you aren't using an obsolete version:
048:         * http://www.lowagie.com/iText/
049:         */
050:
051:        package com.lowagie.text;
052:
053:        import java.awt.Color;
054:        import java.net.URL;
055:        import java.util.ArrayList;
056:        import java.util.HashMap;
057:        import java.util.Hashtable;
058:        import java.util.Set;
059:
060:        import com.lowagie.text.pdf.HyphenationEvent;
061:        import com.lowagie.text.pdf.PdfAction;
062:        import com.lowagie.text.pdf.PdfAnnotation;
063:        import com.lowagie.text.pdf.PdfContentByte;
064:
065:        /**
066:         * This is the smallest significant part of text that can be added to a
067:         * document.
068:         * <P>
069:         * Most elements can be divided in one or more <CODE>Chunk</CODE>s. A chunk
070:         * is a <CODE>String</CODE> with a certain <CODE>Font</CODE>. All other
071:         * layout parameters should be defined in the object to which this chunk of text
072:         * is added.
073:         * <P>
074:         * Example: <BLOCKQUOTE>
075:         * 
076:         * <PRE>
077:         * 
078:         * <STRONG>Chunk chunk = new Chunk("Hello world",
079:         * FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0,
080:         * 0))); </STRONG> document.add(chunk);
081:         * 
082:         * </PRE>
083:         * 
084:         * </BLOCKQUOTE>
085:         */
086:
087:        public class Chunk implements  Element {
088:
089:            // public static membervariables
090:
091:            /** The character stand in for an image. */
092:            public static final String OBJECT_REPLACEMENT_CHARACTER = "\ufffc";
093:
094:            /** This is a Chunk containing a newline. */
095:            public static final Chunk NEWLINE = new Chunk("\n");
096:
097:            /** This is a Chunk containing a newpage. */
098:            public static final Chunk NEXTPAGE = new Chunk("");
099:            static {
100:                NEXTPAGE.setNewPage();
101:            }
102:
103:            // member variables
104:
105:            /** This is the content of this chunk of text. */
106:            protected StringBuffer content = null;
107:
108:            /** This is the <CODE>Font</CODE> of this chunk of text. */
109:            protected Font font = null;
110:
111:            /** Contains some of the attributes for this Chunk. */
112:            protected HashMap attributes = null;
113:
114:            // constructors
115:
116:            /**
117:             * Empty constructor.
118:             */
119:            public Chunk() {
120:                this .content = new StringBuffer();
121:                this .font = new Font();
122:            }
123:
124:            /**
125:             * A <CODE>Chunk</CODE> copy constructor.
126:             * @param ck the <CODE>Chunk</CODE> to be copied
127:             */
128:            public Chunk(Chunk ck) {
129:                if (ck.content != null) {
130:                    content = new StringBuffer(ck.content.toString());
131:                }
132:                if (ck.font != null) {
133:                    font = new Font(ck.font);
134:                }
135:                if (ck.attributes != null) {
136:                    attributes = new HashMap(ck.attributes);
137:                }
138:            }
139:
140:            /**
141:             * Constructs a chunk of text with a certain content and a certain <CODE>
142:             * Font</CODE>.
143:             * 
144:             * @param content
145:             *            the content
146:             * @param font
147:             *            the font
148:             */
149:            public Chunk(String content, Font font) {
150:                this .content = new StringBuffer(content);
151:                this .font = font;
152:            }
153:
154:            /**
155:             * Constructs a chunk of text with a certain content, without specifying a
156:             * <CODE>Font</CODE>.
157:             * 
158:             * @param content
159:             *            the content
160:             */
161:            public Chunk(String content) {
162:                this (content, new Font());
163:            }
164:
165:            /**
166:             * Constructs a chunk of text with a char and a certain <CODE>Font</CODE>.
167:             * 
168:             * @param c
169:             *            the content
170:             * @param font
171:             *            the font
172:             */
173:            public Chunk(char c, Font font) {
174:                this .content = new StringBuffer();
175:                this .content.append(c);
176:                this .font = font;
177:            }
178:
179:            /**
180:             * Constructs a chunk of text with a char, without specifying a <CODE>Font
181:             * </CODE>.
182:             * 
183:             * @param c
184:             *            the content
185:             */
186:            public Chunk(char c) {
187:                this (c, new Font());
188:            }
189:
190:            /**
191:             * Constructs a chunk containing an <CODE>Image</CODE>.
192:             * 
193:             * @param image
194:             *            the image
195:             * @param offsetX
196:             *            the image offset in the x direction
197:             * @param offsetY
198:             *            the image offset in the y direction
199:             */
200:            public Chunk(Image image, float offsetX, float offsetY) {
201:                this (OBJECT_REPLACEMENT_CHARACTER, new Font());
202:                Image copyImage = Image.getInstance(image);
203:                copyImage.setAbsolutePosition(Float.NaN, Float.NaN);
204:                setAttribute(IMAGE, new Object[] { copyImage,
205:                        new Float(offsetX), new Float(offsetY), Boolean.FALSE });
206:            }
207:
208:            /**
209:             * Constructs a chunk containing an <CODE>Image</CODE>.
210:             * 
211:             * @param image
212:             *            the image
213:             * @param offsetX
214:             *            the image offset in the x direction
215:             * @param offsetY
216:             *            the image offset in the y direction
217:             * @param changeLeading
218:             *            true if the leading has to be adapted to the image
219:             */
220:            public Chunk(Image image, float offsetX, float offsetY,
221:                    boolean changeLeading) {
222:                this (OBJECT_REPLACEMENT_CHARACTER, new Font());
223:                setAttribute(IMAGE, new Object[] { image, new Float(offsetX),
224:                        new Float(offsetY), new Boolean(changeLeading) });
225:            }
226:
227:            // implementation of the Element-methods
228:
229:            /**
230:             * Processes the element by adding it (or the different parts) to an <CODE>
231:             * ElementListener</CODE>.
232:             * 
233:             * @param listener
234:             *            an <CODE>ElementListener</CODE>
235:             * @return <CODE>true</CODE> if the element was processed successfully
236:             */
237:            public boolean process(ElementListener listener) {
238:                try {
239:                    return listener.add(this );
240:                } catch (DocumentException de) {
241:                    return false;
242:                }
243:            }
244:
245:            /**
246:             * Gets the type of the text element.
247:             * 
248:             * @return a type
249:             */
250:            public int type() {
251:                return Element.CHUNK;
252:            }
253:
254:            /**
255:             * Gets all the chunks in this element.
256:             * 
257:             * @return an <CODE>ArrayList</CODE>
258:             */
259:            public ArrayList getChunks() {
260:                ArrayList tmp = new ArrayList();
261:                tmp.add(this );
262:                return tmp;
263:            }
264:
265:            // methods that change the member variables
266:
267:            /**
268:             * appends some text to this <CODE>Chunk</CODE>.
269:             * 
270:             * @param string
271:             *            <CODE>String</CODE>
272:             * @return a <CODE>StringBuffer</CODE>
273:             */
274:            public StringBuffer append(String string) {
275:                return content.append(string);
276:            }
277:
278:            /**
279:             * Sets the font of this <CODE>Chunk</CODE>.
280:             * 
281:             * @param font
282:             *            a <CODE>Font</CODE>
283:             */
284:            public void setFont(Font font) {
285:                this .font = font;
286:            }
287:
288:            // methods to retrieve information
289:
290:            /**
291:             * Gets the font of this <CODE>Chunk</CODE>.
292:             * 
293:             * @return a <CODE>Font</CODE>
294:             */
295:            public Font getFont() {
296:                return font;
297:            }
298:
299:            /**
300:             * Returns the content of this <CODE>Chunk</CODE>.
301:             * 
302:             * @return a <CODE>String</CODE>
303:             */
304:            public String getContent() {
305:                return content.toString();
306:            }
307:
308:            /**
309:             * Returns the content of this <CODE>Chunk</CODE>.
310:             * 
311:             * @return a <CODE>String</CODE>
312:             */
313:            public String toString() {
314:                return getContent();
315:            }
316:
317:            /**
318:             * Checks is this <CODE>Chunk</CODE> is empty.
319:             * 
320:             * @return <CODE>false</CODE> if the Chunk contains other characters than
321:             *         space.
322:             */
323:            public boolean isEmpty() {
324:                return (content.toString().trim().length() == 0)
325:                        && (content.toString().indexOf("\n") == -1)
326:                        && (attributes == null);
327:            }
328:
329:            /**
330:             * Gets the width of the Chunk in points.
331:             * 
332:             * @return a width in points
333:             */
334:            public float getWidthPoint() {
335:                if (getImage() != null) {
336:                    return getImage().getScaledWidth();
337:                }
338:                return font.getCalculatedBaseFont(true).getWidthPoint(
339:                        getContent(), font.getCalculatedSize())
340:                        * getHorizontalScaling();
341:            }
342:
343:            // attributes
344:
345:            /**
346:             * Checks the attributes of this <CODE>Chunk</CODE>.
347:             * 
348:             * @return false if there aren't any.
349:             */
350:
351:            public boolean hasAttributes() {
352:                return attributes != null;
353:            }
354:
355:            /**
356:             * Gets the attributes for this <CODE>Chunk</CODE>.
357:             * <P>
358:             * It may be null.
359:             * 
360:             * @return the attributes for this <CODE>Chunk</CODE>
361:             */
362:
363:            public HashMap getAttributes() {
364:                return attributes;
365:            }
366:
367:            /**
368:             * Sets the attributes all at once.
369:             * @param	attributes	the attributes of a Chunk
370:             */
371:            public void setAttributes(HashMap attributes) {
372:                this .attributes = attributes;
373:            }
374:
375:            /**
376:             * Sets an arbitrary attribute.
377:             * 
378:             * @param name
379:             *            the key for the attribute
380:             * @param obj
381:             *            the value of the attribute
382:             * @return this <CODE>Chunk</CODE>
383:             */
384:
385:            private Chunk setAttribute(String name, Object obj) {
386:                if (attributes == null)
387:                    attributes = new HashMap();
388:                attributes.put(name, obj);
389:                return this ;
390:            }
391:
392:            // the attributes are ordered as they appear in the book 'iText in Action'
393:
394:            /** Key for text horizontal scaling. */
395:            public static final String HSCALE = "HSCALE";
396:
397:            /**
398:             * Sets the text horizontal scaling. A value of 1 is normal and a value of
399:             * 0.5f shrinks the text to half it's width.
400:             * 
401:             * @param scale
402:             *            the horizontal scaling factor
403:             * @return this <CODE>Chunk</CODE>
404:             */
405:            public Chunk setHorizontalScaling(float scale) {
406:                return setAttribute(HSCALE, new Float(scale));
407:            }
408:
409:            /**
410:             * Gets the horizontal scaling.
411:             * 
412:             * @return a percentage in float
413:             */
414:            public float getHorizontalScaling() {
415:                if (attributes == null)
416:                    return 1f;
417:                Float f = (Float) attributes.get(HSCALE);
418:                if (f == null)
419:                    return 1f;
420:                return f.floatValue();
421:            }
422:
423:            /** Key for underline. */
424:            public static final String UNDERLINE = "UNDERLINE";
425:
426:            /**
427:             * Sets an horizontal line that can be an underline or a strikethrough.
428:             * Actually, the line can be anywhere vertically and has always the <CODE>
429:             * Chunk</CODE> width. Multiple call to this method will produce multiple
430:             * lines.
431:             * 
432:             * @param thickness
433:             *            the absolute thickness of the line
434:             * @param yPosition
435:             *            the absolute y position relative to the baseline
436:             * @return this <CODE>Chunk</CODE>
437:             */
438:            public Chunk setUnderline(float thickness, float yPosition) {
439:                return setUnderline(null, thickness, 0f, yPosition, 0f,
440:                        PdfContentByte.LINE_CAP_BUTT);
441:            }
442:
443:            /**
444:             * Sets an horizontal line that can be an underline or a strikethrough.
445:             * Actually, the line can be anywhere vertically and has always the <CODE>
446:             * Chunk</CODE> width. Multiple call to this method will produce multiple
447:             * lines.
448:             * 
449:             * @param color
450:             *            the color of the line or <CODE>null</CODE> to follow the
451:             *            text color
452:             * @param thickness
453:             *            the absolute thickness of the line
454:             * @param thicknessMul
455:             *            the thickness multiplication factor with the font size
456:             * @param yPosition
457:             *            the absolute y position relative to the baseline
458:             * @param yPositionMul
459:             *            the position multiplication factor with the font size
460:             * @param cap
461:             *            the end line cap. Allowed values are
462:             *            PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND
463:             *            and PdfContentByte.LINE_CAP_PROJECTING_SQUARE
464:             * @return this <CODE>Chunk</CODE>
465:             */
466:            public Chunk setUnderline(Color color, float thickness,
467:                    float thicknessMul, float yPosition, float yPositionMul,
468:                    int cap) {
469:                if (attributes == null)
470:                    attributes = new HashMap();
471:                Object obj[] = {
472:                        color,
473:                        new float[] { thickness, thicknessMul, yPosition,
474:                                yPositionMul, (float) cap } };
475:                Object unders[][] = Utilities.addToArray(
476:                        (Object[][]) attributes.get(UNDERLINE), obj);
477:                return setAttribute(UNDERLINE, unders);
478:            }
479:
480:            /** Key for sub/superscript. */
481:            public static final String SUBSUPSCRIPT = "SUBSUPSCRIPT";
482:
483:            /**
484:             * Sets the text displacement relative to the baseline. Positive values rise
485:             * the text, negative values lower the text.
486:             * <P>
487:             * It can be used to implement sub/superscript.
488:             * 
489:             * @param rise
490:             *            the displacement in points
491:             * @return this <CODE>Chunk</CODE>
492:             */
493:
494:            public Chunk setTextRise(float rise) {
495:                return setAttribute(SUBSUPSCRIPT, new Float(rise));
496:            }
497:
498:            /**
499:             * Gets the text displacement relatiev to the baseline.
500:             * 
501:             * @return a displacement in points
502:             */
503:            public float getTextRise() {
504:                if (attributes != null && attributes.containsKey(SUBSUPSCRIPT)) {
505:                    Float f = (Float) attributes.get(SUBSUPSCRIPT);
506:                    return f.floatValue();
507:                }
508:                return 0.0f;
509:            }
510:
511:            /** Key for text skewing. */
512:            public static final String SKEW = "SKEW";
513:
514:            /**
515:             * Skews the text to simulate italic and other effects. Try <CODE>alpha=0
516:             * </CODE> and <CODE>beta=12</CODE>.
517:             * 
518:             * @param alpha
519:             *            the first angle in degrees
520:             * @param beta
521:             *            the second angle in degrees
522:             * @return this <CODE>Chunk</CODE>
523:             */
524:            public Chunk setSkew(float alpha, float beta) {
525:                alpha = (float) Math.tan(alpha * Math.PI / 180);
526:                beta = (float) Math.tan(beta * Math.PI / 180);
527:                return setAttribute(SKEW, new float[] { alpha, beta });
528:            }
529:
530:            /** Key for background. */
531:            public static final String BACKGROUND = "BACKGROUND";
532:
533:            /**
534:             * Sets the color of the background <CODE>Chunk</CODE>.
535:             * 
536:             * @param color
537:             *            the color of the background
538:             * @return this <CODE>Chunk</CODE>
539:             */
540:            public Chunk setBackground(Color color) {
541:                return setBackground(color, 0, 0, 0, 0);
542:            }
543:
544:            /**
545:             * Sets the color and the size of the background <CODE>Chunk</CODE>.
546:             * 
547:             * @param color
548:             *            the color of the background
549:             * @param extraLeft
550:             *            increase the size of the rectangle in the left
551:             * @param extraBottom
552:             *            increase the size of the rectangle in the bottom
553:             * @param extraRight
554:             *            increase the size of the rectangle in the right
555:             * @param extraTop
556:             *            increase the size of the rectangle in the top
557:             * @return this <CODE>Chunk</CODE>
558:             */
559:            public Chunk setBackground(Color color, float extraLeft,
560:                    float extraBottom, float extraRight, float extraTop) {
561:                return setAttribute(BACKGROUND, new Object[] {
562:                        color,
563:                        new float[] { extraLeft, extraBottom, extraRight,
564:                                extraTop } });
565:            }
566:
567:            /** Key for text rendering mode. */
568:            public static final String TEXTRENDERMODE = "TEXTRENDERMODE";
569:
570:            /**
571:             * Sets the text rendering mode. It can outline text, simulate bold and make
572:             * text invisible.
573:             * 
574:             * @param mode
575:             *            the text rendering mode. It can be <CODE>
576:             *            PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE>
577:             *            PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE>,<CODE>
578:             *            PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE> and <CODE>
579:             *            PdfContentByte.TEXT_RENDER_MODE_INVISIBLE</CODE>.
580:             * @param strokeWidth
581:             *            the stroke line width for the modes <CODE>
582:             *            PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE> and <CODE>
583:             *            PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>.
584:             * @param strokeColor
585:             *            the stroke color or <CODE>null</CODE> to follow the text
586:             *            color
587:             * @return this <CODE>Chunk</CODE>
588:             */
589:            public Chunk setTextRenderMode(int mode, float strokeWidth,
590:                    Color strokeColor) {
591:                return setAttribute(TEXTRENDERMODE,
592:                        new Object[] { new Integer(mode),
593:                                new Float(strokeWidth), strokeColor });
594:            }
595:
596:            /** Key for split character. */
597:            public static final String SPLITCHARACTER = "SPLITCHARACTER";
598:
599:            /**
600:             * Sets the split characters.
601:             * 
602:             * @param splitCharacter
603:             *            the <CODE>SplitCharacter</CODE> interface
604:             * @return this <CODE>Chunk</CODE>
605:             */
606:
607:            public Chunk setSplitCharacter(SplitCharacter splitCharacter) {
608:                return setAttribute(SPLITCHARACTER, splitCharacter);
609:            }
610:
611:            /** Key for hyphenation. */
612:            public static final String HYPHENATION = "HYPHENATION";
613:
614:            /**
615:             * sets the hyphenation engine to this <CODE>Chunk</CODE>.
616:             * 
617:             * @param hyphenation
618:             *            the hyphenation engine
619:             * @return this <CODE>Chunk</CODE>
620:             */
621:            public Chunk setHyphenation(HyphenationEvent hyphenation) {
622:                return setAttribute(HYPHENATION, hyphenation);
623:            }
624:
625:            /** Key for remote goto. */
626:            public static final String REMOTEGOTO = "REMOTEGOTO";
627:
628:            /**
629:             * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
630:             * 
631:             * @param filename
632:             *            the file name of the destination document
633:             * @param name
634:             *            the name of the destination to go to
635:             * @return this <CODE>Chunk</CODE>
636:             */
637:
638:            public Chunk setRemoteGoto(String filename, String name) {
639:                return setAttribute(REMOTEGOTO, new Object[] { filename, name });
640:            }
641:
642:            /**
643:             * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
644:             * 
645:             * @param filename
646:             *            the file name of the destination document
647:             * @param page
648:             *            the page of the destination to go to. First page is 1
649:             * @return this <CODE>Chunk</CODE>
650:             */
651:
652:            public Chunk setRemoteGoto(String filename, int page) {
653:                return setAttribute(REMOTEGOTO, new Object[] { filename,
654:                        new Integer(page) });
655:            }
656:
657:            /** Key for local goto. */
658:            public static final String LOCALGOTO = "LOCALGOTO";
659:
660:            /**
661:             * Sets a local goto for this <CODE>Chunk</CODE>.
662:             * <P>
663:             * There must be a local destination matching the name.
664:             * 
665:             * @param name
666:             *            the name of the destination to go to
667:             * @return this <CODE>Chunk</CODE>
668:             */
669:
670:            public Chunk setLocalGoto(String name) {
671:                return setAttribute(LOCALGOTO, name);
672:            }
673:
674:            /** Key for local destination. */
675:            public static final String LOCALDESTINATION = "LOCALDESTINATION";
676:
677:            /**
678:             * Sets a local destination for this <CODE>Chunk</CODE>.
679:             * 
680:             * @param name
681:             *            the name for this destination
682:             * @return this <CODE>Chunk</CODE>
683:             */
684:            public Chunk setLocalDestination(String name) {
685:                return setAttribute(LOCALDESTINATION, name);
686:            }
687:
688:            /** Key for generic tag. */
689:            public static final String GENERICTAG = "GENERICTAG";
690:
691:            /**
692:             * Sets the generic tag <CODE>Chunk</CODE>.
693:             * <P>
694:             * The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>.
695:             * 
696:             * @param text
697:             *            the text for the tag
698:             * @return this <CODE>Chunk</CODE>
699:             */
700:
701:            public Chunk setGenericTag(String text) {
702:                return setAttribute(GENERICTAG, text);
703:            }
704:
705:            /** Key for image. */
706:            public static final String IMAGE = "IMAGE";
707:
708:            /**
709:             * Returns the image.
710:             * 
711:             * @return the image
712:             */
713:
714:            public Image getImage() {
715:                if (attributes == null)
716:                    return null;
717:                Object obj[] = (Object[]) attributes.get(Chunk.IMAGE);
718:                if (obj == null)
719:                    return null;
720:                else {
721:                    return (Image) obj[0];
722:                }
723:            }
724:
725:            /** Key for Action. */
726:            public static final String ACTION = "ACTION";
727:
728:            /**
729:             * Sets an action for this <CODE>Chunk</CODE>.
730:             * 
731:             * @param action
732:             *            the action
733:             * @return this <CODE>Chunk</CODE>
734:             */
735:
736:            public Chunk setAction(PdfAction action) {
737:                return setAttribute(ACTION, action);
738:            }
739:
740:            /**
741:             * Sets an anchor for this <CODE>Chunk</CODE>.
742:             * 
743:             * @param url
744:             *            the <CODE>URL</CODE> to link to
745:             * @return this <CODE>Chunk</CODE>
746:             */
747:
748:            public Chunk setAnchor(URL url) {
749:                return setAttribute(ACTION, new PdfAction(url.toExternalForm()));
750:            }
751:
752:            /**
753:             * Sets an anchor for this <CODE>Chunk</CODE>.
754:             * 
755:             * @param url
756:             *            the url to link to
757:             * @return this <CODE>Chunk</CODE>
758:             */
759:
760:            public Chunk setAnchor(String url) {
761:                return setAttribute(ACTION, new PdfAction(url));
762:            }
763:
764:            /** Key for newpage. */
765:            public static final String NEWPAGE = "NEWPAGE";
766:
767:            /**
768:             * Sets a new page tag..
769:             * 
770:             * @return this <CODE>Chunk</CODE>
771:             */
772:
773:            public Chunk setNewPage() {
774:                return setAttribute(NEWPAGE, null);
775:            }
776:
777:            /** Key for annotation. */
778:            public static final String PDFANNOTATION = "PDFANNOTATION";
779:
780:            /**
781:             * Sets a generic annotation to this <CODE>Chunk</CODE>.
782:             * 
783:             * @param annotation
784:             *            the annotation
785:             * @return this <CODE>Chunk</CODE>
786:             */
787:            public Chunk setAnnotation(PdfAnnotation annotation) {
788:                return setAttribute(PDFANNOTATION, annotation);
789:            }
790:
791:            // keys used in PdfChunk
792:
793:            /** Key for color. */
794:            public static final String COLOR = "COLOR";
795:
796:            /** Key for encoding. */
797:            public static final String ENCODING = "ENCODING";
798:
799:            // deprecated
800:
801:            /**
802:             * Returns a <CODE>Chunk</CODE> that has been constructed taking in
803:             * account the value of some <VAR>attributes </VAR>.
804:             * 
805:             * @param attributes
806:             *            Some attributes
807:             * @deprecated use ElementFactory.getChunk()
808:             */
809:
810:            public Chunk(java.util.Properties attributes) {
811:                this (com.lowagie.text.factories.ElementFactory
812:                        .getChunk(attributes));
813:            }
814:
815:            /**
816:             * Returns the content of this <CODE>Chunk</CODE>.
817:             * 
818:             * @return a <CODE>String</CODE>
819:             * @deprecated Use {@link #getContent()} instead
820:             */
821:            public String content() {
822:                return getContent();
823:            }
824:
825:            /**
826:             * Gets the font of this <CODE>Chunk</CODE>.
827:             * 
828:             * @return a <CODE>Font</CODE>
829:             * @deprecated Use {@link #getFont()} instead
830:             */
831:
832:            public Font font() {
833:                return getFont();
834:            }
835:
836:            /**
837:             * Gets the keys of a Hashtable
838:             * 
839:             * @param table
840:             *            a Hashtable
841:             * @return the keyset of a Hashtable (or an empty set if table is null)
842:             * @deprecated Use {@link Utilities#getKeySet(Hashtable)} instead
843:             */
844:            public static Set getKeySet(Hashtable table) {
845:                return Utilities.getKeySet(table);
846:            }
847:
848:            /**
849:             * Utility method to extend an array.
850:             * 
851:             * @param original
852:             *            the original array or <CODE>null</CODE>
853:             * @param item
854:             *            the item to be added to the array
855:             * @return a new array with the item appended
856:             * @deprecated Use {@link Utilities#addToArray(Object[][],Object[])} instead
857:             */
858:            public static Object[][] addToArray(Object original[][],
859:                    Object item[]) {
860:                return Utilities.addToArray(original, item);
861:            }
862:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.