diff --git a/src/java/org/apache/poi/hssf/record/CFRule12Record.java b/src/java/org/apache/poi/hssf/record/CFRule12Record.java index 3e72e5810..e7974a092 100644 --- a/src/java/org/apache/poi/hssf/record/CFRule12Record.java +++ b/src/java/org/apache/poi/hssf/record/CFRule12Record.java @@ -202,6 +202,21 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord { return multistate; } + public boolean containsColorGradientBlock() { + return (color_gradient != null); + } + public ColorGradientFormatting getColorGradientFormatting() { + return color_gradient; + } + public ColorGradientFormatting createColorGradientFormatting() { + if (color_gradient != null) return color_gradient; + + // Convert, setup and return + setConditionType(CONDITION_TYPE_COLOR_SCALE); + color_gradient = new ColorGradientFormatting(); + return color_gradient; + } + /** * get the stack of the scale expression as a list * diff --git a/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java b/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java index 12b1f71d1..3b58af74e 100644 --- a/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java +++ b/src/java/org/apache/poi/hssf/record/cf/ColorGradientFormatting.java @@ -64,6 +64,16 @@ public final class ColorGradientFormatting implements Cloneable { in.readFully(colors); } + public int getNumControlPoints() { + return thresholds.length; + } + public void setNumControlPoints(int num) { + if (num != thresholds.length) { + thresholds = new Threshold[num]; + // TODO Colors + } + } + public Threshold[] getThresholds() { return thresholds; } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java b/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java new file mode 100644 index 000000000..6e82072d4 --- /dev/null +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFColorScaleFormatting.java @@ -0,0 +1,75 @@ +/* ==================================================================== + 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.usermodel; + +import org.apache.poi.hssf.record.CFRule12Record; +import org.apache.poi.hssf.record.cf.ColorGradientFormatting; +import org.apache.poi.hssf.record.cf.Threshold; +import org.apache.poi.ss.usermodel.Color; +import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold; + +/** + * High level representation for Color Scale / Color Gradient + * Formatting component of Conditional Formatting settings + */ +public final class HSSFColorScaleFormatting implements org.apache.poi.ss.usermodel.ColorScaleFormatting { + private final HSSFSheet sheet; + private final CFRule12Record cfRule12Record; + private final ColorGradientFormatting colorFormatting; + + protected HSSFColorScaleFormatting(CFRule12Record cfRule12Record, HSSFSheet sheet) { + this.sheet = sheet; + this.cfRule12Record = cfRule12Record; + this.colorFormatting = this.cfRule12Record.getColorGradientFormatting(); + } + + public int getNumControlPoints() { + return colorFormatting.getNumControlPoints(); + } + public void setNumControlPoints(int num) { + colorFormatting.setNumControlPoints(num); + } + + public Color[] getColors() { + return null; // TODO + } + public void setColors(Color[] colors) { + // TODO + } + + public HSSFConditionalFormattingThreshold[] getThresholds() { + Threshold[] t = colorFormatting.getThresholds(); + HSSFConditionalFormattingThreshold[] ht = new HSSFConditionalFormattingThreshold[t.length]; + for (int i=0; inull otherwise */ public HSSFIconMultiStateFormatting getMultiStateFormatting() { return getMultiStateFormatting(false); } - /** * create a new icon / multi-state formatting object if it does not exist, * otherwise just return the existing object. @@ -209,6 +210,37 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin return getMultiStateFormatting(true); } + private HSSFColorScaleFormatting getColorScaleFormatting(boolean create) { + CFRule12Record cfRule12Record = getCFRule12Record(create); + ColorGradientFormatting colorFormatting = cfRule12Record.getColorGradientFormatting(); + if (colorFormatting != null) + { + return new HSSFColorScaleFormatting(cfRule12Record, sheet); + } + else if( create ) + { + colorFormatting = cfRule12Record.createColorGradientFormatting(); + return new HSSFColorScaleFormatting(cfRule12Record, sheet); + } + else + { + return null; + } + } + /** + * @return color scale / gradient formatting object if defined, null otherwise + */ + public HSSFColorScaleFormatting getColorScaleFormatting() { + return getColorScaleFormatting(false); + } + /** + * create a new color scale / gradient formatting object if it does not exist, + * otherwise just return the existing object. + */ + public HSSFColorScaleFormatting createColorScaleFormatting() { + return getColorScaleFormatting(true); + } + /** * @return - the conditiontype for the cfrule */