]> source.dussan.org Git - poi.git/commitdiff
XSSF color scale CF objects
authorNick Burch <nick@apache.org>
Sun, 19 Jul 2015 22:22:09 +0000 (22:22 +0000)
committerNick Burch <nick@apache.org>
Sun, 19 Jul 2015 22:22:09 +0000 (22:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691859 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColorScaleFormatting.java [new file with mode: 0644]
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java

diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColorScaleFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColorScaleFormatting.java
new file mode 100644 (file)
index 0000000..f32feea
--- /dev/null
@@ -0,0 +1,94 @@
+/*\r
+ *  ====================================================================\r
+ *    Licensed to the Apache Software Foundation (ASF) under one or more\r
+ *    contributor license agreements.  See the NOTICE file distributed with\r
+ *    this work for additional information regarding copyright ownership.\r
+ *    The ASF licenses this file to You under the Apache License, Version 2.0\r
+ *    (the "License"); you may not use this file except in compliance with\r
+ *    the License.  You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ * ====================================================================\r
+ */\r
+package org.apache.poi.xssf.usermodel;\r
+\r
+import org.apache.poi.ss.usermodel.Color;\r
+import org.apache.poi.ss.usermodel.ColorScaleFormatting;\r
+import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColorScale;\r
+\r
+/**\r
+ * High level representation for Color Scale / Color Gradient Formatting \r
+ *  component of Conditional Formatting settings\r
+ */\r
+public class XSSFColorScaleFormatting implements ColorScaleFormatting {\r
+    CTColorScale _scale;\r
+\r
+    /*package*/ XSSFColorScaleFormatting(CTColorScale scale){\r
+        _scale = scale;\r
+    }\r
+    \r
+    public int getNumControlPoints() {\r
+        return _scale.sizeOfCfvoArray();\r
+    }\r
+    public void setNumControlPoints(int num) {\r
+        while (num < _scale.sizeOfCfvoArray()) {\r
+            _scale.removeCfvo(_scale.sizeOfCfvoArray()-1);\r
+            _scale.removeColor(_scale.sizeOfColorArray()-1);\r
+        }\r
+        while (num > _scale.sizeOfCfvoArray()) {\r
+            _scale.addNewCfvo();\r
+            _scale.addNewColor();\r
+        }\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    public XSSFColor[] getColors() {\r
+        CTColor[] ctcols = _scale.getColorArray();\r
+        XSSFColor[] c = new XSSFColor[ctcols.length];\r
+        for (int i=0; i<ctcols.length; i++) {\r
+            c[i] = new XSSFColor(ctcols[i]);\r
+        }\r
+        return c;\r
+    }\r
+    public void setColors(Color[] colors) {\r
+        CTColor[] ctcols = new CTColor[colors.length];\r
+        for (int i=0; i<colors.length; i++) {\r
+            ctcols[i] = ((XSSFColor)colors[i]).getCTColor();\r
+        }\r
+        _scale.setColorArray(ctcols);\r
+    }\r
+\r
+    @SuppressWarnings("deprecation")\r
+    public XSSFConditionalFormattingThreshold[] getThresholds() {\r
+        CTCfvo[] cfvos = _scale.getCfvoArray();\r
+        XSSFConditionalFormattingThreshold[] t = \r
+                new XSSFConditionalFormattingThreshold[cfvos.length];\r
+        for (int i=0; i<cfvos.length; i++) {\r
+            t[i] = new XSSFConditionalFormattingThreshold(cfvos[i]);\r
+        }\r
+        return t;\r
+    }\r
+    public void setThresholds(ConditionalFormattingThreshold[] thresholds) {\r
+        CTCfvo[] cfvos = new CTCfvo[thresholds.length];\r
+        for (int i=0; i<thresholds.length; i++) {\r
+            cfvos[i] = ((XSSFConditionalFormattingThreshold)thresholds[i]).getCTCfvo();\r
+        }\r
+        _scale.setCfvoArray(cfvos);\r
+    }\r
+    \r
+    public XSSFColor createColor() {\r
+        return new XSSFColor(_scale.addNewColor());\r
+    }\r
+    public XSSFConditionalFormattingThreshold createThreshold() {\r
+        return new XSSFConditionalFormattingThreshold(_scale.addNewCfvo());\r
+    }\r
+}\r
index 814e73ca098329fdffa8265ecdab124f1a979fd2..f396a5dc8add3e930e19ca7cd1b67ab760a744c0 100644 (file)
@@ -216,6 +216,19 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
             return null;\r
         }\r
     }\r
+    \r
+    public XSSFColorScaleFormatting createColorScaleFormatting() {\r
+        // TODO Implement\r
+        return null;\r
+    }\r
+    public XSSFColorScaleFormatting getColorScaleFormatting() {\r
+        if (_cfRule.isSetColorScale()) {\r
+            CTColorScale scale = _cfRule.getColorScale();\r
+            return new XSSFColorScaleFormatting(scale);\r
+        } else {\r
+            return null;\r
+        }\r
+    }\r
 \r
     /**\r
      * Type of conditional formatting rule.\r