KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: HeaderFooter.java 2688 2007-04-17 13:46:52Z 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 package com.lowagie.text;
52
53
54 /**
55  * A <CODE>HeaderFooter</CODE>-object is a <CODE>Rectangle</CODe> with text
56  * that can be put above and/or below every page.
57  * <P>
58  * Example:
59  * <BLOCKQUOTE><PRE>
60  * <STRONG>HeaderFooter header = new HeaderFooter(new Phrase("This is a header."), false);</STRONG>
61  * <STRONG>HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));</STRONG>
62  * document.setHeader(header);
63  * document.setFooter(footer);
64  * </PRE></BLOCKQUOTE>
65  */

66
67 public class HeaderFooter extends Rectangle {
68     
69     // membervariables
70

71 /** Does the page contain a pagenumber? */
72     private boolean numbered;
73     
74 /** This is the <CODE>Phrase</CODE> that comes before the pagenumber. */
75     private Phrase before = null;
76     
77 /** This is number of the page. */
78     private int pageN;
79     
80 /** This is the <CODE>Phrase</CODE> that comes after the pagenumber. */
81     private Phrase after = null;
82     
83 /** This is alignment of the header/footer. */
84     private int alignment;
85     
86     // constructors
87

88 /**
89  * Constructs a <CODE>HeaderFooter</CODE>-object.
90  *
91  * @param before the <CODE>Phrase</CODE> before the pagenumber
92  * @param after the <CODE>Phrase</CODE> before the pagenumber
93  */

94     
95     public HeaderFooter(Phrase before, Phrase after) {
96         super(0, 0, 0, 0);
97         setBorder(TOP + BOTTOM);
98         setBorderWidth(1);
99         
100         numbered = true;
101         this.before = before;
102         this.after = after;
103     }
104     
105 /**
106  * Constructs a <CODE>Header</CODE>-object with a pagenumber at the end.
107  *
108  * @param before the <CODE>Phrase</CODE> before the pagenumber
109  * @param numbered <CODE>true</CODE> if the page has to be numbered
110  */

111     
112     public HeaderFooter(Phrase before, boolean numbered) {
113         super(0, 0, 0, 0);
114         setBorder(TOP + BOTTOM);
115         setBorderWidth(1);
116         
117         this.numbered = numbered;
118         this.before = before;
119     }
120     
121     // methods
122

123 /**
124  * Checks if the HeaderFooter contains a page number.
125  *
126  * @return true if the page has to be numbered
127  */

128     
129     public boolean isNumbered() {
130         return numbered;
131     }
132     
133 /**
134  * Gets the part that comes before the pageNumber.
135  *
136  * @return a Phrase
137  */

138     
139     public Phrase getBefore() {
140         return before;
141     }
142     
143 /**
144  * Gets the part that comes after the pageNumber.
145  *
146  * @return a Phrase
147  */

148     
149     public Phrase getAfter() {
150         return after;
151     }
152     
153 /**
154  * Sets the page number.
155  *
156  * @param pageN the new page number
157  */

158     
159     public void setPageNumber(int pageN) {
160         this.pageN = pageN;
161     }
162     
163 /**
164  * Sets the alignment.
165  *
166  * @param alignment the new alignment
167  */

168     
169     public void setAlignment(int alignment) {
170         this.alignment = alignment;
171     }
172
173     // methods to retrieve the membervariables
174

175 /**
176  * Gets the <CODE>Paragraph</CODE> that can be used as header or footer.
177  *
178  * @return a <CODE>Paragraph</CODE>
179  */

180     
181     public Paragraph paragraph() {
182         Paragraph paragraph = new Paragraph(before.getLeading());
183         paragraph.add(before);
184         if (numbered) {
185             paragraph.addSpecial(new Chunk(String.valueOf(pageN), before.getFont()));
186         }
187         if (after != null) {
188             paragraph.addSpecial(after);
189         }
190         paragraph.setAlignment(alignment);
191         return paragraph;
192     }
193
194     /**
195      * Gets the alignment of this HeaderFooter.
196      *
197      * @return alignment
198      */

199
200         public int alignment() {
201             return alignment;
202         }
203
204 }
Popular Tags