aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2007-10-26 09:43:01 +0000
committerVincent Hennebert <vhennebert@apache.org>2007-10-26 09:43:01 +0000
commite4a2afe6df24165452e06c16bc239ca9b89910b7 (patch)
treeb15ac00ed8727b90f706395601c2fba6578b88e0
parent9fd779a18a0dac95dd125c6880bafdad650c856f (diff)
downloadxmlgraphics-fop-e4a2afe6df24165452e06c16bc239ca9b89910b7.tar.gz
xmlgraphics-fop-e4a2afe6df24165452e06c16bc239ca9b89910b7.zip
Created an abstract TableCellContainer class meant to contain the logic in TableRowIterator.
Factored some code common to TableBody and TableRow in it. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@588586 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/fo/flow/TableBody.java28
-rw-r--r--src/java/org/apache/fop/fo/flow/TableCellContainer.java161
-rw-r--r--src/java/org/apache/fop/fo/flow/TableFObj.java91
-rw-r--r--src/java/org/apache/fop/fo/flow/TableRow.java28
4 files changed, 165 insertions, 143 deletions
diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java
index 9811a7c15..3c68410f5 100644
--- a/src/java/org/apache/fop/fo/flow/TableBody.java
+++ b/src/java/org/apache/fop/fo/flow/TableBody.java
@@ -36,7 +36,7 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
/**
* Class modelling the fo:table-body object.
*/
-public class TableBody extends TableFObj {
+public class TableBody extends TableCellContainer {
// The value of properties relevant for fo:table-body.
private CommonBorderPaddingBackground commonBorderPaddingBackground;
// Unused but valid items, commented out for performance:
@@ -177,31 +177,7 @@ public class TableBody extends TableFObj {
break;
case FO_TABLE_CELL:
TableCell cell = (TableCell) child;
- int colNr = cell.getColumnNumber();
- int colSpan = cell.getNumberColumnsSpanned();
- Length colWidth = null;
-
- if (cell.getWidth().getEnum() != EN_AUTO
- && colSpan == 1) {
- colWidth = cell.getWidth();
- }
-
- for (int i = colNr; i < colNr + colSpan; ++i) {
- if (t.columns.size() < i
- || t.columns.get(i - 1) == null) {
- t.addDefaultColumn(colWidth,
- i == colNr
- ? cell.getColumnNumber()
- : 0);
- } else {
- TableColumn col =
- (TableColumn) t.columns.get(i - 1);
- if (!col.isDefaultColumn()
- && colWidth != null) {
- col.setColumnWidth(colWidth);
- }
- }
- }
+ addTableCellChild(cell);
break;
default:
//nop
diff --git a/src/java/org/apache/fop/fo/flow/TableCellContainer.java b/src/java/org/apache/fop/fo/flow/TableCellContainer.java
new file mode 100644
index 000000000..f19102e95
--- /dev/null
+++ b/src/java/org/apache/fop/fo/flow/TableCellContainer.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fo.flow;
+
+import java.util.List;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.Length;
+import org.apache.fop.fo.FONode;
+
+/**
+ * A common class for fo:table-body and fo:table-row which both can contain fo:table-cell.
+ */
+public abstract class TableCellContainer extends TableFObj {
+
+ public TableCellContainer(FONode parent) {
+ super(parent);
+ }
+
+ protected void addTableCellChild(TableCell cell) throws FOPException {
+ Table t = getTable();
+ int colNr = cell.getColumnNumber();
+ int colSpan = cell.getNumberColumnsSpanned();
+ Length colWidth = null;
+
+ if (cell.getWidth().getEnum() != EN_AUTO
+ && colSpan == 1) {
+ colWidth = cell.getWidth();
+ }
+
+ for (int i = colNr; i < colNr + colSpan; ++i) {
+ if (t.columns.size() < i
+ || t.columns.get(i - 1) == null) {
+ t.addDefaultColumn(colWidth,
+ i == colNr
+ ? cell.getColumnNumber()
+ : 0);
+ } else {
+ TableColumn col =
+ (TableColumn) t.columns.get(i - 1);
+ if (!col.isDefaultColumn()
+ && colWidth != null) {
+ col.setColumnWidth(colWidth);
+ }
+ }
+ }
+ }
+
+ protected void addChildNode(FONode child) throws FOPException {
+ if (!inMarker()
+ && child.getNameId() == FO_TABLE_CELL) {
+ /* update current column index for the table-body/table-row */
+ updateColumnIndex((TableCell) child);
+ }
+ super.addChildNode(child);
+ }
+
+
+ private void updateColumnIndex(TableCell cell) {
+
+ int rowSpan = cell.getNumberRowsSpanned();
+ int colSpan = cell.getNumberColumnsSpanned();
+ int columnIndex = getCurrentColumnIndex();
+ int i;
+
+ if (getNameId() == FO_TABLE_ROW) {
+
+ TableRow row = (TableRow) this;
+
+ for (i = colSpan;
+ --i >= 0 || row.pendingSpans.size() < cell.getColumnNumber();) {
+ row.pendingSpans.add(null);
+ }
+
+ /* if the current cell spans more than one row,
+ * update pending span list for the next row
+ */
+ if (rowSpan > 1) {
+ for (i = colSpan; --i >= 0;) {
+ row.pendingSpans.set(columnIndex - 1 + i,
+ new PendingSpan(rowSpan));
+ }
+ }
+ } else {
+
+ TableBody body = (TableBody) this;
+
+ /* if body.firstRow is still true, and :
+ * a) the cell starts a row,
+ * b) there was a previous cell
+ * c) that previous cell didn't explicitly end the previous row
+ * => set firstRow flag to false
+ */
+ if (body.firstRow && cell.startsRow()) {
+ if (!body.previousCellEndedRow()) {
+ body.firstRow = false;
+ }
+ }
+
+ /* pendingSpans not initialized for the first row...
+ */
+ if (body.firstRow) {
+ for (i = colSpan;
+ --i >= 0|| body.pendingSpans.size() < cell.getColumnNumber();) {
+ body.pendingSpans.add(null);
+ }
+ }
+
+ /* if the current cell spans more than one row,
+ * update pending span list for the next row
+ */
+ if (rowSpan > 1) {
+ for (i = colSpan; --i >= 0;) {
+ body.pendingSpans.set(columnIndex - 1 + i,
+ new PendingSpan(rowSpan));
+ }
+ }
+ }
+
+ /* flag column indices used by this cell,
+ * take into account that possibly not all column-numbers
+ * are used by columns in the parent table (if any),
+ * so a cell spanning three columns, might actually
+ * take up more than three columnIndices...
+ */
+ int startIndex = columnIndex - 1;
+ int endIndex = startIndex + colSpan;
+ if (getTable().columns != null) {
+ List cols = getTable().columns;
+ int tmpIndex = endIndex;
+ for (i = startIndex; i <= tmpIndex; ++i) {
+ if (i < cols.size() && cols.get(i) == null) {
+ endIndex++;
+ }
+ }
+ }
+ flagColumnIndices(startIndex, endIndex);
+ if (getNameId() != FO_TABLE_ROW && cell.endsRow()) {
+ ((TableBody) this).firstRow = false;
+ ((TableBody) this).resetColumnIndex();
+ }
+ }
+
+}
diff --git a/src/java/org/apache/fop/fo/flow/TableFObj.java b/src/java/org/apache/fop/fo/flow/TableFObj.java
index d1490a578..007bd4800 100644
--- a/src/java/org/apache/fop/fo/flow/TableFObj.java
+++ b/src/java/org/apache/fop/fo/flow/TableFObj.java
@@ -19,8 +19,6 @@
package org.apache.fop.fo.flow;
-import java.util.List;
-
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.datatypes.ValidationPercentBaseContext;
@@ -98,98 +96,9 @@ public abstract class TableFObj extends FObj {
* {@inheritDoc}
*/
protected void addChildNode(FONode child) throws FOPException {
- if (!inMarker()
- && child.getNameId() == FO_TABLE_CELL) {
- /* update current column index for the table-body/table-row */
- updateColumnIndex((TableCell) child);
- }
super.addChildNode(child);
}
- private void updateColumnIndex(TableCell cell) {
-
- int rowSpan = cell.getNumberRowsSpanned();
- int colSpan = cell.getNumberColumnsSpanned();
- int columnIndex = getCurrentColumnIndex();
- int i;
-
- if (getNameId() == FO_TABLE_ROW) {
-
- TableRow row = (TableRow) this;
-
- for (i = colSpan;
- --i >= 0 || row.pendingSpans.size() < cell.getColumnNumber();) {
- row.pendingSpans.add(null);
- }
-
- /* if the current cell spans more than one row,
- * update pending span list for the next row
- */
- if (rowSpan > 1) {
- for (i = colSpan; --i >= 0;) {
- row.pendingSpans.set(columnIndex - 1 + i,
- new PendingSpan(rowSpan));
- }
- }
- } else {
-
- TableBody body = (TableBody) this;
-
- /* if body.firstRow is still true, and :
- * a) the cell starts a row,
- * b) there was a previous cell
- * c) that previous cell didn't explicitly end the previous row
- * => set firstRow flag to false
- */
- if (body.firstRow && cell.startsRow()) {
- if (!body.previousCellEndedRow()) {
- body.firstRow = false;
- }
- }
-
- /* pendingSpans not initialized for the first row...
- */
- if (body.firstRow) {
- for (i = colSpan;
- --i >= 0|| body.pendingSpans.size() < cell.getColumnNumber();) {
- body.pendingSpans.add(null);
- }
- }
-
- /* if the current cell spans more than one row,
- * update pending span list for the next row
- */
- if (rowSpan > 1) {
- for (i = colSpan; --i >= 0;) {
- body.pendingSpans.set(columnIndex - 1 + i,
- new PendingSpan(rowSpan));
- }
- }
- }
-
- /* flag column indices used by this cell,
- * take into account that possibly not all column-numbers
- * are used by columns in the parent table (if any),
- * so a cell spanning three columns, might actually
- * take up more than three columnIndices...
- */
- int startIndex = columnIndex - 1;
- int endIndex = startIndex + colSpan;
- if (getTable().columns != null) {
- List cols = getTable().columns;
- int tmpIndex = endIndex;
- for (i = startIndex; i <= tmpIndex; ++i) {
- if (i < cols.size() && cols.get(i) == null) {
- endIndex++;
- }
- }
- }
- flagColumnIndices(startIndex, endIndex);
- if (getNameId() != FO_TABLE_ROW && cell.endsRow()) {
- ((TableBody) this).firstRow = false;
- ((TableBody) this).resetColumnIndex();
- }
- }
/**
*
diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java
index 47ce543db..b6feeabba 100644
--- a/src/java/org/apache/fop/fo/flow/TableRow.java
+++ b/src/java/org/apache/fop/fo/flow/TableRow.java
@@ -37,7 +37,7 @@ import org.apache.fop.fo.properties.LengthRangeProperty;
/**
* Class modelling the fo:table-row object.
*/
-public class TableRow extends TableFObj {
+public class TableRow extends TableCellContainer {
// The value of properties relevant for fo:table-row.
private LengthRangeProperty blockProgressionDimension;
private CommonBorderPaddingBackground commonBorderPaddingBackground;
@@ -99,34 +99,10 @@ public class TableRow extends TableFObj {
*/
protected void addChildNode(FONode child) throws FOPException {
if (!inMarker()) {
- Table t = getTable();
TableBody body = (TableBody) getParent();
if (body.isFirst(this)) {
TableCell cell = (TableCell) child;
- int colNr = cell.getColumnNumber();
- int colSpan = cell.getNumberColumnsSpanned();
- Length colWidth = null;
-
- if (cell.getWidth().getEnum() != EN_AUTO
- && colSpan == 1) {
- colWidth = cell.getWidth();
- }
-
- for (int i = colNr; i < colNr + colSpan; ++i) {
- if (t.columns.size() < i
- || t.columns.get(i - 1) == null) {
- t.addDefaultColumn(colWidth,
- i == colNr
- ? cell.getColumnNumber()
- : 0);
- } else {
- TableColumn col = (TableColumn) t.columns.get(i - 1);
- if (!col.isDefaultColumn()
- && colWidth != null) {
- col.setColumnWidth(colWidth);
- }
- }
- }
+ addTableCellChild(cell);
}
}
super.addChildNode(child);