1
2
3
4
5
6
7
8
9
10
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
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
105
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
122
123
124
125 if ((body.getBeforeFloat() != null) || (body.getFootnote() != null)){
126
127
128 MainReferenceFigure mrf = body.getMainReference();
129 Point loc = getOrigin(parent);
130
131
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
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 }