]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Moved *GridUnit from layoutmgr/table to fo/flow/table
authorVincent Hennebert <vhennebert@apache.org>
Tue, 13 Nov 2007 16:50:09 +0000 (16:50 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Tue, 13 Nov 2007 16:50:09 +0000 (16:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594578 13f79535-47bb-0310-9956-ffa450edef68

19 files changed:
src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java
src/java/org/apache/fop/fo/flow/table/EmptyGridUnit.java [new file with mode: 0644]
src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java
src/java/org/apache/fop/fo/flow/table/GridUnit.java [new file with mode: 0644]
src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java [new file with mode: 0644]
src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java
src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
src/java/org/apache/fop/layoutmgr/table/CollapsingBorderModel.java
src/java/org/apache/fop/layoutmgr/table/EffRow.java
src/java/org/apache/fop/layoutmgr/table/EmptyGridUnit.java [deleted file]
src/java/org/apache/fop/layoutmgr/table/GridUnit.java [deleted file]
src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java
src/java/org/apache/fop/layoutmgr/table/PrimaryGridUnit.java [deleted file]
src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/RowPainter.java
src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java
src/java/org/apache/fop/layoutmgr/table/TableStepper.java

index 732acb6be0a8b7c58818ac54b513a0d867ca6094..c4f7f9a7870dc2a7c27c7eefabb8151c45699233 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.layoutmgr.table.GridUnit;
 
 /**
  * A class that implements the border-collapsing model.
diff --git a/src/java/org/apache/fop/fo/flow/table/EmptyGridUnit.java b/src/java/org/apache/fop/fo/flow/table/EmptyGridUnit.java
new file mode 100644 (file)
index 0000000..bbed8a9
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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.table;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
+
+/**
+ * GridUnit subclass for empty grid units.
+ */
+public class EmptyGridUnit extends GridUnit {
+
+    private TableRow row;
+    private TableBody body;
+
+    /**
+     * @param table the containing table
+     * @param startRow index of the row this grid unit belongs to, 0-based
+     * @param startCol column index, 0-based
+     */
+    public EmptyGridUnit(Table table, int startRow, int startCol) {
+        super(table, table.getColumn(startCol), startCol, 0, 0);
+    }
+
+    /** {@inheritDoc} */
+    protected void setBorder(int side) {
+        resolvedBorders[side] = new BorderSpecification(
+                new CommonBorderPaddingBackground.BorderInfo(Constants.EN_NONE, null, null),
+                Constants.FO_TABLE_CELL);
+    }
+
+    /** {@inheritDoc} */
+    public PrimaryGridUnit getPrimary() {
+        throw new UnsupportedOperationException();
+//        return this; TODO
+    }
+
+    /** {@inheritDoc} */
+    public boolean isPrimary() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public TableBody getBody() {
+        return this.body;
+    }
+
+    /** {@inheritDoc} */
+    public TableRow getRow() {
+        return this.row;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isLastGridUnitColSpan() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isLastGridUnitRowSpan() {
+        return true;
+    }
+}
index 602ae84a68507b8ebb24021c4da155e9752e65b3..0b10ebe18d91e9377931e16f090fffa8c841a7db 100644 (file)
@@ -24,9 +24,6 @@ import java.util.List;
 import java.util.ListIterator;
 
 import org.apache.fop.fo.ValidationException;
-import org.apache.fop.layoutmgr.table.EmptyGridUnit;
-import org.apache.fop.layoutmgr.table.GridUnit;
-import org.apache.fop.layoutmgr.table.PrimaryGridUnit;
 
 
 /**
diff --git a/src/java/org/apache/fop/fo/flow/table/GridUnit.java b/src/java/org/apache/fop/fo/flow/table/GridUnit.java
new file mode 100644 (file)
index 0000000..ff91ae8
--- /dev/null
@@ -0,0 +1,427 @@
+/*
+ * 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.table;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
+import org.apache.fop.layoutmgr.table.CollapsingBorderModel;
+
+/**
+ * This class represents one grid unit inside a table.
+ */
+public class GridUnit {
+
+    private static Log log = LogFactory.getLog(GridUnit.class);
+
+    /** Indicates that the grid unit is in the first column. */
+    public static final int IN_FIRST_COLUMN = 0;
+
+    /** Indicates that the grid unit is in the last column. */
+    public static final int IN_LAST_COLUMN = 1;
+
+    /** Indicates that the grid unit is in the first row of the table. */
+    public static final int FIRST_IN_TABLE = 2;
+
+    /**
+     * Indicates that the grid unit is in the first row of the table part (header, footer,
+     * body).
+     */
+    public static final int FIRST_IN_PART = 3;
+
+    /**
+     * Indicates that the grid unit is in the last row of the table part (header, footer,
+     * body).
+     */
+    public static final int LAST_IN_PART = 4;
+
+    /** Indicates that the grid unit is in the last row of the table. */
+    public static final int LAST_IN_TABLE = 5;
+
+    /** Indicates that the primary grid unit has a pending keep-with-next. */
+    public static final int KEEP_WITH_NEXT_PENDING = 6;
+
+    /** Indicates that the primary grid unit has a pending keep-with-previous. */
+    public static final int KEEP_WITH_PREVIOUS_PENDING = 7;
+
+    /** Primary grid unit */
+    private PrimaryGridUnit primary;
+
+    /** Table cell which occupies this grid unit */
+    protected TableCell cell;
+
+    /** Table row which occupies this grid unit (may be null) */
+    private TableRow row;
+
+    /** Table column that this grid unit belongs to */
+    private TableColumn column;
+
+    /** start index of grid unit within row in column direction */
+    private int startCol;
+
+    /** index of grid unit within cell in column direction */
+    private int colSpanIndex;
+
+    /** index of grid unit within cell in row direction */
+    private int rowSpanIndex;
+
+    /** effective borders for a cell slot */
+    private CommonBorderPaddingBackground effectiveBorders;
+
+    /** flags for the grid unit */
+    private byte flags = 0;
+
+    protected BorderSpecification[] resolvedBorders;
+
+    private CollapsingBorderModel collapsingBorderModel;
+
+    /**
+     * Creates a new grid unit.
+     * 
+     * @param table the containing table
+     * @param column table column this grid unit belongs to
+     * @param startCol index of the column this grid unit belongs to
+     * @param colSpanIndex index of this grid unit in the span, in column direction
+     * @param rowSpanIndex index of this grid unit in the span, in row direction
+     */
+    protected GridUnit(Table table, TableColumn column, int startCol, int colSpanIndex,
+            int rowSpanIndex) {
+        this(column, startCol, colSpanIndex, rowSpanIndex);
+        setBorders(table);
+    }
+
+    /**
+     * Creates a new grid unit.
+     * 
+     * @param cell table cell which occupies this grid unit
+     * @param column table column this grid unit belongs to
+     * @param startCol index of the column this grid unit belongs to
+     * @param colSpanIndex index of this grid unit in the span, in column direction
+     * @param rowSpanIndex index of this grid unit in the span, in row direction
+     */
+    protected GridUnit(TableCell cell, TableColumn column, int startCol, int colSpanIndex,
+            int rowSpanIndex) {
+        this(column, startCol, colSpanIndex, rowSpanIndex);
+        this.cell = cell;
+        setBorders(cell.getTable());
+    }
+
+    /**
+     * Creates a new grid unit.
+     * 
+     * @param primary the before-start grid unit of the cell containing this grid unit
+     * @param column table column this grid unit belongs to
+     * @param startCol index of the column this grid unit belongs to
+     * @param colSpanIndex index of this grid unit in the span, in column direction
+     * @param rowSpanIndex index of this grid unit in the span, in row direction
+     */
+    public GridUnit(PrimaryGridUnit primary, TableColumn column, int startCol, int colSpanIndex,
+            int rowSpanIndex) {
+        this(primary.getCell(), column, startCol, colSpanIndex, rowSpanIndex);
+        this.primary = primary;
+    }
+
+    private GridUnit(TableColumn column, int startCol, int colSpanIndex, int rowSpanIndex) {
+        this.column = column;
+        this.startCol = startCol;
+        this.colSpanIndex = colSpanIndex;
+        this.rowSpanIndex = rowSpanIndex;
+    }
+
+    private void setBorders(Table table/*TODO*/) {
+        if (table.isSeparateBorderModel()) {
+            assignBorderForSeparateBorderModel();
+        } else {
+            resolvedBorders = new BorderSpecification[4];
+            collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
+                    .getBorderCollapse());
+            if (rowSpanIndex == 0) {
+                setBorder(CommonBorderPaddingBackground.BEFORE);
+            }
+            if (isLastGridUnitRowSpan()) {
+                setBorder(CommonBorderPaddingBackground.AFTER);
+            }
+            if (colSpanIndex == 0) {
+                setBorder(CommonBorderPaddingBackground.START);
+            }
+            if (isLastGridUnitColSpan()) {
+                setBorder(CommonBorderPaddingBackground.END);
+            }
+        }
+    }
+
+    protected void setBorder(int side) {
+        resolvedBorders[side] = cell.resolvedBorders[side];
+    }
+
+    public TableCell getCell() {
+        return cell;
+    }
+
+    public TableColumn getColumn() {
+        return column;
+    }
+
+    public TableRow getRow() {
+        if (row != null) {
+            return row;
+        } else if (getCell().getParent() instanceof TableRow) {
+            return (TableRow) getCell().getParent();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Sets the table-row FO, if applicable.
+     * 
+     * @param row the table-row FO
+     */
+    public void setRow(TableRow row) {
+        this.row = row;
+    }
+
+    public TableBody getBody() {
+        FONode node = getCell();
+        while (node != null && !(node instanceof TableBody)) {
+            node = node.getParent();
+        }
+        return (TableBody) node;
+    }
+
+    /**
+     * Returns the before-start grid unit of the cell containing this grid unit.
+     * 
+     * @return the before-start grid unit of the cell containing this grid unit.
+     */
+    public PrimaryGridUnit getPrimary() {
+        return primary;
+    }
+
+    /**
+     * Is this grid unit the before-start grid unit of the cell?
+     * 
+     * @return true if this grid unit is the before-start grid unit of the cell
+     */
+    public boolean isPrimary() {
+        return false;
+    }
+
+    /**
+     * Does this grid unit belong to an empty cell?
+     * 
+     * @return true if this grid unit belongs to an empty cell
+     */
+    public boolean isEmpty() {
+        return cell == null;
+    }
+
+    public int getStartCol() {
+        return startCol;
+    }
+
+    /** @return true if the grid unit is the last in column spanning direction */
+    public boolean isLastGridUnitColSpan() {
+        return (colSpanIndex == cell.getNumberColumnsSpanned() - 1);
+    }
+
+    /** @return true if the grid unit is the last in row spanning direction */
+    public boolean isLastGridUnitRowSpan() {
+        return (rowSpanIndex == cell.getNumberRowsSpanned() - 1);
+    }
+
+    /**
+     * @return the index of the grid unit inside a cell in row direction
+     */
+    public int getRowSpanIndex() {
+        return rowSpanIndex;
+    }
+
+    /**
+     * @return the index of the grid unit inside a cell in column direction
+     */
+    public int getColSpanIndex() {
+        return colSpanIndex;
+    }
+
+    /**
+     * Returns a BorderInfo instance for a side of the currently applicable cell before
+     * border resolution (i.e. the value from the FO). A return value of null indicates an
+     * empty cell. See CollapsingBorderModel(EyeCatching) where this method is used.
+     * 
+     * @param side for which side to return the BorderInfo
+     * @return the requested BorderInfo instance or null if the grid unit is an empty cell
+     */
+    public BorderInfo getOriginalBorderInfoForCell(int side) {
+        if (cell != null) {
+            return cell.getCommonBorderPaddingBackground().getBorderInfo(side);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * @return the resolved normal borders for this grid unit
+     */
+    public CommonBorderPaddingBackground getBorders() {
+        // TODO
+        if (effectiveBorders == null) {
+            effectiveBorders = new CommonBorderPaddingBackground();
+            setBorderInfo(CommonBorderPaddingBackground.BEFORE);
+            setBorderInfo(CommonBorderPaddingBackground.AFTER);
+            setBorderInfo(CommonBorderPaddingBackground.START);
+            setBorderInfo(CommonBorderPaddingBackground.END);
+            if (cell != null) {
+                effectiveBorders.setPadding(cell.getCommonBorderPaddingBackground());
+            }
+            if (log.isDebugEnabled()) {
+                log.debug(this + " resolved borders: " + "before="
+                        + effectiveBorders.getBorderBeforeWidth(false) + ", " + "after="
+                        + effectiveBorders.getBorderAfterWidth(false) + ", " + "start="
+                        + effectiveBorders.getBorderStartWidth(false) + ", " + "end="
+                        + effectiveBorders.getBorderEndWidth(false));
+            }
+        }
+        return effectiveBorders;
+    }
+
+    private void setBorderInfo(int side) {
+        if (resolvedBorders[side] != null) {
+            effectiveBorders.setBorderInfo(resolvedBorders[side].getBorderInfo(), side);
+        }
+    }
+
+    /**
+     * @return true if the grid unit has any borders.
+     */
+    public boolean hasBorders() {
+        return (getBorders() != null) && getBorders().hasBorder();
+    }
+
+    /**
+     * Assigns the borders from the given cell to this cell info. Used in case of separate
+     * border model.
+     */
+    public void assignBorderForSeparateBorderModel() {
+        if (cell != null) {
+            effectiveBorders = cell.getCommonBorderPaddingBackground();
+        }
+    }
+
+    /**
+     * Resolve collapsing borders for the given cell. Used in case of the collapsing
+     * border model.
+     * 
+     * @param other neighbouring grid unit
+     * @param side the side to resolve (one of
+     * CommonBorderPaddingBackground.BEFORE|AFTER|START|END)
+     */
+    public void resolveBorder(GridUnit other, int side) {
+        BorderSpecification resolvedBorder = collapsingBorderModel.determineWinner(
+                resolvedBorders[side], other.resolvedBorders[CollapsingBorderModel
+                        .getOtherSide(side)]);
+        if (resolvedBorder != null) {
+            this.resolvedBorders[side] = resolvedBorder;
+            other.resolvedBorders[CollapsingBorderModel.getOtherSide(side)] = resolvedBorder;
+        }
+    }
+
+    /**
+     * Resolves the border on the given side of this grid unit, comparing it against the
+     * same border of the given parent element.
+     * 
+     * @param side the side to resolve (one of
+     * CommonBorderPaddingBackground.BEFORE|AFTER|START|END)
+     * @param parent the parent element holding a competing border
+     */
+    public void resolveBorder(int side, TableFObj parent) {
+        resolvedBorders[side] = collapsingBorderModel.determineWinner(resolvedBorders[side],
+                parent.resolvedBorders[side]);
+    }
+
+    /**
+     * Returns a flag for this GridUnit.
+     * 
+     * @param which the requested flag
+     * @return the value of the flag
+     */
+    public boolean getFlag(int which) {
+        return (flags & (1 << which)) != 0;
+    }
+
+    /**
+     * Sets a flag on a GridUnit.
+     * 
+     * @param which the flag to set
+     * @param value the new value for the flag
+     */
+    public void setFlag(int which, boolean value) {
+        if (value) {
+            flags |= (1 << which); // set flag
+        } else {
+            flags &= ~(1 << which); // clear flag
+        }
+    }
+
+    /**
+     * Sets the given flag on this grid unit.
+     * 
+     * @param which the flag to set
+     */
+    public void setFlag(int which) {
+        setFlag(which, true);
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        if (isEmpty()) {
+            buffer.append("EMPTY");
+        } else if (isPrimary()) {
+            buffer.append("Primary");
+        }
+        buffer.append("GridUnit:");
+        if (colSpanIndex > 0) {
+            buffer.append(" colSpan=").append(colSpanIndex);
+            if (isLastGridUnitColSpan()) {
+                buffer.append("(last)");
+            }
+        }
+        if (rowSpanIndex > 0) {
+            buffer.append(" rowSpan=").append(rowSpanIndex);
+            if (isLastGridUnitRowSpan()) {
+                buffer.append("(last)");
+            }
+        }
+        buffer.append(" startCol=").append(startCol);
+        if (!isPrimary() && getPrimary() != null) {
+            buffer.append(" primary=").append(getPrimary().getStartRow());
+            buffer.append("/").append(getPrimary().getStartCol());
+            if (getPrimary().getCell() != null) {
+                buffer.append(" id=" + getPrimary().getCell().getId());
+            }
+        }
+        buffer.append(" flags=").append(Integer.toBinaryString(flags));
+        return buffer.toString();
+    }
+
+}
diff --git a/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java b/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java
new file mode 100644 (file)
index 0000000..5dbc911
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+ * 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.table;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fop.layoutmgr.table.TableCellLayoutManager;
+
+/**
+ * This class represents a primary grid unit of a spanned cell. This is the "before-start"
+ * (top-left, usually) grid unit of the span.
+ */
+public class PrimaryGridUnit extends GridUnit {
+
+    private static Log log = LogFactory.getLog(PrimaryGridUnit.class);
+
+    /** Cell layout manager. */
+    private TableCellLayoutManager cellLM;
+    /** List of Knuth elements representing the contents of the cell. */
+    private LinkedList elements;
+    /** Index of row where this cell starts */
+    private int startRow;
+    /** Links to the spanned grid units. (List of GridUnit arrays, one array represents a row) */
+    private List rows;
+    /** The calculated size of the cell's content. (cached value) */
+    private int contentLength = -1;
+
+    /**
+     * Creates a new primary grid unit.
+     *
+     * @param cell table cell which occupies this grid unit
+     * @param column table column this grid unit belongs to
+     * @param startCol index of the column this grid unit belongs to, zero-based
+     * @param startRow index of the row this grid unit belongs to, zero-based
+     */
+    public PrimaryGridUnit(TableCell cell, TableColumn column, int startCol, int startRow) {
+        super(cell, column, startCol, 0, 0);
+        this.startRow = startRow;
+        log.trace("PrimaryGridUnit created, row " + startRow + " col " + startCol);
+    }
+
+    public TableCellLayoutManager getCellLM() {
+        assert cellLM != null;
+        return cellLM;
+    }
+
+    /** {@inheritDoc} */
+    public PrimaryGridUnit getPrimary() {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    public boolean isPrimary() {
+        return true;
+    }
+
+    /**
+     * Sets the Knuth elements for the table cell containing this grid unit.
+     *
+     * @param elements a list of ListElement (?)
+     */
+    public void setElements(LinkedList elements) {
+        this.elements = elements;
+    }
+
+    public LinkedList getElements() {
+        return this.elements;
+    }
+
+    /**
+     * @return half the maximum before border width of this cell.
+     */
+    public int getHalfMaxBeforeBorderWidth() {
+        int value = 0;
+        if (getRows() != null) {
+            int before = 0;
+            //first row for before borders
+            GridUnit[] row = (GridUnit[])getRows().get(0);
+            for (int i = 0; i < row.length; i++) {
+                if (row[i].hasBorders()) {
+                    before = Math.max(before,
+                            row[i].getBorders().getBorderBeforeWidth(false));
+                }
+            }
+            value += before / 2;
+        } else {
+            if (hasBorders()) {
+                value += getBorders().getBorderBeforeWidth(false) / 2;
+            }
+        }
+        return value;
+    }
+
+    /**
+     * @return half the maximum after border width of this cell.
+     */
+    public int getHalfMaxAfterBorderWidth() {
+        int value = 0;
+        if (getRows() != null) {
+            //Last row for after borders
+            int after = 0;
+            GridUnit[] row = (GridUnit[])getRows().get(getRows().size() - 1);
+            for (int i = 0; i < row.length; i++) {
+                if (row[i].hasBorders()) {
+                    after = Math.max(after, row[i].getBorders().getBorderAfterWidth(false));
+                }
+            }
+            value += after / 2;
+        } else {
+            if (hasBorders()) {
+                value += getBorders().getBorderAfterWidth(false) / 2;
+            }
+        }
+        return value;
+    }
+
+    /**
+     * @return the sum of half the maximum before and after border
+     * widths of this cell.
+     */
+    public int getHalfMaxBorderWidth() {
+        return getHalfMaxBeforeBorderWidth() + getHalfMaxAfterBorderWidth();
+    }
+
+    /** @param value The length of the cell content to remember. */
+    public void setContentLength(int value) {
+        this.contentLength = value;
+    }
+
+    /** @return the length of the cell content. */
+    public int getContentLength() {
+        return contentLength;
+    }
+
+    /** @return true if cell/row has an explicit BPD/height */
+    public boolean hasBPD() {
+        if (!getCell().getBlockProgressionDimension().getOptimum(null).isAuto()) {
+            return true;
+        }
+        if (getRow() != null
+                && !getRow().getBlockProgressionDimension().getOptimum(null).isAuto()) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the grid units belonging to the same span as this one.
+     *
+     * @return a list of GridUnit[], each array corresponds to a row
+     */
+    public List getRows() {
+        return this.rows;
+    }
+
+    public void addRow(GridUnit[] row) {
+        if (rows == null) {
+            rows = new java.util.ArrayList();
+        }
+        rows.add(row);
+    }
+
+    /**
+     * Returns the index of the row this grid unit belongs to.
+     *
+     * @return the index of the row this grid unit belongs to.
+     */
+    public int getStartRow() {
+        return this.startRow;
+    }
+
+    /**
+     * Returns the widths of the start- and end-borders of the span this grid unit belongs
+     * to.
+     *
+     * @return a two-element array containing the widths of the start-border then the
+     * end-border
+     */
+    public int[] getStartEndBorderWidths() {
+        int[] widths = new int[2];
+        if (rows == null) {
+            widths[0] = getBorders().getBorderStartWidth(false);
+            widths[1] = getBorders().getBorderEndWidth(false);
+        } else {
+            for (int i = 0; i < rows.size(); i++) {
+                GridUnit[] gridUnits = (GridUnit[])rows.get(i);
+                widths[0] = Math.max(widths[0],
+                        (gridUnits[0]).
+                            getBorders().getBorderStartWidth(false));
+                widths[1] = Math.max(widths[1],
+                        (gridUnits[gridUnits.length - 1]).
+                            getBorders().getBorderEndWidth(false));
+            }
+        }
+        return widths;
+    }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        StringBuffer sb = new StringBuffer(super.toString());
+        sb.append(" startRow=").append(startRow);
+        return sb.toString();
+    }
+
+    /** @return true if this cell spans over more than one grid unit. */
+    public boolean hasSpanning() {
+        return (getCell().getNumberColumnsSpanned() > 1)
+            || (getCell().getNumberRowsSpanned() > 1);
+    }
+
+    /**
+     * Creates a cellLM for the corresponding table-cell. A new one must be created
+     * for each new static-content (TODO).
+     */
+    public void createCellLM() {
+        cellLM = new TableCellLayoutManager(cell, this);
+    }
+
+}
index 7f09f7d4654f35b99d568f2b8dad2bd32239f0da..1e1f9b8944a65eaf79215625e39ed3ddfdcc87c4 100644 (file)
@@ -20,7 +20,6 @@
 package org.apache.fop.fo.flow.table;
 
 import org.apache.fop.fo.ValidationException;
-import org.apache.fop.layoutmgr.table.GridUnit;
 
 /**
  * A class that creates groups of rows belonging to a same set of spans. The first row of
index 99fd12483f894b09993ccb750ffea7c7836a4725..d9268dcb538c6d6feda60f6b2a4bd1541630c091 100644 (file)
@@ -22,6 +22,8 @@ package org.apache.fop.layoutmgr.table;
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
index 5cfe5e382d77d2c2f5513fe0da769083909564fa..a0bff3b5e5f069f1b0aea511723cff7c7b42775e 100644 (file)
@@ -76,7 +76,7 @@ public abstract class CollapsingBorderModel {
      * @param side the side on the current cell
      * @return the adjacent side on the neighbouring cell
      */
-    static int getOtherSide(int side) {
+    public/*TODO*/ static int getOtherSide(int side) {
         switch (side) {
             case CommonBorderPaddingBackground.BEFORE:
                 return CommonBorderPaddingBackground.AFTER;
index fe57809e90f359551a9b37bed55dcc391d6a4a67..fa39202d65f3828274d886562db075b47862198b 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.fop.layoutmgr.table;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.traits.MinOptMax;
 
diff --git a/src/java/org/apache/fop/layoutmgr/table/EmptyGridUnit.java b/src/java/org/apache/fop/layoutmgr/table/EmptyGridUnit.java
deleted file mode 100644 (file)
index 50500c4..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.layoutmgr.table;
-
-import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.flow.table.BorderSpecification;
-import org.apache.fop.fo.flow.table.Table;
-import org.apache.fop.fo.flow.table.TableBody;
-import org.apache.fop.fo.flow.table.TableRow;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-
-/**
- * GridUnit subclass for empty grid units.
- */
-public class EmptyGridUnit extends GridUnit {
-
-    private TableRow row;
-    private TableBody body;
-
-    /**
-     * @param table the containing table
-     * @param startRow index of the row this grid unit belongs to, 0-based
-     * @param startCol column index, 0-based
-     */
-    public EmptyGridUnit(Table table, int startRow, int startCol) {
-        super(table, table.getColumn(startCol), startCol, 0, 0);
-    }
-
-    /** {@inheritDoc} */
-    protected void setBorder(int side) {
-        resolvedBorders[side] = new BorderSpecification(
-                new CommonBorderPaddingBackground.BorderInfo(Constants.EN_NONE, null, null),
-                Constants.FO_TABLE_CELL);
-    }
-
-    /** {@inheritDoc} */
-    public PrimaryGridUnit getPrimary() {
-        throw new UnsupportedOperationException();
-//        return this; TODO
-    }
-
-    /** {@inheritDoc} */
-    public boolean isPrimary() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    public TableBody getBody() {
-        return this.body;
-    }
-
-    /** {@inheritDoc} */
-    public TableRow getRow() {
-        return this.row;
-    }
-
-    /** {@inheritDoc} */
-    public boolean isLastGridUnitColSpan() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    public boolean isLastGridUnitRowSpan() {
-        return true;
-    }
-}
diff --git a/src/java/org/apache/fop/layoutmgr/table/GridUnit.java b/src/java/org/apache/fop/layoutmgr/table/GridUnit.java
deleted file mode 100644 (file)
index 7f71335..0000000
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * 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.layoutmgr.table;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.flow.table.BorderSpecification;
-import org.apache.fop.fo.flow.table.Table;
-import org.apache.fop.fo.flow.table.TableBody;
-import org.apache.fop.fo.flow.table.TableCell;
-import org.apache.fop.fo.flow.table.TableColumn;
-import org.apache.fop.fo.flow.table.TableFObj;
-import org.apache.fop.fo.flow.table.TableRow;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
-import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
-
-/**
- * This class represents one grid unit inside a table.
- */
-public class GridUnit {
-
-    private static Log log = LogFactory.getLog(GridUnit.class);
-
-    /** Indicates that the grid unit is in the first column. */
-    public static final int IN_FIRST_COLUMN = 0;
-
-    /** Indicates that the grid unit is in the last column. */
-    public static final int IN_LAST_COLUMN = 1;
-
-    /** Indicates that the grid unit is in the first row of the table. */
-    public static final int FIRST_IN_TABLE = 2;
-
-    /**
-     * Indicates that the grid unit is in the first row of the table part (header, footer,
-     * body).
-     */
-    public static final int FIRST_IN_PART = 3;
-
-    /**
-     * Indicates that the grid unit is in the last row of the table part (header, footer,
-     * body).
-     */
-    public static final int LAST_IN_PART = 4;
-
-    /** Indicates that the grid unit is in the last row of the table. */
-    public static final int LAST_IN_TABLE = 5;
-
-    /** Indicates that the primary grid unit has a pending keep-with-next. */
-    public static final int KEEP_WITH_NEXT_PENDING = 6;
-
-    /** Indicates that the primary grid unit has a pending keep-with-previous. */
-    public static final int KEEP_WITH_PREVIOUS_PENDING = 7;
-
-    /** Primary grid unit */
-    private PrimaryGridUnit primary;
-
-    /** Table cell which occupies this grid unit */
-    protected TableCell cell;
-
-    /** Table row which occupies this grid unit (may be null) */
-    private TableRow row;
-
-    /** Table column that this grid unit belongs to */
-    private TableColumn column;
-
-    /** start index of grid unit within row in column direction */
-    private int startCol;
-
-    /** index of grid unit within cell in column direction */
-    private int colSpanIndex;
-
-    /** index of grid unit within cell in row direction */
-    private int rowSpanIndex;
-
-    /** effective borders for a cell slot */
-    private CommonBorderPaddingBackground effectiveBorders;
-
-    /** flags for the grid unit */
-    private byte flags = 0;
-
-    protected BorderSpecification[] resolvedBorders;
-
-    private CollapsingBorderModel collapsingBorderModel;
-
-    /**
-     * Creates a new grid unit.
-     * 
-     * @param table the containing table
-     * @param column table column this grid unit belongs to
-     * @param startCol index of the column this grid unit belongs to
-     * @param colSpanIndex index of this grid unit in the span, in column direction
-     * @param rowSpanIndex index of this grid unit in the span, in row direction
-     */
-    protected GridUnit(Table table, TableColumn column, int startCol, int colSpanIndex,
-            int rowSpanIndex) {
-        this(column, startCol, colSpanIndex, rowSpanIndex);
-        setBorders(table);
-    }
-
-    /**
-     * Creates a new grid unit.
-     * 
-     * @param cell table cell which occupies this grid unit
-     * @param column table column this grid unit belongs to
-     * @param startCol index of the column this grid unit belongs to
-     * @param colSpanIndex index of this grid unit in the span, in column direction
-     * @param rowSpanIndex index of this grid unit in the span, in row direction
-     */
-    protected GridUnit(TableCell cell, TableColumn column, int startCol, int colSpanIndex,
-            int rowSpanIndex) {
-        this(column, startCol, colSpanIndex, rowSpanIndex);
-        this.cell = cell;
-        setBorders(cell.getTable());
-    }
-
-    /**
-     * Creates a new grid unit.
-     * 
-     * @param primary the before-start grid unit of the cell containing this grid unit
-     * @param column table column this grid unit belongs to
-     * @param startCol index of the column this grid unit belongs to
-     * @param colSpanIndex index of this grid unit in the span, in column direction
-     * @param rowSpanIndex index of this grid unit in the span, in row direction
-     */
-    public GridUnit(PrimaryGridUnit primary, TableColumn column, int startCol, int colSpanIndex,
-            int rowSpanIndex) {
-        this(primary.getCell(), column, startCol, colSpanIndex, rowSpanIndex);
-        this.primary = primary;
-    }
-
-    private GridUnit(TableColumn column, int startCol, int colSpanIndex, int rowSpanIndex) {
-        this.column = column;
-        this.startCol = startCol;
-        this.colSpanIndex = colSpanIndex;
-        this.rowSpanIndex = rowSpanIndex;
-    }
-
-    private void setBorders(Table table/*TODO*/) {
-        if (table.isSeparateBorderModel()) {
-            assignBorderForSeparateBorderModel();
-        } else {
-            resolvedBorders = new BorderSpecification[4];
-            collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
-                    .getBorderCollapse());
-            if (rowSpanIndex == 0) {
-                setBorder(CommonBorderPaddingBackground.BEFORE);
-            }
-            if (isLastGridUnitRowSpan()) {
-                setBorder(CommonBorderPaddingBackground.AFTER);
-            }
-            if (colSpanIndex == 0) {
-                setBorder(CommonBorderPaddingBackground.START);
-            }
-            if (isLastGridUnitColSpan()) {
-                setBorder(CommonBorderPaddingBackground.END);
-            }
-        }
-    }
-
-    protected void setBorder(int side) {
-        resolvedBorders[side] = cell.resolvedBorders[side];
-    }
-
-    public TableCell getCell() {
-        return cell;
-    }
-
-    public TableColumn getColumn() {
-        return column;
-    }
-
-    public TableRow getRow() {
-        if (row != null) {
-            return row;
-        } else if (getCell().getParent() instanceof TableRow) {
-            return (TableRow) getCell().getParent();
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Sets the table-row FO, if applicable.
-     * 
-     * @param row the table-row FO
-     */
-    public void setRow(TableRow row) {
-        this.row = row;
-    }
-
-    public TableBody getBody() {
-        FONode node = getCell();
-        while (node != null && !(node instanceof TableBody)) {
-            node = node.getParent();
-        }
-        return (TableBody) node;
-    }
-
-    /**
-     * Returns the before-start grid unit of the cell containing this grid unit.
-     * 
-     * @return the before-start grid unit of the cell containing this grid unit.
-     */
-    public PrimaryGridUnit getPrimary() {
-        return primary;
-    }
-
-    /**
-     * Is this grid unit the before-start grid unit of the cell?
-     * 
-     * @return true if this grid unit is the before-start grid unit of the cell
-     */
-    public boolean isPrimary() {
-        return false;
-    }
-
-    /**
-     * Does this grid unit belong to an empty cell?
-     * 
-     * @return true if this grid unit belongs to an empty cell
-     */
-    public boolean isEmpty() {
-        return cell == null;
-    }
-
-    public int getStartCol() {
-        return startCol;
-    }
-
-    /** @return true if the grid unit is the last in column spanning direction */
-    public boolean isLastGridUnitColSpan() {
-        return (colSpanIndex == cell.getNumberColumnsSpanned() - 1);
-    }
-
-    /** @return true if the grid unit is the last in row spanning direction */
-    public boolean isLastGridUnitRowSpan() {
-        return (rowSpanIndex == cell.getNumberRowsSpanned() - 1);
-    }
-
-    /**
-     * @return the index of the grid unit inside a cell in row direction
-     */
-    public int getRowSpanIndex() {
-        return rowSpanIndex;
-    }
-
-    /**
-     * @return the index of the grid unit inside a cell in column direction
-     */
-    public int getColSpanIndex() {
-        return colSpanIndex;
-    }
-
-    /**
-     * Returns a BorderInfo instance for a side of the currently applicable cell before
-     * border resolution (i.e. the value from the FO). A return value of null indicates an
-     * empty cell. See CollapsingBorderModel(EyeCatching) where this method is used.
-     * 
-     * @param side for which side to return the BorderInfo
-     * @return the requested BorderInfo instance or null if the grid unit is an empty cell
-     */
-    public BorderInfo getOriginalBorderInfoForCell(int side) {
-        if (cell != null) {
-            return cell.getCommonBorderPaddingBackground().getBorderInfo(side);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * @return the resolved normal borders for this grid unit
-     */
-    public CommonBorderPaddingBackground getBorders() {
-        // TODO
-        if (effectiveBorders == null) {
-            effectiveBorders = new CommonBorderPaddingBackground();
-            setBorderInfo(CommonBorderPaddingBackground.BEFORE);
-            setBorderInfo(CommonBorderPaddingBackground.AFTER);
-            setBorderInfo(CommonBorderPaddingBackground.START);
-            setBorderInfo(CommonBorderPaddingBackground.END);
-            if (cell != null) {
-                effectiveBorders.setPadding(cell.getCommonBorderPaddingBackground());
-            }
-            if (log.isDebugEnabled()) {
-                log.debug(this + " resolved borders: " + "before="
-                        + effectiveBorders.getBorderBeforeWidth(false) + ", " + "after="
-                        + effectiveBorders.getBorderAfterWidth(false) + ", " + "start="
-                        + effectiveBorders.getBorderStartWidth(false) + ", " + "end="
-                        + effectiveBorders.getBorderEndWidth(false));
-            }
-        }
-        return effectiveBorders;
-    }
-
-    private void setBorderInfo(int side) {
-        if (resolvedBorders[side] != null) {
-            effectiveBorders.setBorderInfo(resolvedBorders[side].getBorderInfo(), side);
-        }
-    }
-
-    /**
-     * @return true if the grid unit has any borders.
-     */
-    public boolean hasBorders() {
-        return (getBorders() != null) && getBorders().hasBorder();
-    }
-
-    /**
-     * Assigns the borders from the given cell to this cell info. Used in case of separate
-     * border model.
-     */
-    public void assignBorderForSeparateBorderModel() {
-        if (cell != null) {
-            effectiveBorders = cell.getCommonBorderPaddingBackground();
-        }
-    }
-
-    /**
-     * Resolve collapsing borders for the given cell. Used in case of the collapsing
-     * border model.
-     * 
-     * @param other neighbouring grid unit
-     * @param side the side to resolve (one of
-     * CommonBorderPaddingBackground.BEFORE|AFTER|START|END)
-     */
-    public void resolveBorder(GridUnit other, int side) {
-        BorderSpecification resolvedBorder = collapsingBorderModel.determineWinner(
-                resolvedBorders[side], other.resolvedBorders[CollapsingBorderModel
-                        .getOtherSide(side)]);
-        if (resolvedBorder != null) {
-            this.resolvedBorders[side] = resolvedBorder;
-            other.resolvedBorders[CollapsingBorderModel.getOtherSide(side)] = resolvedBorder;
-        }
-    }
-
-    /**
-     * Resolves the border on the given side of this grid unit, comparing it against the
-     * same border of the given parent element.
-     * 
-     * @param side the side to resolve (one of
-     * CommonBorderPaddingBackground.BEFORE|AFTER|START|END)
-     * @param parent the parent element holding a competing border
-     */
-    public void resolveBorder(int side, TableFObj parent) {
-        resolvedBorders[side] = collapsingBorderModel.determineWinner(resolvedBorders[side],
-                parent.resolvedBorders[side]);
-    }
-
-    /**
-     * Returns a flag for this GridUnit.
-     * 
-     * @param which the requested flag
-     * @return the value of the flag
-     */
-    public boolean getFlag(int which) {
-        return (flags & (1 << which)) != 0;
-    }
-
-    /**
-     * Sets a flag on a GridUnit.
-     * 
-     * @param which the flag to set
-     * @param value the new value for the flag
-     */
-    public void setFlag(int which, boolean value) {
-        if (value) {
-            flags |= (1 << which); // set flag
-        } else {
-            flags &= ~(1 << which); // clear flag
-        }
-    }
-
-    /**
-     * Sets the given flag on this grid unit.
-     * 
-     * @param which the flag to set
-     */
-    public void setFlag(int which) {
-        setFlag(which, true);
-    }
-
-    /** {@inheritDoc} */
-    public String toString() {
-        StringBuffer buffer = new StringBuffer();
-        if (isEmpty()) {
-            buffer.append("EMPTY");
-        } else if (isPrimary()) {
-            buffer.append("Primary");
-        }
-        buffer.append("GridUnit:");
-        if (colSpanIndex > 0) {
-            buffer.append(" colSpan=").append(colSpanIndex);
-            if (isLastGridUnitColSpan()) {
-                buffer.append("(last)");
-            }
-        }
-        if (rowSpanIndex > 0) {
-            buffer.append(" rowSpan=").append(rowSpanIndex);
-            if (isLastGridUnitRowSpan()) {
-                buffer.append("(last)");
-            }
-        }
-        buffer.append(" startCol=").append(startCol);
-        if (!isPrimary() && getPrimary() != null) {
-            buffer.append(" primary=").append(getPrimary().getStartRow());
-            buffer.append("/").append(getPrimary().getStartCol());
-            if (getPrimary().getCell() != null) {
-                buffer.append(" id=" + getPrimary().getCell().getId());
-            }
-        }
-        buffer.append(" flags=").append(Integer.toBinaryString(flags));
-        return buffer.toString();
-    }
-
-}
index 28064b3e3ac72a6b205ddd0a683436952c984b29..e0cdfccf14125d07531d4d23be6f18313806fac8 100644 (file)
@@ -19,6 +19,9 @@
 
 package org.apache.fop.layoutmgr.table;
 
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
+
 /**
  * Represents a non-dividable part of a grid unit. Used by the table stepper.
  */
diff --git a/src/java/org/apache/fop/layoutmgr/table/PrimaryGridUnit.java b/src/java/org/apache/fop/layoutmgr/table/PrimaryGridUnit.java
deleted file mode 100644 (file)
index 34daf7d..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * 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.layoutmgr.table;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fop.fo.flow.table.TableCell;
-import org.apache.fop.fo.flow.table.TableColumn;
-
-/**
- * This class represents a primary grid unit of a spanned cell. This is the "before-start"
- * (top-left, usually) grid unit of the span.
- */
-public class PrimaryGridUnit extends GridUnit {
-
-    private static Log log = LogFactory.getLog(PrimaryGridUnit.class);
-
-    /** Cell layout manager. */
-    private TableCellLayoutManager cellLM;
-    /** List of Knuth elements representing the contents of the cell. */
-    private LinkedList elements;
-    /** Index of row where this cell starts */
-    private int startRow;
-    /** Links to the spanned grid units. (List of GridUnit arrays, one array represents a row) */
-    private List rows;
-    /** The calculated size of the cell's content. (cached value) */
-    private int contentLength = -1;
-
-    /**
-     * Creates a new primary grid unit.
-     *
-     * @param cell table cell which occupies this grid unit
-     * @param column table column this grid unit belongs to
-     * @param startCol index of the column this grid unit belongs to, zero-based
-     * @param startRow index of the row this grid unit belongs to, zero-based
-     */
-    public PrimaryGridUnit(TableCell cell, TableColumn column, int startCol, int startRow) {
-        super(cell, column, startCol, 0, 0);
-        this.startRow = startRow;
-        log.trace("PrimaryGridUnit created, row " + startRow + " col " + startCol);
-    }
-
-    public TableCellLayoutManager getCellLM() {
-        assert cellLM != null;
-        return cellLM;
-    }
-
-    /** {@inheritDoc} */
-    public PrimaryGridUnit getPrimary() {
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    public boolean isPrimary() {
-        return true;
-    }
-
-    /**
-     * Sets the Knuth elements for the table cell containing this grid unit.
-     *
-     * @param elements a list of ListElement (?)
-     */
-    public void setElements(LinkedList elements) {
-        this.elements = elements;
-    }
-
-    public LinkedList getElements() {
-        return this.elements;
-    }
-
-    /**
-     * @return half the maximum before border width of this cell.
-     */
-    public int getHalfMaxBeforeBorderWidth() {
-        int value = 0;
-        if (getRows() != null) {
-            int before = 0;
-            //first row for before borders
-            GridUnit[] row = (GridUnit[])getRows().get(0);
-            for (int i = 0; i < row.length; i++) {
-                if (row[i].hasBorders()) {
-                    before = Math.max(before,
-                            row[i].getBorders().getBorderBeforeWidth(false));
-                }
-            }
-            value += before / 2;
-        } else {
-            if (hasBorders()) {
-                value += getBorders().getBorderBeforeWidth(false) / 2;
-            }
-        }
-        return value;
-    }
-
-    /**
-     * @return half the maximum after border width of this cell.
-     */
-    public int getHalfMaxAfterBorderWidth() {
-        int value = 0;
-        if (getRows() != null) {
-            //Last row for after borders
-            int after = 0;
-            GridUnit[] row = (GridUnit[])getRows().get(getRows().size() - 1);
-            for (int i = 0; i < row.length; i++) {
-                if (row[i].hasBorders()) {
-                    after = Math.max(after, row[i].getBorders().getBorderAfterWidth(false));
-                }
-            }
-            value += after / 2;
-        } else {
-            if (hasBorders()) {
-                value += getBorders().getBorderAfterWidth(false) / 2;
-            }
-        }
-        return value;
-    }
-
-    /**
-     * @return the sum of half the maximum before and after border
-     * widths of this cell.
-     */
-    public int getHalfMaxBorderWidth() {
-        return getHalfMaxBeforeBorderWidth() + getHalfMaxAfterBorderWidth();
-    }
-
-    /** @param value The length of the cell content to remember. */
-    public void setContentLength(int value) {
-        this.contentLength = value;
-    }
-
-    /** @return the length of the cell content. */
-    public int getContentLength() {
-        return contentLength;
-    }
-
-    /** @return true if cell/row has an explicit BPD/height */
-    public boolean hasBPD() {
-        if (!getCell().getBlockProgressionDimension().getOptimum(null).isAuto()) {
-            return true;
-        }
-        if (getRow() != null
-                && !getRow().getBlockProgressionDimension().getOptimum(null).isAuto()) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Returns the grid units belonging to the same span as this one.
-     *
-     * @return a list of GridUnit[], each array corresponds to a row
-     */
-    public List getRows() {
-        return this.rows;
-    }
-
-    public void addRow(GridUnit[] row) {
-        if (rows == null) {
-            rows = new java.util.ArrayList();
-        }
-        rows.add(row);
-    }
-
-    /**
-     * Returns the index of the row this grid unit belongs to.
-     *
-     * @return the index of the row this grid unit belongs to.
-     */
-    public int getStartRow() {
-        return this.startRow;
-    }
-
-    /**
-     * Returns the widths of the start- and end-borders of the span this grid unit belongs
-     * to.
-     *
-     * @return a two-element array containing the widths of the start-border then the
-     * end-border
-     */
-    public int[] getStartEndBorderWidths() {
-        int[] widths = new int[2];
-        if (rows == null) {
-            widths[0] = getBorders().getBorderStartWidth(false);
-            widths[1] = getBorders().getBorderEndWidth(false);
-        } else {
-            for (int i = 0; i < rows.size(); i++) {
-                GridUnit[] gridUnits = (GridUnit[])rows.get(i);
-                widths[0] = Math.max(widths[0],
-                        (gridUnits[0]).
-                            getBorders().getBorderStartWidth(false));
-                widths[1] = Math.max(widths[1],
-                        (gridUnits[gridUnits.length - 1]).
-                            getBorders().getBorderEndWidth(false));
-            }
-        }
-        return widths;
-    }
-
-    /** {@inheritDoc} */
-    public String toString() {
-        StringBuffer sb = new StringBuffer(super.toString());
-        sb.append(" startRow=").append(startRow);
-        return sb.toString();
-    }
-
-    /** @return true if this cell spans over more than one grid unit. */
-    public boolean hasSpanning() {
-        return (getCell().getNumberColumnsSpanned() > 1)
-            || (getCell().getNumberRowsSpanned() > 1);
-    }
-
-    /**
-     * Creates a cellLM for the corresponding table-cell. A new one must be created
-     * for each new static-content (TODO).
-     */
-    public void createCellLM() {
-        cellLM = new TableCellLayoutManager(cell, this);
-    }
-
-}
index c7776ff7b60c69d95bea3c6466bf8191d97bfd16..9117f4ecbb843b1c9d07b38e5f432bf60b7ccc7b 100644 (file)
@@ -26,6 +26,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.LengthRangeProperty;
index 5b5fece32cd07896711992d79d121f989d72308d..ee953ebf552945c6748c4472f5b71341b4038dbb 100644 (file)
@@ -25,6 +25,8 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.fo.properties.LengthRangeProperty;
 import org.apache.fop.layoutmgr.ElementListUtils;
index 61b7c9e65ef18b37a068aeee021bac9899f0dad4..2d196de3a47c88ff7356d2882b1f3aaa86cc6b39 100644 (file)
@@ -25,6 +25,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.datatypes.PercentBaseContext;
 import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TableCell;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
index 8f3c3195cb8ad84880b4741ef3b6080554164ef6..d9893a1200ce17bb38dcd97f83ccdc81fe1ed1f8 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.fop.area.Trait;
 import org.apache.fop.datatypes.PercentBaseContext;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TableBody;
 import org.apache.fop.fo.flow.table.TableRow;
index 3acde70d38db06982b4c18be52101bfb86927e20..578cf2a1931c06c5f616053aba2002ed6de0bedf 100644 (file)
@@ -29,6 +29,8 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FONode.FONodeIterator;
 import org.apache.fop.fo.flow.Marker;
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TableBody;
 import org.apache.fop.fo.flow.table.TableCell;
index 92c62cff7215b91b7cb21379d4fd4efaa7da4325..6b50c2bda38c68aca008efe975384bfbb183b275 100644 (file)
@@ -27,6 +27,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.flow.table.GridUnit;
+import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.TableRow;
 import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.KnuthBox;