1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.tools; 21 22 import java.util.List ; 23 24 import org.apache.commons.logging.impl.SimpleLog; 25 import org.apache.commons.logging.Log; 26 import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableColumnsInfo; 27 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; 28 29 30 41 42 public class TableContext implements ITableColumnsInfo { 43 private final Log log = new SimpleLog("FOP/RTF"); 44 private final BuilderContext context; 45 private final List colWidths = new java.util.ArrayList (); 46 private int colIndex; 47 48 54 private final List colRowSpanningNumber = new java.util.ArrayList (); 55 56 62 private final List colRowSpanningAttrs = new java.util.ArrayList (); 63 64 69 private final List colFirstSpanningCol = new java.util.ArrayList (); 70 71 private boolean bNextRowBelongsToHeader = false; 72 73 77 public void setNextRowBelongsToHeader(boolean value) { 78 this.bNextRowBelongsToHeader = value; 79 } 80 81 85 public boolean getNextRowBelongsToHeader() { 86 return bNextRowBelongsToHeader; 87 } 88 89 93 public TableContext(BuilderContext ctx) { 94 context = ctx; 95 } 96 97 101 public void setNextColumnWidth(Float width) { 102 colWidths.add(width); 103 } 104 105 109 public RtfAttributes getColumnRowSpanningAttrs() { 110 return (RtfAttributes)colRowSpanningAttrs.get(colIndex); 111 } 112 113 117 public Integer getColumnRowSpanningNumber() { 118 return (Integer )colRowSpanningNumber.get(colIndex); 119 } 120 121 125 public boolean getFirstSpanningCol() { 126 Boolean b = (Boolean ) colFirstSpanningCol.get(colIndex); 127 return b.booleanValue(); 128 } 129 130 135 public void setCurrentColumnRowSpanning( 136 Integer iRowSpanning, RtfAttributes attrs) { 137 138 if (colIndex < colRowSpanningNumber.size()) { 139 colRowSpanningNumber.set(colIndex, iRowSpanning); 140 colRowSpanningAttrs.set(colIndex, attrs); 141 } else { 142 colRowSpanningNumber.add(iRowSpanning); 143 colRowSpanningAttrs.add(colIndex, attrs); 144 } 145 } 146 147 152 public void setNextColumnRowSpanning(Integer iRowSpanning, 153 RtfAttributes attrs) { 154 colRowSpanningNumber.add(iRowSpanning); 155 colRowSpanningAttrs.add(colIndex, attrs); 156 } 157 158 163 public void setCurrentFirstSpanningCol( 164 boolean bFirstSpanningCol) { 165 166 if (colIndex < colRowSpanningNumber.size()) { 167 while (colIndex >= colFirstSpanningCol.size()) { 168 setNextFirstSpanningCol(false); 169 } 170 colFirstSpanningCol.set(colIndex, new Boolean (bFirstSpanningCol)); 171 } else { 172 colFirstSpanningCol.add(new Boolean (bFirstSpanningCol)); 173 } 174 } 175 176 181 public void setNextFirstSpanningCol( 182 boolean bFirstSpanningCol) { 183 colFirstSpanningCol.add(new Boolean (bFirstSpanningCol)); 184 } 185 186 192 public void decreaseRowSpannings() { 193 for (int z = 0; z < colRowSpanningNumber.size(); ++z) { 194 Integer i = (Integer )colRowSpanningNumber.get(z); 195 196 if (i.intValue() > 0) { 197 i = new Integer (i.intValue() - 1); 198 } 199 200 colRowSpanningNumber.set(z, i); 201 202 if (i.intValue() == 0) { 203 colRowSpanningAttrs.set(z, null); 204 colFirstSpanningCol.set(z, new Boolean (false)); 205 } 206 } 207 } 208 209 214 public void selectFirstColumn() { 215 colIndex = 0; 216 } 217 218 223 public void selectNextColumn() { 224 colIndex++; 225 } 226 227 233 public float getColumnWidth() { 234 if (colIndex < 0) { 235 throw new IllegalStateException ("colIndex must not be negative!"); 236 } else if (colIndex >= getNumberOfColumns()) { 237 log.warn("Column width for column " + (colIndex + 1) + " is not defined, using " 238 + INVALID_COLUMN_WIDTH); 239 while (colIndex >= getNumberOfColumns()) { 240 setNextColumnWidth(new Float (INVALID_COLUMN_WIDTH)); 241 } 242 } 243 return ((Float )colWidths.get(colIndex)).floatValue(); 244 } 245 246 250 public void setColumnIndex(int index) { 251 colIndex = index; 252 } 253 254 257 public int getColumnIndex() { 258 return colIndex; 259 } 260 261 262 265 public int getNumberOfColumns() { 266 return colWidths.size(); 267 } 268 269 } 270 271 | Popular Tags |