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 2015/07/13 21:47:21 UTC

svn commit: r1690803 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/

Author: nick
Date: Mon Jul 13 19:47:21 2015
New Revision: 1690803

URL: http://svn.apache.org/r1690803
Log:
Provide a Conditional Formatting type class, and deprecate the byte-based types, to better work with the wider range

Added:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionType.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java?rev=1690803&r1=1690802&r2=1690803&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java Mon Jul 13 19:47:21 2015
@@ -25,6 +25,7 @@ import org.apache.poi.hssf.record.cf.Bor
 import org.apache.poi.hssf.record.cf.FontFormatting;
 import org.apache.poi.hssf.record.cf.PatternFormatting;
 import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.usermodel.ConditionType;
 import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
 
 /**
@@ -33,8 +34,7 @@ import org.apache.poi.ss.usermodel.Condi
  * It allows to specify formula based conditions for the Conditional Formatting
  * and the formatting settings such as font, border and pattern.
  */
-public final class HSSFConditionalFormattingRule implements ConditionalFormattingRule
-{
+public final class HSSFConditionalFormattingRule implements ConditionalFormattingRule {
 	private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
 
 	private final CFRuleBase cfRuleRecord;
@@ -172,6 +172,12 @@ public final class HSSFConditionalFormat
 	public byte getConditionType() {
 		return cfRuleRecord.getConditionType();
 	}
+    /**
+     * @return -  the conditiontype for the cfrule
+     */
+	public ConditionType getConditionTypeType() {
+	    return ConditionType.forId(getConditionType());
+	}
 
 	/**
 	 * @return - the comparisionoperatation for the cfrule

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java?rev=1690803&r1=1690802&r2=1690803&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ComparisonOperator.java Mon Jul 13 19:47:21 2015
@@ -24,9 +24,6 @@ package org.apache.poi.ss.usermodel;
  * <p>
  * For example, "highlight cells that begin with "M2" and contain "Mountain Gear".
  * </p>
- *
- * @author Dmitriy Kumshayev
- * @author Yegor Kozlov
  */
 public final class ComparisonOperator {
     public static final byte NO_COMPARISON = 0;

Added: poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionType.java?rev=1690803&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionType.java (added)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionType.java Mon Jul 13 19:47:21 2015
@@ -0,0 +1,88 @@
+/*
+ *  ====================================================================
+ *    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.ss.usermodel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents a type of a conditional formatting rule
+ */
+public class ConditionType {
+    private static Map<Integer,ConditionType> lookup = new HashMap<Integer, ConditionType>();
+    
+    /**
+     * This conditional formatting rule compares a cell value
+     * to a formula calculated result, using an operator
+     */
+    public static final ConditionType CELL_VALUE_IS = 
+            new ConditionType(1, "cellIs");
+
+    /**
+     * This conditional formatting rule contains a formula to evaluate.
+     * When the formula result is true, the cell is highlighted.
+     */
+    public static final ConditionType FORMULA = 
+            new ConditionType(2, "expression");
+    
+    /**
+     * This conditional formatting rule contains a color scale,
+     * with the cell background set according to a gradient.
+     */
+    public static final ConditionType COLOR_SCALE = 
+            new ConditionType(3, "colorScale");
+    
+    /**
+     * This conditional formatting rule sets a data bar, with the
+     *  cell populated with bars based on their values
+     */
+    public static final ConditionType DATA_BAR = 
+            new ConditionType(4, "dataBar");
+    
+    /**
+     * This conditional formatting rule that files the values
+     */
+    public static final ConditionType FILTER = 
+            new ConditionType(5, null);
+    
+    /**
+     * This conditional formatting rule sets a data bar, with the
+     *  cell populated with bars based on their values
+     */
+    public static final ConditionType ICON_SET = 
+            new ConditionType(6, "iconSet");
+    
+    
+    public final byte id;
+    public final String type;
+
+    
+    public static ConditionType forId(byte id) {
+        return forId((int)id);
+    }
+    public static ConditionType forId(int id) {
+        return lookup.get(id);
+    }
+        
+    private ConditionType(int id, String type) {
+        this.id = (byte)id; this.type = type;
+        lookup.put(id, this);
+    }
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java?rev=1690803&r1=1690802&r2=1690803&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java Mon Jul 13 19:47:21 2015
@@ -19,6 +19,8 @@
 
 package org.apache.poi.ss.usermodel;
 
+import static org.apache.poi.ss.usermodel.ConditionType.*;
+
 /**
  * Represents a description of a conditional formatting rule
  */
@@ -26,14 +28,16 @@ public interface ConditionalFormattingRu
     /**
      * This conditional formatting rule compares a cell value
      * to a formula calculated result, using an operator
+     * @deprecated Use {@link ConditionType#CELL_VALUE_IS}
      */
-    public static final byte CONDITION_TYPE_CELL_VALUE_IS = 1;
+    public static final byte CONDITION_TYPE_CELL_VALUE_IS = CELL_VALUE_IS.id;
 
     /**
      *  This conditional formatting rule contains a formula to evaluate.
      *  When the formula result is true, the cell is highlighted.
+     * @deprecated Use {@link ConditionType#FORMULA}
      */
-    public static final byte CONDITION_TYPE_FORMULA = 2;
+    public static final byte CONDITION_TYPE_FORMULA = FORMULA.id;
 
     /**
      * Create a new border formatting structure if it does not exist,
@@ -77,12 +81,20 @@ public interface ConditionalFormattingRu
     /**
      * Type of conditional formatting rule.
      * <p>
-     * MUST be either {@link #CONDITION_TYPE_CELL_VALUE_IS} or  {@link #CONDITION_TYPE_FORMULA}
+     * MUST be one of the IDs of a {@link ConditionType}
      * </p>
      *
      * @return the type of condition
+     * @deprecated Use {@link #getConditionTypeType()}
      */
     byte getConditionType();
+    
+    /**
+     * Type of conditional formatting rule.
+     *
+     * @return the type of condition
+     */
+    ConditionType getConditionTypeType();
 
     /**
      * The comparison function used when the type of conditional formatting is set to

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java?rev=1690803&r1=1690802&r2=1690803&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/SheetConditionalFormatting.java Mon Jul 13 19:47:21 2015
@@ -83,7 +83,7 @@ public interface SheetConditionalFormatt
      * <p>
      * The created conditional formatting rule compares a cell value
      * to a formula calculated result, using the specified operator.
-     * The type  of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}
+     * The type  of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS}
      * </p>
      *
      * @param comparisonOperation - MUST be a constant value from
@@ -112,7 +112,7 @@ public interface SheetConditionalFormatt
      * Create a conditional formatting rule that compares a cell value
      * to a formula calculated result, using an operator     *
      * <p>
-      * The type  of the created condition is {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}
+      * The type  of the created condition is {@link ConditionalFormattingRule#CONDITION_CELL_VALUE_IS}
      * </p>
      *
      * @param comparisonOperation  MUST be a constant value from
@@ -129,7 +129,7 @@ public interface SheetConditionalFormatt
      *  When the formula result is true, the cell is highlighted.
      *
      * <p>
-     *  The type of the created format condition is  {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA}
+     *  The type of the created format condition is  {@link ConditionalFormattingRule#CONDITION_FORMULA}
      * </p>
      * @param formula   the formula to evaluate. MUST be a Boolean function.
      */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java?rev=1690803&r1=1690802&r2=1690803&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java Mon Jul 13 19:47:21 2015
@@ -19,6 +19,9 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFFontFormatting;
 import org.apache.poi.xssf.model.StylesTable;
@@ -36,6 +39,30 @@ import org.openxmlformats.schemas.spread
 public class XSSFConditionalFormattingRule implements ConditionalFormattingRule {
     private final CTCfRule _cfRule;
     private XSSFSheet _sh;
+    
+    private static Map<STCfType.Enum, ConditionType> typeLookup = new HashMap<STCfType.Enum, ConditionType>();
+    static {
+        typeLookup.put(STCfType.CELL_IS, ConditionType.CELL_VALUE_IS);
+        typeLookup.put(STCfType.EXPRESSION, ConditionType.FORMULA);
+        typeLookup.put(STCfType.COLOR_SCALE, ConditionType.COLOR_SCALE);
+        typeLookup.put(STCfType.DATA_BAR, ConditionType.DATA_BAR);
+        typeLookup.put(STCfType.ICON_SET, ConditionType.ICON_SET);
+        
+        // These are all subtypes of Filter, we think...
+        typeLookup.put(STCfType.TOP_10, ConditionType.FILTER);
+        typeLookup.put(STCfType.UNIQUE_VALUES, ConditionType.FILTER);
+        typeLookup.put(STCfType.DUPLICATE_VALUES, ConditionType.FILTER);
+        typeLookup.put(STCfType.CONTAINS_TEXT, ConditionType.FILTER);
+        typeLookup.put(STCfType.NOT_CONTAINS_TEXT, ConditionType.FILTER);
+        typeLookup.put(STCfType.BEGINS_WITH, ConditionType.FILTER);
+        typeLookup.put(STCfType.ENDS_WITH, ConditionType.FILTER);
+        typeLookup.put(STCfType.CONTAINS_BLANKS, ConditionType.FILTER);
+        typeLookup.put(STCfType.NOT_CONTAINS_BLANKS, ConditionType.FILTER);
+        typeLookup.put(STCfType.CONTAINS_ERRORS, ConditionType.FILTER);
+        typeLookup.put(STCfType.NOT_CONTAINS_ERRORS, ConditionType.FILTER);
+        typeLookup.put(STCfType.TIME_PERIOD, ConditionType.FILTER);
+        typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);
+    }
 
     /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){
         _cfRule = CTCfRule.Factory.newInstance();
@@ -153,19 +180,23 @@ public class XSSFConditionalFormattingRu
     /**
      * Type of conditional formatting rule.
      * <p>
-     * MUST be either {@link ConditionalFormattingRule#CONDITION_TYPE_CELL_VALUE_IS}
-     * or  {@link ConditionalFormattingRule#CONDITION_TYPE_FORMULA}
+     * MUST be one of the IDs of a {@link ConditionType}
      * </p>
      *
      * @return the type of condition
      */
     public byte getConditionType(){
-        switch (_cfRule.getType().intValue()){
-            case STCfType.INT_EXPRESSION: return ConditionalFormattingRule.CONDITION_TYPE_FORMULA;
-            case STCfType.INT_CELL_IS: return ConditionalFormattingRule.CONDITION_TYPE_CELL_VALUE_IS;
-        }
+        ConditionType type = getConditionTypeType();
+        if (type != null) return type.id;
         return 0;
     }
+    
+    /**
+     * Type of conditional formatting rule.
+     */
+    public ConditionType getConditionTypeType() {
+        return typeLookup.get(_cfRule.getType());
+    }
 
     /**
      * The comparison function used when the type of conditional formatting is set to



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org