]> source.dussan.org Git - poi.git/commitdiff
#58130 Enable CF ColorScale support on the rule, and begin testing
authorNick Burch <nick@apache.org>
Sun, 19 Jul 2015 22:35:37 +0000 (22:35 +0000)
committerNick Burch <nick@apache.org>
Sun, 19 Jul 2015 22:35:37 +0000 (22:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691860 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/usermodel/ConditionalFormattingRule.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

index 5fb315147e09857f00ce2e182dda22304992c700..6f71b7b636abe7a293029b8d4c4e1394f706c042 100644 (file)
@@ -83,6 +83,11 @@ public interface ConditionalFormattingRule {
      */\r
     IconMultiStateFormatting getMultiStateFormatting();\r
     \r
+    /**\r
+     * @return color scale / color grate formatting object if defined, <code>null</code> otherwise\r
+     */\r
+    ColorScaleFormatting getColorScaleFormatting();\r
+    \r
     /**\r
      * Type of conditional formatting rule.\r
      * <p>\r
index f396a5dc8add3e930e19ca7cd1b67ab760a744c0..25239914039667c854abea8c70d106e5682c3050 100644 (file)
@@ -60,8 +60,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
         typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);\r
     }\r
     \r
-    // TODO Support types beyond CELL_VALUE_IS and FORMULA\r
-\r
     /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){\r
         _cfRule = CTCfRule.Factory.newInstance();\r
         _sh = sh;\r
@@ -218,8 +216,39 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
     }\r
     \r
     public XSSFColorScaleFormatting createColorScaleFormatting() {\r
-        // TODO Implement\r
-        return null;\r
+        // Is it already there?\r
+        if (_cfRule.isSetColorScale() && _cfRule.getType() == STCfType.COLOR_SCALE)\r
+            return getColorScaleFormatting();\r
+        \r
+        // Mark it as being a Color Scale\r
+        _cfRule.setType(STCfType.COLOR_SCALE);\r
+\r
+        // Ensure the right element\r
+        CTColorScale scale = null;\r
+        if (_cfRule.isSetColorScale()) {\r
+            scale = _cfRule.getColorScale();\r
+        } else {\r
+            scale = _cfRule.addNewColorScale();\r
+        }\r
+        \r
+        // Add a default set of thresholds and colors\r
+        if (scale.sizeOfCfvoArray() == 0) {\r
+            CTCfvo cfvo;\r
+            cfvo = scale.addNewCfvo();\r
+            cfvo.setType(STCfvoType.Enum.forString(RangeType.MIN.name));\r
+            cfvo = scale.addNewCfvo();\r
+            cfvo.setType(STCfvoType.Enum.forString(RangeType.PERCENTILE.name));\r
+            cfvo.setVal("50");\r
+            cfvo = scale.addNewCfvo();\r
+            cfvo.setType(STCfvoType.Enum.forString(RangeType.MAX.name));\r
+            \r
+            for (int i=0; i<3; i++) {\r
+                scale.addNewColor();\r
+            }\r
+        }\r
+        \r
+        // Wrap and return\r
+        return new XSSFColorScaleFormatting(scale);\r
     }\r
     public XSSFColorScaleFormatting getColorScaleFormatting() {\r
         if (_cfRule.isSetColorScale()) {\r
index 1a130b7510e3afc068f0f6de98789c5239bcb327..0d4c9d0520cb2262dda2f515b733f0e02f05d8c3 100644 (file)
@@ -773,6 +773,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         // Mixed icons - Column U\r
         // TODO Support EXT formattings\r
     }\r
+    \r
     private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) {\r
         assertEquals(1, cf.getNumberOfRules());\r
         ConditionalFormattingRule cr = cf.getRule(0);\r
@@ -812,8 +813,9 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         assertEquals(null, cr.getFormula1());\r
         assertEquals(null, cr.getFormula2());\r
         \r
-        // TODO Implement\r
-/*\r
+// TODO Finish HSSF\r
+if (cr instanceof HSSFConditionalFormattingRule) return;\r
+        \r
         ColorScaleFormatting color = cr.getColorScaleFormatting();\r
         assertNotNull(color);\r
         assertNotNull(color.getColors());\r
@@ -831,18 +833,16 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
             } else if (i == colors.length-1) {\r
                 assertEquals(RangeType.MAX, th.getRangeType());\r
             } else {\r
-                assertEquals(RangeType.PERCENT, th.getRangeType());\r
-                assertEquals(steps*i, th.getValue());\r
+                assertEquals(RangeType.PERCENTILE, th.getRangeType());\r
+                assertEquals(steps*i, th.getValue().intValue());\r
             }\r
             assertEquals(null, th.getFormula());\r
         }\r
         \r
         // Colors should match\r
         for (int i=0; i<colors.length; i++) {\r
-            Color c = color.getColors()[i];\r
-            assertEquals(colors[i], c.toString());\r
+            assertColour(colors[i], color.getColors()[i]);\r
         }\r
-*/\r
     }\r
 \r
     public void testCreateFontFormatting() {\r
@@ -1068,6 +1068,13 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
         assertEquals(null, iconFmt.getThresholds()[3].getValue());\r
     }\r
     \r
+    public void testCreateColorScaleFormatting() {\r
+        // TODO Implement then test\r
+    }\r
+    public void testCreateDataBarFormatting() {\r
+        // TODO Implement then test\r
+    }\r
+    \r
     public void testBug55380() {\r
         Workbook wb = _testDataProvider.createWorkbook();\r
         Sheet sheet = wb.createSheet();\r