KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > field > RtfTableOfContents


1 /*
2  * $Id: RtfTableOfContents.java 2784 2007-05-24 15:43:40Z hallm $
3  * $Name$
4  *
5  * Copyright 2004 by Mark Hall
6  * Uses code Copyright 2002
7  * Steffen.Stundzig (Steffen.Stundzig@smb-tec.com)
8  *
9  * The contents of this file are subject to the Mozilla Public License Version 1.1
10  * (the "License"); you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15  * for the specific language governing rights and limitations under the License.
16  *
17  * The Original Code is 'iText, a free JAVA-PDF library'.
18  *
19  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
20  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
21  * All Rights Reserved.
22  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
23  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
24  *
25  * Contributor(s): all the names of the contributors are added in the source code
26  * where applicable.
27  *
28  * Alternatively, the contents of this file may be used under the terms of the
29  * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
30  * provisions of LGPL are applicable instead of those above. If you wish to
31  * allow use of your version of this file only under the terms of the LGPL
32  * License and not to allow others to use your version of this file under
33  * the MPL, indicate your decision by deleting the provisions above and
34  * replace them with the notice and other provisions required by the LGPL.
35  * If you do not delete the provisions above, a recipient may use your version
36  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
37  *
38  * This library is free software; you can redistribute it and/or modify it
39  * under the terms of the MPL as stated above or under the terms of the GNU
40  * Library General Public License as published by the Free Software Foundation;
41  * either version 2 of the License, or any later version.
42  *
43  * This library is distributed in the hope that it will be useful, but WITHOUT
44  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
45  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
46  * details.
47  *
48  * If you didn't download this code from the following link, you should check if
49  * you aren't using an obsolete version:
50  * http://www.lowagie.com/iText/
51  */

52
53 package com.lowagie.text.rtf.field;
54
55 import java.io.*;
56
57 import com.lowagie.text.Font;
58
59
60
61 /**
62  * The RtfTableOfContents together with multiple RtfTOCEntry objects generates a table
63  * of contents. The table of contents will display no entries in the viewing program
64  * and the user will have to update it first. A text to inform the user of this is
65  * displayed instead.
66  *
67  * @version $Id: RtfTableOfContents.java 2784 2007-05-24 15:43:40Z hallm $
68  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
69  * @author Steffen.Stundzig (Steffen.Stundzig@smb-tec.com)
70  * @author Thomas Bickel (tmb99@inode.at)
71  */

72 public class RtfTableOfContents extends RtfField {
73
74     /**
75      * field inst content
76      */

77     private final static String JavaDoc FIELD_INST = "TOC \\\\f \\\\h \\\\u \\\\o \"1-5\" ";
78     /**
79      * The default text to display
80      */

81     private String JavaDoc defaultText = "Table of Contents - Click to update";
82     
83     /**
84      * Constructs a RtfTableOfContents. The default text is the text that is displayed
85      * before the user updates the table of contents
86      *
87      * @param defaultText The default text to display
88      */

89     public RtfTableOfContents(String JavaDoc defaultText) {
90         super(null, new Font());
91         this.defaultText = defaultText;
92     }
93     
94     /**
95      * Writes the field instruction content
96      *
97      * @return A byte array containing with the field instructions
98      * @deprecated
99      * @throws IOException
100      */

101     protected byte[] writeFieldInstContent() throws IOException
102     {
103         return FIELD_INST.getBytes();
104     }
105     /**
106      * Writes the field instruction content
107      */

108     protected void writeFieldInstContent(final OutputStream out) throws IOException
109     {
110         out.write(FIELD_INST.getBytes());
111     }
112
113     /**
114      * Writes the field result content
115      *
116      * @return An byte array containing the default text
117      * @deprecated
118      * @throws IOException
119      */

120     protected byte[] writeFieldResultContent() throws IOException
121     {
122         ByteArrayOutputStream out = new ByteArrayOutputStream();
123         writeFieldResultContent(out);
124         return out.toByteArray();
125     }
126     /**
127      * Writes the field result content
128      */

129     protected void writeFieldResultContent(final OutputStream out) throws IOException
130     {
131         document.filterSpecialChar(out, defaultText, true, true);
132 // byte[] b = getDefaultTextBytes();
133
// if(b != null) out.write(b);
134
}
135     
136 // private byte[] getDefaultTextBytes()
137
// {
138
// return(document.filterSpecialChar(defaultText, true, true).getBytes());
139
// }
140

141 }
142
Popular Tags