}
public void setColumn(int targetColumnIx, Short xfIndex, Integer width,
Integer level, Boolean hidden, Boolean collapsed) {
ColumnInfoRecord ci = null;
int k = 0;
for (k = 0; k < records.size(); k++) {
ColumnInfoRecord tci = (ColumnInfoRecord) records.get(k);
if (tci.containsColumn(targetColumnIx)) {
ci = tci;
break;
}
if (tci.getFirstColumn() > targetColumnIx) {
// call column infos after k are for later columns
break; // exit now so k will be the correct insert pos
}
}
if (ci == null) {
// okay so there ISN'T a column info record that covers this column so lets create one!
ColumnInfoRecord nci = new ColumnInfoRecord();
nci.setFirstColumn(targetColumnIx);
nci.setLastColumn(targetColumnIx);
setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
insertColumn(k, nci);
attemptMergeColInfoRecords(k);
return;
}
boolean styleChanged = xfIndex != null && ci.getXFIndex() != xfIndex.shortValue();
boolean widthChanged = width != null && ci.getColumnWidth() != width.shortValue();
boolean levelChanged = level != null && ci.getOutlineLevel() != level.intValue();
boolean hiddenChanged = hidden != null && ci.getHidden() != hidden.booleanValue();
boolean collapsedChanged = collapsed != null && ci.getCollapsed() != collapsed.booleanValue();
boolean columnChanged = styleChanged || widthChanged || levelChanged || hiddenChanged || collapsedChanged;
if (!columnChanged) {
// do nothing...nothing changed.
return;
}
if (ci.getFirstColumn() == targetColumnIx && ci.getLastColumn() == targetColumnIx) {
// ColumnInfo ci for a single column, the target column
setColumnInfoFields(ci, xfIndex, width, level, hidden, collapsed);
attemptMergeColInfoRecords(k);
return;
}
if (ci.getFirstColumn() == targetColumnIx || ci.getLastColumn() == targetColumnIx) {
// The target column is at either end of the multi-column ColumnInfo ci
// we'll just divide the info and create a new one
if (ci.getFirstColumn() == targetColumnIx) {
ci.setFirstColumn(targetColumnIx + 1);
} else {
ci.setLastColumn(targetColumnIx - 1);
k++; // adjust insert pos to insert after
}
ColumnInfoRecord nci = copyColInfo(ci);
nci.setFirstColumn(targetColumnIx);
nci.setLastColumn(targetColumnIx);
setColumnInfoFields( nci, xfIndex, width, level, hidden, collapsed );
insertColumn(k, nci);
attemptMergeColInfoRecords(k);
} else {
//split to 3 records
ColumnInfoRecord ciStart = ci;
ColumnInfoRecord ciMid = copyColInfo(ci);
ColumnInfoRecord ciEnd = copyColInfo(ci);
int lastcolumn = ci.getLastColumn();
ciStart.setLastColumn(targetColumnIx - 1);
ciMid.setFirstColumn(targetColumnIx);
ciMid.setLastColumn(targetColumnIx);
setColumnInfoFields(ciMid, xfIndex, width, level, hidden, collapsed);
insertColumn(++k, ciMid);
ciEnd.setFirstColumn(targetColumnIx+1);
ciEnd.setLastColumn(lastcolumn);
insertColumn(++k, ciEnd);
// no need to attemptMergeColInfoRecords because we
// know both on each side are different
}
}