001: /*
002: * $Id: ListItem.java 2748 2007-05-12 15:11:48Z 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: /**
054: * A <CODE>ListItem</CODE> is a <CODE>Paragraph</CODE>
055: * that can be added to a <CODE>List</CODE>.
056: * <P>
057: * <B>Example 1:</B>
058: * <BLOCKQUOTE><PRE>
059: * List list = new List(true, 20);
060: * list.add(<STRONG>new ListItem("First line")</STRONG>);
061: * 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>);
062: * list.add(<STRONG>new ListItem("Third line")</STRONG>);
063: * </PRE></BLOCKQUOTE>
064: *
065: * The result of this code looks like this:
066: * <OL>
067: * <LI>
068: * First line
069: * </LI>
070: * <LI>
071: * The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?
072: * </LI>
073: * <LI>
074: * Third line
075: * </LI>
076: * </OL>
077: *
078: * <B>Example 2:</B>
079: * <BLOCKQUOTE><PRE>
080: * List overview = new List(false, 10);
081: * overview.add(<STRONG>new ListItem("This is an item")</STRONG>);
082: * overview.add("This is another item");
083: * </PRE></BLOCKQUOTE>
084: *
085: * The result of this code looks like this:
086: * <UL>
087: * <LI>
088: * This is an item
089: * </LI>
090: * <LI>
091: * This is another item
092: * </LI>
093: * </UL>
094: *
095: * @see Element
096: * @see List
097: * @see Paragraph
098: */
099:
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 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 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 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 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: } else {
236: setIndentationLeft(indentation);
237: }
238: }
239:
240: // methods to retrieve information
241:
242: /**
243: * Returns the listsymbol.
244: *
245: * @return a <CODE>Chunk</CODE>
246: */
247: public Chunk getListSymbol() {
248: return symbol;
249: }
250:
251: // deprecated stuff
252:
253: /**
254: * Returns a <CODE>ListItem</CODE> that has been constructed taking in account
255: * the value of some <VAR>attributes</VAR>.
256: *
257: * @param attributes Some attributes
258: * @deprecated use ElementFactory.getParagraph(attributes)
259: */
260: public ListItem(java.util.Properties attributes) {
261: this (com.lowagie.text.factories.ElementFactory
262: .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: }
|