001/* 002 * $Id: ListItem.java 4847 2011-05-05 19:46:13Z redlab_b $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text; 045 046/** 047 * A <CODE>ListItem</CODE> is a <CODE>Paragraph</CODE> 048 * that can be added to a <CODE>List</CODE>. 049 * <P> 050 * <B>Example 1:</B> 051 * <BLOCKQUOTE><PRE> 052 * List list = new List(true, 20); 053 * list.add(<STRONG>new ListItem("First line")</STRONG>); 054 * 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>); 055 * list.add(<STRONG>new ListItem("Third line")</STRONG>); 056 * </PRE></BLOCKQUOTE> 057 * 058 * The result of this code looks like this: 059 * <OL> 060 * <LI> 061 * First line 062 * </LI> 063 * <LI> 064 * The second line is longer to see what happens once the end of the line is reached. Will it start on a new line? 065 * </LI> 066 * <LI> 067 * Third line 068 * </LI> 069 * </OL> 070 * 071 * <B>Example 2:</B> 072 * <BLOCKQUOTE><PRE> 073 * List overview = new List(false, 10); 074 * overview.add(<STRONG>new ListItem("This is an item")</STRONG>); 075 * overview.add("This is another item"); 076 * </PRE></BLOCKQUOTE> 077 * 078 * The result of this code looks like this: 079 * <UL> 080 * <LI> 081 * This is an item 082 * </LI> 083 * <LI> 084 * This is another item 085 * </LI> 086 * </UL> 087 * 088 * @see Element 089 * @see List 090 * @see Paragraph 091 */ 092 093public class ListItem extends Paragraph { 094 095 // constants 096 private static final long serialVersionUID = 1970670787169329006L; 097 098 // member variables 099 100 /** 101 * this is the symbol that will precede the listitem. 102 * @since 5.0 used to be private 103 */ 104 protected Chunk symbol; 105 106 // constructors 107 108 /** 109 * Constructs a <CODE>ListItem</CODE>. 110 */ 111 public ListItem() { 112 super(); 113 } 114 115 /** 116 * Constructs a <CODE>ListItem</CODE> with a certain leading. 117 * 118 * @param leading the leading 119 */ 120 public ListItem(final float leading) { 121 super(leading); 122 } 123 124 /** 125 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>. 126 * 127 * @param chunk a <CODE>Chunk</CODE> 128 */ 129 public ListItem(final Chunk chunk) { 130 super(chunk); 131 } 132 133 /** 134 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>. 135 * 136 * @param string a <CODE>String</CODE> 137 */ 138 public ListItem(final String string) { 139 super(string); 140 } 141 142 /** 143 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE> 144 * and a certain <CODE>Font</CODE>. 145 * 146 * @param string a <CODE>String</CODE> 147 * @param font a <CODE>String</CODE> 148 */ 149 public ListItem(final String string, final Font font) { 150 super(string, font); 151 } 152 153 /** 154 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE> 155 * and a certain leading. 156 * 157 * @param leading the leading 158 * @param chunk a <CODE>Chunk</CODE> 159 */ 160 public ListItem(final float leading, final Chunk chunk) { 161 super(leading, chunk); 162 } 163 164 /** 165 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE> 166 * and a certain leading. 167 * 168 * @param leading the leading 169 * @param string a <CODE>String</CODE> 170 */ 171 public ListItem(final float leading, final String string) { 172 super(leading, string); 173 } 174 175 /** 176 * Constructs a <CODE>ListItem</CODE> with a certain leading, <CODE>String</CODE> 177 * and <CODE>Font</CODE>. 178 * 179 * @param leading the leading 180 * @param string a <CODE>String</CODE> 181 * @param font a <CODE>Font</CODE> 182 */ 183 public ListItem(final float leading, final String string, final Font font) { 184 super(leading, string, font); 185 } 186 187 /** 188 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Phrase</CODE>. 189 * 190 * @param phrase a <CODE>Phrase</CODE> 191 */ 192 public ListItem(final Phrase phrase) { 193 super(phrase); 194 } 195 196 // implementation of the Element-methods 197 198 /** 199 * Gets the type of the text element. 200 * 201 * @return a type 202 */ 203 @Override 204 public int type() { 205 return Element.LISTITEM; 206 } 207 208 // methods 209 210 /** 211 * Sets the listsymbol. 212 * 213 * @param symbol a <CODE>Chunk</CODE> 214 */ 215 public void setListSymbol(final Chunk symbol) { 216 if (this.symbol == null) { 217 this.symbol = symbol; 218 if (this.symbol.getFont().isStandardFont()) { 219 this.symbol.setFont(font); 220 } 221 } 222 } 223 224 /** 225 * Sets the indentation of this paragraph on the left side. 226 * 227 * @param indentation the new indentation 228 * @param autoindent if set to true, indentation is done automagically, the given indentation float is disregarded. 229 */ 230 public void setIndentationLeft(final float indentation, final boolean autoindent) { 231 if (autoindent) { 232 setIndentationLeft(getListSymbol().getWidthPoint()); 233 } 234 else { 235 setIndentationLeft(indentation); 236 } 237 } 238 239 /** 240 * Changes the font of the list symbol to the font of the first chunk 241 * in the list item. 242 * @since 5.0.6 243 */ 244 public void adjustListSymbolFont() { 245 java.util.List<Chunk> cks = getChunks(); 246 if (!cks.isEmpty() && symbol != null) 247 symbol.setFont(cks.get(0).getFont()); 248 } 249 250 // methods to retrieve information 251 252 /** 253 * Returns the listsymbol. 254 * 255 * @return a <CODE>Chunk</CODE> 256 */ 257 public Chunk getListSymbol() { 258 return symbol; 259 } 260 261}