@@ -88,17 +88,18 @@ public class Table extends BlockElement<Table> implements ILargeElement {
88
88
89
89
/**
90
90
* Constructs a {@code Table} with the preferable column widths.
91
- * <p />
92
- * Since 7.0.2 table layout was introduced. Auto layout is default, except large tables.
91
+ * <br />
92
+ * Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables.
93
93
* For large table 100% width and fixed layout set implicitly.
94
- * <p />
94
+ * <br />
95
95
* Note, the eventual columns width depends on selected layout, table width,
96
96
* cell's width, cell's min-widths, and cell's max-widths.
97
97
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
98
- * where {@code columnWidths} is <colgroup>'s width values .
98
+ * where {@code columnWidths} is <colgroup>'s widths .
99
99
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
100
100
*
101
- * @param columnWidths preferable column widths in points.
101
+ * @param columnWidths preferable column widths in points. Values must be greater than or equal to zero,
102
+ * otherwise it will be interpreted as undefined.
102
103
* @param largeTable whether parts of the table will be written before all data is added.
103
104
* @see #setAutoLayout()
104
105
* @see #setFixedLayout()
@@ -117,17 +118,18 @@ public Table(float[] columnWidths, boolean largeTable) {
117
118
118
119
/**
119
120
* Constructs a {@code Table} with the preferable column widths.
120
- * <p />
121
- * Since 7.0.2 table layout was introduced. Auto layout is default, except large tables.
121
+ * <br />
122
+ * Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables.
122
123
* For large table 100% width and fixed layout set implicitly.
123
- * <p />
124
+ * <br />
124
125
* Note, the eventual columns width depends on selected layout, table width,
125
126
* cell's width, cell's min-widths, and cell's max-widths.
126
127
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
127
- * where {@code columnWidths} is <colgroup>'s width values .
128
+ * where {@code columnWidths} is <colgroup>'s widths .
128
129
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
129
130
*
130
- * @param columnWidths preferable column widths, points and/or percents.
131
+ * @param columnWidths preferable column widths, points and/or percents. Values must be greater than or equal to zero,
132
+ * otherwise it will be interpreted as undefined.
131
133
* @param largeTable whether parts of the table will be written before all data is added.
132
134
* @see #setAutoLayout()
133
135
* @see #setFixedLayout()
@@ -148,16 +150,17 @@ public Table(UnitValue[] columnWidths, boolean largeTable) {
148
150
149
151
/**
150
152
* Constructs a {@code Table} with the preferable column widths.
151
- * <p />
152
- * Since 7.0.2 table layout was introduced. Auto layout is default.
153
- * <p />
153
+ * <br />
154
+ * Since 7.0.2 table layout algorithms were introduced. Auto layout is default.
155
+ * <br />
154
156
* Note, the eventual columns width depends on selected layout, table width,
155
157
* cell's width, cell's min-widths, and cell's max-widths.
156
158
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
157
- * where {@code columnWidths} is <colgroup>'s width values .
159
+ * where {@code columnWidths} is <colgroup>'s widths .
158
160
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
159
161
*
160
- * @param columnWidths preferable column widths, points and/or percents.
162
+ * @param columnWidths preferable column widths, points and/or percents. Values must be greater than or equal to zero,
163
+ * otherwise it will be interpreted as undefined.
161
164
* @see #setAutoLayout()
162
165
* @see #setFixedLayout()
163
166
*/
@@ -167,16 +170,17 @@ public Table(UnitValue[] columnWidths) {
167
170
168
171
/**
169
172
* Constructs a {@code Table} with the preferable column widths.
170
- * <p />
171
- * Since 7.0.2 table layout was introduced. Auto layout is default.
172
- * <p />
173
+ * <br />
174
+ * Since 7.0.2 table layout algorithms were introduced. Auto layout is default.
175
+ * <br />
173
176
* Note, the eventual columns width depends on selected layout, table width,
174
177
* cell's width, cell's min-widths, and cell's max-widths.
175
178
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
176
- * where {@code columnWidths} is <colgroup>'s width values .
179
+ * where {@code columnWidths} is <colgroup>'s widths .
177
180
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
178
181
*
179
- * @param pointColumnWidths preferable column widths in points.
182
+ * @param pointColumnWidths preferable column widths in points. Values must be greater than or equal to zero,
183
+ * otherwise it will be interpreted as undefined.
180
184
* @see #setAutoLayout()
181
185
* @see #setFixedLayout()
182
186
*/
@@ -187,14 +191,14 @@ public Table(float[] pointColumnWidths) {
187
191
/**
188
192
* Constructs a {@code Table} with number of columns. Each column will get equal percent width.
189
193
* 100% table width set implicitly for backward compatibility.
190
- * <p />
191
- * Since 7.0.2 table layout was introduced. Auto layout is default, except large tables.
194
+ * <br />
195
+ * Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables.
192
196
* For large table fixed layout set implicitly.
193
- * <p />
197
+ * <br />
194
198
* Note, the eventual columns width depends on selected layout, table width,
195
199
* cell's width, cell's min-widths, and cell's max-widths.
196
200
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
197
- * where {@code columnWidths} is <colgroup>'s width values .
201
+ * where {@code columnWidths} is <colgroup>'s widths .
198
202
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
199
203
*
200
204
* @param numColumns the number of columns, each column will have equal percent width.
@@ -215,7 +219,7 @@ public Table(int numColumns, boolean largeTable) {
215
219
}
216
220
//TODO remove in 7.1. It shall work as html tables.
217
221
useAllAvailableWidth ();
218
- this .columnWidths = normalizeColumnWidths (numColumns , true );
222
+ this .columnWidths = normalizeColumnWidths (numColumns );
219
223
initializeLargeTable (largeTable );
220
224
initializeRows ();
221
225
}
@@ -230,7 +234,7 @@ public Table(int numColumns, boolean largeTable) {
230
234
* Note, the eventual columns width depends on selected layout, table width,
231
235
* cell's width, cell's min-widths, and cell's max-widths.
232
236
* Table layout algorithm has the same behaviour as expected for CSS table-layout property,
233
- * where {@code columnWidths} is <colgroup>'s width values .
237
+ * where {@code columnWidths} is <colgroup>'s widths .
234
238
* For more information see {@link #setAutoLayout()} and {@link #setFixedLayout()}.
235
239
*
236
240
* @param numColumns the number of columns, each column will have equal percent width.
@@ -271,34 +275,41 @@ private static UnitValue[] normalizeColumnWidths(UnitValue[] unitColumnWidths) {
271
275
return normalized ;
272
276
}
273
277
274
- private static boolean hasNegativeValue (UnitValue [] unitColumnWidths ) {
275
- for (UnitValue uv : unitColumnWidths ) {
276
- if (uv .getValue () < 0 ) return true ;
277
- }
278
- return false ;
279
- }
280
-
281
- private static UnitValue [] normalizeColumnWidths (int numberOfColumns , boolean usePercents ) {
278
+ private static UnitValue [] normalizeColumnWidths (int numberOfColumns ) {
282
279
UnitValue [] normalized = new UnitValue [numberOfColumns ];
283
280
for (int i = 0 ; i < numberOfColumns ; i ++) {
284
- normalized [i ] = usePercents
285
- ? UnitValue .createPercentValue ((float ) 100 / numberOfColumns )
286
- : UnitValue .createPointValue (-1 );
281
+ normalized [i ] = UnitValue .createPercentValue ((float ) 100 / numberOfColumns );
287
282
}
288
283
return normalized ;
289
284
}
290
285
291
286
/**
292
- * Set fixed layout. {@link Property#WIDTH} must be set.
287
+ * Set fixed layout. Analog of {@code table-layout:fixed} CSS property.
288
+ * Note, the table must have width property, otherwise auto layout will be used.
293
289
* <p/>
294
- * 1.
290
+ * Algorithm description
291
+ * <br/>
292
+ * 1. Scan columns for width property and set it. (Columns have set in constructor, analog of {@code <colgroup>} element in HTML)<br/>
293
+ * 2. Scan the very first row of table for width property and set it to undefined columns (cell width has lower priority in comparing with column).
294
+ * If cell has colspan, each column will get equal width: {@code (width/colspan)}.<br/>
295
+ * 3. If sum of columns is less, than table width, there are two options:<br/>
296
+ * 3.1. If undefined columns still exist, they will get the rest remaining width.<br/>
297
+ * 3.2. Otherwise all columns will be expanded proportionally based on its width.<br/>
298
+ *
295
299
* @return this element.
296
300
*/
297
301
public Table setFixedLayout () {
298
302
setProperty (Property .TABLE_LAYOUT , "fixed" );
299
303
return this ;
300
304
}
301
305
306
+ /**
307
+ * Set auto layout.
308
+ * <p/>
309
+ * 1.
310
+ * @return this element.
311
+ */
312
+
302
313
public Table setAutoLayout () {
303
314
setProperty (Property .TABLE_LAYOUT , "auto" );
304
315
return this ;
@@ -868,9 +879,6 @@ private void ensureFooterIsInitialized() {
868
879
private void initializeLargeTable (boolean largeTable ) {
869
880
this .isComplete = !largeTable ;
870
881
if (largeTable ) {
871
- if (hasNegativeValue (this .columnWidths )) {
872
- throw new IllegalArgumentException ("Large table must have valid column widths." );
873
- }
874
882
setWidth (UnitValue .createPercentValue (100 ));
875
883
setFixedLayout ();
876
884
}
0 commit comments