poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1691858 - in /poi/trunk/src/java/org/apache/poi/hssf: record/ record/cf/ usermodel/
Date Sun, 19 Jul 2015 22:09:42 GMT
Author: nick
Date: Sun Jul 19 22:09:41 2015
New Revision: 1691858

URL: http://svn.apache.org/r1691858
Log:
#58130 CF Threshold formats differ slightly between types

Added:
    poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java
    poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java
      - copied, changed from r1691844, poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java
    poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
    poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
    poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java?rev=1691858&r1=1691857&r2=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRule12Record.java Sun Jul 19 22:09:41
2015
@@ -21,6 +21,7 @@ import java.util.Arrays;
 
 import org.apache.poi.hssf.record.cf.ColorGradientFormatting;
 import org.apache.poi.hssf.record.cf.IconMultiStateFormatting;
+import org.apache.poi.hssf.record.cf.IconMultiStateThreshold;
 import org.apache.poi.hssf.record.cf.Threshold;
 import org.apache.poi.hssf.record.common.FtrHeader;
 import org.apache.poi.hssf.record.common.FutureRecord;
@@ -125,7 +126,7 @@ public final class CFRule12Record extend
     public static CFRule12Record create(HSSFSheet sheet, IconSet iconSet) {
         Threshold[] ts = new Threshold[iconSet.num];
         for (int i=0; i<ts.length; i++) {
-            ts[i] = new Threshold();
+            ts[i] = new IconMultiStateThreshold();
         }
         
         CFRule12Record r = new CFRule12Record(CONDITION_TYPE_COLOR_SCALE, 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java?rev=1691858&r1=1691857&r2=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java Sun Jul
19 22:09:41 2015
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.cf;
 
+import org.apache.poi.hssf.record.common.ExtendedColor;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndianInput;
@@ -33,15 +34,16 @@ public final class ColorGradientFormatti
     private static POILogger log = POILogFactory.getLogger(ColorGradientFormatting.class);
 
     private byte options = 0;
-    private Threshold[] thresholds;
-    private byte[] colors; // TODO Decode
+    private ColorGradientThreshold[] thresholds;
+    private ExtendedColor[] colors;
     
     private static BitField clamp = BitFieldFactory.getInstance(0x01);
     private static BitField background = BitFieldFactory.getInstance(0x02);
     
     public ColorGradientFormatting() {
         options = 3;
-        thresholds = new Threshold[3];
+        thresholds = new ColorGradientThreshold[3];
+        colors = new ExtendedColor[3];  
     }
     public ColorGradientFormatting(LittleEndianInput in) {
         in.readShort(); // Ignored
@@ -53,15 +55,15 @@ public final class ColorGradientFormatti
         }
         options = in.readByte();
         
-        // TODO Are these correct?
-        thresholds = new Threshold[numI];
+        thresholds = new ColorGradientThreshold[numI];
         for (int i=0; i<thresholds.length; i++) {
-            thresholds[i] = new Threshold(in);
-            in.readDouble(); // Rather pointless value...
+            thresholds[i] = new ColorGradientThreshold(in);
+        }
+        colors = new ExtendedColor[numG];
+        for (int i=0; i<colors.length; i++) {
+            in.readDouble(); // Slightly pointless step counter
+            colors[i] = new ExtendedColor(in);
         }
-        // TODO Decode colors
-        colors = new byte[in.available()];
-        in.readFully(colors);
     }
     
     public int getNumControlPoints() {
@@ -69,19 +71,34 @@ public final class ColorGradientFormatti
     }
     public void setNumControlPoints(int num) {
         if (num != thresholds.length) {
-            thresholds = new Threshold[num];
-            // TODO Colors
+            ColorGradientThreshold[] nt = new ColorGradientThreshold[num];
+            ExtendedColor[] nc = new ExtendedColor[num];
+            
+            int copy = Math.min(thresholds.length, num);
+            System.arraycopy(thresholds, 0, nt, 0, copy);
+            System.arraycopy(colors, 0, nc, 0, copy);
+            
+            this.thresholds = nt;
+            this.colors = nc;
+            
+            updateThresholdPositions();
         }
     }
     
-    public Threshold[] getThresholds() {
+    public ColorGradientThreshold[] getThresholds() {
         return thresholds;
     }
-    public void setThresholds(Threshold[] thresholds) {
+    public void setThresholds(ColorGradientThreshold[] thresholds) {
         this.thresholds = thresholds;
+        updateThresholdPositions();
     }
 
-    // TODO Colors
+    public ExtendedColor[] getColors() {
+        return colors;
+    }
+    public void setColors(ExtendedColor[] colors) {
+        this.colors = colors;
+    }
     
     public boolean isClampToCurve() {
         return getOptionFlag(clamp);
@@ -93,6 +110,13 @@ public final class ColorGradientFormatti
         int value = field.getValue(options);
         return value==0 ? false : true;
     }
+
+    private void updateThresholdPositions() {
+        double step = 1d / (thresholds.length-1);
+        for (int i=0; i<thresholds.length; i++) {
+            thresholds[i].setPosition(step*i);
+        }
+    }    
     
     public String toString() {
         StringBuffer buffer = new StringBuffer();
@@ -102,6 +126,9 @@ public final class ColorGradientFormatti
         for (Threshold t : thresholds) {
             buffer.append(t.toString());
         }
+        for (ExtendedColor c : colors) {
+            buffer.append(c.toString());
+        }
         buffer.append("    [/Color Gradient Formatting]\n");
         return buffer.toString();
     }
@@ -109,9 +136,10 @@ public final class ColorGradientFormatti
     public Object clone()  {
       ColorGradientFormatting rec = new ColorGradientFormatting();
       rec.options = options;
-      rec.thresholds = new Threshold[thresholds.length];
+      rec.thresholds = new ColorGradientThreshold[thresholds.length];
+      rec.colors = new ExtendedColor[colors.length];
       System.arraycopy(thresholds, 0, rec.thresholds, 0, thresholds.length);
-      // TODO Colors
+      System.arraycopy(colors, 0, rec.colors, 0, colors.length);
       return rec;
     }
     
@@ -119,9 +147,11 @@ public final class ColorGradientFormatti
         int len = 6;
         for (Threshold t : thresholds) {
             len += t.getDataLength();
+        }
+        for (ExtendedColor c : colors) {
+            len += c.getDataLength();
             len += 8;
         }
-        len += colors.length;
         return len;
     }
 
@@ -132,13 +162,16 @@ public final class ColorGradientFormatti
         out.writeByte(thresholds.length);
         out.writeByte(options);
         
-        double step = 1d / (thresholds.length-1);
-        for (int i=0; i<thresholds.length; i++) {
-            Threshold t = thresholds[i];
+        for (ColorGradientThreshold t : thresholds) {
             t.serialize(out);
-            out.writeDouble(step*i);
         }
         
-        out.write(colors);
+        double step = 1d / (colors.length-1);
+        for (int i=0; i<colors.length; i++) {
+            out.writeDouble(i*step);
+            
+            ExtendedColor c = colors[i];
+            c.serialize(out);
+        }
     }
 }

Added: poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java?rev=1691858&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java (added)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/ColorGradientThreshold.java Sun Jul 19
22:09:41 2015
@@ -0,0 +1,63 @@
+/* ====================================================================
+   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.hssf.record.cf;
+
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+
+/**
+ * Color Gradient / Color Scale specific Threshold / value (CFVO),
+ *  for changes in Conditional Formatting
+ */
+public final class ColorGradientThreshold extends Threshold {
+    private double position;
+
+    public ColorGradientThreshold() {
+        super();
+        position = 0d;
+    }
+
+    /** Creates new Ico Multi-State Threshold */
+    public ColorGradientThreshold(LittleEndianInput in) {
+        super(in);
+        position = in.readDouble();
+    }
+
+    public double getPosition() {
+        return position;
+    }
+    public void setPosition(double position) {
+        this.position = position;
+    }
+
+    public int getDataLength() {
+        return super.getDataLength() + 8;
+    }
+
+    public Object clone() {
+      ColorGradientThreshold rec = new ColorGradientThreshold();
+      super.copyTo(rec);
+      rec.position = position;
+      return rec;
+    }
+
+    public void serialize(LittleEndianOutput out) {
+        super.serialize(out);
+        out.writeDouble(position);
+    }
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java?rev=1691858&r1=1691857&r2=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateFormatting.java Sun Jul
19 22:09:41 2015
@@ -56,7 +56,7 @@ public final class IconMultiStateFormatt
         
         thresholds = new Threshold[iconSet.num];
         for (int i=0; i<thresholds.length; i++) {
-            thresholds[i] = new Threshold(in);
+            thresholds[i] = new IconMultiStateThreshold(in);
         }
     }
     

Copied: poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java (from
r1691844, poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java?p2=poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java&p1=poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java&r1=1691844&r2=1691858&rev=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/IconMultiStateThreshold.java Sun Jul
19 22:09:41 2015
@@ -17,18 +17,14 @@
 
 package org.apache.poi.hssf.record.cf;
 
-import java.util.Arrays;
-
-import org.apache.poi.ss.formula.Formula;
-import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Threshold / value for changes in Conditional Formatting
+ * Icon / Multi-State specific Threshold / value (CFVO),
+ *  for changes in Conditional Formatting
  */
-public final class Threshold {
+public final class IconMultiStateThreshold extends Threshold {
     /**
      * Cell values that are equal to the threshold value do not pass the threshold
      */
@@ -38,74 +34,21 @@ public final class Threshold {
      */
     public static final byte EQUALS_INCLUDE = 1;
     
-    private byte type;
-    private Formula formula;
-    private Double value;
     private byte equals;
 
-    public Threshold() {
-        type = (byte)RangeType.NUMBER.id;
-        formula = Formula.create(null);
-        value = 0d;
-    }
-
-    /** Creates new Threshold */
-    public Threshold(LittleEndianInput in) {
-        type = in.readByte();
-        short formulaLen = in.readShort();
-        if (formulaLen > 0) {
-            formula = Formula.read(formulaLen, in);
-        } else {
-            formula = Formula.create(null);
-        }
-        // Value is only there for non-formula, non min/max thresholds
-        if (formulaLen == 0 && type != RangeType.MIN.id &&
-                type != RangeType.MAX.id) {
-            value = in.readDouble();
-        }
+    public IconMultiStateThreshold() {
+        super();
+        equals = EQUALS_INCLUDE;
+    }
+
+    /** Creates new Ico Multi-State Threshold */
+    public IconMultiStateThreshold(LittleEndianInput in) {
+        super(in);
         equals = in.readByte();
         // Reserved, 4 bytes, all 0
         in.readInt();
     }
 
-    public byte getType() {
-        return type;
-    }
-    public void setType(byte type) {
-        this.type = type;
-
-        // Ensure the value presense / absense is consistent for the new type
-        if (type == RangeType.MIN.id || type == RangeType.MAX.id ||
-               type == RangeType.FORMULA.id) {
-            this.value = null;
-        } else if (value == null) {
-            this.value = 0d;
-        }
-    }
-    public void setType(int type) {
-        this.type = (byte)type;
-    }
-
-    protected Formula getFormula() {
-        return formula;
-    }
-    public Ptg[] getParsedExpression() {
-        return formula.getTokens();
-    }
-    public void setParsedExpression(Ptg[] ptgs) {
-        formula = Formula.create(ptgs);
-        if (ptgs.length > 0) {
-            this.value = null;
-        }
-    }
-
-    public Double getValue() {
-        return value;
-    }
-    public void setValue(Double value) {
-        this.value = value;
-    }
-    
     public byte getEquals() {
         return equals;
     }
@@ -114,43 +57,18 @@ public final class Threshold {
     }
 
     public int getDataLength() {
-        int len = 1 + formula.getEncodedSize();
-        if (value != null) {
-            len += 8;
-        }
-        len += 5;
-        return len;
-    }
-
-    public String toString() {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("    [CF Threshold]\n");
-        buffer.append("          .type    = ").append(Integer.toHexString(type)).append("\n");
-        buffer.append("          .formula = ").append(Arrays.toString(formula.getTokens())).append("\n");
-        buffer.append("          .value   = ").append(value).append("\n");
-        buffer.append("    [/CF Threshold]\n");
-        return buffer.toString();
+        return super.getDataLength() + 5;
     }
 
     public Object clone() {
-      Threshold rec = new Threshold();
-      rec.type = type;
-      rec.formula = formula;
-      rec.value = value;
+      IconMultiStateThreshold rec = new IconMultiStateThreshold();
+      super.copyTo(rec);
       rec.equals = equals;
       return rec;
     }
 
     public void serialize(LittleEndianOutput out) {
-        out.writeByte(type);
-        if (formula.getTokens().length == 0) {
-            out.writeShort(0);
-        } else {
-            formula.serialize(out);
-        }
-        if (value != null) {
-            out.writeDouble(value);
-        }
+        super.serialize(out);
         out.writeByte(equals);
         out.writeInt(0); // Reserved
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java?rev=1691858&r1=1691857&r2=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/cf/Threshold.java Sun Jul 19 22:09:41 2015
@@ -26,31 +26,21 @@ import org.apache.poi.util.LittleEndianI
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Threshold / value for changes in Conditional Formatting
+ * Threshold / value (CFVO) for changes in Conditional Formatting
  */
-public final class Threshold {
-    /**
-     * Cell values that are equal to the threshold value do not pass the threshold
-     */
-    public static final byte EQUALS_EXCLUDE = 0;
-    /**
-     * Cell values that are equal to the threshold value pass the threshold.
-     */
-    public static final byte EQUALS_INCLUDE = 1;
-    
+public abstract class Threshold {
     private byte type;
     private Formula formula;
     private Double value;
-    private byte equals;
 
-    public Threshold() {
+    protected Threshold() {
         type = (byte)RangeType.NUMBER.id;
         formula = Formula.create(null);
         value = 0d;
     }
 
     /** Creates new Threshold */
-    public Threshold(LittleEndianInput in) {
+    protected Threshold(LittleEndianInput in) {
         type = in.readByte();
         short formulaLen = in.readShort();
         if (formulaLen > 0) {
@@ -63,9 +53,6 @@ public final class Threshold {
                 type != RangeType.MAX.id) {
             value = in.readDouble();
         }
-        equals = in.readByte();
-        // Reserved, 4 bytes, all 0
-        in.readInt();
     }
 
     public byte getType() {
@@ -74,7 +61,7 @@ public final class Threshold {
     public void setType(byte type) {
         this.type = type;
 
-        // Ensure the value presense / absense is consistent for the new type
+        // Ensure the value presence / absence is consistent for the new type
         if (type == RangeType.MIN.id || type == RangeType.MAX.id ||
                type == RangeType.FORMULA.id) {
             this.value = null;
@@ -106,19 +93,11 @@ public final class Threshold {
         this.value = value;
     }
     
-    public byte getEquals() {
-        return equals;
-    }
-    public void setEquals(byte equals) {
-        this.equals = equals;
-    }
-
     public int getDataLength() {
         int len = 1 + formula.getEncodedSize();
         if (value != null) {
             len += 8;
         }
-        len += 5;
         return len;
     }
 
@@ -132,13 +111,10 @@ public final class Threshold {
         return buffer.toString();
     }
 
-    public Object clone() {
-      Threshold rec = new Threshold();
+    public void copyTo(Threshold rec) {
       rec.type = type;
       rec.formula = formula;
       rec.value = value;
-      rec.equals = equals;
-      return rec;
     }
 
     public void serialize(LittleEndianOutput out) {
@@ -151,7 +127,5 @@ public final class Threshold {
         if (value != null) {
             out.writeDouble(value);
         }
-        out.writeByte(equals);
-        out.writeInt(0); // Reserved
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java?rev=1691858&r1=1691857&r2=1691858&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java Sun Jul
19 22:09:41 2015
@@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.hssf.record.CFRule12Record;
 import org.apache.poi.hssf.record.cf.ColorGradientFormatting;
+import org.apache.poi.hssf.record.cf.ColorGradientThreshold;
 import org.apache.poi.hssf.record.cf.Threshold;
 import org.apache.poi.ss.usermodel.Color;
 import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold;
@@ -62,14 +63,15 @@ public final class HSSFColorScaleFormatt
     }
 
     public void setThresholds(ConditionalFormattingThreshold[] thresholds) {
-        Threshold[] t = new Threshold[thresholds.length];
+        ColorGradientThreshold[] t = new ColorGradientThreshold[thresholds.length];
         for (int i=0; i<t.length; i++) {
-            t[i] = ((HSSFConditionalFormattingThreshold)thresholds[i]).getThreshold();
+            HSSFConditionalFormattingThreshold hssfT = (HSSFConditionalFormattingThreshold)thresholds[i];
+            t[i] = (ColorGradientThreshold)hssfT.getThreshold();
         }
         colorFormatting.setThresholds(t);
     }
 
     public HSSFConditionalFormattingThreshold createThreshold() {
-        return new HSSFConditionalFormattingThreshold(new Threshold(), sheet);
+        return new HSSFConditionalFormattingThreshold(new ColorGradientThreshold(), sheet);
     }
 }



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


Mime
View raw message