]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Made the columns field in Table private, and created suitable accessors to it
authorVincent Hennebert <vhennebert@apache.org>
Fri, 26 Oct 2007 11:20:59 +0000 (11:20 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Fri, 26 Oct 2007 11:20:59 +0000 (11:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@588604 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/Table.java
src/java/org/apache/fop/fo/flow/TableBody.java
src/java/org/apache/fop/fo/flow/TableCellContainer.java

index e752c5fbedf2a749e72ed674805facae03bb201b..e8f60701235f101d3a5011561d843f750f3879ba 100644 (file)
@@ -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;
         }
index 44369d89977a7da55f5960d3868001f02ae99993..cef5c78a1f263a227c48288646dfdfd9e35c8a57 100644 (file)
@@ -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++;
         }
     }
 
index f19102e956ca813497afe83b37d7cd3a5fea8b3e..9fa602a190a217b3ba723f574d9f366e42dd81ad 100644 (file)
@@ -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);