KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > Chapter


1 /*
2  * $Id: Chapter.java 2748 2007-05-12 15:11:48Z blowagie $
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
52 package com.lowagie.text;
53
54 import java.util.ArrayList JavaDoc;
55
56 /**
57  * A <CODE>Chapter</CODE> is a special <CODE>Section</CODE>.
58  * <P>
59  * A chapter number has to be created using a <CODE>Paragraph</CODE> as title
60  * and an <CODE>int</CODE> as chapter number. The chapter number is shown be
61  * default. If you don't want to see the chapter number, you have to set the
62  * numberdepth to <VAR>0</VAR>.
63  * <P>
64  * Example:
65  * <BLOCKQUOTE><PRE>
66  * Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
67  * <STRONG>Chapter chapter2 = new Chapter(title2, 2);</STRONG>
68  * <STRONG>chapter2.setNumberDepth(0);</STRONG>
69  * Paragraph someText = new Paragraph("This is some text");
70  * <STRONG>chapter2.add(someText);</STRONG>
71  * Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
72  * Section section1 = <STRONG>chapter2.addSection(title21);</STRONG>
73  * Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section.");
74  * section1.add(someSectionText);
75  * </PRE></BLOCKQUOTE>
76  */

77
78 public class Chapter extends Section {
79     
80     // constant
81
private static final long serialVersionUID = 1791000695779357361L;
82     
83     /**
84      * Constructs a new <CODE>Chapter</CODE>.
85      * @param number the Chapter number
86      */

87     public Chapter(int number) {
88         super(null, 1);
89         numbers = new ArrayList JavaDoc();
90         numbers.add(new Integer JavaDoc(number));
91         triggerNewPage = true;
92     }
93     
94     /**
95      * Constructs a new <CODE>Chapter</CODE>.
96      *
97      * @param title the Chapter title (as a <CODE>Paragraph</CODE>)
98      * @param number the Chapter number
99      */

100     
101     public Chapter(Paragraph title, int number) {
102         super(title, 1);
103         numbers = new ArrayList JavaDoc();
104         numbers.add(new Integer JavaDoc(number));
105         triggerNewPage = true;
106     }
107     
108     /**
109      * Constructs a new <CODE>Chapter</CODE>.
110      *
111      * @param title the Chapter title (as a <CODE>String</CODE>)
112      * @param number the Chapter number
113      */

114     public Chapter(String JavaDoc title, int number) {
115         this(new Paragraph(title), number);
116     }
117     
118     // implementation of the Element-methods
119

120     /**
121      * Gets the type of the text element.
122      *
123      * @return a type
124      */

125     public int type() {
126         return Element.CHAPTER;
127     }
128     
129 // deprecated stuff
130

131     /**
132      * Creates a new <CODE>Chapter</CODE> following a set of attributes.
133      *
134      * @param attributes the attributes
135      * @param number a userdefined Chapter number
136      * @deprecated Use ElementFactory.getChapter(attributes)
137      */

138     public Chapter(java.util.Properties JavaDoc attributes, int number) {
139         this("", number);
140         Chapter chapter = com.lowagie.text.factories.ElementFactory.getChapter(attributes);
141         setNumberDepth(chapter.getNumberDepth());
142         setIndentation(chapter.getIndentation());
143         setIndentationLeft(chapter.getIndentationLeft());
144         setIndentationRight(chapter.getIndentationRight());
145     }
146 }
Popular Tags