--- /dev/null
+/*\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