diff options
author | Vincent Hennebert <vhennebert@apache.org> | 2007-10-26 11:20:59 +0000 |
---|---|---|
committer | Vincent Hennebert <vhennebert@apache.org> | 2007-10-26 11:20:59 +0000 |
commit | d90b57d62d350299abdaed81d09cb6696074db87 (patch) | |
tree | 94b38ba72d1b4c52481a8ee27963261f9726b1fa /src | |
parent | 6929a1442cceee9799c0fe2a52f437be5aea5004 (diff) | |
download | xmlgraphics-fop-d90b57d62d350299abdaed81d09cb6696074db87.tar.gz xmlgraphics-fop-d90b57d62d350299abdaed81d09cb6696074db87.zip |
Made the columns field in Table private, and created suitable accessors to it
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@588604 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/fo/flow/Table.java | 22 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/TableBody.java | 32 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/flow/TableCellContainer.java | 18 |
3 files changed, 41 insertions, 31 deletions
diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java index e752c5fbe..e8f607012 100644 --- a/src/java/org/apache/fop/fo/flow/Table.java +++ b/src/java/org/apache/fop/fo/flow/Table.java @@ -71,7 +71,7 @@ public class Table extends TableFObj { private Length orphanContentLimit; /** collection of columns in this table */ - protected List columns = new ArrayList(); + private List columns = new ArrayList(); /** helper variables for implicit column-numbering */ private int columnIndex = 1; @@ -341,6 +341,24 @@ public class Table extends TableFObj { return columns; } + /** + * Returns the column at the given index, if any. + * + * @param index index of the column to be retrieved, 0-based + * @return the corresponding column, or null if their is no column at the given index + */ + TableColumn getColumn(int index) { + if (index >= columns.size()) { + return null; + } else { + return (TableColumn) columns.get(index); + } + } + + int getNumberOfColumns() { + return columns.size(); + } + /** @return the body for the table-header. */ public TableBody getTableHeader() { return tableHeader; @@ -509,7 +527,7 @@ public class Table extends TableFObj { FObj fobj = (FObj) super.clone(parent, removeChildren); if (removeChildren) { Table t = (Table) fobj; - t.columns = null; + t.columns = new ArrayList(); t.tableHeader = null; t.tableFooter = null; } diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index 44369d899..cef5c78a1 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -82,14 +82,12 @@ public class TableBody extends TableCellContainer { Attributes attlist, PropertyList pList) throws FOPException { if (!inMarker()) { - if (getTable().columns != null) { - int cap = getTable().columns.size(); - pendingSpans = new java.util.ArrayList(cap); - usedColumnIndices = new java.util.BitSet(cap); - } else { - pendingSpans = new java.util.ArrayList(); - usedColumnIndices = new java.util.BitSet(); + int cap = getTable().getNumberOfColumns(); + if (cap == 0) { + cap = 10; // Default value for ArrayList } + pendingSpans = new java.util.ArrayList(cap); + usedColumnIndices = new java.util.BitSet(cap); setNextColumnIndex(); } super.processNode(elementName, locator, attlist, pList); @@ -223,14 +221,14 @@ public class TableBody extends TableCellContainer { if (child.getNameId() == FO_TABLE_ROW) { pendingSpans = ((TableRow) child).pendingSpans; } else if (pendingSpans == null) { - if (getTable().columns != null) { - List tableCols = getTable().columns; - pendingSpans = new java.util.ArrayList(tableCols.size()); - for (int i = tableCols.size(); --i >= 0;) { + int colNumber = getTable().getNumberOfColumns(); + if (colNumber == 0) { + pendingSpans = new java.util.ArrayList(); + } else { + pendingSpans = new java.util.ArrayList(colNumber); + for (int i = colNumber; --i >= 0;) { pendingSpans.add(null); } - } else { - pendingSpans = new java.util.ArrayList(); } } } @@ -295,11 +293,9 @@ public class TableBody extends TableCellContainer { //the index is not assigned to any //column, increment further until the next //index occupied by a column... - if (getTable().columns != null) { - while (columnIndex <= getTable().columns.size() - && !getTable().isColumnNumberUsed(columnIndex) ) { - columnIndex++; - } + while (columnIndex <= getTable().getNumberOfColumns() + && !getTable().isColumnNumberUsed(columnIndex) ) { + columnIndex++; } } diff --git a/src/java/org/apache/fop/fo/flow/TableCellContainer.java b/src/java/org/apache/fop/fo/flow/TableCellContainer.java index f19102e95..9fa602a19 100644 --- a/src/java/org/apache/fop/fo/flow/TableCellContainer.java +++ b/src/java/org/apache/fop/fo/flow/TableCellContainer.java @@ -46,15 +46,13 @@ public abstract class TableCellContainer extends TableFObj { } for (int i = colNr; i < colNr + colSpan; ++i) { - if (t.columns.size() < i - || t.columns.get(i - 1) == null) { + TableColumn col = t.getColumn(i - 1); + if (col == 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); @@ -142,13 +140,11 @@ public abstract class TableCellContainer extends TableFObj { */ 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++; - } + List cols = getTable().getColumns(); + int tmpIndex = endIndex; + for (i = startIndex; i <= tmpIndex; ++i) { + if (i < cols.size() && cols.get(i) == null) { + endIndex++; } } flagColumnIndices(startIndex, endIndex); |