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 java.util.List;
15  
16  import org.apache.fop.area.RegionViewport;
17  import org.eclipse.draw2d.IFigure;
18  import org.eclipse.draw2d.geometry.Dimension;
19  import org.eclipse.draw2d.geometry.Point;
20  import org.eclipse.draw2d.geometry.Rectangle;
21  
22  /***
23   * @author TV , refactored by Martin Kollar
24   * 
25   * Refactored on 22.12.2005
26   *
27   */
28  public class BodyRegionFigure extends RegionFigure {
29    
30    private MainReferenceFigure mainReference = null;
31    
32    private FootnoteFigure footnote = null;
33  
34    /***
35     * Constructor
36     * 
37     * @param viewport RegionViewport
38     */
39    public BodyRegionFigure(RegionViewport viewport){
40      super(viewport);
41      setLayoutManager(new BodyRegionLayout());
42    }
43  
44    /*** 
45     * 
46     * @return <code> null </code>
47     */
48    public FOPFigure getBeforeFloat() {
49  	    //TODO : Kollar
50      return null;
51    }
52    
53    /***
54     * @return FootnoteFigure that represents footnotes
55     */
56    public FOPFigure getFootnote() {
57  	    if (footnote == null) {  
58  	      List children = getChildren();
59  	      if ((children != null) && (!children.isEmpty())) {
60  	        for (int i = 0; i < children.size(); i++) {
61  	          Object child = children.get(i);
62  	          if (child instanceof FootnoteFigure) { 
63  	            footnote = (FootnoteFigure)child;
64  	          }
65  	        }
66  	      }
67  	    }
68  	    return footnote;
69    }
70    
71    /***
72     * @return MainReferenceFigure tahat represents the main part of document
73     */
74    public MainReferenceFigure getMainReference() {
75  
76      if (mainReference == null) {  
77        List children = getChildren();
78        if ((children != null) && (!children.isEmpty())) {
79          for (int i = 0; i < children.size(); i++) {
80            Object child = children.get(i);
81            if (child instanceof MainReferenceFigure) { 
82              mainReference = (MainReferenceFigure)child;
83            }
84          }
85        }
86      }
87      return mainReference;
88      
89    }
90  
91    
92    
93    
94    /*** LayoutManager for BodyRegionFigure */
95    public class BodyRegionLayout extends BaseFOLayout {
96    
97      protected BodyRegionFigure body = null;
98      
99      /*** Constructor */
100     public BodyRegionLayout() {
101       super();
102     }
103     
104     /* (non-Javadoc)
105      * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
106      */
107     protected Dimension calculatePreferredSize(IFigure container, int wHint,
108       int hHint) {
109       setBody(container);
110       preferredSize = body.getBounds().getSize().getCopy();
111       return preferredSize;
112     }
113 
114     /***
115      * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure)
116      */
117     public void layout(IFigure parent) {
118       
119       setBody(parent);
120       
121       // situation 0: easy case
122       // no before float or footnode object on the page !!!
123       // main reference area should take all available space
124       
125       if ((body.getBeforeFloat() != null) || (body.getFootnote() != null)){
126     	  //TODO: Kollar do something else - here should be some shifting
127     	  // or smth like that
128           MainReferenceFigure mrf = body.getMainReference();
129           Point loc = getOrigin(parent);
130           
131           // BUG_REPORT: how can mrf be null ???
132           if (mrf != null)
133             mrf.setBounds(new Rectangle(loc, mrf.getPreferredSize()));
134       }
135       else {
136         MainReferenceFigure mrf = body.getMainReference();
137         Point loc = getOrigin(parent);
138         
139         // BUG_REPORT: how can mrf be null ???
140         if (mrf != null)
141           mrf.setBounds(new Rectangle(loc, mrf.getPreferredSize()));
142       } 
143     }
144     
145     protected void setBody(IFigure container) {
146       assert(container != null);
147       
148       if (body == container)
149         return;
150       
151       if (container instanceof BodyRegionFigure) {
152         body = (BodyRegionFigure)container;
153         assert(body.getMainReference() != null);
154         invalidate();
155       }
156     }
157   }
158 
159   
160 }