001/* 002 * $Id: Chapter.java 4861 2011-05-11 11:57:30Z redlab_b $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text; 045 046import java.util.ArrayList; 047 048/** 049 * A <CODE>Chapter</CODE> is a special <CODE>Section</CODE>. 050 * <P> 051 * A chapter number has to be created using a <CODE>Paragraph</CODE> as title 052 * and an <CODE>int</CODE> as chapter number. The chapter number is shown by 053 * default. If you don't want to see the chapter number, you have to set the 054 * numberdepth to <VAR>0</VAR>. 055 * <P> 056 * Example: 057 * <BLOCKQUOTE><PRE> 058 * Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, new Color(0, 0, 255))); 059 * <STRONG>Chapter chapter2 = new Chapter(title2, 2);</STRONG> 060 * <STRONG>chapter2.setNumberDepth(0);</STRONG> 061 * Paragraph someText = new Paragraph("This is some text"); 062 * <STRONG>chapter2.add(someText);</STRONG> 063 * Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0))); 064 * Section section1 = <STRONG>chapter2.addSection(title21);</STRONG> 065 * 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."); 066 * section1.add(someSectionText); 067 * </PRE></BLOCKQUOTE> 068 */ 069 070public class Chapter extends Section { 071 072 // constant 073 private static final long serialVersionUID = 1791000695779357361L; 074 075 /** 076 * Constructs a new <CODE>Chapter</CODE>. 077 * @param number the Chapter number 078 */ 079 public Chapter(int number) { 080 super(null, 1); 081 numbers = new ArrayList<Integer>(); 082 numbers.add(Integer.valueOf(number)); 083 triggerNewPage = true; 084 } 085 086 /** 087 * Constructs a new <CODE>Chapter</CODE>. 088 * 089 * @param title the Chapter title (as a <CODE>Paragraph</CODE>) 090 * @param number the Chapter number 091 */ 092 093 public Chapter(Paragraph title, int number) { 094 super(title, 1); 095 numbers = new ArrayList<Integer>(); 096 numbers.add(Integer.valueOf(number)); 097 triggerNewPage = true; 098 } 099 100 /** 101 * Constructs a new <CODE>Chapter</CODE>. 102 * 103 * @param title the Chapter title (as a <CODE>String</CODE>) 104 * @param number the Chapter number 105 */ 106 public Chapter(String title, int number) { 107 this(new Paragraph(title), number); 108 } 109 110 // implementation of the Element-methods 111 112 /** 113 * Gets the type of the text element. 114 * 115 * @return a type 116 */ 117 @Override 118 public int type() { 119 return Element.CHAPTER; 120 } 121 122 /** 123 * @see com.itextpdf.text.Element#isNestable() 124 * @since iText 2.0.8 125 */ 126 @Override 127 public boolean isNestable() { 128 return false; 129 } 130 131}