Further HSSF Color Gradient support
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691796 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
929ee429ea
commit
1a2524c8ea
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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; i<t.length; i++) {
|
||||
ht[i] = new HSSFConditionalFormattingThreshold(t[i], sheet);
|
||||
}
|
||||
return ht;
|
||||
}
|
||||
|
||||
public void setThresholds(ConditionalFormattingThreshold[] thresholds) {
|
||||
Threshold[] t = new Threshold[thresholds.length];
|
||||
for (int i=0; i<t.length; i++) {
|
||||
t[i] = ((HSSFConditionalFormattingThreshold)thresholds[i]).getThreshold();
|
||||
}
|
||||
colorFormatting.setThresholds(t);
|
||||
}
|
||||
|
||||
public HSSFConditionalFormattingThreshold createThreshold() {
|
||||
return new HSSFConditionalFormattingThreshold(new Threshold(), sheet);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import org.apache.poi.hssf.record.CFRuleBase;
|
||||
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
|
||||
import org.apache.poi.hssf.record.CFRuleRecord;
|
||||
import org.apache.poi.hssf.record.cf.BorderFormatting;
|
||||
import org.apache.poi.hssf.record.cf.ColorGradientFormatting;
|
||||
import org.apache.poi.hssf.record.cf.FontFormatting;
|
||||
import org.apache.poi.hssf.record.cf.IconMultiStateFormatting;
|
||||
import org.apache.poi.hssf.record.cf.PatternFormatting;
|
||||
@ -55,10 +56,18 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||
cfRuleRecord = pRuleRecord;
|
||||
}
|
||||
|
||||
CFRuleBase getCfRuleRecord()
|
||||
{
|
||||
CFRuleBase getCfRuleRecord() {
|
||||
return cfRuleRecord;
|
||||
}
|
||||
private CFRule12Record getCFRule12Record(boolean create) {
|
||||
if (cfRuleRecord instanceof CFRule12Record) {
|
||||
// Good
|
||||
} else {
|
||||
if (create) throw new IllegalArgumentException("Can't convert a CF into a CF12 record");
|
||||
return null;
|
||||
}
|
||||
return (CFRule12Record)cfRuleRecord;
|
||||
}
|
||||
|
||||
private HSSFFontFormatting getFontFormatting(boolean create)
|
||||
{
|
||||
@ -171,13 +180,7 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||
}
|
||||
|
||||
private HSSFIconMultiStateFormatting getMultiStateFormatting(boolean create) {
|
||||
if (cfRuleRecord instanceof CFRule12Record) {
|
||||
// Good
|
||||
} else {
|
||||
if (create) throw new IllegalArgumentException("Can't convert a CF into a CF12 record");
|
||||
return null;
|
||||
}
|
||||
CFRule12Record cfRule12Record = (CFRule12Record)cfRuleRecord;
|
||||
CFRule12Record cfRule12Record = getCFRule12Record(create);
|
||||
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting();
|
||||
if (iconFormatting != null)
|
||||
{
|
||||
@ -193,14 +196,12 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return icon / multi-state formatting object if defined, <code>null</code> 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, <code>null</code> 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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user