/* Minimum number of proportional units. */
double tuMin = Double.MAX_VALUE;
/* Loop through the columns and total the fixed widths and proportional
* units for each one. */
for (int i = 0; i < table.getTableColumns().length; i++) {
final TableColumn column = table.getTableColumns()[i];
if (column == null) {
getLogger().warn("No table-column specification for column " +
(i + 1) + ".");
} else {
final 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(this) == 0) {
tuMin = tu;
}
totalTableUnits += tu;
totalFixedWidth += column.traitColumnWidth(this);
}
}
double dWidthFactor = 0.0;
double dUnitLength = 0.0;
int optIPD;
int minIPD;
int maxIPD;
final boolean bHasProportionalUnits = totalTableUnits > 0.0;
if (table.traitIpDimensionMax(this) >= 0) {
maxIPD = table.traitIpDimensionMax(this);
} else {
maxIPD = maxAllocationIPD;
}
if (table.traitIpDimensionOpt(this) < 0) {
optIPD = -1;
} else {
optIPD = table.traitIpDimensionOpt(this);
}
if (table.traitIpDimensionMin(this) < 0) {
minIPD = -1;
} else {
minIPD = table.traitIpDimensionMin(this);
}
if (bHasProportionalUnits && optIPD < 0) {
if (minIPD > 0) {
if (table.traitIpDimensionMax(this) >= 0) {
optIPD = (minIPD + maxIPD) / 2;
} else {
optIPD = minIPD;
}
} else if (table.traitIpDimensionMax(this) >= 0) {
optIPD = maxIPD;
} else {
getLogger().error("At least one of minimum, optimum, or "
+ "maximum IPD must be specified on table.");
optIPD = maxIPD;
}
}
if (totalTableUnits > 0.0) {
int iProportionalWidth = 0;
if (optIPD > totalFixedWidth) {
iProportionalWidth = optIPD - totalFixedWidth;
} else if (maxIPD > totalFixedWidth) {
iProportionalWidth = maxIPD - totalFixedWidth;
} else {
iProportionalWidth = maxAllocationIPD - totalFixedWidth;
}
if (iProportionalWidth > 0) {
dUnitLength = iProportionalWidth / totalTableUnits;
} else {
getLogger().error("Sum of fixed column widths "
+ totalFixedWidth
+ " greater than maximum available IPD "
+ maxAllocationIPD + "; no space for "
+ totalTableUnits + " proportional units.");
/* Set remaining proportional units to a number which
* will assure the minimum column size for tuMin.
*/
dUnitLength = TableRA.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 (minIPD > totalFixedWidth) {
// Add extra space to each column
dWidthFactor = (double) minIPD / (double) totalFixedWidth;
} else if (maxIPD < totalFixedWidth) {
// Note: if maxIPD=auto, use maxAllocWidth
getLogger().warn("Sum of fixed column widths "
+ totalFixedWidth
+ " greater than maximum specified IPD " + maxIPD);
} else if (optIPD != -1 && totalFixedWidth != optIPD) {
getLogger().warn("Sum of fixed column widths "
+ totalFixedWidth
+ " differs from specified optimum IPD " + optIPD);
}
}
// Now distribute the extra units onto each column and set offsets
int columnOffset = 0;
for (int i = 0; i < table.getTableColumns().length; i++) {
final TableColumn column = table.getTableColumns()[i];
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(this);
}
// Check minimum values and adjust if necessary
if (colWidth <= 0) {
getLogger().warn("Zero-width table column!");