~ubuntu-branches/ubuntu/feisty/libitext-java/feisty

« back to all changes in this revision

Viewing changes to com/lowagie/text/ListItem.java

  • Committer: Bazaar Package Importer
  • Author(s): Gerardo Curiel
  • Date: 2006-09-21 00:08:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060921000853-le9rrpcnw9fc57sm
Tags: 1.4.5-1
* New upstream release
* debian/rules modified due to a new build.xml file
* Patched Pdfgraphics2d.java to remove privative dependencie on com.sun.image.codec.jpeg.*
  (more information on
  http://developer.classpath.org/mediation/ClasspathMigration#head-d4ee9efe53a641e29ffdcd96e985bf38bbc671c1 )
* ant/.ant.properties paths fixed
* Build package with the packages provided by java-gcj-compat-dev
* Removed unused README.Debian
* Removed unused debian/patches/01libitext-java-addbuildscript.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: ListItem.java,v 1.79 2006/04/12 11:41:05 blowagie Exp $
 
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.util.Properties;
 
54
 
 
55
import com.lowagie.text.markup.MarkupTags;
 
56
import com.lowagie.text.markup.MarkupParser;
 
57
 
 
58
/**
 
59
 * A <CODE>ListItem</CODE> is a <CODE>Paragraph</CODE>
 
60
 * that can be added to a <CODE>List</CODE>.
 
61
 * <P>
 
62
 * <B>Example 1:</B>
 
63
 * <BLOCKQUOTE><PRE>
 
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>);
 
68
 * </PRE></BLOCKQUOTE>
 
69
 *
 
70
 * The result of this code looks like this:
 
71
 *      <OL>
 
72
 *              <LI>
 
73
 *                      First line
 
74
 *              </LI>
 
75
 *              <LI>
 
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?
 
77
 *              </LI>
 
78
 *              <LI>
 
79
 *                      Third line
 
80
 *              </LI>
 
81
 *      </OL>
 
82
 *
 
83
 * <B>Example 2:</B>
 
84
 * <BLOCKQUOTE><PRE>
 
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");
 
88
 * </PRE></BLOCKQUOTE>
 
89
 *
 
90
 * The result of this code looks like this:
 
91
 *      <UL>
 
92
 *              <LI>
 
93
 *                      This is an item
 
94
 *              </LI>
 
95
 *              <LI>
 
96
 *                      This is another item
 
97
 *              </LI>
 
98
 *      </UL>
 
99
 *
 
100
 * @see Element
 
101
 * @see List
 
102
 * @see Paragraph
 
103
 */
 
104
 
 
105
public class ListItem extends Paragraph implements TextElementArray, MarkupAttributes {
 
106
    
 
107
    // membervariables
 
108
    
 
109
/** this is the symbol that wil proceed the listitem. */
 
110
    private Chunk symbol;
 
111
    
 
112
    // constructors
 
113
    
 
114
/**
 
115
 * Constructs a <CODE>ListItem</CODE>.
 
116
 */
 
117
    
 
118
    public ListItem() {
 
119
        super();
 
120
    }
 
121
    
 
122
/**
 
123
 * Constructs a <CODE>ListItem</CODE> with a certain leading.
 
124
 *
 
125
 * @param       leading         the leading
 
126
 */
 
127
    
 
128
    public ListItem(float leading) {
 
129
        super(leading);
 
130
    }
 
131
    
 
132
/**
 
133
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>.
 
134
 *
 
135
 * @param       chunk           a <CODE>Chunk</CODE>
 
136
 */
 
137
    
 
138
    public ListItem(Chunk chunk) {
 
139
        super(chunk);
 
140
    }
 
141
    
 
142
/**
 
143
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>.
 
144
 *
 
145
 * @param       string          a <CODE>String</CODE>
 
146
 */
 
147
    
 
148
    public ListItem(String string) {
 
149
        super(string);
 
150
    }
 
151
    
 
152
/**
 
153
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
 
154
 * and a certain <CODE>Font</CODE>.
 
155
 *
 
156
 * @param       string          a <CODE>String</CODE>
 
157
 * @param       font            a <CODE>String</CODE>
 
158
 */
 
159
    
 
160
    public ListItem(String string, Font font) {
 
161
        super(string, font);
 
162
    }
 
163
    
 
164
/**
 
165
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Chunk</CODE>
 
166
 * and a certain leading.
 
167
 *
 
168
 * @param       leading         the leading
 
169
 * @param       chunk           a <CODE>Chunk</CODE>
 
170
 */
 
171
    
 
172
    public ListItem(float leading, Chunk chunk) {
 
173
        super(leading, chunk);
 
174
    }
 
175
    
 
176
/**
 
177
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>String</CODE>
 
178
 * and a certain leading.
 
179
 *
 
180
 * @param       leading         the leading
 
181
 * @param       string          a <CODE>String</CODE>
 
182
 */
 
183
    
 
184
    public ListItem(float leading, String string) {
 
185
        super(leading, string);
 
186
    }
 
187
    
 
188
/**
 
189
 * Constructs a <CODE>ListItem</CODE> with a certain leading, <CODE>String</CODE>
 
190
 * and <CODE>Font</CODE>.
 
191
 *
 
192
 * @param       leading         the leading
 
193
 * @param       string          a <CODE>String</CODE>
 
194
 * @param       font            a <CODE>Font</CODE>
 
195
 */
 
196
    
 
197
    public ListItem(float leading, String string, Font font) {
 
198
        super(leading, string, font);
 
199
    }
 
200
    
 
201
/**
 
202
 * Constructs a <CODE>ListItem</CODE> with a certain <CODE>Phrase</CODE>.
 
203
 *
 
204
 * @param       phrase          a <CODE>Phrase</CODE>
 
205
 */
 
206
    
 
207
    public ListItem(Phrase phrase) {
 
208
        super(phrase);
 
209
    }
 
210
    
 
211
        /**
 
212
         * Returns a <CODE>ListItem</CODE> that has been constructed taking in account
 
213
         * the value of some <VAR>attributes</VAR>.
 
214
         *
 
215
         * @param       attributes              Some attributes
 
216
         */
 
217
    
 
218
    public ListItem(Properties attributes) {
 
219
        super("", FontFactory.getFont(attributes));
 
220
        String value;
 
221
        if ((value = (String)attributes.remove(ElementTags.ITEXT)) != null) {
 
222
            add(new Chunk(value));
 
223
        }
 
224
        if ((value = (String)attributes.remove(ElementTags.LEADING)) != null) {
 
225
            setLeading(Float.valueOf(value + "f").floatValue());
 
226
        }
 
227
        else if ((value = (String)attributes.remove(MarkupTags.CSS_KEY_LINEHEIGHT)) != null) {
 
228
            setLeading(MarkupParser.parseLength(value));
 
229
        }
 
230
        if ((value = (String)attributes.remove(ElementTags.INDENTATIONLEFT)) != null) {
 
231
            setIndentationLeft(Float.valueOf(value + "f").floatValue());
 
232
        }
 
233
        if ((value = (String)attributes.remove(ElementTags.INDENTATIONRIGHT)) != null) {
 
234
            setIndentationRight(Float.valueOf(value + "f").floatValue());
 
235
        }
 
236
        if ((value = (String)attributes.remove(ElementTags.ALIGN)) != null) {
 
237
            setAlignment(value);
 
238
        }
 
239
        if (attributes.size() > 0) setMarkupAttributes(attributes);
 
240
    }
 
241
    
 
242
    // implementation of the Element-methods
 
243
    
 
244
/**
 
245
 * Gets the type of the text element.
 
246
 *
 
247
 * @return      a type
 
248
 */
 
249
    
 
250
    public int type() {
 
251
        return Element.LISTITEM;
 
252
    }
 
253
    
 
254
    // methods
 
255
    
 
256
/**
 
257
 * Sets the listsymbol.
 
258
 *
 
259
 * @param       symbol  a <CODE>Chunk</CODE>
 
260
 */
 
261
    
 
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);
 
267
                }
 
268
        }
 
269
    }
 
270
    
 
271
    // methods to retrieve information
 
272
    
 
273
/**
 
274
 * Returns the listsymbol.
 
275
 *
 
276
 * @return      a <CODE>Chunk</CODE>
 
277
 */
 
278
    
 
279
    public Chunk listSymbol() {
 
280
        return symbol;
 
281
    }
 
282
    
 
283
/**
 
284
 * Checks if a given tag corresponds with this object.
 
285
 *
 
286
 * @param   tag     the given tag
 
287
 * @return  true if the tag corresponds
 
288
 */
 
289
    
 
290
    public static boolean isTag(String tag) {
 
291
        return ElementTags.LISTITEM.equals(tag);
 
292
    }
 
293
}