You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableBody.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.flow;
  8. // FOP
  9. import org.apache.fop.fo.*;
  10. import org.apache.fop.fo.properties.*;
  11. import org.apache.fop.datatypes.*;
  12. import org.apache.fop.layout.*;
  13. import org.apache.fop.apps.FOPException;
  14. // Java
  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. public class TableBody extends FObj {
  18. int spaceBefore;
  19. int spaceAfter;
  20. ColorType backgroundColor;
  21. String id;
  22. ArrayList columns;
  23. RowSpanMgr rowSpanMgr; // manage information about spanning rows
  24. AreaContainer areaContainer;
  25. public TableBody(FONode parent) {
  26. super(parent);
  27. }
  28. public void setColumns(ArrayList columns) {
  29. this.columns = columns;
  30. }
  31. public void setYPosition(int value) {
  32. areaContainer.setYPosition(value);
  33. }
  34. public int getYPosition() {
  35. return areaContainer.getCurrentYPosition();
  36. }
  37. public int getHeight() {
  38. return areaContainer.getHeight() + spaceBefore + spaceAfter;
  39. }
  40. public Status layout(Area area) throws FOPException {
  41. if (this.marker == BREAK_AFTER) {
  42. return new Status(Status.OK);
  43. }
  44. if (this.marker == START) {
  45. // Common Accessibility Properties
  46. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  47. // Common Aural Properties
  48. AuralProps mAurProps = propMgr.getAuralProps();
  49. // Common Border, Padding, and Background Properties
  50. BorderAndPadding bap = propMgr.getBorderAndPadding();
  51. BackgroundProps bProps = propMgr.getBackgroundProps();
  52. // Common Relative Position Properties
  53. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  54. // this.properties.get("id");
  55. this.spaceBefore =
  56. this.properties.get("space-before.optimum").getLength().mvalue();
  57. this.spaceAfter =
  58. this.properties.get("space-after.optimum").getLength().mvalue();
  59. this.backgroundColor =
  60. this.properties.get("background-color").getColorType();
  61. this.id = this.properties.get("id").getString();
  62. area.getIDReferences().createID(id);
  63. if (area instanceof BlockArea) {
  64. area.end();
  65. }
  66. if (rowSpanMgr == null) {
  67. rowSpanMgr = new RowSpanMgr(columns.size());
  68. }
  69. // if (this.isInListBody) {
  70. // startIndent += bodyIndent + distanceBetweenStarts;
  71. // }
  72. this.marker = 0;
  73. }
  74. if ((spaceBefore != 0) && (this.marker == 0)) {
  75. area.increaseHeight(spaceBefore);
  76. }
  77. if (marker == 0) {
  78. // configure id
  79. area.getIDReferences().configureID(id, area);
  80. }
  81. int spaceLeft = area.spaceLeft();
  82. /*
  83. * Note: the parent FO must be a Table. The parent Area is the Block
  84. * type area created by the Table, which is also a reference area.
  85. * The content "width" (IPD) of the TableBody is the same as that
  86. * of the containing table area, and its relative position is 0,0.
  87. * Strictly speaking (CR), this FO should generate no areas!
  88. */
  89. this.areaContainer =
  90. new AreaContainer(propMgr.getFontState(area.getFontInfo()), 0,
  91. area.getContentHeight(),
  92. area.getContentWidth(), // IPD
  93. area.spaceLeft(), Position.RELATIVE);
  94. areaContainer.foCreator = this; // G Seshadri
  95. areaContainer.setPage(area.getPage());
  96. areaContainer.setBackgroundColor(backgroundColor);
  97. areaContainer.setBorderAndPadding(propMgr.getBorderAndPadding());
  98. areaContainer.start();
  99. areaContainer.setAbsoluteHeight(area.getAbsoluteHeight());
  100. areaContainer.setIDReferences(area.getIDReferences());
  101. ArrayList keepWith = new ArrayList();
  102. int numChildren = this.children.size();
  103. TableRow lastRow = null;
  104. boolean endKeepGroup = true;
  105. for (int i = this.marker; i < numChildren; i++) {
  106. Object child = children.get(i);
  107. if (!(child instanceof TableRow)) {
  108. throw new FOPException("Currently only Table Rows are supported in table body, header and footer");
  109. }
  110. TableRow row = (TableRow)child;
  111. row.setRowSpanMgr(rowSpanMgr);
  112. row.setColumns(columns);
  113. row.doSetup(areaContainer);
  114. if (row.getKeepWithPrevious().getType()
  115. != KeepValue.KEEP_WITH_AUTO && lastRow != null
  116. && keepWith.indexOf(lastRow)
  117. == -1) {
  118. keepWith.add(lastRow);
  119. } else {
  120. if (endKeepGroup && keepWith.size() > 0) {
  121. keepWith = new ArrayList();
  122. }
  123. }
  124. Status status;
  125. if ((status = row.layout(areaContainer)).isIncomplete()) {
  126. // BUG!!! don't distinguish between break-before and after!
  127. if (status.isPageBreak()) {
  128. this.marker = i;
  129. area.addChild(areaContainer);
  130. // areaContainer.end();
  131. area.increaseHeight(areaContainer.getHeight());
  132. area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  133. if (i == numChildren - 1) {
  134. this.marker = BREAK_AFTER;
  135. if (spaceAfter != 0) {
  136. area.increaseHeight(spaceAfter);
  137. }
  138. }
  139. return status;
  140. }
  141. if (keepWith.size()
  142. > 0) { // && status.getCode() == Status.AREA_FULL_NONE
  143. // FIXME!!! Handle rows spans!!!
  144. row.removeLayout(areaContainer);
  145. for (Iterator e = keepWith.iterator();
  146. e.hasNext(); ) {
  147. TableRow tr = (TableRow)e.next();
  148. tr.removeLayout(areaContainer);
  149. i--;
  150. }
  151. if (i == 0) {
  152. resetMarker();
  153. return new Status(Status.AREA_FULL_NONE);
  154. }
  155. }
  156. this.marker = i;
  157. if ((i != 0) && (status.getCode() == Status.AREA_FULL_NONE)) {
  158. status = new Status(Status.AREA_FULL_SOME);
  159. }
  160. if (!((i == 0) && (areaContainer.getContentHeight() <= 0))) {
  161. area.addChild(areaContainer);
  162. // areaContainer.end();
  163. area.increaseHeight(areaContainer.getHeight());
  164. area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  165. }
  166. return status;
  167. } else if (status.getCode() == Status.KEEP_WITH_NEXT
  168. || rowSpanMgr.hasUnfinishedSpans()) {
  169. keepWith.add(row);
  170. endKeepGroup = false;
  171. } else {
  172. endKeepGroup = true;
  173. }
  174. lastRow = row;
  175. area.setMaxHeight(area.getMaxHeight() - spaceLeft
  176. + this.areaContainer.getMaxHeight());
  177. spaceLeft = area.spaceLeft();
  178. }
  179. area.addChild(areaContainer);
  180. areaContainer.end();
  181. area.increaseHeight(areaContainer.getHeight());
  182. area.setAbsoluteHeight(areaContainer.getAbsoluteHeight());
  183. if (spaceAfter != 0) {
  184. area.increaseHeight(spaceAfter);
  185. area.setMaxHeight(area.getMaxHeight() - spaceAfter);
  186. }
  187. if (area instanceof BlockArea) {
  188. area.start();
  189. }
  190. return new Status(Status.OK);
  191. }
  192. public void removeLayout(Area area) {
  193. if (areaContainer != null) {
  194. area.removeChild(areaContainer);
  195. }
  196. if (spaceBefore != 0) {
  197. area.increaseHeight(-spaceBefore);
  198. }
  199. if (spaceAfter != 0) {
  200. area.increaseHeight(-spaceAfter);
  201. }
  202. this.resetMarker();
  203. this.removeID(area.getIDReferences());
  204. }
  205. }