1 | /* | |
2 | * $Id: PdfTable.java 3373 2008-05-12 16:21:24Z xlv $ | |
3 | * | |
4 | * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text.pdf; | |
51 | ||
52 | import java.util.ArrayList; | |
53 | import java.util.Iterator; | |
54 | ||
55 | import com.lowagie.text.Cell; | |
56 | import com.lowagie.text.Element; | |
57 | import com.lowagie.text.Rectangle; | |
58 | import com.lowagie.text.Row; | |
59 | import com.lowagie.text.Table; | |
60 | ||
61 | /** | |
62 | * <CODE>PdfTable</CODE> is an object that contains the graphics and text of a table. | |
63 | * | |
64 | * @see com.lowagie.text.Table | |
65 | * @see com.lowagie.text.Row | |
66 | * @see com.lowagie.text.Cell | |
67 | * @see PdfCell | |
68 | */ | |
69 | ||
70 | public class PdfTable extends Rectangle { | |
71 | | |
72 | // membervariables | |
73 | | |
74 | /** this is the number of columns in the table. */ | |
75 | private int columns; | |
76 | | |
77 | /** this is the ArrayList with all the cell of the table header. */ | |
78 | private ArrayList headercells; | |
79 | | |
80 | /** this is the ArrayList with all the cells in the table. */ | |
81 | private ArrayList cells; | |
82 | | |
83 | /** Original table used to build this object*/ | |
84 | protected Table table; | |
85 | | |
86 | /** Cached column widths. */ | |
87 | protected float[] positions; | |
88 | | |
89 | // constructors | |
90 | ||
91 | /** | |
92 | * Constructs a <CODE>PdfTable</CODE>-object. | |
93 | * | |
94 | * @param table a <CODE>Table</CODE> | |
95 | * @param left the left border on the page | |
96 | * @param right the right border on the page | |
97 | * @param top the start position of the top of the table | |
98 | * @since a parameter of this method has been removed in iText 2.0.8 | |
99 | */ | |
100 | | |
101 | PdfTable(Table table, float left, float right, float top) { | |
102 | // constructs a Rectangle (the bottom value will be changed afterwards) | |
103 | super(left, top, right, top); | |
104 | this.table = table; | |
105 |
1
1. |
table.complete(); |
106 | | |
107 | // copying the attributes from class Table | |
108 |
1
1. |
cloneNonPositionParameters(table); |
109 | ||
110 | this.columns = table.getColumns(); | |
111 |
1
1. |
positions = table.getWidths(left, right - left); |
112 | | |
113 | // initialization of some parameters | |
114 |
1
1. |
setLeft(positions[0]); |
115 |
2
1. 2. |
setRight(positions[positions.length - 1]); |
116 | | |
117 | headercells = new ArrayList(); | |
118 | cells = new ArrayList(); | |
119 | ||
120 |
1
1. |
updateRowAdditionsInternal(); |
121 | } | |
122 | ||
123 | // methods | |
124 | ||
125 | /** | |
126 | * Updates the table row additions in the underlying table object and deletes all table rows, | |
127 | * in order to preserve memory and detect future row additions. | |
128 | * <p><b>Pre-requisite</b>: the object must have been built with the parameter <code>supportUpdateRowAdditions</code> equals to true. | |
129 | */ | |
130 | | |
131 | void updateRowAdditions() { | |
132 |
1
1. updateRowAdditions : removed call to com/lowagie/text/Table::complete → NO_COVERAGE |
table.complete(); |
133 |
1
1. updateRowAdditions : removed call to com/lowagie/text/pdf/PdfTable::updateRowAdditionsInternal → NO_COVERAGE |
updateRowAdditionsInternal(); |
134 |
1
1. updateRowAdditions : removed call to com/lowagie/text/Table::deleteAllRows → NO_COVERAGE |
table.deleteAllRows(); |
135 | } | |
136 | | |
137 | /** | |
138 | * Updates the table row additions in the underlying table object | |
139 | */ | |
140 | | |
141 | private void updateRowAdditionsInternal() { | |
142 | // correct table : fill empty cells/ parse table in table | |
143 | Row row; | |
144 | int prevRows = rows(); | |
145 | int rowNumber = 0; | |
146 | int groupNumber = 0; | |
147 | boolean groupChange; | |
148 |
1
1. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE |
int firstDataRow = table.getLastHeaderRow() + 1; |
149 | Cell cell; | |
150 | PdfCell currentCell; | |
151 | ArrayList newCells = new ArrayList(); | |
152 |
1
1. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE |
int rows = table.size() + 1; |
153 | float[] offsets = new float[rows]; | |
154 |
3
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : Changed increment from 1 to -1 → NO_COVERAGE 3. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
for (int i = 0; i < rows; i++) { |
155 | offsets[i] = getBottom(); | |
156 | } | |
157 | | |
158 | // loop over all the rows | |
159 | for (Iterator rowIterator = table.iterator(); rowIterator.hasNext(); ) { | |
160 | groupChange = false; | |
161 | row = (Row) rowIterator.next(); | |
162 |
1
1. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (row.isEmpty()) { |
163 |
7
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 3. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 4. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 5. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 6. updateRowAdditionsInternal : negated conditional → NO_COVERAGE 7. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (rowNumber < rows - 1 && offsets[rowNumber + 1] > offsets[rowNumber]) offsets[rowNumber + 1] = offsets[rowNumber]; |
164 | } | |
165 | else { | |
166 |
3
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : Changed increment from 1 to -1 → NO_COVERAGE 3. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
for(int i = 0; i < row.getColumns(); i++) { |
167 | cell = (Cell) row.getCell(i); | |
168 |
1
1. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (cell != null) { |
169 |
2
1. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE |
currentCell = new PdfCell(cell, rowNumber+prevRows, positions[i], positions[i + cell.getColspan()], offsets[rowNumber], cellspacing(), cellpadding()); |
170 |
2
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (rowNumber < firstDataRow) { |
171 |
1
1. updateRowAdditionsInternal : removed call to com/lowagie/text/pdf/PdfCell::setHeader → NO_COVERAGE |
currentCell.setHeader(); |
172 | headercells.add(currentCell); | |
173 |
1
1. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (!table.isNotAddedYet()) |
174 | continue; | |
175 | } | |
176 | try { | |
177 |
5
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE 3. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE 4. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 5. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (offsets[rowNumber] - currentCell.getHeight() - cellpadding() < offsets[rowNumber + currentCell.rowspan()]) { |
178 |
3
1. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE 3. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE |
offsets[rowNumber + currentCell.rowspan()] = offsets[rowNumber] - currentCell.getHeight() - cellpadding(); |
179 | } | |
180 | } | |
181 | catch(ArrayIndexOutOfBoundsException aioobe) { | |
182 |
4
1. updateRowAdditionsInternal : changed conditional boundary → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE 3. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 4. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if (offsets[rowNumber] - currentCell.getHeight() < offsets[rows - 1]) { |
183 |
2
1. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced float subtraction with addition → NO_COVERAGE |
offsets[rows - 1] = offsets[rowNumber] - currentCell.getHeight(); |
184 | } | |
185 | } | |
186 |
1
1. updateRowAdditionsInternal : removed call to com/lowagie/text/pdf/PdfCell::setGroupNumber → NO_COVERAGE |
currentCell.setGroupNumber(groupNumber); |
187 |
1
1. updateRowAdditionsInternal : Replaced bitwise OR with AND → NO_COVERAGE |
groupChange |= cell.getGroupChange(); |
188 | newCells.add(currentCell); | |
189 | } | |
190 | } | |
191 | } | |
192 |
1
1. updateRowAdditionsInternal : Changed increment from 1 to -1 → NO_COVERAGE |
rowNumber++; |
193 |
2
1. updateRowAdditionsInternal : Changed increment from 1 to -1 → NO_COVERAGE 2. updateRowAdditionsInternal : negated conditional → NO_COVERAGE |
if( groupChange ) groupNumber++; |
194 | } | |
195 | | |
196 | // loop over all the cells | |
197 | int n = newCells.size(); | |
198 | for (Object newCell : newCells) { | |
199 | currentCell = (PdfCell) newCell; | |
200 | try { | |
201 |
3
1. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 2. updateRowAdditionsInternal : Replaced integer addition with subtraction → NO_COVERAGE 3. updateRowAdditionsInternal : removed call to com/lowagie/text/pdf/PdfCell::setBottom → NO_COVERAGE |
currentCell.setBottom(offsets[currentCell.rownumber() - prevRows + currentCell.rowspan()]); |
202 | } catch (ArrayIndexOutOfBoundsException aioobe) { | |
203 |
2
1. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 2. updateRowAdditionsInternal : removed call to com/lowagie/text/pdf/PdfCell::setBottom → NO_COVERAGE |
currentCell.setBottom(offsets[rows - 1]); |
204 | } | |
205 | } | |
206 | cells.addAll(newCells); | |
207 |
2
1. updateRowAdditionsInternal : Replaced integer subtraction with addition → NO_COVERAGE 2. updateRowAdditionsInternal : removed call to com/lowagie/text/pdf/PdfTable::setBottom → NO_COVERAGE |
setBottom(offsets[rows - 1]); |
208 | } | |
209 | ||
210 | /** | |
211 | * Get the number of rows | |
212 | */ | |
213 | | |
214 | int rows() { | |
215 |
4
1. rows : Replaced integer subtraction with addition → NO_COVERAGE 2. rows : Replaced integer addition with subtraction → NO_COVERAGE 3. rows : negated conditional → NO_COVERAGE 4. rows : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return cells.isEmpty() ? 0 : ((PdfCell)cells.get(cells.size()-1)).rownumber()+1; |
216 | } | |
217 | ||
218 | /** @see com.lowagie.text.Element#type() */ | |
219 | public int type() { | |
220 | return Element.TABLE; | |
221 | } | |
222 | | |
223 | /** | |
224 | * Returns the arraylist with the cells of the table header. | |
225 | * | |
226 | * @return an <CODE>ArrayList</CODE> | |
227 | */ | |
228 | | |
229 | ArrayList getHeaderCells() { | |
230 | return headercells; | |
231 | } | |
232 | | |
233 | /** | |
234 | * Checks if there is a table header. | |
235 | * | |
236 | * @return an <CODE>ArrayList</CODE> | |
237 | */ | |
238 | | |
239 | boolean hasHeader() { | |
240 |
2
1. hasHeader : negated conditional → NO_COVERAGE 2. hasHeader : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !headercells.isEmpty(); |
241 | } | |
242 | | |
243 | /** | |
244 | * Returns the arraylist with the cells of the table. | |
245 | * | |
246 | * @return an <CODE>ArrayList</CODE> | |
247 | */ | |
248 | | |
249 | ArrayList getCells() { | |
250 | return cells; | |
251 | } | |
252 | | |
253 | /** | |
254 | * Returns the number of columns of the table. | |
255 | * | |
256 | * @return the number of columns | |
257 | */ | |
258 | | |
259 | int columns() { | |
260 | return columns; | |
261 | } | |
262 | | |
263 | /** | |
264 | * Returns the cellpadding of the table. | |
265 | * | |
266 | * @return the cellpadding | |
267 | */ | |
268 | | |
269 | final float cellpadding() { | |
270 | return table.getPadding(); | |
271 | } | |
272 | | |
273 | /** | |
274 | * Returns the cellspacing of the table. | |
275 | * | |
276 | * @return the cellspacing | |
277 | */ | |
278 | | |
279 | final float cellspacing() { | |
280 | return table.getSpacing(); | |
281 | } | |
282 | | |
283 | /** | |
284 | * Checks if this <CODE>Table</CODE> has to fit a page. | |
285 | * | |
286 | * @return true if the table may not be split | |
287 | */ | |
288 | ||
289 | public final boolean hasToFitPageTable() { | |
290 | return table.isTableFitsPage(); | |
291 | } | |
292 | ||
293 | /** | |
294 | * Checks if the cells of this <CODE>Table</CODE> have to fit a page. | |
295 | * | |
296 | * @return true if the cells may not be split | |
297 | */ | |
298 | | |
299 | public final boolean hasToFitPageCells() { | |
300 | return table.isCellsFitPage(); | |
301 | } | |
302 | ||
303 | /** | |
304 | * Gets the offset of this table. | |
305 | * | |
306 | * @return the space between this table and the previous element. | |
307 | */ | |
308 | public float getOffset() { | |
309 | return table.getOffset(); | |
310 | } | |
311 | } | |
Mutations | ||
105 |
1.1 |
|
108 |
1.1 |
|
111 |
1.1 |
|
114 |
1.1 |
|
115 |
1.1 2.2 |
|
120 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
148 |
1.1 |
|
152 |
1.1 |
|
154 |
1.1 2.2 3.3 |
|
162 |
1.1 |
|
163 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
166 |
1.1 2.2 3.3 |
|
168 |
1.1 |
|
169 |
1.1 2.2 |
|
170 |
1.1 2.2 |
|
171 |
1.1 |
|
173 |
1.1 |
|
177 |
1.1 2.2 3.3 4.4 5.5 |
|
178 |
1.1 2.2 3.3 |
|
182 |
1.1 2.2 3.3 4.4 |
|
183 |
1.1 2.2 |
|
186 |
1.1 |
|
187 |
1.1 |
|
192 |
1.1 |
|
193 |
1.1 2.2 |
|
201 |
1.1 2.2 3.3 |
|
203 |
1.1 2.2 |
|
207 |
1.1 2.2 |
|
215 |
1.1 2.2 3.3 4.4 |
|
240 |
1.1 2.2 |