KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > RtfPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: RtfPage.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 import java.io.IOException JavaDoc;
30 import java.io.Writer JavaDoc;
31
32 /** Specifies rtf control words. Is the container for page attributes.
33  * Overrides okToWriteRtf.
34  * @author Christopher Scott, scottc@westinghouse.com
35  */

36
37 public class RtfPage
38 extends RtfContainer {
39     private final RtfAttributes attrib;
40
41     /**RtfPage attributes*/
42     /** constant for page width */
43     public static final String JavaDoc PAGE_WIDTH = "paperw";
44     /** constant for page height */
45     public static final String JavaDoc PAGE_HEIGHT = "paperh";
46
47     /** constant for landscape format */
48     public static final String JavaDoc LANDSCAPE = "landscape";
49
50     /** constant for top margin */
51     public static final String JavaDoc MARGIN_TOP = "margt";
52     /** constant for bottom margin */
53     public static final String JavaDoc MARGIN_BOTTOM = "margb";
54     /** constant for left margin */
55     public static final String JavaDoc MARGIN_LEFT = "margl";
56     /** constant for right margin */
57     public static final String JavaDoc MARGIN_RIGHT = "margr";
58     
59     /** constant for header position */
60     public static final String JavaDoc HEADERY = "headery";
61     /** constant for footer position */
62     public static final String JavaDoc FOOTERY = "footery";
63
64     /** String array of RtfPage attributes */
65     public static final String JavaDoc[] PAGE_ATTR = new String JavaDoc[]{
66         PAGE_WIDTH, PAGE_HEIGHT, LANDSCAPE, MARGIN_TOP, MARGIN_BOTTOM,
67         MARGIN_LEFT, MARGIN_RIGHT, HEADERY, FOOTERY
68     };
69
70     /** RtfPage creates new page attributes with the parent container, the writer
71            and the attributes*/

72     RtfPage(RtfPageArea parent, Writer JavaDoc w, RtfAttributes attrs) throws IOException JavaDoc {
73         super((RtfContainer)parent, w);
74         attrib = attrs;
75     }
76
77     /**
78      * RtfPage writes the attributes the attributes contained in the string
79      * PAGE_ATTR, if not null
80      * @throws IOException for I/O problems
81      */

82     protected void writeRtfContent() throws IOException JavaDoc {
83         writeAttributes(attrib, PAGE_ATTR);
84
85         if (attrib != null) {
86             Object JavaDoc widthRaw = attrib.getValue(PAGE_WIDTH);
87             Object JavaDoc heightRaw = attrib.getValue(PAGE_HEIGHT);
88
89             if ((widthRaw instanceof Integer JavaDoc) && (heightRaw instanceof Integer JavaDoc)
90                     && ((Integer JavaDoc) widthRaw).intValue() > ((Integer JavaDoc) heightRaw).intValue()) {
91                 writeControlWord(LANDSCAPE);
92             }
93         }
94     }
95
96     /**
97      * RtfPage - attributes accessor
98      * @return attributes
99      */

100     public RtfAttributes getAttributes() {
101         return attrib;
102     }
103
104     /**
105      * RtfPage - is overwritten here because page attributes have no content
106      * only attributes. RtfContainer is defined not to write when empty.
107      * Therefore must make this true to print.
108      * @return true
109      */

110     protected boolean okToWriteRtf() {
111         return true;
112     }
113
114 }
115
Popular Tags