Revision: 7489
Author: victormote
Date: 2006-06-09 16:35:11 -0700 (Fri, 09 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7489&view=rev
Log Message:
-----------
Move table column width computation from layout to AreaTree.
Modified Paths:
--------------
trunk/foray/foray-pioneer/src/java/org/foray/pioneer/TablePL.java
Modified: trunk/foray/foray-pioneer/src/java/org/foray/pioneer/TablePL.java
===================================================================
--- trunk/foray/foray-pioneer/src/java/org/foray/pioneer/TablePL.java 2006-06-09 23:35:03 UTC (rev 7488)
+++ trunk/foray/foray-pioneer/src/java/org/foray/pioneer/TablePL.java 2006-06-09 23:35:11 UTC (rev 7489)
@@ -44,17 +44,8 @@
*/
public class TablePL extends BlockPL {
- private static final int MINCOLWIDTH = 10000; // 10pt
-
public int bodyCount = 0;
- /** Optimum inline-progression-dimension */
- private int optIPD;
- /** Minimum inline-progression-dimension */
- private int minIPD;
- /** Maximum inline-progression-dimension */
- private int maxIPD;
-
public TablePL(Table table, PioneerLS layout) {
super(table, layout);
}
@@ -288,177 +279,4 @@
}
}
- public int calcFixedColumnWidths(TableArea tableArea,
- int maxAllocationWidth) {
- Table node = getTableFO();
- int tableWidth = node.traitIPDimensionOpt(tableArea, tableArea.crIPD());
- /* Accumulates the total table units used in columns in this table. */
- double totalTableUnits = 0.0;
- /*
- * Accumulates the total width, in millipoints(?), of the columns that
- * have a fixed width.
- */
- int totalFixedWidth = 0;
- /* Minimum number of proportional units. */
- double tuMin = 100000.0;
- /*
- * Loop through the columns and total the fixed widths and proportional
- * units for each one.
- */
- for (int i = 0; i < node.getTableColumns().size(); i++) {
- TableColumn column = (TableColumn) node.getTableColumns().get(i);
- if (column == null) {
- getLogger().warn("No table-column specification for column " +
- (i + 1) + ".");
- } else {
- double tu = column.traitColumnWidthTableUnits();
- /* Keep track of minimum number of proportional units
- * in any column which has only proportional units.
- */
- if (tu > 0 && tu < tuMin
- && column.traitColumnWidth(tableArea,
- tableWidth) == 0) {
- tuMin = tu;
- }
- totalTableUnits += tu;
- totalFixedWidth += column.traitColumnWidth(tableArea,
- tableWidth);
- }
- }
-
- double dWidthFactor = 0.0;
- double dUnitLength = 0.0;
- setIPD(tableArea, (totalTableUnits > 0.0), maxAllocationWidth);
- if (totalTableUnits > 0.0) {
- int iProportionalWidth = 0;
- if (this.optIPD > totalFixedWidth) {
- iProportionalWidth = this.optIPD - totalFixedWidth;
- }
- else if (this.maxIPD > totalFixedWidth) {
- iProportionalWidth = this.maxIPD - totalFixedWidth;
- }
- else {
- iProportionalWidth = maxAllocationWidth - totalFixedWidth;
- }
- if (iProportionalWidth > 0) {
- dUnitLength = iProportionalWidth / totalTableUnits;
- }
- else {
- getLogger().error("Sum of fixed column widths "
- + totalFixedWidth
- + " greater than maximum available IPD "
- + maxAllocationWidth + "; no space for "
- + totalTableUnits + " proportional units.");
- /* Set remaining proportional units to a number which
- * will assure the minimum column size for tuMin.
- */
- dUnitLength = MINCOLWIDTH/tuMin;
- // Reduce fixed column widths by this much???
- }
- //log.debug("1 table-unit = " + dUnitLength + " mpt");
- }
- else {
- /* No proportional units. If minimum IPD is specified, check
- * that sum of column widths > minIPD.
- */
- if (this.minIPD > totalFixedWidth) {
- // Add extra space to each column
- dWidthFactor = (double)this.minIPD/(double)totalFixedWidth;
- }
- else if (this.maxIPD < totalFixedWidth) {
- // Note: if maxIPD=auto, use maxAllocWidth
- getLogger().warn("Sum of fixed column widths "
- + totalFixedWidth
- + " greater than maximum specified IPD " + this.maxIPD);
- }
- else if (this.optIPD != -1 && totalFixedWidth != this.optIPD) {
- getLogger().warn("Sum of fixed column widths "
- + totalFixedWidth
- + " differs from specified optimum IPD " + this.optIPD);
- }
- }
- // Now distribute the extra units onto each column and set offsets
- int columnOffset = 0;
- for (int i = 0; i < node.getTableColumns().size(); i++) {
- TableColumn column = (TableColumn) node.getTableColumns().get(i);
- TableColumnPL columnPL = (TableColumnPL) column.getProxy();
- if (columnPL != null) {
- columnPL.setColumnOffset(columnOffset);
- }
- if (column != null) {
- //Compute the width of the column
- int colWidth = -1;
- if (column.traitColumnWidthTableUnits() > 0) {
- //Proportional width
- colWidth = ((int)(column.traitColumnWidthTableUnits()
- * dUnitLength));
- } else {
- //Fixed width
- colWidth = column.traitColumnWidth(tableArea, tableWidth);
- }
-
- // Check minimum values and adjust if necessary
- if (colWidth <= 0) {
- getLogger().warn("Zero-width table column!");
- }
- if (dWidthFactor > 0.0) {
- // Increase column sizes to use up extra space
- colWidth *= dWidthFactor;
- }
- tableArea.setResolvedColumnWidth(i, colWidth);
- columnOffset += colWidth;
- }
- }
- // columnOffset now contains the width of the table.
- return columnOffset;
- }
-
- /**
- * Initialize table inline-progression-properties values
- * TODO: A lot of logic in this method appears to duplicate what is in the
- * standard getIPD... methods in FObj. Whatever is different should probably
- * be factored into methods that override (but use) the FObj methods.
- */
- private void setIPD(FOContext context, boolean bHasProportionalUnits,
- int maxAllocIPD) {
- Table node = getTableFO();
- if (node.traitIPDimensionMax(context, maxAllocIPD) >= 0) {
- this.maxIPD = node.traitIPDimensionMax(context, maxAllocIPD);
- } else {
- this.maxIPD = maxAllocIPD;
- }
-
- if (node.traitIPDimensionOpt(context, maxAllocIPD) < 0) {
- this.optIPD = -1;
- } else {
- /* TODO: This looks like a bug. Should be getIPDOptimum()? */
- this.optIPD = node.traitIPDimensionMax(context, maxAllocIPD);
- }
-
- if (node.traitIPDimensionMin(context, maxAllocIPD) < 0) {
- this.minIPD = -1;
- } else {
- this.minIPD = node.traitIPDimensionMin(context, maxAllocIPD);
- }
-
- if (bHasProportionalUnits && this.optIPD < 0) {
- if (this.minIPD > 0) {
- if (node.traitIPDimensionMax(context, maxAllocIPD) >= 0) {
- this.optIPD = (minIPD + maxIPD)/2;
- }
- else {
- this.optIPD = this.minIPD;
- }
- }
- else if (node.traitIPDimensionMax(context, maxAllocIPD) >= 0) {
- this.optIPD = this.maxIPD;
- }
- else {
- getLogger().error("At least one of minimum, optimum, or "
- + "maximum IPD must be specified on table.");
- this.optIPD = this.maxIPD;
- }
- }
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|