KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ListItem.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 /**
54  * A <CODE>ListItem</CODE> is a <CODE>Paragraph</CODE>
55  * that can be added to a <CODE>List</CODE>.
56  * <P>
57  * <B>Example 1:</B>
58  * <BLOCKQUOTE><PRE>
59  * List list = new List(true, 20);
60  * list.add(<STRONG>new ListItem("First line")</STRONG>);
61  * list.add(<STRONG>new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?")</STRONG>);
62  * list.add(<STRONG>new ListItem("Third line")</STRONG>);
63  * </PRE></BLOCKQUOTE>
64  *
65  * The result of this code looks like this:
66  * <OL>
67  * <LI>
68  * First line
69  * </LI>
70  * <LI>
71  * The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?
72  * </LI>
73  * <LI>
74  * Third line
75  * </LI>
76  * </OL>
77  *
78  * <B>Example 2:</B>
79  * <BLOCKQUOTE><PRE>
80  * List overview = new List(false, 10);
81  * overview.add(<STRONG>new ListItem("This is an item")</STRONG>);
82  * overview.add("This is another item");
83  * </PRE></BLOCKQUOTE>
84  *
85  * The result of this code looks like this:
86  * <UL>
87  * <LI>
88  * This is an item
89  * </LI>
90  * <LI>
91  * This is another item
92  * </LI>
93  * </UL>
94  *
95  * @see Element
96  * @see List
97  * @see Paragraph
98  */

99
100 public class ListItem extends Paragraph {
101     
102     // constants
103
private static final long serialVersionUID = 1970670787169329006L;
104     
105     // member variables
106

107     /** this is the symbol that wil precede the listitem. */
108     private Chunk symbol;
109     
110     // constructors
111

112     /**
113      * Constructs a <CODE>ListItem</CODE>.
114      */

115     public ListItem() {
116         super();
117     }
118     
119     /**
120      * Constructs a <CODE>ListItem</CODE> with a certain leading.
121      *
122      * @param leading the leading
123      */

124     public ListItem(float leading) {
125         super(leading);
126     }
127     
128     /**
129      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>.
130      *
131      * @param chunk a <CODE>Chunk</CODE>
132      */

133     public ListItem(Chunk chunk) {
134         super(chunk);
135     }
136     
137     /**
138      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>.
139      *
140      * @param string a <CODE>String</CODE>
141      */

142     public ListItem(String JavaDoc string) {
143         super(string);
144     }
145     
146     /**
147      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
148      * and a certain <CODE>Font</CODE>.
149      *
150      * @param string a <CODE>String</CODE>
151      * @param font a <CODE>String</CODE>
152      */

153     public ListItem(String JavaDoc string, Font font) {
154         super(string, font);
155     }
156     
157     /**
158      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>
159      * and a certain leading.
160      *
161      * @param leading the leading
162      * @param chunk a <CODE>Chunk</CODE>
163      */

164     public ListItem(float leading, Chunk chunk) {
165         super(leading, chunk);
166     }
167     
168     /**
169      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
170      * and a certain leading.
171      *
172      * @param leading the leading
173      * @param string a <CODE>String</CODE>
174      */

175     public ListItem(float leading, String JavaDoc string) {
176         super(leading, string);
177     }
178     
179     /**
180      * Constructs a <CODE>ListItem</CODE> with a certain leading, <CODE>String</CODE>
181      * and <CODE>Font</CODE>.
182      *
183      * @param leading the leading
184      * @param string a <CODE>String</CODE>
185      * @param font a <CODE>Font</CODE>
186      */

187     public ListItem(float leading, String JavaDoc string, Font font) {
188         super(leading, string, font);
189     }
190     
191     /**
192      * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Phrase</CODE>.
193      *
194      * @param phrase a <CODE>Phrase</CODE>
195      */

196     public ListItem(Phrase phrase) {
197         super(phrase);
198     }
199     
200     // implementation of the Element-methods
201

202     /**
203      * Gets the type of the text element.
204      *
205      * @return a type
206      */

207     public int type() {
208         return Element.LISTITEM;
209     }
210     
211     // methods
212

213     /**
214      * Sets the listsymbol.
215      *
216      * @param symbol a <CODE>Chunk</CODE>
217      */

218     public void setListSymbol(Chunk symbol) {
219         if (this.symbol == null) {
220             this.symbol = symbol;
221             if (this.symbol.getFont().isStandardFont()) {
222                 this.symbol.setFont(font);
223             }
224         }
225     }
226     
227     /**
228      * Sets the indentation of this paragraph on the left side.
229      *
230      * @param indentation the new indentation
231      */

232     public void setIndentationLeft(float indentation, boolean autoindent) {
233         if (autoindent) {
234             setIndentationLeft(getListSymbol().getWidthPoint());
235         }
236         else {
237             setIndentationLeft(indentation);
238         }
239     }
240     
241     // methods to retrieve information
242

243     /**
244      * Returns the listsymbol.
245      *
246      * @return a <CODE>Chunk</CODE>
247      */

248     public Chunk getListSymbol() {
249         return symbol;
250     }
251         
252     // deprecated stuff
253

254     /**
255      * Returns a <CODE>ListItem</CODE> that has been constructed taking in account
256      * the value of some <VAR>attributes</VAR>.
257      *
258      * @param attributes Some attributes
259      * @deprecated use ElementFactory.getParagraph(attributes)
260      */

261     public ListItem(java.util.Properties JavaDoc attributes) {
262         this(com.lowagie.text.factories.ElementFactory.getParagraph(attributes));
263     }
264     
265     /**
266      * Returns the listsymbol.
267      *
268      * @return a <CODE>Chunk</CODE>
269      * @deprecated Use {@link #getListSymbol()} instead
270      */

271     public Chunk listSymbol() {
272         return getListSymbol();
273     }
274 }
275
Popular Tags