From 6ce7bdd42f27c6498827558fef97acf1e461886f Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Tue, 6 Mar 2007 09:23:42 +0000 Subject: [PATCH] Extract sub-classes from TableContentLayoutManager and make them top-level classes git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@515041 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/table/GridUnitPart.java | 65 ++++++ .../fop/layoutmgr/table/RowPainter.java | 2 - .../table/TableContentLayoutManager.java | 193 +----------------- .../layoutmgr/table/TableContentPosition.java | 96 +++++++++ .../table/TableHFPenaltyPosition.java | 60 ++++++ .../table/TableHeaderFooterPosition.java | 60 ++++++ .../fop/layoutmgr/table/TableStepper.java | 3 - 7 files changed, 282 insertions(+), 197 deletions(-) create mode 100644 src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java create mode 100644 src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java create mode 100644 src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java create mode 100644 src/java/org/apache/fop/layoutmgr/table/TableHeaderFooterPosition.java diff --git a/src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java b/src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java new file mode 100644 index 000000000..52227ef30 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/table/GridUnitPart.java @@ -0,0 +1,65 @@ +/* + * 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; + +/** + * Represents a non-dividable part of a grid unit. Used by the table stepper. + */ +class GridUnitPart { + + /** Primary grid unit */ + protected PrimaryGridUnit pgu; + /** Index of the starting element of this part */ + protected int start; + /** Index of the ending element of this part */ + protected int end; + + /** + * Creates a new GridUnitPart. + * @param pgu Primary grid unit + * @param start starting element + * @param end ending element + */ + protected GridUnitPart(PrimaryGridUnit pgu, int start, int end) { + this.pgu = pgu; + this.start = start; + this.end = end; + } + + /** @return true if this part is the first part of a cell */ + public boolean isFirstPart() { + return (start == 0); + } + + /** @return true if this part is the last part of a cell */ + public boolean isLastPart() { + return (end >= 0 && end == pgu.getElements().size() - 1); + } + + /** @see java.lang.Object#toString() */ + public String toString() { + StringBuffer sb = new StringBuffer("Part: "); + sb.append(start).append("-").append(end); + sb.append(" [").append(isFirstPart() ? "F" : "-").append(isLastPart() ? "L" : "-"); + sb.append("] ").append(pgu); + return sb.toString(); + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java index e9eaf76d4..3127d6a26 100644 --- a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java +++ b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java @@ -31,8 +31,6 @@ import org.apache.fop.layoutmgr.ElementListUtils; import org.apache.fop.layoutmgr.KnuthPossPosIter; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.SpaceResolver; -import org.apache.fop.layoutmgr.table.TableContentLayoutManager.GridUnitPart; -import org.apache.fop.layoutmgr.table.TableContentLayoutManager.TableContentPosition; class RowPainter { private static Log log = LogFactory.getLog(RowPainter.class); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java index 8d4f25f3d..fb4b3bf22 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java @@ -45,7 +45,6 @@ import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthPenalty; import org.apache.fop.layoutmgr.KnuthPossPosIter; import org.apache.fop.layoutmgr.LayoutContext; -import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.ListElement; import org.apache.fop.layoutmgr.MinOptMaxUtil; import org.apache.fop.layoutmgr.Position; @@ -807,199 +806,9 @@ public class TableContentLayoutManager implements PercentBaseContext { public int getUsedBPD() { return this.usedBPD; } - - /** - * Represents a non-dividable part of a grid unit. Used by the table stepper. - */ - protected static class GridUnitPart { - - /** Primary grid unit */ - protected PrimaryGridUnit pgu; - /** Index of the starting element of this part */ - protected int start; - /** Index of the ending element of this part */ - protected int end; - - /** - * Creates a new GridUnitPart. - * @param pgu Primary grid unit - * @param start starting element - * @param end ending element - */ - protected GridUnitPart(PrimaryGridUnit pgu, int start, int end) { - this.pgu = pgu; - this.start = start; - this.end = end; - } - - /** @return true if this part is the first part of a cell */ - public boolean isFirstPart() { - return (start == 0); - } - - /** @return true if this part is the last part of a cell */ - public boolean isLastPart() { - return (end >= 0 && end == pgu.getElements().size() - 1); - } - - /** @see java.lang.Object#toString() */ - public String toString() { - StringBuffer sb = new StringBuffer("Part: "); - sb.append(start).append("-").append(end); - sb.append(" [").append(isFirstPart() ? "F" : "-").append(isLastPart() ? "L" : "-"); - sb.append("] ").append(pgu); - return sb.toString(); - } - - } - - /** - * This class represents a Position specific to this layout manager. Used for normal content - * cases. - */ - public static class TableContentPosition extends Position { - /** The position is the first of the row group. */ - public static final int FIRST_IN_ROWGROUP = 1; - /** The position is the last of the row group. */ - public static final int LAST_IN_ROWGROUP = 2; - - /** the list of GridUnitParts making up this position */ - protected List gridUnitParts; - /** effective row this position belongs to */ - protected EffRow row; - /** flags for the position */ - protected int flags; - - /** - * Creates a new TableContentPosition. - * @param lm applicable layout manager - * @param gridUnitParts the list of GridUnitPart instances - * @param row effective row this position belongs to - */ - protected TableContentPosition(LayoutManager lm, List gridUnitParts, - EffRow row) { - super(lm); - this.gridUnitParts = gridUnitParts; - this.row = row; - } - - /** - * 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 - } - } - - /** @see org.apache.fop.layoutmgr.Position#generatesAreas() */ - public boolean generatesAreas() { - return true; - } - - /** @see java.lang.Object#toString() */ - public String toString() { - StringBuffer sb = new StringBuffer("TableContentPosition:"); - sb.append(getIndex()); - sb.append("["); - sb.append(row.getIndex()).append("/"); - sb.append(getFlag(FIRST_IN_ROWGROUP) ? "F" : "-"); - sb.append(getFlag(LAST_IN_ROWGROUP) ? "L" : "-").append("]"); - sb.append("("); - sb.append(gridUnitParts); - sb.append(")"); - return sb.toString(); - } - } - - /** - * This class represents a Position specific to this layout manager. Used for table - * headers and footers at the beginning and end of a table. - */ - public static class TableHeaderFooterPosition extends Position { - - /** True indicates a position for a header, false for a footer. */ - protected boolean header; - /** Element list representing the header/footer */ - protected List nestedElements; - - /** - * Creates a new TableHeaderFooterPosition. - * @param lm applicable layout manager - * @param header True indicates a position for a header, false for a footer. - * @param nestedElements Element list representing the header/footer - */ - protected TableHeaderFooterPosition(LayoutManager lm, - boolean header, List nestedElements) { - super(lm); - this.header = header; - this.nestedElements = nestedElements; - } - - /** @see java.lang.Object#toString() */ - public String toString() { - StringBuffer sb = new StringBuffer("Table"); - sb.append(header ? "Header" : "Footer"); - sb.append("Position:"); - sb.append(getIndex()).append("("); - sb.append(nestedElements); - sb.append(")"); - return sb.toString(); - } - } - - /** - * This class represents a Position specific to this layout manager. Used for table - * headers and footers at breaks. - */ - public static class TableHFPenaltyPosition extends Position { - - /** Element list for the header */ - protected List headerElements; - /** Element list for the footer */ - protected List footerElements; - /** Penalty length to be respected for nested content */ - protected int nestedPenaltyLength; - - /** - * Creates a new TableHFPenaltyPosition - * @param lm applicable layout manager - */ - protected TableHFPenaltyPosition(LayoutManager lm) { - super(lm); - } - - /** @see java.lang.Object#toString() */ - public String toString() { - StringBuffer sb = new StringBuffer("TableHFPenaltyPosition:"); - sb.append(getIndex()).append("("); - sb.append("header:"); - sb.append(headerElements); - sb.append(", footer:"); - sb.append(footerElements); - sb.append(", inner penalty length:"); - sb.append(nestedPenaltyLength); - sb.append(")"); - return sb.toString(); - } - } - // --------- Property Resolution related functions --------- // - + /** * @see org.apache.fop.datatypes.PercentBaseContext#getBaseLength(int, FObj) */ diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java b/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java new file mode 100644 index 000000000..e8024bfe5 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java @@ -0,0 +1,96 @@ +/* + * 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.List; + +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.Position; + +/** + * This class represents a Position specific to TableContentLayoutManager. Used for normal + * content cases. + */ +class TableContentPosition extends Position { + + /** The position is the first of the row group. */ + public static final int FIRST_IN_ROWGROUP = 1; + /** The position is the last of the row group. */ + public static final int LAST_IN_ROWGROUP = 2; + + /** the list of GridUnitParts making up this position */ + protected List gridUnitParts; + /** effective row this position belongs to */ + protected EffRow row; + /** flags for the position */ + protected int flags; + + /** + * Creates a new TableContentPosition. + * @param lm applicable layout manager + * @param gridUnitParts the list of GridUnitPart instances + * @param row effective row this position belongs to + */ + protected TableContentPosition(LayoutManager lm, List gridUnitParts, + EffRow row) { + super(lm); + this.gridUnitParts = gridUnitParts; + this.row = row; + } + + /** + * 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 + } + } + + public boolean generatesAreas() { + return true; + } + + public String toString() { + StringBuffer sb = new StringBuffer("TableContentPosition:"); + sb.append(getIndex()); + sb.append("["); + sb.append(row.getIndex()).append("/"); + sb.append(getFlag(FIRST_IN_ROWGROUP) ? "F" : "-"); + sb.append(getFlag(LAST_IN_ROWGROUP) ? "L" : "-").append("]"); + sb.append("("); + sb.append(gridUnitParts); + sb.append(")"); + return sb.toString(); + } +} diff --git a/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java b/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java new file mode 100644 index 000000000..a23c7a705 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/table/TableHFPenaltyPosition.java @@ -0,0 +1,60 @@ +/* + * 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.List; + +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.Position; + +/** + * This class represents a Position specific to TableContentLayoutManager. Used for table + * headers and footers at breaks. + */ +class TableHFPenaltyPosition extends Position { + + /** Element list for the header */ + protected List headerElements; + /** Element list for the footer */ + protected List footerElements; + /** Penalty length to be respected for nested content */ + protected int nestedPenaltyLength; + + /** + * Creates a new TableHFPenaltyPosition + * @param lm applicable layout manager + */ + protected TableHFPenaltyPosition(LayoutManager lm) { + super(lm); + } + + public String toString() { + StringBuffer sb = new StringBuffer("TableHFPenaltyPosition:"); + sb.append(getIndex()).append("("); + sb.append("header:"); + sb.append(headerElements); + sb.append(", footer:"); + sb.append(footerElements); + sb.append(", inner penalty length:"); + sb.append(nestedPenaltyLength); + sb.append(")"); + return sb.toString(); + } +} diff --git a/src/java/org/apache/fop/layoutmgr/table/TableHeaderFooterPosition.java b/src/java/org/apache/fop/layoutmgr/table/TableHeaderFooterPosition.java new file mode 100644 index 000000000..c3ae72c74 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/table/TableHeaderFooterPosition.java @@ -0,0 +1,60 @@ +/* + * 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.List; + +import org.apache.fop.layoutmgr.LayoutManager; +import org.apache.fop.layoutmgr.Position; + +/** + * This class represents a Position specific to TableContentLayoutManager. Used for table + * headers and footers at the beginning and end of a table. + */ +class TableHeaderFooterPosition extends Position { + + /** True indicates a position for a header, false for a footer. */ + protected boolean header; + /** Element list representing the header/footer */ + protected List nestedElements; + + /** + * Creates a new TableHeaderFooterPosition. + * @param lm applicable layout manager + * @param header True indicates a position for a header, false for a footer. + * @param nestedElements Element list representing the header/footer + */ + protected TableHeaderFooterPosition(LayoutManager lm, + boolean header, List nestedElements) { + super(lm); + this.header = header; + this.nestedElements = nestedElements; + } + + public String toString() { + StringBuffer sb = new StringBuffer("Table"); + sb.append(header ? "Header" : "Footer"); + sb.append("Position:"); + sb.append(getIndex()).append("("); + sb.append(nestedElements); + sb.append(")"); + return sb.toString(); + } +} diff --git a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java index f698ea784..8022fde43 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableStepper.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableStepper.java @@ -34,9 +34,6 @@ import org.apache.fop.layoutmgr.KnuthBox; import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthPenalty; import org.apache.fop.layoutmgr.LayoutContext; -import org.apache.fop.layoutmgr.table.TableContentLayoutManager.GridUnitPart; -import org.apache.fop.layoutmgr.table.TableContentLayoutManager.TableContentPosition; -import org.apache.fop.layoutmgr.table.TableContentLayoutManager.TableHFPenaltyPosition; /** * This class processes row groups to create combined element lists for tables. -- 2.39.5