2
* $Id: ListItem.java,v 1.79 2006/04/12 11:41:05 blowagie Exp $
5
* Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
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/
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.
15
* The Original Code is 'iText, a free JAVA-PDF library'.
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.
23
* Contributor(s): all the names of the contributors are added in the source code
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.
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.
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
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/
51
package com.lowagie.text;
53
import java.util.Properties;
55
import com.lowagie.text.markup.MarkupTags;
56
import com.lowagie.text.markup.MarkupParser;
59
* A <CODE>ListItem</CODE> is a <CODE>Paragraph</CODE>
60
* that can be added to a <CODE>List</CODE>.
64
* List list = new List(true, 20);
65
* list.add(<STRONG>new ListItem("First line")</STRONG>);
66
* 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>);
67
* list.add(<STRONG>new ListItem("Third line")</STRONG>);
70
* The result of this code looks like this:
76
* The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?
85
* List overview = new List(false, 10);
86
* overview.add(<STRONG>new ListItem("This is an item")</STRONG>);
87
* overview.add("This is another item");
90
* The result of this code looks like this:
96
* This is another item
105
public class ListItem extends Paragraph implements TextElementArray, MarkupAttributes {
109
/** this is the symbol that wil proceed the listitem. */
110
private Chunk symbol;
115
* Constructs a <CODE>ListItem</CODE>.
123
* Constructs a <CODE>ListItem</CODE> with a certain leading.
125
* @param leading the leading
128
public ListItem(float leading) {
133
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>.
135
* @param chunk a <CODE>Chunk</CODE>
138
public ListItem(Chunk chunk) {
143
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>.
145
* @param string a <CODE>String</CODE>
148
public ListItem(String string) {
153
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
154
* and a certain <CODE>Font</CODE>.
156
* @param string a <CODE>String</CODE>
157
* @param font a <CODE>String</CODE>
160
public ListItem(String string, Font font) {
165
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>
166
* and a certain leading.
168
* @param leading the leading
169
* @param chunk a <CODE>Chunk</CODE>
172
public ListItem(float leading, Chunk chunk) {
173
super(leading, chunk);
177
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
178
* and a certain leading.
180
* @param leading the leading
181
* @param string a <CODE>String</CODE>
184
public ListItem(float leading, String string) {
185
super(leading, string);
189
* Constructs a <CODE>ListItem</CODE> with a certain leading, <CODE>String</CODE>
190
* and <CODE>Font</CODE>.
192
* @param leading the leading
193
* @param string a <CODE>String</CODE>
194
* @param font a <CODE>Font</CODE>
197
public ListItem(float leading, String string, Font font) {
198
super(leading, string, font);
202
* Constructs a <CODE>ListItem</CODE> with a certain <CODE>Phrase</CODE>.
204
* @param phrase a <CODE>Phrase</CODE>
207
public ListItem(Phrase phrase) {
212
* Returns a <CODE>ListItem</CODE> that has been constructed taking in account
213
* the value of some <VAR>attributes</VAR>.
215
* @param attributes Some attributes
218
public ListItem(Properties attributes) {
219
super("", FontFactory.getFont(attributes));
221
if ((value = (String)attributes.remove(ElementTags.ITEXT)) != null) {
222
add(new Chunk(value));
224
if ((value = (String)attributes.remove(ElementTags.LEADING)) != null) {
225
setLeading(Float.valueOf(value + "f").floatValue());
227
else if ((value = (String)attributes.remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null) {
228
setLeading(MarkupParser.parseLength(value));
230
if ((value = (String)attributes.remove(ElementTags.INDENTATIONLEFT)) != null) {
231
setIndentationLeft(Float.valueOf(value + "f").floatValue());
233
if ((value = (String)attributes.remove(ElementTags.INDENTATIONRIGHT)) != null) {
234
setIndentationRight(Float.valueOf(value + "f").floatValue());
236
if ((value = (String)attributes.remove(ElementTags.ALIGN)) != null) {
239
if (attributes.size() > 0) setMarkupAttributes(attributes);
242
// implementation of the Element-methods
245
* Gets the type of the text element.
251
return Element.LISTITEM;
257
* Sets the listsymbol.
259
* @param symbol a <CODE>Chunk</CODE>
262
public void setListSymbol(Chunk symbol) {
263
if (this.symbol == null) {
264
this.symbol = symbol;
265
if (this.symbol.font().isStandardFont()) {
266
this.symbol.setFont(font);
271
// methods to retrieve information
274
* Returns the listsymbol.
276
* @return a <CODE>Chunk</CODE>
279
public Chunk listSymbol() {
284
* Checks if a given tag corresponds with this object.
286
* @param tag the given tag
287
* @return true if the tag corresponds
290
public static boolean isTag(String tag) {
291
return ElementTags.LISTITEM.equals(tag);