001: /*
002: * $Id: Chapter.java 2748 2007-05-12 15:11:48Z blowagie $
003: * $Name$
004: *
005: * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie.
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:
052: package com.lowagie.text;
053:
054: import java.util.ArrayList;
055:
056: /**
057: * A <CODE>Chapter</CODE> is a special <CODE>Section</CODE>.
058: * <P>
059: * A chapter number has to be created using a <CODE>Paragraph</CODE> as title
060: * and an <CODE>int</CODE> as chapter number. The chapter number is shown be
061: * default. If you don't want to see the chapter number, you have to set the
062: * numberdepth to <VAR>0</VAR>.
063: * <P>
064: * Example:
065: * <BLOCKQUOTE><PRE>
066: * Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255)));
067: * <STRONG>Chapter chapter2 = new Chapter(title2, 2);</STRONG>
068: * <STRONG>chapter2.setNumberDepth(0);</STRONG>
069: * Paragraph someText = new Paragraph("This is some text");
070: * <STRONG>chapter2.add(someText);</STRONG>
071: * Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0)));
072: * Section section1 = <STRONG>chapter2.addSection(title21);</STRONG>
073: * 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.");
074: * section1.add(someSectionText);
075: * </PRE></BLOCKQUOTE>
076: */
077:
078: public class Chapter extends Section {
079:
080: // constant
081: private static final long serialVersionUID = 1791000695779357361L;
082:
083: /**
084: * Constructs a new <CODE>Chapter</CODE>.
085: * @param number the Chapter number
086: */
087: public Chapter(int number) {
088: super (null, 1);
089: numbers = new ArrayList();
090: numbers.add(new Integer(number));
091: triggerNewPage = true;
092: }
093:
094: /**
095: * Constructs a new <CODE>Chapter</CODE>.
096: *
097: * @param title the Chapter title (as a <CODE>Paragraph</CODE>)
098: * @param number the Chapter number
099: */
100:
101: public Chapter(Paragraph title, int number) {
102: super (title, 1);
103: numbers = new ArrayList();
104: numbers.add(new Integer(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 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 attributes, int number) {
139: this ("", number);
140: Chapter chapter = com.lowagie.text.factories.ElementFactory
141: .getChapter(attributes);
142: setNumberDepth(chapter.getNumberDepth());
143: setIndentation(chapter.getIndentation());
144: setIndentationLeft(chapter.getIndentationLeft());
145: setIndentationRight(chapter.getIndentationRight());
146: }
147: }
|