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.

RtfTable.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.rtf.rtflib.rtfdoc;
  19. /*
  20. * This file is part of the RTF library of the FOP project, which was originally
  21. * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
  22. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  23. * the FOP project.
  24. */
  25. import java.io.IOException;
  26. import java.io.Writer;
  27. /** Container for RtfRow elements
  28. * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
  29. */
  30. public class RtfTable extends RtfContainer {
  31. private RtfTableRow row;
  32. private int highestRow = 0;
  33. private Boolean isNestedTable = null;
  34. private RtfAttributes borderAttributes = null;
  35. /** Added by Boris Poudérous on 07/22/2002 in order to process
  36. * number-columns-spanned attribute */
  37. private ITableColumnsInfo tableContext;
  38. /** Shows the table depth necessary for nested tables */
  39. private int nestedTableDepth = 0;
  40. /** Create an RTF element as a child of given container */
  41. RtfTable(IRtfTableContainer parent, Writer w, ITableColumnsInfo tc)
  42. throws IOException {
  43. super((RtfContainer)parent, w);
  44. // Line added by Boris Poudérous on 07/22/2002
  45. tableContext = tc;
  46. }
  47. /** Create an RTF element as a child of given container
  48. * Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute
  49. */
  50. RtfTable(IRtfTableContainer parent, Writer w, RtfAttributes attrs,
  51. ITableColumnsInfo tc) throws IOException {
  52. super((RtfContainer)parent, w, attrs);
  53. // Line added by Boris Poudérous on 07/22/2002
  54. tableContext = tc;
  55. }
  56. /**
  57. * Close current row if any and start a new one
  58. * @return new RtfTableRow
  59. * @throws IOException for I/O problems
  60. */
  61. public RtfTableRow newTableRow() throws IOException {
  62. if (row != null) {
  63. row.close();
  64. }
  65. highestRow++;
  66. row = new RtfTableRow(this, writer, attrib, highestRow);
  67. return row;
  68. }
  69. /**
  70. * Close current row if any and start a new one
  71. * @param attrs attributs of new RtfTableRow
  72. * @return new RtfTableRow
  73. * @throws IOException for I/O problems
  74. */
  75. public RtfTableRow newTableRow(RtfAttributes attrs) throws IOException {
  76. RtfAttributes attr = null;
  77. if (attrib != null) {
  78. attr = (RtfAttributes) attrib.clone ();
  79. attr.set (attrs);
  80. } else {
  81. attr = attrs;
  82. }
  83. if (row != null) {
  84. row.close();
  85. }
  86. highestRow++;
  87. row = new RtfTableRow(this, writer, attr, highestRow);
  88. return row;
  89. }
  90. /**
  91. * Overridden to write RTF prefix code, what comes before our children
  92. * @throws IOException for I/O problems
  93. */
  94. protected void writeRtfPrefix() throws IOException {
  95. if (isNestedTable()) {
  96. writeControlWordNS("pard");
  97. }
  98. writeGroupMark(true);
  99. }
  100. /**
  101. * Overridden to write RTF suffix code, what comes after our children
  102. * @throws IOException for I/O problems
  103. */
  104. protected void writeRtfSuffix() throws IOException {
  105. writeGroupMark(false);
  106. if (isNestedTable()) {
  107. getRow().writeRowAndCellsDefintions();
  108. }
  109. }
  110. /**
  111. *
  112. * @param id row to check (??)
  113. * @return true if id is the highestRow
  114. */
  115. public boolean isHighestRow(int id) {
  116. return (highestRow == id) ? true : false;
  117. }
  118. /**
  119. * Added by Boris Poudérous on 07/22/2002
  120. * @return ITableColumnsInfo for this table
  121. */
  122. public ITableColumnsInfo getITableColumnsInfo() {
  123. return this.tableContext;
  124. }
  125. private RtfAttributes headerAttribs = null;
  126. /**
  127. * Added by Normand Masse
  128. * Support for table-header attributes (used instead of table attributes)
  129. * @param attrs attributes to be set
  130. */
  131. public void setHeaderAttribs(RtfAttributes attrs) {
  132. headerAttribs = attrs;
  133. }
  134. /**
  135. *
  136. * @return RtfAttributes of Header
  137. */
  138. public RtfAttributes getHeaderAttribs() {
  139. return headerAttribs;
  140. }
  141. /**
  142. * Added by Normand Masse
  143. * @return the table-header attributes if they are present, otherwise the
  144. * parent's attributes are returned normally.
  145. */
  146. public RtfAttributes getRtfAttributes() {
  147. if (headerAttribs != null) {
  148. return headerAttribs;
  149. }
  150. return super.getRtfAttributes();
  151. }
  152. /** @return true if the the table is a nested table */
  153. public boolean isNestedTable() {
  154. if (isNestedTable == null) {
  155. RtfElement e = this;
  156. while (e.parent != null) {
  157. if (e.parent instanceof RtfTableCell) {
  158. isNestedTable = Boolean.TRUE;
  159. return true;
  160. }
  161. e = e.parent;
  162. }
  163. isNestedTable = Boolean.FALSE;
  164. } else {
  165. return isNestedTable.booleanValue();
  166. }
  167. return false;
  168. }
  169. /**
  170. *
  171. * @return Parent row table (for nested tables only)
  172. */
  173. public RtfTableRow getRow() {
  174. RtfElement e = this;
  175. while (e.parent != null) {
  176. if (e.parent instanceof RtfTableRow) {
  177. return (RtfTableRow) e.parent;
  178. }
  179. e = e.parent;
  180. }
  181. return null;
  182. }
  183. /**
  184. * Sets the nested table depth.
  185. * @param nestedTableDepth the nested table depth
  186. */
  187. public void setNestedTableDepth(int nestedTableDepth) {
  188. this.nestedTableDepth = nestedTableDepth;
  189. }
  190. /**
  191. * Returns the nested table depth.
  192. * @return the nested table depth
  193. */
  194. public int getNestedTableDepth() {
  195. return this.nestedTableDepth;
  196. }
  197. /**
  198. * Sets the RtfAttributes for the borders of the table.
  199. * @param attributes Border attributes of the table.
  200. */
  201. public void setBorderAttributes(RtfAttributes attributes) {
  202. borderAttributes = attributes;
  203. }
  204. /**
  205. * Returns the RtfAttributes for the borders of the table.
  206. * @return Border attributes of the table.
  207. */
  208. public RtfAttributes getBorderAttributes() {
  209. return borderAttributes;
  210. }
  211. }