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/17 04:55:23 UTC

svn commit: r1691479 - in /poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel: XSSFConditionalFormattingRule.java XSSFIconMultiStateFormatting.java XSSFSheetConditionalFormatting.java

Author: nick
Date: Fri Jul 17 02:55:22 2015
New Revision: 1691479

URL: http://svn.apache.org/r1691479
Log:
Start on XSSF CF Iconset for #58130

Added:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingRule.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java

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=1691479&r1=1691478&r2=1691479&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 Fri Jul 17 02:55:22 2015
@@ -23,15 +23,11 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
+import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
 import org.apache.poi.xssf.usermodel.XSSFFontFormatting;
 import org.apache.poi.xssf.model.StylesTable;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 /**
  * XSSF suport for Conditional Formatting rules
@@ -179,12 +175,46 @@ public class XSSFConditionalFormattingRu
         return new XSSFPatternFormatting(dxf.getFill());
     }
     
+    public XSSFIconMultiStateFormatting createMultiStateFormatting(IconSet iconSet) {
+        // Is it already there?
+        if (_cfRule.isSetIconSet() && _cfRule.getType() == STCfType.ICON_SET)
+            return getMultiStateFormatting();
+        
+        // Mark it as being an Icon Set
+        _cfRule.setType(STCfType.ICON_SET);
 
-    public IconMultiStateFormatting createMultiStateFormatting() {
-        throw new IllegalArgumentException("Not implemented yet"); // TODO 
+        // Ensure the right element
+        CTIconSet icons = null;
+        if (_cfRule.isSetIconSet()) {
+            icons = _cfRule.getIconSet();
+        } else {
+            icons = _cfRule.addNewIconSet();
+        }
+        // Set the type of the icon set
+        if (iconSet.name != null) {
+            STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);
+            icons.setIconSet(xIconSet);
+        }
+        
+        // Add a default set of thresholds
+        int jump = 100 / iconSet.num;
+        STCfvoType.Enum type = STCfvoType.Enum.forString(RangeType.PERCENT.name);
+        for (int i=0; i<iconSet.num; i++) {
+            CTCfvo cfvo = icons.addNewCfvo();
+            cfvo.setType(type);
+            cfvo.setVal(Integer.toString(i*jump));
+        }
+        
+        // Wrap and return
+        return new XSSFIconMultiStateFormatting(icons);
     }
-    public IconMultiStateFormatting getMultiStateFormatting() {
-        throw new IllegalArgumentException("Not implemented yet"); // TODO 
+    public XSSFIconMultiStateFormatting getMultiStateFormatting() {
+        if (_cfRule.isSetIconSet()) {
+            CTIconSet icons = _cfRule.getIconSet();
+            return new XSSFIconMultiStateFormatting(icons);
+        } else {
+            return null;
+        }
     }
 
     /**

Added: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java?rev=1691479&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFIconMultiStateFormatting.java Fri Jul 17 02:55:22 2015
@@ -0,0 +1,72 @@
+/*
+ *  ====================================================================
+ *    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.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold;
+import org.apache.poi.ss.usermodel.IconMultiStateFormatting;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;
+
+/**
+ * High level representation for Icon / Multi-State Formatting 
+ *  component of Conditional Formatting settings
+ */
+public class XSSFIconMultiStateFormatting implements IconMultiStateFormatting {
+    CTIconSet _iconset;
+
+    /*package*/ XSSFIconMultiStateFormatting(CTIconSet iconset){
+        _iconset = iconset;
+    }
+
+    public IconSet getIconSet() {
+        return IconSet.valueOf(
+                _iconset.getIconSet().toString()
+        );
+    }
+    public void setIconSet(IconSet set) {
+        STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(set.name);
+        _iconset.setIconSet(xIconSet);
+    }
+
+    public boolean isIconOnly() {
+        if (_iconset.isSetShowValue())
+            return !_iconset.getShowValue();
+        return false;
+    }
+    public void setIconOnly(boolean only) {
+        _iconset.setShowValue(!only);
+    }
+
+    public boolean isReversed() {
+        if (_iconset.isSetReverse())
+            return _iconset.getReverse();
+        return false;
+    }
+    public void setReversed(boolean reversed) {
+        _iconset.setReverse(reversed);
+    }
+
+    public XSSFConditionalFormattingThreshold[] getThresholds() {
+        // TODO Implement
+        return null;
+    }
+    public void setThresholds(ConditionalFormattingThreshold[] thresholds) {
+        // TODO Implement
+    }
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java?rev=1691479&r1=1691478&r2=1691479&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java Fri Jul 17 02:55:22 2015
@@ -27,19 +27,14 @@ import org.apache.poi.ss.SpreadsheetVers
 import org.apache.poi.ss.usermodel.ComparisonOperator;
 import org.apache.poi.ss.usermodel.ConditionalFormatting;
 import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
-import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
 import org.apache.poi.ss.usermodel.IconMultiStateFormatting.IconSet;
 import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfRule;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCfvo;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTConditionalFormatting;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIconSet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfType;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCfvoType;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STConditionalFormattingOperator;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STIconSetType;
 
 /**
  * XSSF Conditional Formattings
@@ -136,25 +131,8 @@ public class XSSFSheetConditionalFormatt
     public XSSFConditionalFormattingRule createConditionalFormattingRule(IconSet iconSet) {
         XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);
         
-        // Mark it as being an Icon Set
-        CTCfRule cfRule = rule.getCTCfRule();
-        cfRule.setType(STCfType.ICON_SET);
-
-        // Set the type of the icon set
-        CTIconSet icons = cfRule.addNewIconSet();
-        if (iconSet.name != null) {
-            STIconSetType.Enum xIconSet = STIconSetType.Enum.forString(iconSet.name);
-            icons.setIconSet(xIconSet);
-        }
-        
-        // Add a default set of thresholds
-        int jump = 100 / iconSet.num;
-        STCfvoType.Enum type = STCfvoType.Enum.forString(RangeType.PERCENT.name);
-        for (int i=0; i<iconSet.num; i++) {
-            CTCfvo cfvo = icons.addNewCfvo();
-            cfvo.setType(type);
-            cfvo.setVal(Integer.toString(i*jump));
-        }
+        // Have it setup, with suitable defaults
+        rule.createMultiStateFormatting(iconSet);
         
         // All done!
         return rule;



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