KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > Chunk


1 /*
2  * $Id: Chunk.java 2748 2007-05-12 15:11:48Z blowagie $
3  * $Name$
4  *
5  * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text;
52
53 import java.awt.Color JavaDoc;
54 import java.net.URL JavaDoc;
55 import java.util.ArrayList JavaDoc;
56 import java.util.HashMap JavaDoc;
57 import java.util.Hashtable JavaDoc;
58 import java.util.Set JavaDoc;
59
60 import com.lowagie.text.pdf.HyphenationEvent;
61 import com.lowagie.text.pdf.PdfAction;
62 import com.lowagie.text.pdf.PdfAnnotation;
63 import com.lowagie.text.pdf.PdfContentByte;
64
65 /**
66  * This is the smallest significant part of text that can be added to a
67  * document.
68  * <P>
69  * Most elements can be divided in one or more <CODE>Chunk</CODE>s. A chunk
70  * is a <CODE>String</CODE> with a certain <CODE>Font</CODE>. All other
71  * layout parameters should be defined in the object to which this chunk of text
72  * is added.
73  * <P>
74  * Example: <BLOCKQUOTE>
75  *
76  * <PRE>
77  *
78  * <STRONG>Chunk chunk = new Chunk("Hello world",
79  * FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, 0,
80  * 0))); </STRONG> document.add(chunk);
81  *
82  * </PRE>
83  *
84  * </BLOCKQUOTE>
85  */

86
87 public class Chunk implements Element {
88
89     // public static membervariables
90

91     /** The character stand in for an image. */
92     public static final String JavaDoc OBJECT_REPLACEMENT_CHARACTER = "\ufffc";
93
94     /** This is a Chunk containing a newline. */
95     public static final Chunk NEWLINE = new Chunk("\n");
96
97     /** This is a Chunk containing a newpage. */
98     public static final Chunk NEXTPAGE = new Chunk("");
99     static {
100         NEXTPAGE.setNewPage();
101     }
102
103     // member variables
104

105     /** This is the content of this chunk of text. */
106     protected StringBuffer JavaDoc 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 JavaDoc attributes = null;
113
114     // constructors
115

116     /**
117      * Empty constructor.
118      */

119     public Chunk() {
120         this.content = new StringBuffer JavaDoc();
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 JavaDoc(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 JavaDoc(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 JavaDoc content, Font font) {
150         this.content = new StringBuffer JavaDoc(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 JavaDoc 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 JavaDoc();
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 JavaDoc[] { copyImage, new Float JavaDoc(offsetX),
205                 new Float JavaDoc(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 JavaDoc[] { image, new Float JavaDoc(offsetX),
224                 new Float JavaDoc(offsetY), new Boolean JavaDoc(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 JavaDoc getChunks() {
260         ArrayList JavaDoc tmp = new ArrayList JavaDoc();
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 JavaDoc append(String JavaDoc 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 JavaDoc 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 JavaDoc 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(getContent(),
339                 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 JavaDoc getAttributes() {
364         return attributes;
365     }
366
367     /**
368      * Sets an arbitrary attribute.
369      *
370      * @param name
371      * the key for the attribute
372      * @param obj
373      * the value of the attribute
374      * @return this <CODE>Chunk</CODE>
375      */

376
377     private Chunk setAttribute(String JavaDoc name, Object JavaDoc obj) {
378         if (attributes == null)
379             attributes = new HashMap JavaDoc();
380         attributes.put(name, obj);
381         return this;
382     }
383
384     // the attributes are ordered as they appear in the book 'iText in Action'
385

386     /** Key for text horizontal scaling. */
387     public static final String JavaDoc HSCALE = "HSCALE";
388
389     /**
390      * Sets the text horizontal scaling. A value of 1 is normal and a value of
391      * 0.5f shrinks the text to half it's width.
392      *
393      * @param scale
394      * the horizontal scaling factor
395      * @return this <CODE>Chunk</CODE>
396      */

397     public Chunk setHorizontalScaling(float scale) {
398         return setAttribute(HSCALE, new Float JavaDoc(scale));
399     }
400
401     /**
402      * Gets the horizontal scaling.
403      *
404      * @return a percentage in float
405      */

406     public float getHorizontalScaling() {
407         if (attributes == null)
408             return 1f;
409         Float JavaDoc f = (Float JavaDoc) attributes.get(HSCALE);
410         if (f == null)
411             return 1f;
412         return f.floatValue();
413     }
414
415     /** Key for underline. */
416     public static final String JavaDoc UNDERLINE = "UNDERLINE";
417
418     /**
419      * Sets an horizontal line that can be an underline or a strikethrough.
420      * Actually, the line can be anywhere vertically and has always the <CODE>
421      * Chunk</CODE> width. Multiple call to this method will produce multiple
422      * lines.
423      *
424      * @param thickness
425      * the absolute thickness of the line
426      * @param yPosition
427      * the absolute y position relative to the baseline
428      * @return this <CODE>Chunk</CODE>
429      */

430     public Chunk setUnderline(float thickness, float yPosition) {
431         return setUnderline(null, thickness, 0f, yPosition, 0f,
432                 PdfContentByte.LINE_CAP_BUTT);
433     }
434
435     /**
436      * Sets an horizontal line that can be an underline or a strikethrough.
437      * Actually, the line can be anywhere vertically and has always the <CODE>
438      * Chunk</CODE> width. Multiple call to this method will produce multiple
439      * lines.
440      *
441      * @param color
442      * the color of the line or <CODE>null</CODE> to follow the
443      * text color
444      * @param thickness
445      * the absolute thickness of the line
446      * @param thicknessMul
447      * the thickness multiplication factor with the font size
448      * @param yPosition
449      * the absolute y position relative to the baseline
450      * @param yPositionMul
451      * the position multiplication factor with the font size
452      * @param cap
453      * the end line cap. Allowed values are
454      * PdfContentByte.LINE_CAP_BUTT, PdfContentByte.LINE_CAP_ROUND
455      * and PdfContentByte.LINE_CAP_PROJECTING_SQUARE
456      * @return this <CODE>Chunk</CODE>
457      */

458     public Chunk setUnderline(Color JavaDoc color, float thickness, float thicknessMul,
459             float yPosition, float yPositionMul, int cap) {
460         if (attributes == null)
461             attributes = new HashMap JavaDoc();
462         Object JavaDoc obj[] = {
463                 color,
464                 new float[] { thickness, thicknessMul, yPosition, yPositionMul,
465                         (float) cap } };
466         Object JavaDoc unders[][] = Utilities.addToArray((Object JavaDoc[][]) attributes.get(UNDERLINE),
467                 obj);
468         return setAttribute(UNDERLINE, unders);
469     }
470     
471     /** Key for sub/superscript. */
472     public static final String JavaDoc SUBSUPSCRIPT = "SUBSUPSCRIPT";
473     
474     /**
475      * Sets the text displacement relative to the baseline. Positive values rise
476      * the text, negative values lower the text.
477      * <P>
478      * It can be used to implement sub/superscript.
479      *
480      * @param rise
481      * the displacement in points
482      * @return this <CODE>Chunk</CODE>
483      */

484
485     public Chunk setTextRise(float rise) {
486         return setAttribute(SUBSUPSCRIPT, new Float JavaDoc(rise));
487     }
488
489     /**
490      * Gets the text displacement relatiev to the baseline.
491      *
492      * @return a displacement in points
493      */

494     public float getTextRise() {
495         if (attributes != null && attributes.containsKey(SUBSUPSCRIPT)) {
496             Float JavaDoc f = (Float JavaDoc) attributes.get(SUBSUPSCRIPT);
497             return f.floatValue();
498         }
499         return 0.0f;
500     }
501
502     /** Key for text skewing. */
503     public static final String JavaDoc SKEW = "SKEW";
504
505     /**
506      * Skews the text to simulate italic and other effects. Try <CODE>alpha=0
507      * </CODE> and <CODE>beta=12</CODE>.
508      *
509      * @param alpha
510      * the first angle in degrees
511      * @param beta
512      * the second angle in degrees
513      * @return this <CODE>Chunk</CODE>
514      */

515     public Chunk setSkew(float alpha, float beta) {
516         alpha = (float) Math.tan(alpha * Math.PI / 180);
517         beta = (float) Math.tan(beta * Math.PI / 180);
518         return setAttribute(SKEW, new float[] { alpha, beta });
519     }
520
521     /** Key for background. */
522     public static final String JavaDoc BACKGROUND = "BACKGROUND";
523
524     /**
525      * Sets the color of the background <CODE>Chunk</CODE>.
526      *
527      * @param color
528      * the color of the background
529      * @return this <CODE>Chunk</CODE>
530      */

531     public Chunk setBackground(Color JavaDoc color) {
532         return setBackground(color, 0, 0, 0, 0);
533     }
534
535     /**
536      * Sets the color and the size of the background <CODE>Chunk</CODE>.
537      *
538      * @param color
539      * the color of the background
540      * @param extraLeft
541      * increase the size of the rectangle in the left
542      * @param extraBottom
543      * increase the size of the rectangle in the bottom
544      * @param extraRight
545      * increase the size of the rectangle in the right
546      * @param extraTop
547      * increase the size of the rectangle in the top
548      * @return this <CODE>Chunk</CODE>
549      */

550     public Chunk setBackground(Color JavaDoc color, float extraLeft, float extraBottom,
551             float extraRight, float extraTop) {
552         return setAttribute(BACKGROUND, new Object JavaDoc[] { color,
553                 new float[] { extraLeft, extraBottom, extraRight, extraTop } });
554     }
555
556     /** Key for text rendering mode. */
557     public static final String JavaDoc TEXTRENDERMODE = "TEXTRENDERMODE";
558
559     /**
560      * Sets the text rendering mode. It can outline text, simulate bold and make
561      * text invisible.
562      *
563      * @param mode
564      * the text rendering mode. It can be <CODE>
565      * PdfContentByte.TEXT_RENDER_MODE_FILL</CODE>,<CODE>
566      * PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE>,<CODE>
567      * PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE> and <CODE>
568      * PdfContentByte.TEXT_RENDER_MODE_INVISIBLE</CODE>.
569      * @param strokeWidth
570      * the stroke line width for the modes <CODE>
571      * PdfContentByte.TEXT_RENDER_MODE_STROKE</CODE> and <CODE>
572      * PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE</CODE>.
573      * @param strokeColor
574      * the stroke color or <CODE>null</CODE> to follow the text
575      * color
576      * @return this <CODE>Chunk</CODE>
577      */

578     public Chunk setTextRenderMode(int mode, float strokeWidth,
579             Color JavaDoc strokeColor) {
580         return setAttribute(TEXTRENDERMODE, new Object JavaDoc[] { new Integer JavaDoc(mode),
581                 new Float JavaDoc(strokeWidth), strokeColor });
582     }
583
584     /** Key for split character. */
585     public static final String JavaDoc SPLITCHARACTER = "SPLITCHARACTER";
586
587     /**
588      * Sets the split characters.
589      *
590      * @param splitCharacter
591      * the <CODE>SplitCharacter</CODE> interface
592      * @return this <CODE>Chunk</CODE>
593      */

594
595     public Chunk setSplitCharacter(SplitCharacter splitCharacter) {
596         return setAttribute(SPLITCHARACTER, splitCharacter);
597     }
598
599     /** Key for hyphenation. */
600     public static final String JavaDoc HYPHENATION = "HYPHENATION";
601     
602     /**
603      * sets the hyphenation engine to this <CODE>Chunk</CODE>.
604      *
605      * @param hyphenation
606      * the hyphenation engine
607      * @return this <CODE>Chunk</CODE>
608      */

609     public Chunk setHyphenation(HyphenationEvent hyphenation) {
610         return setAttribute(HYPHENATION, hyphenation);
611     }
612
613     /** Key for remote goto. */
614     public static final String JavaDoc REMOTEGOTO = "REMOTEGOTO";
615
616     /**
617      * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
618      *
619      * @param filename
620      * the file name of the destination document
621      * @param name
622      * the name of the destination to go to
623      * @return this <CODE>Chunk</CODE>
624      */

625
626     public Chunk setRemoteGoto(String JavaDoc filename, String JavaDoc name) {
627         return setAttribute(REMOTEGOTO, new Object JavaDoc[] { filename, name });
628     }
629
630     /**
631      * Sets a goto for a remote destination for this <CODE>Chunk</CODE>.
632      *
633      * @param filename
634      * the file name of the destination document
635      * @param page
636      * the page of the destination to go to. First page is 1
637      * @return this <CODE>Chunk</CODE>
638      */

639
640     public Chunk setRemoteGoto(String JavaDoc filename, int page) {
641         return setAttribute(REMOTEGOTO, new Object JavaDoc[] { filename,
642                 new Integer JavaDoc(page) });
643     }
644
645     /** Key for local goto. */
646     public static final String JavaDoc LOCALGOTO = "LOCALGOTO";
647     
648     /**
649      * Sets a local goto for this <CODE>Chunk</CODE>.
650      * <P>
651      * There must be a local destination matching the name.
652      *
653      * @param name
654      * the name of the destination to go to
655      * @return this <CODE>Chunk</CODE>
656      */

657
658     public Chunk setLocalGoto(String JavaDoc name) {
659         return setAttribute(LOCALGOTO, name);
660     }
661
662     /** Key for local destination. */
663     public static final String JavaDoc LOCALDESTINATION = "LOCALDESTINATION";
664
665     /**
666      * Sets a local destination for this <CODE>Chunk</CODE>.
667      *
668      * @param name
669      * the name for this destination
670      * @return this <CODE>Chunk</CODE>
671      */

672     public Chunk setLocalDestination(String JavaDoc name) {
673         return setAttribute(LOCALDESTINATION, name);
674     }
675
676     /** Key for generic tag. */
677     public static final String JavaDoc GENERICTAG = "GENERICTAG";
678
679     /**
680      * Sets the generic tag <CODE>Chunk</CODE>.
681      * <P>
682      * The text for this tag can be retrieved with <CODE>PdfPageEvent</CODE>.
683      *
684      * @param text
685      * the text for the tag
686      * @return this <CODE>Chunk</CODE>
687      */

688
689     public Chunk setGenericTag(String JavaDoc text) {
690         return setAttribute(GENERICTAG, text);
691     }
692     
693     /** Key for image. */
694     public static final String JavaDoc IMAGE = "IMAGE";
695
696     /**
697      * Returns the image.
698      *
699      * @return the image
700      */

701
702     public Image getImage() {
703         if (attributes == null)
704             return null;
705         Object JavaDoc obj[] = (Object JavaDoc[]) attributes.get(Chunk.IMAGE);
706         if (obj == null)
707             return null;
708         else {
709             return (Image) obj[0];
710         }
711     }
712     
713     /** Key for Action. */
714     public static final String JavaDoc ACTION = "ACTION";
715
716     /**
717      * Sets an action for this <CODE>Chunk</CODE>.
718      *
719      * @param action
720      * the action
721      * @return this <CODE>Chunk</CODE>
722      */

723
724     public Chunk setAction(PdfAction action) {
725         return setAttribute(ACTION, action);
726     }
727
728     /**
729      * Sets an anchor for this <CODE>Chunk</CODE>.
730      *
731      * @param url
732      * the <CODE>URL</CODE> to link to
733      * @return this <CODE>Chunk</CODE>
734      */

735
736     public Chunk setAnchor(URL JavaDoc url) {
737         return setAttribute(ACTION, new PdfAction(url.toExternalForm()));
738     }
739
740     /**
741      * Sets an anchor for this <CODE>Chunk</CODE>.
742      *
743      * @param url
744      * the url to link to
745      * @return this <CODE>Chunk</CODE>
746      */

747
748     public Chunk setAnchor(String JavaDoc url) {
749         return setAttribute(ACTION, new PdfAction(url));
750     }
751     
752     /** Key for newpage. */
753     public static final String JavaDoc NEWPAGE = "NEWPAGE";
754
755     /**
756      * Sets a new page tag..
757      *
758      * @return this <CODE>Chunk</CODE>
759      */

760
761     public Chunk setNewPage() {
762         return setAttribute(NEWPAGE, null);
763     }
764
765     /** Key for annotation. */
766     public static final String JavaDoc PDFANNOTATION = "PDFANNOTATION";
767
768     /**
769      * Sets a generic annotation to this <CODE>Chunk</CODE>.
770      *
771      * @param annotation
772      * the annotation
773      * @return this <CODE>Chunk</CODE>
774      */

775     public Chunk setAnnotation(PdfAnnotation annotation) {
776         return setAttribute(PDFANNOTATION, annotation);
777     }
778     
779     // keys used in PdfChunk
780

781     /** Key for color. */
782     public static final String JavaDoc COLOR = "COLOR";
783
784     /** Key for encoding. */
785     public static final String JavaDoc ENCODING = "ENCODING";
786     
787     // deprecated
788

789     /**
790      * Returns a <CODE>Chunk</CODE> that has been constructed taking in
791      * account the value of some <VAR>attributes </VAR>.
792      *
793      * @param attributes
794      * Some attributes
795      * @deprecated use ElementFactory.getChunk()
796      */

797
798     public Chunk(java.util.Properties JavaDoc attributes) {
799         this(com.lowagie.text.factories.ElementFactory.getChunk(attributes));
800     }
801
802     /**
803      * Returns the content of this <CODE>Chunk</CODE>.
804      *
805      * @return a <CODE>String</CODE>
806      * @deprecated Use {@link #getContent()} instead
807      */

808     public String JavaDoc content() {
809         return getContent();
810     }
811
812     /**
813      * Gets the font of this <CODE>Chunk</CODE>.
814      *
815      * @return a <CODE>Font</CODE>
816      * @deprecated Use {@link #getFont()} instead
817      */

818     
819     public Font font() {
820         return getFont();
821     }
822
823     /**
824      * Gets the keys of a Hashtable
825      *
826      * @param table
827      * a Hashtable
828      * @return the keyset of a Hashtable (or an empty set if table is null)
829      * @deprecated Use {@link Utilities#getKeySet(Hashtable)} instead
830      */

831     public static Set JavaDoc getKeySet(Hashtable JavaDoc table) {
832         return Utilities.getKeySet(table);
833     }
834     
835     /**
836      * Utility method to extend an array.
837      *
838      * @param original
839      * the original array or <CODE>null</CODE>
840      * @param item
841      * the item to be added to the array
842      * @return a new array with the item appended
843      * @deprecated Use {@link Utilities#addToArray(Object[][],Object[])} instead
844      */

845     public static Object JavaDoc[][] addToArray(Object JavaDoc original[][], Object JavaDoc item[]) {
846         return Utilities.addToArray(original, item);
847     }
848 }
Popular Tags