View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.foRenderer.figures;
13  
14  import org.apache.fop.area.RegionViewport;
15  import org.eclipse.draw2d.geometry.Dimension;
16  import org.eclipse.draw2d.geometry.Rectangle;
17  
18  /***
19   * @author TV
20   * Created on 20.1.2004
21   *
22   * RegionFigure is built from a RegionViewport object. RegionViewport has 
23   * absolute coordinates in its page.
24   * 
25   */
26  public class RegionFigure extends BasicFOPFigure {
27  
28    protected Rectangle viewportRect = null;
29    
30    protected int leftMargin = 0;
31    protected int topMargin = 0;
32    protected int bottomMargin = 0;
33    protected int rightMargin = 0;
34    
35    /***
36     * Constructor 
37     * 
38     * @param viewport RegionViewport
39     * @see RegionViewport
40     */
41    public RegionFigure(RegionViewport viewport){
42      super(viewport);
43  //    setBorder(new LineBorder(ColorConstants.green,10));
44    }
45  
46    /***
47     * Returns area from that was this figure created
48     * @return RegionViewport
49     */
50    public RegionViewport getRegionVieport() {
51  	    return (RegionViewport)getArea();
52    }
53    
54    /***
55     * 
56     * @return  width and height (in pixels) of area designed to place children
57     *          (content rectangle) of the body region 
58     */
59    public Dimension getContentSize() {
60      return new Dimension(viewportRect.width - leftMargin - rightMargin, 
61        viewportRect.height - topMargin - bottomMargin); 
62    }
63  
64  
65    /***
66     * @return
67     */
68    public int getMarginBottom() {
69      return bottomMargin;
70    }
71    
72    /***
73     * @return
74     */
75    public int getMarginLeft() {
76      return leftMargin;
77    }
78  
79    /***
80     * @return
81     */
82    public int getMarginRight() {
83      return rightMargin;
84    }
85  
86    /***
87     * @return
88     */
89    public int getMarginTop() {
90      return topMargin;
91    }
92    
93    /***
94     * 
95     * @return view area of the viewport
96     */
97    public Rectangle getViewportRectangle() {
98      return this.viewportRect.getCopy();
99    }
100   
101   /***
102    * Sets Margins
103    * 
104    * @param r Rectangle is just a structure to store 4 values
105    */
106   public void setMargins(Rectangle r) {
107     leftMargin = r.x;
108     topMargin = r.y;
109     rightMargin = r.width;
110     bottomMargin = r.height;
111   }
112 
113   /***
114    * 
115    * @param viewportRect view area of the viewport
116    */
117   public void setViewportRectangle(Rectangle viewportRect) {
118     this.viewportRect = viewportRect.getCopy();
119   }
120 }