From 622ff5c3ddce50b1b601ee99adbd7e81c4788222 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Mon, 31 Mar 2008 05:10:35 +0000 Subject: [PATCH] More work on Conditional Formatting (bug 30311) junit and fixes from Dmitriy. Some other clean-up. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@642878 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 2 + src/documentation/content/xdocs/status.xml | 2 + .../poi/hssf/record/CFHeaderRecord.java | 121 +- .../apache/poi/hssf/record/CFRuleRecord.java | 1027 ++++++++--------- .../record/aggregates/CFRecordsAggregate.java | 162 ++- .../apache/poi/hssf/record/cf/CellRange.java | 478 ++++++-- .../hssf/usermodel/HSSFBorderFormatting.java | 200 ++-- .../usermodel/HSSFConditionalFormatting.java | 161 +-- .../HSSFConditionalFormattingRule.java | 230 +--- .../apache/poi/hssf/usermodel/HSSFSheet.java | 137 +-- .../poi/hssf/record/AllRecordTests.java | 4 + .../poi/hssf/record/TestCFHeaderRecord.java | 199 ++-- .../poi/hssf/record/TestCFRuleRecord.java | 399 ++++--- .../aggregates/AllRecordAggregateTests.java | 40 + .../aggregates/TestCFRecordsAggregate.java | 130 +-- .../poi/hssf/record/cf/TestCellRange.java | 105 +- .../TestHSSFConfditionalFormatting.java | 203 ++++ 17 files changed, 1965 insertions(+), 1635 deletions(-) create mode 100644 src/testcases/org/apache/poi/hssf/record/aggregates/AllRecordAggregateTests.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConfditionalFormatting.java diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index ab9a4c796e..9be4485aeb 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -26,6 +26,7 @@ + @@ -36,6 +37,7 @@ + 30311 - More work on Conditional Formatting Move the Formula Evaluator code out of scratchpad Move the missing record aware eventusermodel code out of scratchpad 44652 / 44603 - Improved handling of Pictures in Word Documents diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 14c7b817a1..f8712cc30f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -22,6 +22,7 @@ + @@ -33,6 +34,7 @@ + 30311 - More work on Conditional Formatting Move the Formula Evaluator code out of scratchpad Move the missing record aware eventusermodel code out of scratchpad 44652 / 44603 - Improved handling of Pictures in Word Documents diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java index 00a8646b4f..7f2d5c3197 100644 --- a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java @@ -15,18 +15,10 @@ limitations under the License. ==================================================================== */ -/* - * ConditionalFormattingHeaderRecord.java - * - * Created on January 17, 2008, 3:05 AM - */ package org.apache.poi.hssf.record; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import org.apache.poi.hssf.record.cf.CellRange; +import org.apache.poi.hssf.util.Region; import org.apache.poi.util.LittleEndian; /** @@ -34,19 +26,27 @@ import org.apache.poi.util.LittleEndian; * * @author Dmitriy Kumshayev */ -public class CFHeaderRecord extends Record +public final class CFHeaderRecord extends Record { public static final short sid = 0x1B0; + private static final CellRange[] EMPTY_CELL_RANGE_ARRAY = { }; + private int field_1_numcf; private int field_2_need_recalculation; private CellRange field_3_enclosing_cell_range; - private List field_4_cell_ranges; + private CellRange[] field_4_cell_ranges; /** Creates new CFHeaderRecord */ public CFHeaderRecord() { - field_4_cell_ranges = new ArrayList(5); + field_4_cell_ranges = EMPTY_CELL_RANGE_ARRAY; + } + public CFHeaderRecord(Region[] regions) + { + CellRange[] unmergedRanges = CellRange.convertRegionsToCellRanges(regions); + CellRange[] mergeCellRanges = CellRange.mergeCellRanges(unmergedRanges); + setCellRanges(mergeCellRanges); } public CFHeaderRecord(RecordInputStream in) @@ -60,11 +60,12 @@ public class CFHeaderRecord extends Record field_2_need_recalculation = in.readShort(); field_3_enclosing_cell_range = new CellRange(in.readShort(),in.readShort(),in.readShort(),in.readShort()); int numCellRanges = in.readShort(); - field_4_cell_ranges = new ArrayList(5); + CellRange[] crs = new CellRange[numCellRanges]; for( int i=0; i0) + buffer.append(" .id = ").append(Integer.toHexString(sid)).append("\n"); + buffer.append(" .numCF = ").append(getNumberOfConditionalFormats()).append("\n"); + buffer.append(" .needRecalc = ").append(getNeedRecalculation()).append("\n"); + buffer.append(" .enclosingCellRange= ").append(getEnclosingCellRange()).append("\n"); + if( field_4_cell_ranges.length>0) { - buffer.append(" .cfranges=["); - for( int i=0; i