KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > list > RtfList


1 /*
2  * $Id: RtfList.java 2825 2007-06-04 09:15:21Z blowagie $
3  * $Name$
4  *
5  * Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
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.rtf.list;
52
53 import java.awt.Color JavaDoc;
54 import java.io.ByteArrayOutputStream JavaDoc;
55 import java.io.IOException JavaDoc;
56 import java.io.OutputStream JavaDoc;
57 import java.util.ArrayList JavaDoc;
58
59 import com.lowagie.text.Chunk;
60 import com.lowagie.text.DocumentException;
61 import com.lowagie.text.Element;
62 import com.lowagie.text.Font;
63 import com.lowagie.text.List;
64 import com.lowagie.text.ListItem;
65 import com.lowagie.text.RomanList;
66 import com.lowagie.text.factories.RomanAlphabetFactory;
67 import com.lowagie.text.factories.RomanNumberFactory;
68 import com.lowagie.text.rtf.RtfBasicElement;
69 import com.lowagie.text.rtf.RtfElement;
70 import com.lowagie.text.rtf.RtfExtendedElement;
71 import com.lowagie.text.rtf.document.RtfDocument;
72 import com.lowagie.text.rtf.style.RtfFont;
73 import com.lowagie.text.rtf.style.RtfFontList;
74 import com.lowagie.text.rtf.style.RtfParagraphStyle;
75 import com.lowagie.text.rtf.text.RtfParagraph;
76
77
78 /**
79  * The RtfList stores one List. It also provides the methods to write the
80  * list declaration and the list data.
81  *
82  * @version $Id: RtfList.java 2825 2007-06-04 09:15:21Z blowagie $
83  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
84  * @author Thomas Bickel (tmb99@inode.at)
85  * @author Felix Satyaputra (f_satyaputra@yahoo.co.uk)
86  */

87 public class RtfList extends RtfElement implements RtfExtendedElement {
88
89     /**
90      * Constant for list level
91      */

92     private static final byte[] LIST_LEVEL = "\\listlevel".getBytes();
93     /**
94      * Constant for list level style old
95      */

96     private static final byte[] LIST_LEVEL_TYPE = "\\levelnfc".getBytes();
97     /**
98      * Constant for list level style new
99      */

100     private static final byte[] LIST_LEVEL_TYPE_NEW = "\\levelnfcn".getBytes();
101     /**
102      * Constant for list level alignment old
103      */

104     private static final byte[] LIST_LEVEL_ALIGNMENT = "\\leveljc".getBytes();
105     /**
106      * Constant for list level alignment new
107      */

108     private static final byte[] LIST_LEVEL_ALIGNMENT_NEW = "\\leveljcn".getBytes();
109     /**
110      * Constant for list level start at
111      */

112     private static final byte[] LIST_LEVEL_START_AT = "\\levelstartat".getBytes();
113     /**
114      * Constant for list level text
115      */

116     private static final byte[] LIST_LEVEL_TEXT = "\\leveltext".getBytes();
117     /**
118      * Constant for the beginning of the list level numbered style
119      */

120     private static final byte[] LIST_LEVEL_STYLE_NUMBERED_BEGIN = "\\\'02\\\'".getBytes();
121     /**
122      * Constant for the end of the list level numbered style
123      */

124     private static final byte[] LIST_LEVEL_STYLE_NUMBERED_END = ".;".getBytes();
125     /**
126      * Constant for the beginning of the list level bulleted style
127      */

128     private static final byte[] LIST_LEVEL_STYLE_BULLETED_BEGIN = "\\\'01".getBytes();
129     /**
130      * Constant for the end of the list level bulleted style
131      */

132     private static final byte[] LIST_LEVEL_STYLE_BULLETED_END = ";".getBytes();
133     /**
134      * Constant for the beginning of the list level numbers
135      */

136     private static final byte[] LIST_LEVEL_NUMBERS_BEGIN = "\\levelnumbers".getBytes();
137     /**
138      * Constant for the list level numbers
139      */

140     private static final byte[] LIST_LEVEL_NUMBERS_NUMBERED = "\\\'01".getBytes();
141     /**
142      * Constant for the end of the list level numbers
143      */

144     private static final byte[] LIST_LEVEL_NUMBERS_END = ";".getBytes();
145     /**
146      * Constant for the first indentation
147      */

148     private static final byte[] LIST_LEVEL_FIRST_INDENT = "\\fi".getBytes();
149     /**
150      * Constant for the symbol indentation
151      */

152     private static final byte[] LIST_LEVEL_SYMBOL_INDENT = "\\tx".getBytes();
153     /**
154      * Constant for the list level value
155      */

156     private static final byte[] LIST_LEVEL_NUMBER = "\\ilvl".getBytes();
157     /**
158      * Constant for a tab character
159      */

160     private static final byte[] TAB = "\\tab".getBytes();
161     /**
162      * Constant for the old list text
163      */

164     private static final byte[] LIST_TEXT = "\\listtext".getBytes();
165     /**
166      * Constant for the old list number end
167      */

168     private static final byte[] LIST_NUMBER_END = ".".getBytes();
169     /**
170      * Constant for the old bulleted list
171      */

172     private static final byte[] LIST_BULLET = "\\\'b7".getBytes();
173     
174     private static final int LIST_TYPE_BULLET = 0;
175     private static final int LIST_TYPE_NUMBERED = 1;
176     private static final int LIST_TYPE_UPPER_LETTERS = 2;
177     private static final int LIST_TYPE_LOWER_LETTERS = 3;
178     private static final int LIST_TYPE_UPPER_ROMAN = 4;
179     private static final int LIST_TYPE_LOWER_ROMAN = 5;
180     
181     /**
182      * The subitems of this RtfList
183      */

184     private ArrayList JavaDoc items;
185     /**
186      * The level of this RtfList
187      */

188     private int listLevel = 0;
189     /**
190      * The first indentation of this RtfList
191      */

192     private int firstIndent = 0;
193     /**
194      * The left indentation of this RtfList
195      */

196     private int leftIndent = 0;
197     /**
198      * The right indentation of this RtfList
199      */

200     private int rightIndent = 0;
201     /**
202      * The symbol indentation of this RtfList
203      */

204     private int symbolIndent = 0;
205     /**
206      * The list number of this RtfList
207      */

208     private int listNumber = 1;
209     /**
210      * Whether this RtfList is numbered
211      */

212     private int listType = LIST_TYPE_BULLET;
213     /**
214      * The RtfFont for numbered lists
215      */

216     private RtfFont fontNumber;
217     /**
218      * The RtfFont for bulleted lists
219      */

220     private RtfFont fontBullet;
221     /**
222      * The alignment of this RtfList
223      */

224     private int alignment = Element.ALIGN_LEFT;
225     /**
226      * The parent List in multi-level lists.
227      */

228     private RtfList parentList = null;
229     /**
230      * The text to use as the bullet character
231      */

232     private String JavaDoc bulletCharacter = "\u00b7";
233     
234     /**
235      * Constructs a new RtfList for the specified List.
236      *
237      * @param doc The RtfDocument this RtfList belongs to
238      * @param list The List this RtfList is based on
239      */

240     public RtfList(RtfDocument doc, List JavaDoc list) {
241         super(doc);
242         
243         this.listNumber = document.getDocumentHeader().getListNumber(this);
244         
245         this.items = new ArrayList JavaDoc();
246         if(list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {
247             this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
248             this.leftIndent = (int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR);
249         } else if(list.getSymbolIndent() > 0) {
250             this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
251             this.leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR);
252         } else if(list.getIndentationLeft() > 0) {
253             this.firstIndent = 0;
254             this.leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR);
255         } else {
256             this.firstIndent = 0;
257             this.leftIndent = 0;
258         }
259         this.rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR);
260         this.symbolIndent = (int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR);
261         
262         if(list instanceof RomanList) {
263             if(list.isLowercase()) {
264                 this.listType = LIST_TYPE_LOWER_ROMAN;
265             } else {
266                 this.listType = LIST_TYPE_UPPER_ROMAN;
267             }
268         } else if(list.isNumbered()) {
269             this.listType = LIST_TYPE_NUMBERED;
270         } else if(list.isLettered()) {
271             if(list.isLowercase()) {
272                 this.listType = LIST_TYPE_LOWER_LETTERS;
273             } else {
274                 this.listType = LIST_TYPE_UPPER_LETTERS;
275             }
276         }
277         
278         for(int i = 0; i < list.getItems().size(); i++) {
279             try {
280                 Element element = (Element) list.getItems().get(i);
281                 if(element.type() == Element.CHUNK) {
282                     element = new ListItem((Chunk) element);
283                 }
284                 if(element instanceof ListItem) {
285                     this.alignment = ((ListItem) element).getAlignment();
286                 }
287                 RtfBasicElement rtfElement = doc.getMapper().mapElement(element);
288                 if(rtfElement instanceof RtfList) {
289                     ((RtfList) rtfElement).setListNumber(listNumber);
290                     ((RtfList) rtfElement).setListLevel(listLevel + 1);
291                     ((RtfList) rtfElement).setParent(this);
292                 } else if(rtfElement instanceof RtfListItem) {
293                     ((RtfListItem) rtfElement).setParent(this);
294                     ((RtfListItem) rtfElement).inheritListSettings(listNumber, listLevel + 1);
295                 }
296                 items.add(rtfElement);
297             } catch(DocumentException de) {
298                 de.printStackTrace();
299             }
300         }
301         
302         if(this.listLevel == 0) {
303             correctIndentation();
304         }
305         
306         fontNumber = new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color JavaDoc(0, 0, 0)));
307         if (list.getSymbol() != null && list.getSymbol().getFont() != null && !list.getSymbol().getContent().startsWith("-") && list.getSymbol().getContent().length() > 0) {
308             // only set this to bullet symbol is not default
309
this.fontBullet = new RtfFont(document, list.getSymbol().getFont());
310             this.bulletCharacter = list.getSymbol().getContent().substring(0, 1);
311         } else {
312             this.fontBullet = new RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color JavaDoc(0, 0, 0)));
313         }
314     }
315     
316     /**
317      * @deprecated
318      * @return a byte array
319      */

320     private byte[] writeIndentations() {
321         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
322         try {
323             writeIndentations(result);
324         } catch(IOException JavaDoc ioe) {
325             ioe.printStackTrace();
326         }
327         return result.toByteArray();
328     }
329     
330     private void writeIndentations(final OutputStream JavaDoc result) throws IOException JavaDoc
331     {
332         result.write(LIST_LEVEL_FIRST_INDENT);
333         result.write(intToByteArray(firstIndent));
334         result.write(RtfParagraphStyle.INDENT_LEFT);
335         result.write(intToByteArray(leftIndent));
336         result.write(RtfParagraphStyle.INDENT_RIGHT);
337         result.write(intToByteArray(rightIndent));
338     }
339     
340     /**
341      * Writes the definition part of this list level
342      *
343      * @return A byte array containing the definition of this list level
344      * @deprecated replaced by {@link #writeDefinition(OutputStream)}
345      */

346     public byte[] writeDefinition()
347     {
348         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
349         try {
350             writeDefinition(result);
351         } catch(IOException JavaDoc ioe) {
352             ioe.printStackTrace();
353         }
354         return result.toByteArray();
355     }
356     /**
357      * Writes the definition part of this list level
358      */

359     public void writeDefinition(final OutputStream JavaDoc result) throws IOException JavaDoc
360     {
361         result.write(OPEN_GROUP);
362         result.write(LIST_LEVEL);
363         result.write(LIST_LEVEL_TYPE);
364         switch(this.listType) {
365             case LIST_TYPE_BULLET : result.write(intToByteArray(23)); break;
366             case LIST_TYPE_NUMBERED : result.write(intToByteArray(0)); break;
367             case LIST_TYPE_UPPER_LETTERS : result.write(intToByteArray(3)); break;
368             case LIST_TYPE_LOWER_LETTERS : result.write(intToByteArray(4)); break;
369             case LIST_TYPE_UPPER_ROMAN : result.write(intToByteArray(1)); break;
370             case LIST_TYPE_LOWER_ROMAN : result.write(intToByteArray(2)); break;
371         }
372         result.write(LIST_LEVEL_TYPE_NEW);
373         switch(this.listType) {
374             case LIST_TYPE_BULLET : result.write(intToByteArray(23)); break;
375             case LIST_TYPE_NUMBERED : result.write(intToByteArray(0)); break;
376             case LIST_TYPE_UPPER_LETTERS : result.write(intToByteArray(3)); break;
377             case LIST_TYPE_LOWER_LETTERS : result.write(intToByteArray(4)); break;
378             case LIST_TYPE_UPPER_ROMAN : result.write(intToByteArray(1)); break;
379             case LIST_TYPE_LOWER_ROMAN : result.write(intToByteArray(2)); break;
380         }
381         result.write(LIST_LEVEL_ALIGNMENT);
382         result.write(intToByteArray(0));
383         result.write(LIST_LEVEL_ALIGNMENT_NEW);
384         result.write(intToByteArray(0));
385         result.write(LIST_LEVEL_START_AT);
386         result.write(intToByteArray(1));
387         result.write(OPEN_GROUP);
388         result.write(LIST_LEVEL_TEXT);
389         if(this.listType != LIST_TYPE_BULLET) {
390             result.write(LIST_LEVEL_STYLE_NUMBERED_BEGIN);
391             if(listLevel < 10) {
392                 result.write(intToByteArray(0));
393             }
394             result.write(intToByteArray(listLevel));
395             result.write(LIST_LEVEL_STYLE_NUMBERED_END);
396         } else {
397             result.write(LIST_LEVEL_STYLE_BULLETED_BEGIN);
398             this.document.filterSpecialChar(result, this.bulletCharacter, false, false);
399             result.write(LIST_LEVEL_STYLE_BULLETED_END);
400         }
401         result.write(CLOSE_GROUP);
402         result.write(OPEN_GROUP);
403         result.write(LIST_LEVEL_NUMBERS_BEGIN);
404         if(this.listType != LIST_TYPE_BULLET) {
405             result.write(LIST_LEVEL_NUMBERS_NUMBERED);
406         }
407         result.write(LIST_LEVEL_NUMBERS_END);
408         result.write(CLOSE_GROUP);
409         result.write(RtfFontList.FONT_NUMBER);
410         if(this.listType != LIST_TYPE_BULLET) {
411             result.write(intToByteArray(fontNumber.getFontNumber()));
412         } else {
413             result.write(intToByteArray(fontBullet.getFontNumber()));
414         }
415         //.result.write(writeIndentations());
416
writeIndentations(result);
417         result.write(LIST_LEVEL_SYMBOL_INDENT);
418         result.write(intToByteArray(this.leftIndent));
419         result.write(CLOSE_GROUP);
420         result.write("\n".getBytes());
421         for(int i = 0; i < items.size(); i++) {
422             RtfElement rtfElement = (RtfElement) items.get(i);
423             if(rtfElement instanceof RtfList) {
424                 RtfList rl = (RtfList)rtfElement;
425                 //.result.write(((RtfList) rtfElement).writeDefinition());
426
rl.writeDefinition(result);
427                 break;
428             } else if(rtfElement instanceof RtfListItem) {
429                 RtfListItem rli = (RtfListItem) rtfElement;
430                 //.byte[] data = rli.writeDefinition();
431
//.if(data.length > 0) {
432
//. result.write(data);
433
//. break;
434
//.}
435
if(rli.writeDefinition(result)) break;
436             }
437         }
438     }
439
440     
441     /**
442      * Writes the initialisation part of the RtfList
443      *
444      * @return A byte array containing the initialisation part
445      */

446     protected byte[] writeListBeginning() {
447         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
448         try {
449             result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
450             if(this.inTable) {
451                 result.write(RtfParagraph.IN_TABLE);
452             }
453             switch (this.alignment) {
454                 case Element.ALIGN_LEFT:
455                     result.write(RtfParagraphStyle.ALIGN_LEFT);
456                     break;
457                 case Element.ALIGN_RIGHT:
458                     result.write(RtfParagraphStyle.ALIGN_RIGHT);
459                     break;
460                 case Element.ALIGN_CENTER:
461                     result.write(RtfParagraphStyle.ALIGN_CENTER);
462                     break;
463                 case Element.ALIGN_JUSTIFIED:
464                 case Element.ALIGN_JUSTIFIED_ALL:
465                     result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
466                     break;
467             }
468             //.result.write(writeIndentations());
469
writeIndentations(result);
470             result.write(RtfFont.FONT_SIZE);
471             result.write(intToByteArray(fontNumber.getFontSize() * 2));
472             if(this.symbolIndent > 0) {
473                 result.write("\\tx".getBytes());
474                 result.write(intToByteArray(this.leftIndent));
475             }
476         } catch(IOException JavaDoc ioe) {
477             ioe.printStackTrace();
478         }
479         return result.toByteArray();
480     }
481
482     /**
483      * Writes only the list number and list level number.
484      *
485      * @return The list number and list level number of this RtfList.
486      */

487     protected byte[] writeListNumbers() {
488         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
489         try {
490             result.write(RtfListTable.LIST_NUMBER);
491             result.write(intToByteArray(listNumber));
492             if(listLevel > 0) {
493                 result.write(LIST_LEVEL_NUMBER);
494                 result.write(intToByteArray(listLevel));
495             }
496         } catch(IOException JavaDoc ioe) {
497             ioe.printStackTrace();
498         }
499         return result.toByteArray();
500     }
501     
502     /**
503      * Writes the content of the RtfList
504      *
505      * @return A byte array containing the actual content of the RtfList
506      * @deprecated replaced by {@link #writeContent(OutputStream)}
507      */

508     public byte[] write()
509     {
510         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
511         try {
512             writeContent(result);
513         } catch(IOException JavaDoc ioe) {
514             ioe.printStackTrace();
515         }
516         return result.toByteArray();
517     }
518     
519     
520     /**
521      * Writes the content of the RtfList
522      */

523     public void writeContent(final OutputStream JavaDoc result) throws IOException JavaDoc
524     {
525         result.write(OPEN_GROUP);
526         int itemNr = 0;
527         for(int i = 0; i < items.size(); i++) {
528             RtfElement rtfElement = (RtfElement) items.get(i);
529             if(rtfElement instanceof RtfListItem) {
530                 itemNr++;
531                 result.write(writeListBeginning());
532                 result.write(writeListNumbers());
533                 result.write(OPEN_GROUP);
534                 result.write(LIST_TEXT);
535                 result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
536                 if(this.inTable) {
537                     result.write(RtfParagraph.IN_TABLE);
538                 }
539                 result.write(RtfFontList.FONT_NUMBER);
540                 if(this.listType != LIST_TYPE_BULLET) {
541                     result.write(intToByteArray(fontNumber.getFontNumber()));
542                 } else {
543                     result.write(intToByteArray(fontBullet.getFontNumber()));
544                 }
545                 //.result.write(writeIndentations());
546
writeIndentations(result);
547                 result.write(DELIMITER);
548                 if(this.listType != LIST_TYPE_BULLET) {
549                     switch(this.listType) {
550                         case LIST_TYPE_NUMBERED : result.write(intToByteArray(itemNr)); break;
551                         case LIST_TYPE_UPPER_LETTERS : result.write(RomanAlphabetFactory.getUpperCaseString(itemNr).getBytes()); break;
552                         case LIST_TYPE_LOWER_LETTERS : result.write(RomanAlphabetFactory.getLowerCaseString(itemNr).getBytes()); break;
553                         case LIST_TYPE_UPPER_ROMAN : result.write(RomanNumberFactory.getUpperCaseString(itemNr).getBytes()); break;
554                         case LIST_TYPE_LOWER_ROMAN : result.write(RomanNumberFactory.getLowerCaseString(itemNr).getBytes()); break;
555                     }
556                     result.write(LIST_NUMBER_END);
557                 } else {
558                     this.document.filterSpecialChar(result, this.bulletCharacter, true, false);
559                 }
560                 result.write(TAB);
561                 result.write(CLOSE_GROUP);
562                 //.result.write(rtfElement.write());
563
rtfElement.writeContent(result);
564                 if(i < (items.size() - 1) || !this.inTable || this.listLevel > 0) {
565                     result.write(RtfParagraph.PARAGRAPH);
566                 }
567                 result.write("\n".getBytes());
568             } else if(rtfElement instanceof RtfList) {
569                 //.result.write(rtfElement.write());
570
rtfElement.writeContent(result);
571                 result.write("\n".getBytes());
572             }
573         }
574         result.write(CLOSE_GROUP);
575         
576         if(!this.inTable) {
577             result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
578         }
579     }
580     
581     /**
582      * Gets the list level of this RtfList
583      *
584      * @return Returns the list level.
585      */

586     public int getListLevel() {
587         return listLevel;
588     }
589     
590     /**
591      * Sets the list level of this RtfList. A list level > 0 will
592      * unregister this RtfList from the RtfListTable
593      *
594      * @param listLevel The list level to set.
595      */

596     public void setListLevel(int listLevel) {
597         this.listLevel = listLevel;
598         if(this.listLevel != 0) {
599             document.getDocumentHeader().freeListNumber(this);
600             for(int i = 0; i < this.items.size(); i++) {
601                 if(this.items.get(i) instanceof RtfList) {
602                     ((RtfList) this.items.get(i)).setListNumber(this.listNumber);
603                     ((RtfList) this.items.get(i)).setListLevel(this.listLevel + 1);
604                 }
605             }
606         } else {
607             this.listNumber = document.getDocumentHeader().getListNumber(this);
608         }
609     }
610     
611     /**
612      * Sets the parent RtfList of this RtfList
613      *
614      * @param parent The parent RtfList to use.
615      */

616     protected void setParent(RtfList parent) {
617         this.parentList = parent;
618     }
619     
620     /**
621      * Gets the id of this list
622      *
623      * @return Returns the list number.
624      */

625     public int getListNumber() {
626         return listNumber;
627     }
628     
629     /**
630      * Sets the id of this list
631      *
632      * @param listNumber The list number to set.
633      */

634     public void setListNumber(int listNumber) {
635         this.listNumber = listNumber;
636     }
637     
638     /**
639      * Sets whether this RtfList is in a table. Sets the correct inTable setting for all
640      * child elements.
641      *
642      * @param inTable <code>True</code> if this RtfList is in a table, <code>false</code> otherwise
643      */

644     public void setInTable(boolean inTable) {
645         super.setInTable(inTable);
646         for(int i = 0; i < this.items.size(); i++) {
647             ((RtfBasicElement) this.items.get(i)).setInTable(inTable);
648         }
649     }
650     
651     /**
652      * Sets whether this RtfList is in a header. Sets the correct inTable setting for all
653      * child elements.
654      *
655      * @param inHeader <code>True</code> if this RtfList is in a header, <code>false</code> otherwise
656      */

657     public void setInHeader(boolean inHeader) {
658         super.setInHeader(inHeader);
659         for(int i = 0; i < this.items.size(); i++) {
660             ((RtfBasicElement) this.items.get(i)).setInHeader(inHeader);
661         }
662     }
663
664     /**
665      * Correct the indentation of this RtfList by adding left/first line indentation
666      * from the parent RtfList. Also calls correctIndentation on all child RtfLists.
667      */

668     protected void correctIndentation() {
669         if(this.parentList != null) {
670             this.leftIndent = this.leftIndent + this.parentList.getLeftIndent() + this.parentList.getFirstIndent();
671         }
672         for(int i = 0; i < this.items.size(); i++) {
673             if(this.items.get(i) instanceof RtfList) {
674                 ((RtfList) this.items.get(i)).correctIndentation();
675             } else if(this.items.get(i) instanceof RtfListItem) {
676                 ((RtfListItem) this.items.get(i)).correctIndentation();
677             }
678         }
679     }
680
681     /**
682      * Get the left indentation of this RtfList.
683      *
684      * @return The left indentation.
685      */

686     private int getLeftIndent() {
687         return this.leftIndent;
688     }
689     
690     /**
691      * Get the first line indentation of this RtfList.
692      *
693      * @return The first line indentation.
694      */

695     private int getFirstIndent() {
696         return this.firstIndent;
697     }
698 }
699
Popular Tags