Source Code Cross Referenced for RtfList.java in  » PDF » pdf-itext » com » lowagie » text » rtf » list » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » PDF » pdf itext » com.lowagie.text.rtf.list 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: RtfList.java 2825 2007-06-04 09:15:21Z blowagie $
003:         * $Name$
004:         *
005:         * Copyright 2001, 2002, 2003, 2004, 2005 by Mark Hall
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.rtf.list;
052:
053:        import java.awt.Color;
054:        import java.io.ByteArrayOutputStream;
055:        import java.io.IOException;
056:        import java.io.OutputStream;
057:        import java.util.ArrayList;
058:
059:        import com.lowagie.text.Chunk;
060:        import com.lowagie.text.DocumentException;
061:        import com.lowagie.text.Element;
062:        import com.lowagie.text.Font;
063:        import com.lowagie.text.List;
064:        import com.lowagie.text.ListItem;
065:        import com.lowagie.text.RomanList;
066:        import com.lowagie.text.factories.RomanAlphabetFactory;
067:        import com.lowagie.text.factories.RomanNumberFactory;
068:        import com.lowagie.text.rtf.RtfBasicElement;
069:        import com.lowagie.text.rtf.RtfElement;
070:        import com.lowagie.text.rtf.RtfExtendedElement;
071:        import com.lowagie.text.rtf.document.RtfDocument;
072:        import com.lowagie.text.rtf.style.RtfFont;
073:        import com.lowagie.text.rtf.style.RtfFontList;
074:        import com.lowagie.text.rtf.style.RtfParagraphStyle;
075:        import com.lowagie.text.rtf.text.RtfParagraph;
076:
077:        /**
078:         * The RtfList stores one List. It also provides the methods to write the
079:         * list declaration and the list data.
080:         *  
081:         * @version $Id: RtfList.java 2825 2007-06-04 09:15:21Z blowagie $
082:         * @author Mark Hall (mhall@edu.uni-klu.ac.at)
083:         * @author Thomas Bickel (tmb99@inode.at)
084:         * @author Felix Satyaputra (f_satyaputra@yahoo.co.uk)
085:         */
086:        public class RtfList extends RtfElement implements  RtfExtendedElement {
087:
088:            /**
089:             * Constant for list level
090:             */
091:            private static final byte[] LIST_LEVEL = "\\listlevel".getBytes();
092:            /**
093:             * Constant for list level style old
094:             */
095:            private static final byte[] LIST_LEVEL_TYPE = "\\levelnfc"
096:                    .getBytes();
097:            /**
098:             * Constant for list level style new
099:             */
100:            private static final byte[] LIST_LEVEL_TYPE_NEW = "\\levelnfcn"
101:                    .getBytes();
102:            /**
103:             * Constant for list level alignment old
104:             */
105:            private static final byte[] LIST_LEVEL_ALIGNMENT = "\\leveljc"
106:                    .getBytes();
107:            /**
108:             * Constant for list level alignment new
109:             */
110:            private static final byte[] LIST_LEVEL_ALIGNMENT_NEW = "\\leveljcn"
111:                    .getBytes();
112:            /**
113:             * Constant for list level start at
114:             */
115:            private static final byte[] LIST_LEVEL_START_AT = "\\levelstartat"
116:                    .getBytes();
117:            /**
118:             * Constant for list level text
119:             */
120:            private static final byte[] LIST_LEVEL_TEXT = "\\leveltext"
121:                    .getBytes();
122:            /**
123:             * Constant for the beginning of the list level numbered style
124:             */
125:            private static final byte[] LIST_LEVEL_STYLE_NUMBERED_BEGIN = "\\\'02\\\'"
126:                    .getBytes();
127:            /**
128:             * Constant for the end of the list level numbered style
129:             */
130:            private static final byte[] LIST_LEVEL_STYLE_NUMBERED_END = ".;"
131:                    .getBytes();
132:            /**
133:             * Constant for the beginning of the list level bulleted style
134:             */
135:            private static final byte[] LIST_LEVEL_STYLE_BULLETED_BEGIN = "\\\'01"
136:                    .getBytes();
137:            /**
138:             * Constant for the end of the list level bulleted style
139:             */
140:            private static final byte[] LIST_LEVEL_STYLE_BULLETED_END = ";"
141:                    .getBytes();
142:            /**
143:             * Constant for the beginning of the list level numbers
144:             */
145:            private static final byte[] LIST_LEVEL_NUMBERS_BEGIN = "\\levelnumbers"
146:                    .getBytes();
147:            /**
148:             * Constant for the list level numbers
149:             */
150:            private static final byte[] LIST_LEVEL_NUMBERS_NUMBERED = "\\\'01"
151:                    .getBytes();
152:            /**
153:             * Constant for the end of the list level numbers
154:             */
155:            private static final byte[] LIST_LEVEL_NUMBERS_END = ";".getBytes();
156:            /**
157:             * Constant for the first indentation
158:             */
159:            private static final byte[] LIST_LEVEL_FIRST_INDENT = "\\fi"
160:                    .getBytes();
161:            /**
162:             * Constant for the symbol indentation
163:             */
164:            private static final byte[] LIST_LEVEL_SYMBOL_INDENT = "\\tx"
165:                    .getBytes();
166:            /**
167:             * Constant for the list level value
168:             */
169:            private static final byte[] LIST_LEVEL_NUMBER = "\\ilvl".getBytes();
170:            /**
171:             * Constant for a tab character
172:             */
173:            private static final byte[] TAB = "\\tab".getBytes();
174:            /**
175:             * Constant for the old list text
176:             */
177:            private static final byte[] LIST_TEXT = "\\listtext".getBytes();
178:            /**
179:             * Constant for the old list number end
180:             */
181:            private static final byte[] LIST_NUMBER_END = ".".getBytes();
182:            /**
183:             * Constant for the old bulleted list 
184:             */
185:            private static final byte[] LIST_BULLET = "\\\'b7".getBytes();
186:
187:            private static final int LIST_TYPE_BULLET = 0;
188:            private static final int LIST_TYPE_NUMBERED = 1;
189:            private static final int LIST_TYPE_UPPER_LETTERS = 2;
190:            private static final int LIST_TYPE_LOWER_LETTERS = 3;
191:            private static final int LIST_TYPE_UPPER_ROMAN = 4;
192:            private static final int LIST_TYPE_LOWER_ROMAN = 5;
193:
194:            /**
195:             * The subitems of this RtfList
196:             */
197:            private ArrayList items;
198:            /**
199:             * The level of this RtfList
200:             */
201:            private int listLevel = 0;
202:            /**
203:             * The first indentation of this RtfList
204:             */
205:            private int firstIndent = 0;
206:            /**
207:             * The left indentation of this RtfList
208:             */
209:            private int leftIndent = 0;
210:            /**
211:             * The right indentation of this RtfList
212:             */
213:            private int rightIndent = 0;
214:            /**
215:             * The symbol indentation of this RtfList
216:             */
217:            private int symbolIndent = 0;
218:            /**
219:             * The list number of this RtfList
220:             */
221:            private int listNumber = 1;
222:            /**
223:             * Whether this RtfList is numbered
224:             */
225:            private int listType = LIST_TYPE_BULLET;
226:            /**
227:             * The RtfFont for numbered lists
228:             */
229:            private RtfFont fontNumber;
230:            /**
231:             * The RtfFont for bulleted lists
232:             */
233:            private RtfFont fontBullet;
234:            /**
235:             * The alignment of this RtfList
236:             */
237:            private int alignment = Element.ALIGN_LEFT;
238:            /**
239:             * The parent List in multi-level lists.
240:             */
241:            private RtfList parentList = null;
242:            /**
243:             * The text to use as the bullet character
244:             */
245:            private String bulletCharacter = "\u00b7";
246:
247:            /**
248:             * Constructs a new RtfList for the specified List.
249:             * 
250:             * @param doc The RtfDocument this RtfList belongs to
251:             * @param list The List this RtfList is based on
252:             */
253:            public RtfList(RtfDocument doc, List list) {
254:                super (doc);
255:
256:                this .listNumber = document.getDocumentHeader().getListNumber(
257:                        this );
258:
259:                this .items = new ArrayList();
260:                if (list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {
261:                    this .firstIndent = (int) (list.getSymbolIndent()
262:                            * RtfElement.TWIPS_FACTOR * -1);
263:                    this .leftIndent = (int) ((list.getIndentationLeft() + list
264:                            .getSymbolIndent()) * RtfElement.TWIPS_FACTOR);
265:                } else if (list.getSymbolIndent() > 0) {
266:                    this .firstIndent = (int) (list.getSymbolIndent()
267:                            * RtfElement.TWIPS_FACTOR * -1);
268:                    this .leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR);
269:                } else if (list.getIndentationLeft() > 0) {
270:                    this .firstIndent = 0;
271:                    this .leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR);
272:                } else {
273:                    this .firstIndent = 0;
274:                    this .leftIndent = 0;
275:                }
276:                this .rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR);
277:                this .symbolIndent = (int) ((list.getSymbolIndent() + list
278:                        .getIndentationLeft()) * RtfElement.TWIPS_FACTOR);
279:
280:                if (list instanceof  RomanList) {
281:                    if (list.isLowercase()) {
282:                        this .listType = LIST_TYPE_LOWER_ROMAN;
283:                    } else {
284:                        this .listType = LIST_TYPE_UPPER_ROMAN;
285:                    }
286:                } else if (list.isNumbered()) {
287:                    this .listType = LIST_TYPE_NUMBERED;
288:                } else if (list.isLettered()) {
289:                    if (list.isLowercase()) {
290:                        this .listType = LIST_TYPE_LOWER_LETTERS;
291:                    } else {
292:                        this .listType = LIST_TYPE_UPPER_LETTERS;
293:                    }
294:                }
295:
296:                for (int i = 0; i < list.getItems().size(); i++) {
297:                    try {
298:                        Element element = (Element) list.getItems().get(i);
299:                        if (element.type() == Element.CHUNK) {
300:                            element = new ListItem((Chunk) element);
301:                        }
302:                        if (element instanceof  ListItem) {
303:                            this .alignment = ((ListItem) element)
304:                                    .getAlignment();
305:                        }
306:                        RtfBasicElement rtfElement = doc.getMapper()
307:                                .mapElement(element);
308:                        if (rtfElement instanceof  RtfList) {
309:                            ((RtfList) rtfElement).setListNumber(listNumber);
310:                            ((RtfList) rtfElement).setListLevel(listLevel + 1);
311:                            ((RtfList) rtfElement).setParent(this );
312:                        } else if (rtfElement instanceof  RtfListItem) {
313:                            ((RtfListItem) rtfElement).setParent(this );
314:                            ((RtfListItem) rtfElement).inheritListSettings(
315:                                    listNumber, listLevel + 1);
316:                        }
317:                        items.add(rtfElement);
318:                    } catch (DocumentException de) {
319:                        de.printStackTrace();
320:                    }
321:                }
322:
323:                if (this .listLevel == 0) {
324:                    correctIndentation();
325:                }
326:
327:                fontNumber = new RtfFont(document, new Font(Font.TIMES_ROMAN,
328:                        10, Font.NORMAL, new Color(0, 0, 0)));
329:                if (list.getSymbol() != null
330:                        && list.getSymbol().getFont() != null
331:                        && !list.getSymbol().getContent().startsWith("-")
332:                        && list.getSymbol().getContent().length() > 0) {
333:                    // only set this to bullet symbol is not default
334:                    this .fontBullet = new RtfFont(document, list.getSymbol()
335:                            .getFont());
336:                    this .bulletCharacter = list.getSymbol().getContent()
337:                            .substring(0, 1);
338:                } else {
339:                    this .fontBullet = new RtfFont(document, new Font(
340:                            Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
341:                }
342:            }
343:
344:            /**
345:             * @deprecated
346:             * @return a byte array
347:             */
348:            private byte[] writeIndentations() {
349:                ByteArrayOutputStream result = new ByteArrayOutputStream();
350:                try {
351:                    writeIndentations(result);
352:                } catch (IOException ioe) {
353:                    ioe.printStackTrace();
354:                }
355:                return result.toByteArray();
356:            }
357:
358:            private void writeIndentations(final OutputStream result)
359:                    throws IOException {
360:                result.write(LIST_LEVEL_FIRST_INDENT);
361:                result.write(intToByteArray(firstIndent));
362:                result.write(RtfParagraphStyle.INDENT_LEFT);
363:                result.write(intToByteArray(leftIndent));
364:                result.write(RtfParagraphStyle.INDENT_RIGHT);
365:                result.write(intToByteArray(rightIndent));
366:            }
367:
368:            /**
369:             * Writes the definition part of this list level
370:             * 
371:             * @return A byte array containing the definition of this list level
372:             * @deprecated replaced by {@link #writeDefinition(OutputStream)}
373:             */
374:            public byte[] writeDefinition() {
375:                ByteArrayOutputStream result = new ByteArrayOutputStream();
376:                try {
377:                    writeDefinition(result);
378:                } catch (IOException ioe) {
379:                    ioe.printStackTrace();
380:                }
381:                return result.toByteArray();
382:            }
383:
384:            /**
385:             * Writes the definition part of this list level
386:             */
387:            public void writeDefinition(final OutputStream result)
388:                    throws IOException {
389:                result.write(OPEN_GROUP);
390:                result.write(LIST_LEVEL);
391:                result.write(LIST_LEVEL_TYPE);
392:                switch (this .listType) {
393:                case LIST_TYPE_BULLET:
394:                    result.write(intToByteArray(23));
395:                    break;
396:                case LIST_TYPE_NUMBERED:
397:                    result.write(intToByteArray(0));
398:                    break;
399:                case LIST_TYPE_UPPER_LETTERS:
400:                    result.write(intToByteArray(3));
401:                    break;
402:                case LIST_TYPE_LOWER_LETTERS:
403:                    result.write(intToByteArray(4));
404:                    break;
405:                case LIST_TYPE_UPPER_ROMAN:
406:                    result.write(intToByteArray(1));
407:                    break;
408:                case LIST_TYPE_LOWER_ROMAN:
409:                    result.write(intToByteArray(2));
410:                    break;
411:                }
412:                result.write(LIST_LEVEL_TYPE_NEW);
413:                switch (this .listType) {
414:                case LIST_TYPE_BULLET:
415:                    result.write(intToByteArray(23));
416:                    break;
417:                case LIST_TYPE_NUMBERED:
418:                    result.write(intToByteArray(0));
419:                    break;
420:                case LIST_TYPE_UPPER_LETTERS:
421:                    result.write(intToByteArray(3));
422:                    break;
423:                case LIST_TYPE_LOWER_LETTERS:
424:                    result.write(intToByteArray(4));
425:                    break;
426:                case LIST_TYPE_UPPER_ROMAN:
427:                    result.write(intToByteArray(1));
428:                    break;
429:                case LIST_TYPE_LOWER_ROMAN:
430:                    result.write(intToByteArray(2));
431:                    break;
432:                }
433:                result.write(LIST_LEVEL_ALIGNMENT);
434:                result.write(intToByteArray(0));
435:                result.write(LIST_LEVEL_ALIGNMENT_NEW);
436:                result.write(intToByteArray(0));
437:                result.write(LIST_LEVEL_START_AT);
438:                result.write(intToByteArray(1));
439:                result.write(OPEN_GROUP);
440:                result.write(LIST_LEVEL_TEXT);
441:                if (this .listType != LIST_TYPE_BULLET) {
442:                    result.write(LIST_LEVEL_STYLE_NUMBERED_BEGIN);
443:                    if (listLevel < 10) {
444:                        result.write(intToByteArray(0));
445:                    }
446:                    result.write(intToByteArray(listLevel));
447:                    result.write(LIST_LEVEL_STYLE_NUMBERED_END);
448:                } else {
449:                    result.write(LIST_LEVEL_STYLE_BULLETED_BEGIN);
450:                    this .document.filterSpecialChar(result,
451:                            this .bulletCharacter, false, false);
452:                    result.write(LIST_LEVEL_STYLE_BULLETED_END);
453:                }
454:                result.write(CLOSE_GROUP);
455:                result.write(OPEN_GROUP);
456:                result.write(LIST_LEVEL_NUMBERS_BEGIN);
457:                if (this .listType != LIST_TYPE_BULLET) {
458:                    result.write(LIST_LEVEL_NUMBERS_NUMBERED);
459:                }
460:                result.write(LIST_LEVEL_NUMBERS_END);
461:                result.write(CLOSE_GROUP);
462:                result.write(RtfFontList.FONT_NUMBER);
463:                if (this .listType != LIST_TYPE_BULLET) {
464:                    result.write(intToByteArray(fontNumber.getFontNumber()));
465:                } else {
466:                    result.write(intToByteArray(fontBullet.getFontNumber()));
467:                }
468:                //.result.write(writeIndentations());
469:                writeIndentations(result);
470:                result.write(LIST_LEVEL_SYMBOL_INDENT);
471:                result.write(intToByteArray(this .leftIndent));
472:                result.write(CLOSE_GROUP);
473:                result.write("\n".getBytes());
474:                for (int i = 0; i < items.size(); i++) {
475:                    RtfElement rtfElement = (RtfElement) items.get(i);
476:                    if (rtfElement instanceof  RtfList) {
477:                        RtfList rl = (RtfList) rtfElement;
478:                        //.result.write(((RtfList) rtfElement).writeDefinition());
479:                        rl.writeDefinition(result);
480:                        break;
481:                    } else if (rtfElement instanceof  RtfListItem) {
482:                        RtfListItem rli = (RtfListItem) rtfElement;
483:                        //.byte[] data = rli.writeDefinition();
484:                        //.if(data.length > 0) {
485:                        //.    result.write(data);
486:                        //.    break;
487:                        //.}
488:                        if (rli.writeDefinition(result))
489:                            break;
490:                    }
491:                }
492:            }
493:
494:            /**
495:             * Writes the initialisation part of the RtfList
496:             * 
497:             * @return A byte array containing the initialisation part
498:             */
499:            protected byte[] writeListBeginning() {
500:                ByteArrayOutputStream result = new ByteArrayOutputStream();
501:                try {
502:                    result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
503:                    if (this .inTable) {
504:                        result.write(RtfParagraph.IN_TABLE);
505:                    }
506:                    switch (this .alignment) {
507:                    case Element.ALIGN_LEFT:
508:                        result.write(RtfParagraphStyle.ALIGN_LEFT);
509:                        break;
510:                    case Element.ALIGN_RIGHT:
511:                        result.write(RtfParagraphStyle.ALIGN_RIGHT);
512:                        break;
513:                    case Element.ALIGN_CENTER:
514:                        result.write(RtfParagraphStyle.ALIGN_CENTER);
515:                        break;
516:                    case Element.ALIGN_JUSTIFIED:
517:                    case Element.ALIGN_JUSTIFIED_ALL:
518:                        result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
519:                        break;
520:                    }
521:                    //.result.write(writeIndentations());
522:                    writeIndentations(result);
523:                    result.write(RtfFont.FONT_SIZE);
524:                    result.write(intToByteArray(fontNumber.getFontSize() * 2));
525:                    if (this .symbolIndent > 0) {
526:                        result.write("\\tx".getBytes());
527:                        result.write(intToByteArray(this .leftIndent));
528:                    }
529:                } catch (IOException ioe) {
530:                    ioe.printStackTrace();
531:                }
532:                return result.toByteArray();
533:            }
534:
535:            /**
536:             * Writes only the list number and list level number.
537:             * 
538:             * @return The list number and list level number of this RtfList.
539:             */
540:            protected byte[] writeListNumbers() {
541:                ByteArrayOutputStream result = new ByteArrayOutputStream();
542:                try {
543:                    result.write(RtfListTable.LIST_NUMBER);
544:                    result.write(intToByteArray(listNumber));
545:                    if (listLevel > 0) {
546:                        result.write(LIST_LEVEL_NUMBER);
547:                        result.write(intToByteArray(listLevel));
548:                    }
549:                } catch (IOException ioe) {
550:                    ioe.printStackTrace();
551:                }
552:                return result.toByteArray();
553:            }
554:
555:            /**
556:             * Writes the content of the RtfList
557:             * 
558:             * @return A byte array containing the actual content of the RtfList
559:             * @deprecated replaced by {@link #writeContent(OutputStream)}
560:             */
561:            public byte[] write() {
562:                ByteArrayOutputStream result = new ByteArrayOutputStream();
563:                try {
564:                    writeContent(result);
565:                } catch (IOException ioe) {
566:                    ioe.printStackTrace();
567:                }
568:                return result.toByteArray();
569:            }
570:
571:            /**
572:             * Writes the content of the RtfList
573:             */
574:            public void writeContent(final OutputStream result)
575:                    throws IOException {
576:                result.write(OPEN_GROUP);
577:                int itemNr = 0;
578:                for (int i = 0; i < items.size(); i++) {
579:                    RtfElement rtfElement = (RtfElement) items.get(i);
580:                    if (rtfElement instanceof  RtfListItem) {
581:                        itemNr++;
582:                        result.write(writeListBeginning());
583:                        result.write(writeListNumbers());
584:                        result.write(OPEN_GROUP);
585:                        result.write(LIST_TEXT);
586:                        result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
587:                        if (this .inTable) {
588:                            result.write(RtfParagraph.IN_TABLE);
589:                        }
590:                        result.write(RtfFontList.FONT_NUMBER);
591:                        if (this .listType != LIST_TYPE_BULLET) {
592:                            result.write(intToByteArray(fontNumber
593:                                    .getFontNumber()));
594:                        } else {
595:                            result.write(intToByteArray(fontBullet
596:                                    .getFontNumber()));
597:                        }
598:                        //.result.write(writeIndentations());
599:                        writeIndentations(result);
600:                        result.write(DELIMITER);
601:                        if (this .listType != LIST_TYPE_BULLET) {
602:                            switch (this .listType) {
603:                            case LIST_TYPE_NUMBERED:
604:                                result.write(intToByteArray(itemNr));
605:                                break;
606:                            case LIST_TYPE_UPPER_LETTERS:
607:                                result.write(RomanAlphabetFactory
608:                                        .getUpperCaseString(itemNr).getBytes());
609:                                break;
610:                            case LIST_TYPE_LOWER_LETTERS:
611:                                result.write(RomanAlphabetFactory
612:                                        .getLowerCaseString(itemNr).getBytes());
613:                                break;
614:                            case LIST_TYPE_UPPER_ROMAN:
615:                                result.write(RomanNumberFactory
616:                                        .getUpperCaseString(itemNr).getBytes());
617:                                break;
618:                            case LIST_TYPE_LOWER_ROMAN:
619:                                result.write(RomanNumberFactory
620:                                        .getLowerCaseString(itemNr).getBytes());
621:                                break;
622:                            }
623:                            result.write(LIST_NUMBER_END);
624:                        } else {
625:                            this .document.filterSpecialChar(result,
626:                                    this .bulletCharacter, true, false);
627:                        }
628:                        result.write(TAB);
629:                        result.write(CLOSE_GROUP);
630:                        //.result.write(rtfElement.write());
631:                        rtfElement.writeContent(result);
632:                        if (i < (items.size() - 1) || !this .inTable
633:                                || this .listLevel > 0) {
634:                            result.write(RtfParagraph.PARAGRAPH);
635:                        }
636:                        result.write("\n".getBytes());
637:                    } else if (rtfElement instanceof  RtfList) {
638:                        //.result.write(rtfElement.write());
639:                        rtfElement.writeContent(result);
640:                        result.write("\n".getBytes());
641:                    }
642:                }
643:                result.write(CLOSE_GROUP);
644:
645:                if (!this .inTable) {
646:                    result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
647:                }
648:            }
649:
650:            /**
651:             * Gets the list level of this RtfList
652:             * 
653:             * @return Returns the list level.
654:             */
655:            public int getListLevel() {
656:                return listLevel;
657:            }
658:
659:            /**
660:             * Sets the list level of this RtfList. A list level > 0 will
661:             * unregister this RtfList from the RtfListTable
662:             * 
663:             * @param listLevel The list level to set.
664:             */
665:            public void setListLevel(int listLevel) {
666:                this .listLevel = listLevel;
667:                if (this .listLevel != 0) {
668:                    document.getDocumentHeader().freeListNumber(this );
669:                    for (int i = 0; i < this .items.size(); i++) {
670:                        if (this .items.get(i) instanceof  RtfList) {
671:                            ((RtfList) this .items.get(i))
672:                                    .setListNumber(this .listNumber);
673:                            ((RtfList) this .items.get(i))
674:                                    .setListLevel(this .listLevel + 1);
675:                        }
676:                    }
677:                } else {
678:                    this .listNumber = document.getDocumentHeader()
679:                            .getListNumber(this );
680:                }
681:            }
682:
683:            /**
684:             * Sets the parent RtfList of this RtfList
685:             * 
686:             * @param parent The parent RtfList to use.
687:             */
688:            protected void setParent(RtfList parent) {
689:                this .parentList = parent;
690:            }
691:
692:            /**
693:             * Gets the id of this list
694:             * 
695:             * @return Returns the list number.
696:             */
697:            public int getListNumber() {
698:                return listNumber;
699:            }
700:
701:            /**
702:             * Sets the id of this list
703:             * 
704:             * @param listNumber The list number to set.
705:             */
706:            public void setListNumber(int listNumber) {
707:                this .listNumber = listNumber;
708:            }
709:
710:            /**
711:             * Sets whether this RtfList is in a table. Sets the correct inTable setting for all
712:             * child elements.
713:             * 
714:             * @param inTable <code>True</code> if this RtfList is in a table, <code>false</code> otherwise
715:             */
716:            public void setInTable(boolean inTable) {
717:                super .setInTable(inTable);
718:                for (int i = 0; i < this .items.size(); i++) {
719:                    ((RtfBasicElement) this .items.get(i)).setInTable(inTable);
720:                }
721:            }
722:
723:            /**
724:             * Sets whether this RtfList is in a header. Sets the correct inTable setting for all
725:             * child elements.
726:             * 
727:             * @param inHeader <code>True</code> if this RtfList is in a header, <code>false</code> otherwise
728:             */
729:            public void setInHeader(boolean inHeader) {
730:                super .setInHeader(inHeader);
731:                for (int i = 0; i < this .items.size(); i++) {
732:                    ((RtfBasicElement) this .items.get(i)).setInHeader(inHeader);
733:                }
734:            }
735:
736:            /**
737:             * Correct the indentation of this RtfList by adding left/first line indentation
738:             * from the parent RtfList. Also calls correctIndentation on all child RtfLists.
739:             */
740:            protected void correctIndentation() {
741:                if (this .parentList != null) {
742:                    this .leftIndent = this .leftIndent
743:                            + this .parentList.getLeftIndent()
744:                            + this .parentList.getFirstIndent();
745:                }
746:                for (int i = 0; i < this .items.size(); i++) {
747:                    if (this .items.get(i) instanceof  RtfList) {
748:                        ((RtfList) this .items.get(i)).correctIndentation();
749:                    } else if (this .items.get(i) instanceof  RtfListItem) {
750:                        ((RtfListItem) this .items.get(i)).correctIndentation();
751:                    }
752:                }
753:            }
754:
755:            /**
756:             * Get the left indentation of this RtfList.
757:             * 
758:             * @return The left indentation.
759:             */
760:            private int getLeftIndent() {
761:                return this .leftIndent;
762:            }
763:
764:            /**
765:             * Get the first line indentation of this RtfList.
766:             * 
767:             * @return The first line indentation.
768:             */
769:            private int getFirstIndent() {
770:                return this.firstIndent;
771:            }
772:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.