1 51 package org.apache.fop.fo.flow; 52 53 import org.apache.fop.fo.*; 55 import org.apache.fop.fo.properties.*; 56 import org.apache.fop.datatypes.*; 57 import org.apache.fop.layout.*; 58 import org.apache.fop.apps.FOPException; 59 60 import java.util.ArrayList ; 62 63 public abstract class AbstractTableBody extends FObj { 64 65 int spaceBefore; 66 int spaceAfter; 67 String id; 68 69 ArrayList columns; 70 RowSpanMgr rowSpanMgr; 72 AreaContainer areaContainer; 73 74 public AbstractTableBody(FObj parent, PropertyList propertyList, 75 String systemId, int line, int column) 76 throws FOPException { 77 super(parent, propertyList, systemId, line, column); 78 if (!(parent instanceof Table)) { 79 throw new FOPException("A table body must be child of fo:table," 80 + " not " + parent.getName(), 81 systemId, line, column); 82 } 83 } 84 85 public void setColumns(ArrayList columns) { 86 this.columns = columns; 87 } 88 89 public void setYPosition(int value) { 90 areaContainer.setYPosition(value); 91 } 92 93 public int getYPosition() { 94 return areaContainer.getCurrentYPosition(); 95 } 96 97 public int getHeight() { 98 return areaContainer.getHeight() + spaceBefore + spaceAfter; 99 } 100 101 public int layout(Area area) throws FOPException { 102 if (this.marker == BREAK_AFTER) { 103 return Status.OK; 104 } 105 106 if (this.marker == START) { 107 108 AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); 110 111 AuralProps mAurProps = propMgr.getAuralProps(); 113 114 BorderAndPadding bap = propMgr.getBorderAndPadding(); 116 BackgroundProps bProps = propMgr.getBackgroundProps(); 117 118 RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); 120 121 123 this.spaceBefore = 124 this.properties.get("space-before.optimum").getLength().mvalue(); 125 this.spaceAfter = 126 this.properties.get("space-after.optimum").getLength().mvalue(); 127 this.id = this.properties.get("id").getString(); 128 129 try { 130 area.getIDReferences().createID(id); 131 } 132 catch(FOPException e) { 133 if (!e.isLocationSet()) { 134 e.setLocation(systemId, line, column); 135 } 136 throw e; 137 } 138 139 if (area instanceof BlockArea) { 140 area.end(); 141 } 142 143 if (rowSpanMgr == null) { 144 rowSpanMgr = new RowSpanMgr(columns.size()); 145 } 146 147 151 this.marker = 0; 152 153 } 154 155 if ((spaceBefore != 0) && (this.marker == 0)) { 156 area.increaseHeight(spaceBefore); 157 } 158 159 if (marker == 0) { 160 area.getIDReferences().configureID(id, area); 162 } 163 164 int spaceLeft = area.spaceLeft(); 165 166 173 this.areaContainer = 174 new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0, 175 area.getContentHeight(), 176 area.getContentWidth(), area.spaceLeft(), Position.RELATIVE); 178 areaContainer.foCreator = this; areaContainer.setPage(area.getPage()); 180 areaContainer.setParent(area); 181 areaContainer.setBackground(propMgr.getBackgroundProps()); 182 areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding()); 183 areaContainer.start(); 184 185 areaContainer.setAbsoluteHeight(area.getAbsoluteHeight()); 186 areaContainer.setIDReferences(area.getIDReferences()); 187 188 ArrayList keepWith = new ArrayList (); 189 int numChildren = this.children.size(); 190 TableRow lastRow = null; 191 boolean endKeepGroup = true; 192 for (int i = this.marker; i < numChildren; i++) { 193 Object child = children.get(i); 194 if (child instanceof Marker) { 195 ((Marker)child).layout(area); 196 continue; 197 } 198 if (!(child instanceof TableRow)) { 199 throw new FOPException("Currently only Table Rows are supported in table body, header and footer", systemId, line, column); 200 } 201 TableRow row = (TableRow)child; 202 203 row.setRowSpanMgr(rowSpanMgr); 204 row.setColumns(columns); 205 row.doSetup(areaContainer); 206 if (row.getKeepWithPrevious().getType() 207 != KeepValue.KEEP_WITH_AUTO && lastRow != null 208 && keepWith.indexOf(lastRow) 209 == -1) { 210 keepWith.add(lastRow); 211 } else { 212 215 if (endKeepGroup && keepWith.size() > 0) { 216 keepWith = new ArrayList (); 217 } 218 if (endKeepGroup && i > this.marker) { 221 rowSpanMgr.setIgnoreKeeps(false); 222 } 223 } 224 225 228 boolean bRowStartsArea = (i == this.marker); 229 if (bRowStartsArea == false && keepWith.size() > 0) { 230 if (children.indexOf(keepWith.get(0)) == this.marker) { 231 bRowStartsArea = true; 232 } 233 } 234 row.setIgnoreKeepTogether(bRowStartsArea && startsAC(area)); 235 int status; 236 if (Status.isIncomplete((status = row.layout(areaContainer)))) { 237 if (Status.isPageBreak(status)) { 239 this.marker = i; 240 area.addChild(areaContainer); 241 243 area.increaseHeight(areaContainer.getHeight()); 244 if (i == numChildren - 1) { 245 this.marker = BREAK_AFTER; 246 if (spaceAfter != 0) { 247 area.increaseHeight(spaceAfter); 248 } 249 } 250 return status; 251 } 252 if ((keepWith.size() > 0) 253 && (!rowSpanMgr.ignoreKeeps())) { 254 row.removeLayout(areaContainer); 257 for (int j = 0; j < keepWith.size(); j++) { 258 TableRow tr = (TableRow)keepWith.get(j); 259 tr.removeLayout(areaContainer); 260 i--; 261 } 262 if (i == 0) { 263 resetMarker(); 264 265 rowSpanMgr.setIgnoreKeeps(true); 267 268 return Status.AREA_FULL_NONE; 269 } 270 } 271 this.marker = i; 272 if ((i != 0) && (status == Status.AREA_FULL_NONE)) { 273 status = Status.AREA_FULL_SOME; 274 } 275 if (!((i == 0) && (areaContainer.getContentHeight() <= 0))) { 276 area.addChild(areaContainer); 277 279 area.increaseHeight(areaContainer.getHeight()); 280 } 281 282 rowSpanMgr.setIgnoreKeeps(true); 284 285 return status; 286 } else if (status == Status.KEEP_WITH_NEXT 287 || rowSpanMgr.hasUnfinishedSpans()) { 288 keepWith.add(row); 289 endKeepGroup = false; 290 } else { 291 endKeepGroup = true; 292 } 293 lastRow = row; 294 area.setMaxHeight(area.getMaxHeight() - spaceLeft 295 + this.areaContainer.getMaxHeight()); 296 spaceLeft = area.spaceLeft(); 297 } 298 area.addChild(areaContainer); 299 areaContainer.end(); 300 301 area.increaseHeight(areaContainer.getHeight()); 302 303 if (spaceAfter != 0) { 304 area.increaseHeight(spaceAfter); 305 area.setMaxHeight(area.getMaxHeight() - spaceAfter); 306 } 307 308 if (area instanceof BlockArea) { 309 area.start(); 310 } 311 312 return Status.OK; 313 } 314 315 public void removeLayout(Area area) { 316 if (areaContainer != null) { 317 area.removeChild(areaContainer); 318 } 319 if (spaceBefore != 0) { 320 area.increaseHeight(-spaceBefore); 321 } 322 if (spaceAfter != 0) { 323 area.increaseHeight(-spaceAfter); 324 } 325 this.resetMarker(); 326 this.removeID(area.getIDReferences()); 327 } 328 329 333 private boolean startsAC(Area area) { 334 Area parent=null; 335 336 while ((parent = area.getParent()) != null && 337 parent.hasNonSpaceChildren() == false) { 338 if (parent instanceof AreaContainer && 341 ((AreaContainer)parent).getPosition() == Position.ABSOLUTE) { 342 return true; 343 } 344 area = parent; 345 } 346 return false; 347 } 348 } 349 | Popular Tags |