You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/03/19 13:29:09 UTC
svn commit: r638812 [1/3] - in /poi/trunk/src: documentation/content/xdocs/
java/org/apache/poi/hssf/model/ java/org/apache/poi/hssf/record/
java/org/apache/poi/hssf/record/aggregates/
java/org/apache/poi/hssf/record/cf/ java/org/apache/poi/hssf/usermo...
Author: nick
Date: Wed Mar 19 05:28:56 2008
New Revision: 638812
URL: http://svn.apache.org/viewvc?rev=638812&view=rev
Log:
Patch from Dmitriy from bug #30311 - Support for conditional formatting records
Added:
poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/cf/
poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java (with props)
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/record/cf/
poi/trunk/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java (with props)
Modified:
poi/trunk/src/documentation/content/xdocs/changes.xml
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
poi/trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=638812&r1=638811&r2=638812&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Wed Mar 19 05:28:56 2008
@@ -36,6 +36,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in formulas, such as '= 4'</action>
<action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in the formula evaluator</action>
<action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string values for evaluated formulas</action>
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=638812&r1=638811&r2=638812&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Mar 19 05:28:56 2008
@@ -33,6 +33,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in formulas, such as '= 4'</action>
<action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in the formula evaluator</action>
<action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string values for evaluated formulas</action>
Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java?rev=638812&r1=638811&r2=638812&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java Wed Mar 19 05:28:56 2008
@@ -24,6 +24,7 @@
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.util.PaneInformation;
@@ -96,6 +97,7 @@
protected ObjectProtectRecord objprotect = null;
protected ScenarioProtectRecord scenprotect = null;
protected PasswordRecord password = null;
+ protected List condFormatting = new ArrayList();;
/** Add an UncalcedRecord if not true indicating formulas have not been calculated */
protected boolean uncalced = false;
@@ -184,6 +186,17 @@
retval.merged = ( MergeCellsRecord ) rec;
retval.numMergedRegions += retval.merged.getNumAreas();
}
+ else if ( rec.getSid() == CFHeaderRecord.sid )
+ {
+ CFRecordsAggregate cfAgg = CFRecordsAggregate.createCFAggregate(recs, k);
+ retval.condFormatting.add(cfAgg);
+ rec = cfAgg;
+ }
+ else if ( rec.getSid() == CFRuleRecord.sid )
+ {
+ // Skip it since it is processed by CFRecordsAggregate
+ rec = null;
+ }
else if (rec.getSid() == ColumnInfoRecord.sid)
{
ColumnInfoRecord col = (ColumnInfoRecord)rec;
@@ -603,6 +616,66 @@
public int getNumMergedRegions()
{
return numMergedRegions;
+ }
+ // Find correct position to add new CF record
+ private int findConditionalFormattingPosition()
+ {
+ // This is default.
+ // If the algorithm does not find the right position,
+ // this one will be used (this is a position before EOF record)
+ int index = records.size()-2;
+
+ for( int i=index; i>=0; i-- )
+ {
+ Record rec = (Record)records.get(i);
+ short sid = rec.getSid();
+
+ // CFRecordsAggregate records already exist, just add to the end
+ if (rec instanceof CFRecordsAggregate) { return i+1; }
+
+ if( sid == (short)0x00ef ) { return i+1; }// PHONETICPR
+ if( sid == (short)0x015f ) { return i+1; }// LABELRANGES
+ if( sid == MergeCellsRecord.sid ) { return i+1; }
+ if( sid == (short)0x0099 ) { return i+1; }// STANDARDWIDTH
+ if( sid == SelectionRecord.sid ) { return i+1; }
+ if( sid == PaneRecord.sid ) { return i+1; }
+ if( sid == SCLRecord.sid ) { return i+1; }
+ if( sid == WindowTwoRecord.sid ) { return i+1; }
+ }
+
+ return index;
+ }
+
+ public int addConditionalFormatting(CFRecordsAggregate cfAggregate)
+ {
+ int index = findConditionalFormattingPosition();
+ records.add(index, cfAggregate);
+ condFormatting.add(cfAggregate);
+ return condFormatting.size()-1;
+ }
+
+ public void removeConditionalFormatting(int index)
+ {
+ if (index >= 0 && index <= condFormatting.size()-1 )
+ {
+ CFRecordsAggregate cfAggregate = getCFRecordsAggregateAt(index);
+ records.remove(cfAggregate);
+ condFormatting.remove(index);
+ }
+ }
+
+ public CFRecordsAggregate getCFRecordsAggregateAt(int index)
+ {
+ if (index >= 0 && index <= condFormatting.size()-1 )
+ {
+ return (CFRecordsAggregate) condFormatting.get(index);
+ }
+ return null;
+ }
+
+ public int getNumConditionalFormattings()
+ {
+ return condFormatting.size();
}
/**
Added: poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java?rev=638812&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java Wed Mar 19 05:28:56 2008
@@ -0,0 +1,223 @@
+/* ====================================================================
+ 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.
+==================================================================== */
+
+/*
+ * 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.util.LittleEndian;
+
+/**
+ * Conditional Formatting Header record (CFHEADER)
+ *
+ * @author Dmitriy Kumshayev
+ */
+public class CFHeaderRecord extends Record
+{
+ public static final short sid = 0x1B0;
+
+ private int field_1_numcf;
+ private int field_2_need_recalculation;
+ private CellRange field_3_enclosing_cell_range;
+ private List field_4_cell_ranges;
+
+ /** Creates new CFHeaderRecord */
+ public CFHeaderRecord()
+ {
+ field_4_cell_ranges = new ArrayList(5);
+ }
+
+ public CFHeaderRecord(RecordInputStream in)
+ {
+ super(in);
+ }
+
+ protected void fillFields(RecordInputStream in)
+ {
+ field_1_numcf = in.readShort();
+ 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);
+ for( int i=0; i<numCellRanges; i++)
+ {
+ field_4_cell_ranges.add(new CellRange(in.readShort(),in.readShort(),in.readShort(),in.readShort()));
+ }
+ }
+
+ public int getNumberOfConditionalFormats()
+ {
+ return field_1_numcf;
+ }
+ public void setNumberOfConditionalFormats(int n)
+ {
+ field_1_numcf=n;
+ }
+
+ public boolean getNeedRecalculation()
+ {
+ return field_2_need_recalculation==1?true:false;
+ }
+
+ public void setNeedRecalculation(boolean b)
+ {
+ field_2_need_recalculation=b?1:0;
+ }
+
+ public CellRange getEnclosingCellRange()
+ {
+ return field_3_enclosing_cell_range;
+ }
+
+ public void setEnclosingCellRange( CellRange cr)
+ {
+ field_3_enclosing_cell_range = cr.cloneCellRange();
+ }
+
+ /**
+ * Set cell ranges list to a single cell range and
+ * modify the enclosing cell range accordingly.
+ * @param List cellRanges - list of CellRange objects
+ */
+ public void setCellRanges( List cellRanges )
+ {
+ field_4_cell_ranges.clear();
+ if(cellRanges!=null)
+ {
+ field_3_enclosing_cell_range=null;
+ for( int i=0; i<cellRanges.size(); i++)
+ {
+ field_4_cell_ranges.add(cellRanges.get(i));
+ recalculateEnclosingRange((CellRange)cellRanges.get(i));
+ }
+ }
+ }
+
+ private void recalculateEnclosingRange(CellRange cellRange)
+ {
+ field_3_enclosing_cell_range = cellRange.createEnclosingCellRange(field_3_enclosing_cell_range);
+ }
+
+ public List getCellRanges()
+ {
+ return field_4_cell_ranges;
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("[CFHEADER]\n");
+ 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.size()>0)
+ {
+ buffer.append(" .cfranges=[");
+ for( int i=0; i<field_4_cell_ranges.size(); i++)
+ {
+ buffer.append(i==0?"":",").append(field_4_cell_ranges.get(i));
+ }
+ buffer.append("]\n");
+ }
+ buffer.append("[/CFHEADER]\n");
+ return buffer.toString();
+ }
+
+ /**
+ * @return byte array containing instance data
+ */
+
+ public int serialize(int offset, byte[] data)
+ {
+ int recordsize = getRecordSize();
+
+ LittleEndian.putShort(data, 0 + offset, sid);
+ LittleEndian.putShort(data, 2 + offset, (short) (recordsize-4));
+ LittleEndian.putShort(data, 4 + offset, (short) field_1_numcf);
+ LittleEndian.putShort(data, 6 + offset, (short) field_2_need_recalculation);
+ LittleEndian.putShort(data, 8 + offset, (short) field_3_enclosing_cell_range.getFirstRow());
+ LittleEndian.putShort(data, 10 + offset, (short) field_3_enclosing_cell_range.getLastRow());
+ LittleEndian.putShort(data, 12 + offset, (short) field_3_enclosing_cell_range.getFirstColumn());
+ LittleEndian.putShort(data, 14 + offset, (short) field_3_enclosing_cell_range.getLastColumn());
+ LittleEndian.putShort(data, 16 + offset, (short) field_4_cell_ranges.size());
+ for( int i=0 ; i!=field_4_cell_ranges.size(); i++)
+ {
+ LittleEndian.putShort(data, 18 + 0 + 8 * i + offset,
+ (short) ((CellRange) field_4_cell_ranges.get(i)).getFirstRow());
+ LittleEndian.putShort(data, 18 + 2 + 8 * i + offset,
+ (short) ((CellRange) field_4_cell_ranges.get(i)).getLastRow());
+ LittleEndian.putShort(data, 18 + 4 + 8 * i + offset,
+ (short) ((CellRange) field_4_cell_ranges.get(i)).getFirstColumn());
+ LittleEndian.putShort(data, 18 + 6 + 8 * i + offset,
+ (short) ((CellRange) field_4_cell_ranges.get(i)).getLastColumn());
+ }
+ return getRecordSize();
+ }
+
+ public int getRecordSize()
+ {
+ return 18+8*field_4_cell_ranges.size();
+ }
+
+ /**
+ * called by constructor, should throw runtime exception in the event of a
+ * record passed with a differing ID.
+ *
+ * @param id alleged id for this record
+ */
+
+ protected void validateSid(short id)
+ {
+ if (id != sid)
+ {
+ throw new RecordFormatException(
+ "NOT A ConditionalFormattingHeaderRecord RECORD");
+ }
+ }
+
+ public short getSid()
+ {
+ return sid;
+ }
+
+ public Object clone()
+ {
+ CFHeaderRecord rec = new CFHeaderRecord();
+ rec.field_1_numcf = field_1_numcf;
+ rec.field_2_need_recalculation = field_2_need_recalculation;
+ rec.field_3_enclosing_cell_range = field_3_enclosing_cell_range;
+ rec.field_4_cell_ranges = new ArrayList(field_4_cell_ranges.size());
+ Iterator iterator = field_4_cell_ranges.iterator();
+ while (iterator.hasNext())
+ {
+ CellRange oldRange = (CellRange)iterator.next();
+ rec.field_4_cell_ranges.add(oldRange.cloneCellRange());
+ }
+ return rec;
+ }
+
+}
Propchange: poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java?rev=638812&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java Wed Mar 19 05:28:56 2008
@@ -0,0 +1,657 @@
+
+/* ====================================================================
+ 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.
+==================================================================== */
+
+
+/*
+ * ConditionalFormattingRuleRecord.java
+ *
+ * Created on January 23, 2008, 9:56 AM
+ */
+package org.apache.poi.hssf.record;
+
+import java.util.List;
+import java.util.Stack;
+
+import org.apache.poi.hssf.record.cf.BorderFormatting;
+import org.apache.poi.hssf.record.cf.FontFormatting;
+import org.apache.poi.hssf.record.cf.PatternFormatting;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Conditional Formatting Rule Record.
+ * @author Dmitriy Kumshayev
+ */
+
+public class CFRuleRecord extends Record
+{
+
+ public static final short sid = 0x01B1;
+
+ private byte field_1_condition_type;
+ public static final byte CONDITION_TYPE_NO_CONDITION_TYPE = 0;
+ public static final byte CONDITION_TYPE_CELL_VALUE_IS = 1;
+ public static final byte CONDITION_TYPE_FORMULA = 2;
+
+ private byte field_2_comparison_operator;
+ public static final byte COMPARISON_OPERATOR_NO_COMPARISON = 0;
+ public static final byte COMPARISON_OPERATOR_BETWEEN = 1;
+ public static final byte COMPARISON_OPERATOR_NOT_BETWEEN = 2;
+ public static final byte COMPARISON_OPERATOR_EQUAL = 3;
+ public static final byte COMPARISON_OPERATOR_NOT_EQUAL = 4;
+ public static final byte COMPARISON_OPERATOR_GT = 5;
+ public static final byte COMPARISON_OPERATOR_LT = 6;
+ public static final byte COMPARISON_OPERATOR_GE = 7;
+ public static final byte COMPARISON_OPERATOR_LE = 8;
+
+ private short field_3_formula1_len;
+ private short field_4_formula2_len;
+
+ private int field_5_options;
+
+ private static final BitField modificationBits = BitFieldFactory.getInstance(0x83FFFFFF); // Bits: font,align,bord,patt,prot
+ private static final BitField alignHor = BitFieldFactory.getInstance(0x00000001); // 0 = Horizontal alignment modified
+ private static final BitField alignVer = BitFieldFactory.getInstance(0x00000002); // 0 = Vertical alignment modified
+ private static final BitField alignWrap = BitFieldFactory.getInstance(0x00000004); // 0 = Text wrapped flag modified
+ private static final BitField alignRot = BitFieldFactory.getInstance(0x00000008); // 0 = Text rotation modified
+ private static final BitField alignJustLast = BitFieldFactory.getInstance(0x00000010); // 0 = Justify last line flag modified
+ private static final BitField alignIndent = BitFieldFactory.getInstance(0x00000020); // 0 = Indentation modified
+ private static final BitField alignShrink = BitFieldFactory.getInstance(0x00000040); // 0 = Shrink to fit flag modified
+ private static final BitField notUsed1 = BitFieldFactory.getInstance(0x00000080); // Always 1
+ private static final BitField protLocked = BitFieldFactory.getInstance(0x00000100); // 0 = Cell locked flag modified
+ private static final BitField protHidden = BitFieldFactory.getInstance(0x00000200); // 0 = Cell hidden flag modified
+ private static final BitField bordLeft = BitFieldFactory.getInstance(0x00000400); // 0 = Left border style and colour modified
+ private static final BitField bordRight = BitFieldFactory.getInstance(0x00000800); // 0 = Right border style and colour modified
+ private static final BitField bordTop = BitFieldFactory.getInstance(0x00001000); // 0 = Top border style and colour modified
+ private static final BitField bordBot = BitFieldFactory.getInstance(0x00002000); // 0 = Bottom border style and colour modified
+ private static final BitField bordTlBr = BitFieldFactory.getInstance(0x00004000); // 0 = Top-left to bottom-right border flag modified
+ private static final BitField bordBlTr = BitFieldFactory.getInstance(0x00008000); // 0 = Bottom-left to top-right border flag modified
+ private static final BitField pattStyle = BitFieldFactory.getInstance(0x00010000); // 0 = Pattern style modified
+ private static final BitField pattCol = BitFieldFactory.getInstance(0x00020000); // 0 = Pattern colour modified
+ private static final BitField pattBgCol = BitFieldFactory.getInstance(0x00040000); // 0 = Pattern background colour modified
+ private static final BitField notUsed2 = BitFieldFactory.getInstance(0x00380000); // Always 111
+ private static final BitField undocumented = BitFieldFactory.getInstance(0x03C00000); // Undocumented bits
+ private static final BitField fmtBlockBits = BitFieldFactory.getInstance(0x7C000000); // Bits: font,align,bord,patt,prot
+ private static final BitField font = BitFieldFactory.getInstance(0x04000000); // 1 = Record contains font formatting block
+ private static final BitField align = BitFieldFactory.getInstance(0x08000000); // 1 = Record contains alignment formatting block
+ private static final BitField bord = BitFieldFactory.getInstance(0x10000000); // 1 = Record contains border formatting block
+ private static final BitField patt = BitFieldFactory.getInstance(0x20000000); // 1 = Record contains pattern formatting block
+ private static final BitField prot = BitFieldFactory.getInstance(0x40000000); // 1 = Record contains protection formatting block
+ private static final BitField alignTextDir = BitFieldFactory.getInstance(0x80000000); // 0 = Text direction modified
+
+
+ private short field_6_not_used;
+
+ private FontFormatting fontFormatting;
+
+ private byte field_8_align_text_break;
+ private byte field_9_align_text_rotation_angle;
+ private short field_10_align_indentation;
+ private short field_11_relative_indentation;
+ private short field_12_not_used;
+
+ private BorderFormatting borderFormatting;
+
+ private PatternFormatting patternFormatting;
+
+ private Stack field_17_formula1;
+ private Stack field_18_formula2;
+
+ /** Creates new CFRuleRecord */
+ public CFRuleRecord()
+ {
+ field_1_condition_type=CONDITION_TYPE_NO_CONDITION_TYPE;
+ field_2_comparison_operator=COMPARISON_OPERATOR_NO_COMPARISON;
+ setExpression1Length((short)0);
+ setExpression2Length((short)0);
+
+ // Set modification flags to 1: by default options are not modified
+ setOptions(modificationBits.setValue(field_5_options, -1));
+ // Set formatting block flags to 0 (no formatting blocks)
+ setOptions(fmtBlockBits.setValue(field_5_options, 0));
+
+ field_6_not_used = 0;
+ fontFormatting=null;
+ field_8_align_text_break = 0;
+ field_9_align_text_rotation_angle = 0;
+ field_10_align_indentation = 0;
+ field_11_relative_indentation = 0;
+ field_12_not_used = 0;
+ borderFormatting=null;
+ patternFormatting=null;
+ field_17_formula1=null;
+ field_18_formula2=null;
+ }
+
+ /**
+ * Constructs a Formula record and sets its fields appropriately.
+ * Note - id must be 0x06 (NOT 0x406 see MSKB #Q184647 for an
+ * "explanation of this bug in the documentation) or an exception
+ * will be throw upon validation
+ *
+ * @param in the RecordInputstream to read the record from
+ */
+
+ public CFRuleRecord(RecordInputStream in)
+ {
+ super(in);
+ }
+
+ protected void fillFields(RecordInputStream in)
+ {
+ try {
+ field_1_condition_type = in.readByte();
+ field_2_comparison_operator = in.readByte();
+ field_3_formula1_len = in.readShort();
+ field_4_formula2_len = in.readShort();
+ field_5_options = in.readInt();
+ field_6_not_used = in.readShort();
+
+ if(containsFontFormattingBlock())
+ {
+ fontFormatting = new FontFormatting(in);
+ }
+
+ if(containsBorderFormattingBlock())
+ {
+ borderFormatting = new BorderFormatting(in);
+ }
+
+ if( containsPatternFormattingBlock())
+ {
+ patternFormatting = new PatternFormatting(in);
+ }
+
+ if(field_3_formula1_len>0)
+ {
+ field_17_formula1 = Ptg.createParsedExpressionTokens(field_3_formula1_len, in);
+
+ // Now convert any fields as required
+ field_17_formula1 = SharedFormulaRecord.convertSharedFormulas(
+ field_17_formula1, 0, 0
+ );
+ }
+ if(field_4_formula2_len>0)
+ {
+ field_18_formula2 = Ptg.createParsedExpressionTokens(field_4_formula2_len, in);
+
+ // Now convert any fields as required
+ field_18_formula2 = SharedFormulaRecord.convertSharedFormulas(
+ field_18_formula2, 0, 0
+ );
+ }
+ } catch (java.lang.UnsupportedOperationException uoe) {
+ throw new RecordFormatException(uoe);
+ }
+
+ }
+
+ public void setConditionType(byte conditionType)
+ {
+ field_1_condition_type =
+ conditionType == CONDITION_TYPE_CELL_VALUE_IS ?
+ CONDITION_TYPE_CELL_VALUE_IS :
+ CONDITION_TYPE_FORMULA;
+ }
+
+ public byte getConditionType()
+ {
+ return field_1_condition_type;
+ }
+
+ /**
+ * set the option flags
+ *
+ * @param options bitmask
+ */
+
+ public void setOptions(int options)
+ {
+ field_5_options = options;
+ }
+
+ public boolean containsFontFormattingBlock()
+ {
+ return getOptionFlag(font);
+ }
+ public void setFontFormatting(FontFormatting fontFormatting)
+ {
+ this.fontFormatting = fontFormatting;
+ setOptionFlag(true,font);
+ }
+ public void setFontFormattingUnchanged()
+ {
+ setOptionFlag(false,font);
+ }
+
+ public boolean containsAlignFormattingBlock()
+ {
+ return getOptionFlag(align);
+ }
+ public void setAlignFormattingUnchanged()
+ {
+ setOptionFlag(false,align);
+ }
+
+ public boolean containsBorderFormattingBlock()
+ {
+ return getOptionFlag(bord);
+ }
+ public void setBorderFormatting(BorderFormatting borderFormatting)
+ {
+ this.borderFormatting = borderFormatting;
+ setOptionFlag(true,bord);
+ }
+ public void setBorderFormattingUnchanged()
+ {
+ setOptionFlag(false,bord);
+ }
+
+ public boolean containsPatternFormattingBlock()
+ {
+ return getOptionFlag(patt);
+ }
+ public void setPatternFormatting(PatternFormatting patternFormatting)
+ {
+ this.patternFormatting = patternFormatting;
+ setOptionFlag(true,patt);
+ }
+ public void setPatternFormattingUnchanged()
+ {
+ setOptionFlag(false,patt);
+ }
+
+ public boolean containsProtectionFormattingBlock()
+ {
+ return getOptionFlag(prot);
+ }
+ public void setProtectionFormattingUnchanged()
+ {
+ setOptionFlag(false,prot);
+ }
+
+ public void setComparisonOperation(byte operation)
+ {
+ field_2_comparison_operator = operation;
+ }
+
+ public byte getComparisonOperation()
+ {
+ return field_2_comparison_operator;
+ }
+
+ /**
+ * set the length (in number of tokens) of the expression 1
+ * @param len length
+ */
+
+ private void setExpression1Length(short len)
+ {
+ field_3_formula1_len = len;
+ }
+
+ /**
+ * get the length (in number of tokens) of the expression 1
+ * @return expression length
+ */
+
+ public short getExpression1Length()
+ {
+ return field_3_formula1_len;
+ }
+
+ /**
+ * set the length (in number of tokens) of the expression 2
+ * @param len length
+ */
+
+ private void setExpression2Length(short len)
+ {
+ field_4_formula2_len = len;
+ }
+
+ /**
+ * get the length (in number of tokens) of the expression 2
+ * @return expression length
+ */
+
+ public short getExpression2Length()
+ {
+ return field_4_formula2_len;
+ }
+ /**
+ * get the option flags
+ *
+ * @return bit mask
+ */
+ public int getOptions()
+ {
+ return field_5_options;
+ }
+
+ private boolean isModified(BitField field)
+ {
+ return !field.isSet(field_5_options);
+ }
+
+ private void setModified(boolean modified, BitField field)
+ {
+ field_5_options = field.setBoolean(field_5_options, !modified);
+ }
+
+ public boolean isLeftBorderModified()
+ {
+ return isModified(bordLeft);
+ }
+
+ public void setLeftBorderModified(boolean modified)
+ {
+ setModified(modified,bordLeft);
+ }
+
+ public boolean isRightBorderModified()
+ {
+ return isModified(bordRight);
+ }
+
+ public void setRightBorderModified(boolean modified)
+ {
+ setModified(modified,bordRight);
+ }
+
+ public boolean isTopBorderModified()
+ {
+ return isModified(bordTop);
+ }
+
+ public void setTopBorderModified(boolean modified)
+ {
+ setModified(modified,bordTop);
+ }
+
+ public boolean isBottomBorderModified()
+ {
+ return isModified(bordBot);
+ }
+
+ public void setBottomBorderModified(boolean modified)
+ {
+ setModified(modified,bordBot);
+ }
+
+ public boolean isTopLeftBottomRightBorderModified()
+ {
+ return isModified(bordTlBr);
+ }
+
+ public void setTopLeftBottomRightBorderModified(boolean modified)
+ {
+ setModified(modified,bordTlBr);
+ }
+
+ public boolean isBottomLeftTopRightBorderModified()
+ {
+ return isModified(bordBlTr);
+ }
+
+ public void setBottomLeftTopRightBorderModified(boolean modified)
+ {
+ setModified(modified,bordBlTr);
+ }
+
+ public boolean isPatternStyleModified()
+ {
+ return isModified(pattStyle);
+ }
+
+ public void setPatternStyleModified(boolean modified)
+ {
+ setModified(modified,pattStyle);
+ }
+
+ public boolean isPatternColorModified()
+ {
+ return isModified(pattCol);
+ }
+
+ public void setPatternColorModified(boolean modified)
+ {
+ setModified(modified,pattCol);
+ }
+
+ public boolean isPatternBackgroundColorModified()
+ {
+ return isModified(pattBgCol);
+ }
+
+ public void setPatternBackgroundColorModified(boolean modified)
+ {
+ setModified(modified,pattBgCol);
+ }
+
+ private boolean getOptionFlag(BitField field)
+ {
+ return field.isSet(field_5_options);
+ }
+
+ private void setOptionFlag(boolean flag, BitField field)
+ {
+ field_5_options = field.setBoolean(field_5_options, flag);
+ }
+
+ /**
+ * get the stack of the 1st expression as a list
+ *
+ * @return list of tokens (casts stack to a list and returns it!)
+ * this method can return null is we are unable to create Ptgs from
+ * existing excel file
+ * callers should check for null!
+ */
+
+ public List getParsedExpression1()
+ {
+ return field_17_formula1;
+ }
+
+ /**
+ * get the stack of the 2nd expression as a list
+ *
+ * @return list of tokens (casts stack to a list and returns it!)
+ * this method can return null is we are unable to create Ptgs from
+ * existing excel file
+ * callers should check for null!
+ */
+
+ public List getParsedExpression2()
+ {
+ return field_18_formula2;
+ }
+
+ public void setParsedExpression1(Stack ptgs) {
+ setExpression1Length(getTotalPtgSize(field_17_formula1 = ptgs));
+ }
+
+ public void setParsedExpression2(Stack ptgs) {
+ setExpression1Length(getTotalPtgSize(field_18_formula2 = ptgs));
+ }
+
+ /**
+ * called by constructor, should throw runtime exception in the event of a
+ * record passed with a differing ID.
+ *
+ * @param id alleged id for this record
+ */
+
+ protected void validateSid(short id)
+ {
+ if (id != sid)
+ {
+ throw new RecordFormatException("NOT A CFRULE RECORD");
+ }
+ }
+
+ public short getSid()
+ {
+ return sid;
+ }
+
+ /**
+ * called by the class that is responsible for writing this sucker.
+ * Subclasses should implement this so that their data is passed back in a
+ * byte array.
+ *
+ * @param offset to begin writing at
+ * @param data byte array containing instance data
+ * @return number of bytes written
+ */
+
+ public int serialize(int offset, byte [] data)
+ {
+ int recordsize = getRecordSize();
+ LittleEndian.putShort(data, 0 + offset, sid);
+ LittleEndian.putShort(data, 2 + offset, (short)(recordsize-4));
+ data[4 + offset] = field_1_condition_type;
+ data[5 + offset] = field_2_comparison_operator;
+ LittleEndian.putShort(data, 6 + offset, field_3_formula1_len);
+ LittleEndian.putShort(data, 8 + offset, field_4_formula2_len);
+ LittleEndian.putInt(data, 10 + offset, field_5_options);
+ LittleEndian.putShort(data,14 + offset, field_6_not_used);
+
+ offset += 16;
+
+ if( containsFontFormattingBlock() )
+ {
+ byte[] fontFormattingRawRecord = fontFormatting.getRawRecord();
+ System.arraycopy(fontFormattingRawRecord, 0, data, offset, fontFormattingRawRecord.length);
+ offset += fontFormattingRawRecord.length;
+ }
+
+ if( containsBorderFormattingBlock())
+ {
+ offset += borderFormatting.serialize(offset, data);
+ }
+
+ if( containsPatternFormattingBlock() )
+ {
+ offset += patternFormatting.serialize(offset, data);
+ }
+
+ if (getExpression1Length()>0)
+ {
+ Ptg.serializePtgStack(this.field_17_formula1, data, offset);
+ offset += getExpression1Length();
+ }
+
+ if (getExpression2Length()>0)
+ {
+ Ptg.serializePtgStack(this.field_18_formula2, data, offset);
+ offset += getExpression2Length();
+ }
+ return recordsize;
+ }
+
+
+
+
+ public int getRecordSize()
+ {
+ int retval =16+
+ (containsFontFormattingBlock()?fontFormatting.getRawRecord().length:0)+
+ (containsBorderFormattingBlock()?8:0)+
+ (containsPatternFormattingBlock()?4:0)+
+ getExpression1Length()+
+ getExpression2Length()
+ ;
+ return retval;
+ }
+
+ private short getTotalPtgSize(List list)
+ {
+ short retval = 0;
+ if( list!=null)
+ {
+ for (int k = 0; k < list.size(); k++)
+ {
+ Ptg ptg = ( Ptg ) list.get(k);
+
+ retval += ptg.getSize();
+ }
+ }
+ return retval;
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("[CFRULE]\n");
+ if( containsFontFormattingBlock())
+ {
+ buffer.append(fontFormatting.toString());
+ }
+ if( containsBorderFormattingBlock())
+ {
+ buffer.append(borderFormatting.toString());
+ }
+ if( containsPatternFormattingBlock())
+ {
+ buffer.append(patternFormatting.toString());
+ }
+ buffer.append("[/CFRULE]\n");
+ return buffer.toString();
+ }
+
+ public Object clone() {
+ CFRuleRecord rec = new CFRuleRecord();
+ rec.field_1_condition_type= field_1_condition_type;
+ rec.field_2_comparison_operator = field_2_comparison_operator;
+ rec.field_3_formula1_len = field_3_formula1_len;
+ rec.field_4_formula2_len = field_4_formula2_len;
+ rec.field_5_options = field_5_options;
+ rec.field_6_not_used = field_6_not_used;
+ if( containsFontFormattingBlock())
+ {
+ rec.fontFormatting = (FontFormatting)fontFormatting.clone();
+ }
+ if( containsBorderFormattingBlock())
+ {
+ rec.borderFormatting = (BorderFormatting)borderFormatting.clone();
+ }
+ if( containsPatternFormattingBlock())
+ {
+ rec.patternFormatting = (PatternFormatting)patternFormatting.clone();
+ }
+ if( field_3_formula1_len>0)
+ {
+ rec.field_17_formula1 = (Stack)field_17_formula1.clone();
+ }
+ if( field_4_formula2_len>0)
+ {
+ rec.field_18_formula2 = (Stack)field_18_formula2.clone();
+ }
+
+ return rec;
+ }
+
+ public FontFormatting getFontFormatting()
+ {
+ return fontFormatting;
+ }
+
+}
Propchange: poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=638812&r1=638811&r2=638812&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java Wed Mar 19 05:28:56 2008
@@ -82,6 +82,8 @@
SupBookRecord.class,
CRNCountRecord.class,
CRNRecord.class,
+ CFHeaderRecord.class,
+ CFRuleRecord.class,
};
}
private static Map recordsMap = recordsToMap(records);
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java?rev=638812&r1=638811&r2=638812&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java Wed Mar 19 05:28:56 2008
@@ -180,19 +180,17 @@
return ((getFirstRow() <= formulaRow) && (getLastRow() >= formulaRow) &&
(getFirstColumn() <= formulaColumn) && (getLastColumn() >= formulaColumn));
}
-
- /** Creates a non shared formula from the shared formula counter part*/
- public void convertSharedFormulaRecord(FormulaRecord formula) {
- //Sanity checks
- final int formulaRow = formula.getRow();
- final int formulaColumn = formula.getColumn();
- if (isFormulaInShared(formula)) {
- formula.setExpressionLength(getExpressionLength());
+
+ /**
+ * Creates a non shared formula from the shared formula
+ * counter part
+ */
+ protected static Stack convertSharedFormulas(Stack ptgs, int formulaRow, int formulaColumn) {
Stack newPtgStack = new Stack();
- if (field_7_parsed_expr != null)
- for (int k = 0; k < field_7_parsed_expr.size(); k++) {
- Ptg ptg = (Ptg) field_7_parsed_expr.get(k);
+ if (ptgs != null)
+ for (int k = 0; k < ptgs.size(); k++) {
+ Ptg ptg = (Ptg) ptgs.get(k);
if (ptg instanceof RefNPtg) {
RefNPtg refNPtg = (RefNPtg)ptg;
ptg = new ReferencePtg(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative()),
@@ -243,7 +241,23 @@
areaNAPtg.isLastColRelative());
}
newPtgStack.add(ptg);
- }
+ }
+ return newPtgStack;
+ }
+
+ /**
+ * Creates a non shared formula from the shared formula
+ * counter part
+ */
+ public void convertSharedFormulaRecord(FormulaRecord formula) {
+ //Sanity checks
+ final int formulaRow = formula.getRow();
+ final int formulaColumn = formula.getColumn();
+ if (isFormulaInShared(formula)) {
+ formula.setExpressionLength(getExpressionLength());
+
+ Stack newPtgStack =
+ convertSharedFormulas(field_7_parsed_expr, formulaRow, formulaColumn);
formula.setParsedExpression(newPtgStack);
//Now its not shared!
formula.setSharedFormula(false);
@@ -252,7 +266,7 @@
}
}
- private int fixupRelativeColumn(int currentcolumn, int column, boolean relative) {
+ private static int fixupRelativeColumn(int currentcolumn, int column, boolean relative) {
if(relative) {
// mask out upper bits to produce 'wrapping' at column 256 ("IV")
return (column + currentcolumn) & 0x00FF;
@@ -260,7 +274,7 @@
return column;
}
- private int fixupRelativeRow(int currentrow, int row, boolean relative) {
+ private static int fixupRelativeRow(int currentrow, int row, boolean relative) {
if(relative) {
// mask out upper bits to produce 'wrapping' at row 65536
return (row+currentrow) & 0x00FFFF;
Added: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java?rev=638812&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java Wed Mar 19 05:28:56 2008
@@ -0,0 +1,224 @@
+/* ====================================================================
+ 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.
+==================================================================== */
+package org.apache.poi.hssf.record.aggregates;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
+/**
+ * CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord
+ * and number of up to three CFRuleRecord records together to simplify
+ * access to them.
+ *
+ * @author Dmitriy Kumshayev
+ *
+ */
+public class CFRecordsAggregate extends Record
+{
+ public final static short sid = -2008;
+
+ private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
+
+ private CFHeaderRecord header;
+
+ // List of CFRuleRecord objects
+ private List rules;
+
+ public CFRecordsAggregate()
+ {
+ header = null;
+ rules = new ArrayList(3);
+ }
+
+ /**
+ * Create CFRecordsAggregate from a list of CF Records
+ * @param recs - list of {@link Record} objects
+ * @param offset - position of {@link CFHeaderRecord} object in the list of Record objects
+ * @return CFRecordsAggregate object
+ */
+ public static CFRecordsAggregate createCFAggregate(List recs, int offset)
+ {
+ CFRecordsAggregate cfRecords = new CFRecordsAggregate();
+ ArrayList records = new ArrayList(4);
+
+ int count = 0;
+ Record rec = ( Record ) recs.get(offset++);
+
+ if (rec.getSid() == CFHeaderRecord.sid)
+ {
+ records.add(rec);
+ cfRecords.header = (CFHeaderRecord)rec;
+
+ int nRules = cfRecords.header.getNumberOfConditionalFormats();
+ int rulesCount = 0;
+ while( offset<recs.size() &&
+ (rec = (Record)recs.get(offset++)).getSid() == CFRuleRecord.sid &&
+ rec instanceof CFRuleRecord &&
+ rulesCount++ < nRules
+ )
+ {
+ records.add(rec);
+ cfRecords.rules.add(rec);
+ }
+
+ if (nRules != cfRecords.rules.size())
+ {
+ if (log.check(POILogger.DEBUG))
+ {
+ log.log(POILogger.DEBUG, "Expected " + nRules + " Conditional Formats, "
+ + "but found " + cfRecords.rules.size() + " rules");
+ }
+ cfRecords.header.setNumberOfConditionalFormats(nRules);
+ }
+
+ }
+ return cfRecords;
+ }
+
+ /**
+ * Create a deep clone of the record
+ * @return
+ */
+ public CFRecordsAggregate cloneCFAggregate()
+ {
+
+ ArrayList records = new ArrayList(this.rules.size()+1);
+
+ records.add(this.header.clone());
+
+ for (int i=0; i<this.rules.size();i++)
+ {
+ Record rec = (Record)((Record)this.rules.get(i)).clone();
+ records.add(rec);
+ }
+ return createCFAggregate(records, 0);
+ }
+
+ /** You never fill an aggregate */
+ protected void fillFields(RecordInputStream in)
+ {
+ }
+
+ public short getSid()
+ {
+ return sid;
+ }
+
+ /**
+ * called by the class that is responsible for writing this sucker.
+ * Subclasses should implement this so that their data is passed back in a
+ * byte array.
+ *
+ * @param offset to begin writing at
+ * @param data byte array containing instance data
+ * @return number of bytes written
+ */
+
+ public int serialize(int offset, byte[] data)
+ {
+ int pos = offset;
+ if( header != null && rules.size()>0 )
+ {
+ header.setNumberOfConditionalFormats(rules.size());
+
+ pos += (( Record ) header).serialize(pos, data);
+
+ for(Iterator itr = rules.iterator(); itr.hasNext();)
+ {
+ pos += (( Record ) itr.next()).serialize(pos, data);
+ }
+ }
+ return pos - offset;
+ }
+
+ protected void validateSid(short id)
+ {
+ // do nothing here
+ }
+
+ /**
+ * @return the header
+ */
+ public CFHeaderRecord getHeader()
+ {
+ return header;
+ }
+
+ /**
+ * @return the rules
+ */
+ public List getRules()
+ {
+ return rules;
+ }
+
+ /**
+ * @return sum of sizes of all aggregated records
+ */
+ public int getRecordSize()
+ {
+ int size = 0;
+ if( header != null)
+ {
+ size += header.getRecordSize();
+ }
+ if( rules != null)
+ {
+ for(Iterator irecs = rules.iterator(); irecs.hasNext(); )
+ {
+ size += (( Record ) irecs.next()).getRecordSize();
+ }
+ }
+ return size;
+ }
+
+ /**
+ * String representation of CFRecordsAggregate
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("[CF]\n");
+ if( header != null )
+ {
+ buffer.append(header.toString());
+ }
+ if( rules != null )
+ {
+ for(int i=0; i<rules.size(); i++)
+ {
+ CFRuleRecord cfRule = (CFRuleRecord)rules.get(i);
+ if(cfRule!=null)
+ {
+ buffer.append(cfRule.toString());
+ }
+ }
+ }
+ buffer.append("[/CF]\n");
+ return buffer.toString();
+ }
+
+}
Propchange: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java?rev=638812&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java Wed Mar 19 05:28:56 2008
@@ -0,0 +1,560 @@
+
+/* ====================================================================
+ 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.
+==================================================================== */
+
+
+/*
+ * FontFormatting.java
+ *
+ * Created on January 22, 2008, 10:05 PM
+ */
+package org.apache.poi.hssf.record.cf;
+
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.BitField;
+import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndian;
+
+/**
+ * Border Formatting Block of the Conditional Formatting Rule Record.
+ *
+ * @author Dmitriy Kumshayev
+ */
+
+public class BorderFormatting
+{
+
+ /**
+ * No border
+ */
+
+ public final static short BORDER_NONE = 0x0;
+
+ /**
+ * Thin border
+ */
+
+ public final static short BORDER_THIN = 0x1;
+
+ /**
+ * Medium border
+ */
+
+ public final static short BORDER_MEDIUM = 0x2;
+
+ /**
+ * dash border
+ */
+
+ public final static short BORDER_DASHED = 0x3;
+
+ /**
+ * dot border
+ */
+
+ public final static short BORDER_HAIR = 0x4;
+
+ /**
+ * Thick border
+ */
+
+ public final static short BORDER_THICK = 0x5;
+
+ /**
+ * double-line border
+ */
+
+ public final static short BORDER_DOUBLE = 0x6;
+
+ /**
+ * hair-line border
+ */
+
+ public final static short BORDER_DOTTED = 0x7;
+
+ /**
+ * Medium dashed border
+ */
+
+ public final static short BORDER_MEDIUM_DASHED = 0x8;
+
+ /**
+ * dash-dot border
+ */
+
+ public final static short BORDER_DASH_DOT = 0x9;
+
+ /**
+ * medium dash-dot border
+ */
+
+ public final static short BORDER_MEDIUM_DASH_DOT = 0xA;
+
+ /**
+ * dash-dot-dot border
+ */
+
+ public final static short BORDER_DASH_DOT_DOT = 0xB;
+
+ /**
+ * medium dash-dot-dot border
+ */
+
+ public final static short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
+
+ /**
+ * slanted dash-dot border
+ */
+
+ public final static short BORDER_SLANTED_DASH_DOT = 0xD;
+
+ public BorderFormatting()
+ {
+ field_13_border_styles1 = (short)0;
+ field_14_border_styles2 = (short)0;
+ }
+
+ /** Creates new FontFormatting */
+ public BorderFormatting(RecordInputStream in)
+ {
+ field_13_border_styles1 = in.readInt();
+ field_14_border_styles2 = in.readInt();
+ }
+
+ // BORDER FORMATTING BLOCK
+ // For Border Line Style codes see HSSFCellStyle.BORDER_XXXXXX
+ private int field_13_border_styles1;
+ private static final BitField bordLeftLineStyle = BitFieldFactory.getInstance(0x0000000F);
+ private static final BitField bordRightLineStyle = BitFieldFactory.getInstance(0x000000F0);
+ private static final BitField bordTopLineStyle = BitFieldFactory.getInstance(0x00000F00);
+ private static final BitField bordBottomLineStyle= BitFieldFactory.getInstance(0x0000F000);
+ private static final BitField bordLeftLineColor = BitFieldFactory.getInstance(0x007F0000);
+ private static final BitField bordRightLineColor = BitFieldFactory.getInstance(0x3F800000);
+ private static final BitField bordTlBrLineOnOff = BitFieldFactory.getInstance(0x40000000);
+ private static final BitField bordBlTrtLineOnOff = BitFieldFactory.getInstance(0x80000000);
+
+ private int field_14_border_styles2;
+ private static final BitField bordTopLineColor = BitFieldFactory.getInstance(0x0000007F);
+ private static final BitField bordBottomLineColor= BitFieldFactory.getInstance(0x00003f80);
+ private static final BitField bordDiagLineColor = BitFieldFactory.getInstance(0x001FC000);
+ private static final BitField bordDiagLineStyle = BitFieldFactory.getInstance(0x01E00000);
+
+ /**
+ * set the type of border to use for the left border of the cell
+ * @param border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public void setBorderLeft(short border)
+ {
+ field_13_border_styles1 = bordLeftLineStyle.setValue(field_13_border_styles1, border);
+ }
+
+ /**
+ * get the type of border to use for the left border of the cell
+ * @return border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public short getBorderLeft()
+ {
+ return (short)bordLeftLineStyle.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the type of border to use for the right border of the cell
+ * @param border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public void setBorderRight(short border)
+ {
+ field_13_border_styles1 = bordRightLineStyle.setValue(field_13_border_styles1, border);
+ }
+
+ /**
+ * get the type of border to use for the right border of the cell
+ * @return border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public short getBorderRight()
+ {
+ return (short)bordRightLineStyle.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the type of border to use for the top border of the cell
+ * @param border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public void setBorderTop(short border)
+ {
+ field_13_border_styles1 = bordTopLineStyle.setValue(field_13_border_styles1, border);
+ }
+
+ /**
+ * get the type of border to use for the top border of the cell
+ * @return border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public short getBorderTop()
+ {
+ return (short)bordTopLineStyle.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the type of border to use for the bottom border of the cell
+ * @param border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public void setBorderBottom(short border)
+ {
+ field_13_border_styles1 = bordBottomLineStyle.setValue(field_13_border_styles1, border);
+ }
+
+ /**
+ * get the type of border to use for the bottom border of the cell
+ * @return border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+ public short getBorderBottom()
+ {
+ return (short)bordBottomLineStyle.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the type of border to use for the diagonal border of the cell
+ * @param border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+
+ public void setBorderDiagonal(short border)
+ {
+ field_14_border_styles2 = bordDiagLineStyle.setValue(field_14_border_styles2, border);
+ }
+
+ /**
+ * get the type of border to use for the diagonal border of the cell
+ * @return border type
+ * @see #BORDER_NONE
+ * @see #BORDER_THIN
+ * @see #BORDER_MEDIUM
+ * @see #BORDER_DASHED
+ * @see #BORDER_DOTTED
+ * @see #BORDER_THICK
+ * @see #BORDER_DOUBLE
+ * @see #BORDER_HAIR
+ * @see #BORDER_MEDIUM_DASHED
+ * @see #BORDER_DASH_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT
+ * @see #BORDER_DASH_DOT_DOT
+ * @see #BORDER_MEDIUM_DASH_DOT_DOT
+ * @see #BORDER_SLANTED_DASH_DOT
+ */
+ public short getBorderDiagonal()
+ {
+ return (short)bordDiagLineStyle.getValue(field_14_border_styles2);
+ }
+
+ /**
+ * set the color to use for the left border
+ * @param color The index of the color definition
+ */
+ public void setLeftBorderColor(short color)
+ {
+ field_13_border_styles1 = bordLeftLineColor.setValue(field_13_border_styles1, color);
+ }
+
+ /**
+ * get the color to use for the left border
+ * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
+ * @param color The index of the color definition
+ */
+ public short getLeftBorderColor()
+ {
+ return (short)bordLeftLineColor.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the color to use for the right border
+ * @param color The index of the color definition
+ */
+ public void setRightBorderColor(short color)
+ {
+ field_13_border_styles1 = bordRightLineColor.setValue(field_13_border_styles1, color);
+ }
+
+ /**
+ * get the color to use for the right border
+ * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
+ * @param color The index of the color definition
+ */
+ public short getRightBorderColor()
+ {
+ return (short)bordRightLineColor.getValue(field_13_border_styles1);
+ }
+
+ /**
+ * set the color to use for the top border
+ * @param color The index of the color definition
+ */
+ public void setTopBorderColor(short color)
+ {
+ field_14_border_styles2 = bordTopLineColor.setValue(field_14_border_styles2, color);
+ }
+
+ /**
+ * get the color to use for the top border
+ * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
+ * @param color The index of the color definition
+ */
+ public short getTopBorderColor()
+ {
+ return (short)bordTopLineColor.getValue(field_14_border_styles2);
+ }
+
+ /**
+ * set the color to use for the bottom border
+ * @param color The index of the color definition
+ */
+ public void setBottomBorderColor(short color)
+ {
+ field_14_border_styles2 = bordBottomLineColor.setValue(field_14_border_styles2, color);
+ }
+
+ /**
+ * get the color to use for the bottom border
+ * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
+ * @param color The index of the color definition
+ */
+ public short getBottomBorderColor()
+ {
+ return (short)bordBottomLineColor.getValue(field_14_border_styles2);
+ }
+
+ /**
+ * set the color to use for the diagonal borders
+ * @param color The index of the color definition
+ */
+ public void setDiagonalBorderColor(short color)
+ {
+ field_14_border_styles2 = bordDiagLineColor.setValue(field_14_border_styles2, color);
+ }
+
+ /**
+ * get the color to use for the diagonal border
+ * @see org.apache.poi.hssf.usermodel.HSSFPalette#getColor(short)
+ * @param color The index of the color definition
+ */
+ public short getDiagonalBorderColor()
+ {
+ return (short)bordDiagLineColor.getValue(field_14_border_styles2);
+ }
+
+ /**
+ * Of/off bottom left to top right line
+ *
+ * @param on - if true - on, otherwise off
+ */
+ public void setForwardDiagonalOn(boolean on)
+ {
+ field_13_border_styles1 = bordBlTrtLineOnOff.setBoolean(field_13_border_styles1, on);
+ }
+
+ /**
+ * Of/off top left to bottom right line
+ *
+ * @param on - if true - on, otherwise off
+ */
+ public void setBackwardDiagonalOn(boolean on)
+ {
+ field_13_border_styles1 = bordTlBrLineOnOff.setBoolean(field_13_border_styles1, on);
+ }
+
+ /**
+ * @return true if forward diagonal is on
+ */
+ public boolean isForwardDiagonalOn()
+ {
+ return bordBlTrtLineOnOff.isSet(field_13_border_styles1);
+ }
+
+ /**
+ * @return true if backward diagonal is on
+ */
+ public boolean isBackwardDiagonalOn()
+ {
+ return bordTlBrLineOnOff.isSet(field_13_border_styles1);
+ }
+
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(" [Border Formatting]\n");
+ buffer.append(" .lftln = ").append(Integer.toHexString(getBorderLeft())).append("\n");
+ buffer.append(" .rgtln = ").append(Integer.toHexString(getBorderRight())).append("\n");
+ buffer.append(" .topln = ").append(Integer.toHexString(getBorderTop())).append("\n");
+ buffer.append(" .btmln = ").append(Integer.toHexString(getBorderBottom())).append("\n");
+ buffer.append(" .leftborder= ").append(Integer.toHexString(getLeftBorderColor())).append("\n");
+ buffer.append(" .rghtborder= ").append(Integer.toHexString(getRightBorderColor())).append("\n");
+ buffer.append(" .topborder= ").append(Integer.toHexString(getTopBorderColor())).append("\n");
+ buffer.append(" .bottomborder= ").append(Integer.toHexString(getBottomBorderColor())).append("\n");
+ buffer.append(" .fwdiag= ").append(isForwardDiagonalOn()).append("\n");
+ buffer.append(" .bwdiag= ").append(isBackwardDiagonalOn()).append("\n");
+ buffer.append(" [/Border Formatting]\n");
+ return buffer.toString();
+ }
+
+ public Object clone()
+ {
+ BorderFormatting rec = new BorderFormatting();
+ rec.field_13_border_styles1 = field_13_border_styles1;
+ rec.field_14_border_styles2 = field_14_border_styles2;
+ return rec;
+ }
+
+ public int serialize(int offset, byte [] data)
+ {
+ LittleEndian.putInt(data, offset, field_13_border_styles1);
+ offset += 4;
+ LittleEndian.putInt(data, offset, field_14_border_styles2);
+ offset += 4;
+ return 8;
+ }
+}
Propchange: poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java?rev=638812&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java Wed Mar 19 05:28:56 2008
@@ -0,0 +1,259 @@
+/* ====================================================================
+ 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.
+==================================================================== */
+
+package org.apache.poi.hssf.record.cf;
+
+/**
+ * CellRange.java
+ * Created on January 22, 2008, 10:05 PM
+ *
+ * @author Dmitriy Kumshayev
+ */
+
+public class CellRange
+{
+ private int field_1_first_row;
+ private int field_2_last_row;
+ private short field_3_first_column;
+ private short field_4_last_column;
+
+ public CellRange(int firstRow, int lastRow, short firstColumn, short lastColumn)
+ {
+ this.field_1_first_row = firstRow;
+ this.field_2_last_row = lastRow;
+ this.field_3_first_column = firstColumn;
+ this.field_4_last_column = lastColumn;
+ validateRegion();
+ }
+
+ private void validateRegion()
+ {
+ if( field_1_first_row < 0 ||
+ field_2_last_row < -1 ||
+ field_3_first_column < 0 ||
+ field_4_last_column < -1 ||
+ field_2_last_row>=0 && field_2_last_row<field_1_first_row ||
+ field_4_last_column>=0 && field_4_last_column<field_3_first_column
+ )
+ {
+ throw new IllegalArgumentException("Invalid cell region "+toString());
+ }
+ }
+
+ public int getFirstRow()
+ {
+ return field_1_first_row;
+ }
+ private void setFirstRow(int firstRow)
+ {
+ this.field_1_first_row = firstRow;
+ }
+ public int getLastRow()
+ {
+ return field_2_last_row;
+ }
+ private void setLastRow(int lastRow)
+ {
+ this.field_2_last_row = lastRow;
+ }
+ public short getFirstColumn()
+ {
+ return field_3_first_column;
+ }
+ private void setFirstColumn(short firstColumn)
+ {
+ this.field_3_first_column = firstColumn;
+ }
+ public short getLastColumn()
+ {
+ return field_4_last_column;
+ }
+ private void setLastColumn(short lastColumn)
+ {
+ this.field_4_last_column = lastColumn;
+ }
+
+ public static final int NO_INTERSECTION = 1;
+ public static final int OVERLAP = 2;
+ public static final int INSIDE = 3;
+ public static final int ENCLOSES = 4;
+
+ /**
+ * Intersect this range with the specified range.
+ *
+ * @param another - the specified range
+ * @return code which reflects how the specified range is related to this range.<br/>
+ * Possible return codes are:
+ * NO_INTERSECTION - the specified range is outside of this range;<br/>
+ * OVERLAP - both ranges partially overlap;<br/>
+ * INSIDE - the specified range is inside of this one<br/>
+ * ENCLOSES - the specified range encloses this range<br/>
+ */
+ public int intersect(CellRange another )
+ {
+ int firstRow = another.getFirstRow();
+ int lastRow = another.getLastRow();
+ short firstCol = another.getFirstColumn();
+ short lastCol = another.getLastColumn();
+
+ if
+ (
+ gt(this.getFirstRow(),lastRow) ||
+ lt(this.getLastRow(),firstRow) ||
+ gt(this.getFirstColumn(),lastCol) ||
+ lt(this.getLastColumn(),firstCol)
+ )
+ {
+ return NO_INTERSECTION;
+ }
+ else if( this.contains(another) )
+ {
+ return INSIDE;
+ }
+ else if( another.contains(this) )
+ {
+ return ENCLOSES;
+ }
+ else
+ {
+ return OVERLAP;
+ }
+
+ }
+
+ /**
+ * Check if the specified range is located inside of this cell range.
+ *
+ * @param range
+ * @return true if this cell range contains the argument range inside if it's area
+ */
+ public boolean contains(CellRange range)
+ {
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ short firstCol = range.getFirstColumn();
+ short lastCol = range.getLastColumn();
+ return le(this.getFirstRow(), firstRow) && ge(this.getLastRow(), lastRow)
+ && le(this.getFirstColumn(), firstCol) && ge(this.getLastColumn(), lastCol);
+ }
+
+ public boolean contains(int row, short column)
+ {
+ return le(this.getFirstRow(), row) && ge(this.getLastRow(), row)
+ && le(this.getFirstColumn(), column) && ge(this.getLastColumn(), column);
+ }
+
+ /**
+ * Check if the specified cell range has a shared border with the current range.
+ *
+ * @return true if the ranges have a shared border.
+ */
+ public boolean hasSharedBorder(CellRange range)
+ {
+ int firstRow = range.getFirstRow();
+ int lastRow = range.getLastRow();
+ short firstCol = range.getFirstColumn();
+ short lastCol = range.getLastColumn();
+ return
+ (this.getFirstRow()>0 && this.getFirstRow() - 1 == lastRow || firstRow>0 &&this.getLastRow() == firstRow -1)&&
+ (this.getFirstColumn() == firstCol) &&
+ (this.getLastColumn() == lastCol) ||
+ (this.getFirstColumn()>0 && this.getFirstColumn() - 1 == lastCol || firstCol>0 && this.getLastColumn() == firstCol -1) &&
+ (this.getFirstRow() == firstRow) &&
+ (this.getLastRow() == lastRow)
+ ;
+ }
+
+ /**
+ * Create an enclosing CellRange for the two cell ranges.
+ *
+ * @return enclosing CellRange
+ */
+ public CellRange createEnclosingCellRange(CellRange range)
+ {
+ if( range == null)
+ {
+ return cloneCellRange();
+ }
+ else
+ {
+ CellRange cellRange =
+ new CellRange(
+ lt(range.getFirstRow(),getFirstRow())?range.getFirstRow():getFirstRow(),
+ gt(range.getLastRow(),getLastRow())?range.getLastRow():getLastRow(),
+ lt(range.getFirstColumn(),getFirstColumn())?range.getFirstColumn():getFirstColumn(),
+ gt(range.getLastColumn(),getLastColumn())?range.getLastColumn():getLastColumn()
+ );
+ return cellRange;
+ }
+ }
+
+ public CellRange cloneCellRange()
+ {
+ return new CellRange(getFirstRow(),getLastRow(),getFirstColumn(),getLastColumn());
+ }
+
+ /**
+ * Copy data from antother cell range to this cell range
+ * @param cr - another cell range
+ */
+ public void setCellRange(CellRange cr)
+ {
+ setFirstRow(cr.getFirstRow());
+ setLastRow(cr.getLastRow());
+ setFirstColumn(cr.getFirstColumn());
+ setLastColumn(cr.getLastColumn());
+ }
+
+ /**
+ * @return true if a < b
+ */
+ private static boolean lt(int a, int b)
+ {
+ return a == -1 ? false : (b == -1 ? true : a < b);
+ }
+
+ /**
+ * @return true if a <= b
+ */
+ private static boolean le(int a, int b)
+ {
+ return a == b || lt(a,b);
+ }
+
+ /**
+ * @return true if a > b
+ */
+ private static boolean gt(int a, int b)
+ {
+ return lt(b,a);
+ }
+
+ /**
+ * @return true if a >= b
+ */
+ private static boolean ge(int a, int b)
+ {
+ return !lt(a,b);
+ }
+
+ public String toString()
+ {
+ return "("+this.getFirstRow()+","+this.getLastRow()+","+this.getFirstColumn()+","+this.getLastColumn()+")";
+ }
+
+}
Propchange: poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org