KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > txt > border > BorderManager


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: BorderManager.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.txt.border;
21
22 import org.apache.fop.fo.Constants;
23 import org.apache.fop.render.txt.TXTState;
24
25 /**
26  * This keeps all information about borders for current processed page.
27  */

28 public class BorderManager {
29
30     /** Matrix for storing information about one border element. */
31     private AbstractBorderElement[][] borderInfo;
32
33     /** Width of current processed border. */
34     private int width;
35     
36     /** Height of current processed border. */
37     private int height;
38
39     /** x-coordinate of upper left point of current processed border. */
40     private int startX;
41
42     /** y-coordinate of upper left point of current processed border. */
43     private int startY;
44
45     /** Stores TXTState for transforming border elements. */
46     private TXTState state;
47
48     /**
49      * Constructs BorderManger, using <code>pageWidth</code> and
50      * <code>pageHeight</code> for creating <code>borderInfo</code>.
51      *
52      * @param pageWidth page width
53      * @param pageHeight page height
54      * @param state TXTState
55      */

56     public BorderManager(int pageWidth, int pageHeight, TXTState state) {
57         this.state = state;
58         borderInfo = new AbstractBorderElement[pageHeight][pageWidth];
59     }
60
61     /**
62      * Adds border element to <code>borderInfo</code>.
63      *
64      * @param x x-coordinate
65      * @param y y-coordinate
66      * @param style border-style
67      * @param type border element type, binary representation of wich gives
68      * information about availability or absence of corresponding side.
69      */

70     public void addBorderElement(int x, int y, int style, int type) {
71         AbstractBorderElement be = null;
72
73         if (style == Constants.EN_SOLID || style == Constants.EN_DOUBLE) {
74             be = new SolidAndDoubleBorderElement(style, type);
75         } else if (style == Constants.EN_DOTTED) {
76             be = new DottedBorderElement();
77         } else if (style == Constants.EN_DASHED) {
78             be = new DashedBorderElement(type);
79         } else {
80             return;
81         }
82         be.transformElement(state);
83
84         if (borderInfo[y][x] != null) {
85             borderInfo[y][x] = borderInfo[y][x].merge(be);
86         } else {
87             borderInfo[y][x] = be;
88         }
89     }
90
91     /**
92      * @param x x-coordinate
93      * @param y y-coordinate
94      * @return if border element at point (x,y) is available, returns instance
95      * of Character, created on char, given by corresponding border element,
96      * otherwise returns null.
97      */

98     public Character JavaDoc getCharacter(int x, int y) {
99         Character JavaDoc c = null;
100         if (borderInfo[y][x] != null) {
101             c = new Character JavaDoc(borderInfo[y][x].convert2Char());
102         }
103         return c;
104     }
105
106     /**
107      * @return width of current processed border.
108      */

109     public int getWidth() {
110         return width;
111     }
112     
113     /**
114      * Sets width of current processed border.
115      * @param width width of border
116      */

117     public void setWidth(int width) {
118         this.width = width;
119     }
120     
121     /**
122      * @return height of current processed border.
123      */

124     public int getHeight() {
125         return height;
126     }
127
128     /**
129      * Sets height of current processed border.
130      * @param height height of border
131      */

132     public void setHeight(int height) {
133         this.height = height;
134     }
135
136     /**
137      * @return x-coordinate of upper left point of current processed border.
138      */

139     public int getStartX() {
140         return startX;
141     }
142
143     /**
144      * Sets x-coordinate of upper left point of current processed border.
145      * @param startX x-coordinate of upper left border's point.
146      */

147     public void setStartX(int startX) {
148         this.startX = startX;
149     }
150
151     /**
152      * @return y-coordinate of upper left point of current processed border.
153      */

154     public int getStartY() {
155         return startY;
156     }
157
158     /**
159      * Sets y-coordinate of upper left point of current processed border.
160      * @param startY y-coordinate of upper left border's point.
161      */

162     public void setStartY(int startY) {
163         this.startY = startY;
164     }
165 }
166
Popular Tags