#58130 Enable CF ColorScale support on the rule, and begin testing

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-19 22:35:37 +00:00
parent 01779c5721
commit ca1dfbd1e5
3 changed files with 52 additions and 11 deletions

View File

@ -83,6 +83,11 @@ public interface ConditionalFormattingRule {
*/ */
IconMultiStateFormatting getMultiStateFormatting(); IconMultiStateFormatting getMultiStateFormatting();
/**
* @return color scale / color grate formatting object if defined, <code>null</code> otherwise
*/
ColorScaleFormatting getColorScaleFormatting();
/** /**
* Type of conditional formatting rule. * Type of conditional formatting rule.
* <p> * <p>

View File

@ -60,8 +60,6 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER); typeLookup.put(STCfType.ABOVE_AVERAGE, ConditionType.FILTER);
} }
// TODO Support types beyond CELL_VALUE_IS and FORMULA
/*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){ /*package*/ XSSFConditionalFormattingRule(XSSFSheet sh){
_cfRule = CTCfRule.Factory.newInstance(); _cfRule = CTCfRule.Factory.newInstance();
_sh = sh; _sh = sh;
@ -218,8 +216,39 @@ public class XSSFConditionalFormattingRule implements ConditionalFormattingRule
} }
public XSSFColorScaleFormatting createColorScaleFormatting() { public XSSFColorScaleFormatting createColorScaleFormatting() {
// TODO Implement // Is it already there?
return null; if (_cfRule.isSetColorScale() && _cfRule.getType() == STCfType.COLOR_SCALE)
return getColorScaleFormatting();
// Mark it as being a Color Scale
_cfRule.setType(STCfType.COLOR_SCALE);
// Ensure the right element
CTColorScale scale = null;
if (_cfRule.isSetColorScale()) {
scale = _cfRule.getColorScale();
} else {
scale = _cfRule.addNewColorScale();
}
// Add a default set of thresholds and colors
if (scale.sizeOfCfvoArray() == 0) {
CTCfvo cfvo;
cfvo = scale.addNewCfvo();
cfvo.setType(STCfvoType.Enum.forString(RangeType.MIN.name));
cfvo = scale.addNewCfvo();
cfvo.setType(STCfvoType.Enum.forString(RangeType.PERCENTILE.name));
cfvo.setVal("50");
cfvo = scale.addNewCfvo();
cfvo.setType(STCfvoType.Enum.forString(RangeType.MAX.name));
for (int i=0; i<3; i++) {
scale.addNewColor();
}
}
// Wrap and return
return new XSSFColorScaleFormatting(scale);
} }
public XSSFColorScaleFormatting getColorScaleFormatting() { public XSSFColorScaleFormatting getColorScaleFormatting() {
if (_cfRule.isSetColorScale()) { if (_cfRule.isSetColorScale()) {

View File

@ -773,6 +773,7 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
// Mixed icons - Column U // Mixed icons - Column U
// TODO Support EXT formattings // TODO Support EXT formattings
} }
private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) { private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) {
assertEquals(1, cf.getNumberOfRules()); assertEquals(1, cf.getNumberOfRules());
ConditionalFormattingRule cr = cf.getRule(0); ConditionalFormattingRule cr = cf.getRule(0);
@ -812,8 +813,9 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
assertEquals(null, cr.getFormula1()); assertEquals(null, cr.getFormula1());
assertEquals(null, cr.getFormula2()); assertEquals(null, cr.getFormula2());
// TODO Implement // TODO Finish HSSF
/* if (cr instanceof HSSFConditionalFormattingRule) return;
ColorScaleFormatting color = cr.getColorScaleFormatting(); ColorScaleFormatting color = cr.getColorScaleFormatting();
assertNotNull(color); assertNotNull(color);
assertNotNull(color.getColors()); assertNotNull(color.getColors());
@ -831,18 +833,16 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
} else if (i == colors.length-1) { } else if (i == colors.length-1) {
assertEquals(RangeType.MAX, th.getRangeType()); assertEquals(RangeType.MAX, th.getRangeType());
} else { } else {
assertEquals(RangeType.PERCENT, th.getRangeType()); assertEquals(RangeType.PERCENTILE, th.getRangeType());
assertEquals(steps*i, th.getValue()); assertEquals(steps*i, th.getValue().intValue());
} }
assertEquals(null, th.getFormula()); assertEquals(null, th.getFormula());
} }
// Colors should match // Colors should match
for (int i=0; i<colors.length; i++) { for (int i=0; i<colors.length; i++) {
Color c = color.getColors()[i]; assertColour(colors[i], color.getColors()[i]);
assertEquals(colors[i], c.toString());
} }
*/
} }
public void testCreateFontFormatting() { public void testCreateFontFormatting() {
@ -1068,6 +1068,13 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
assertEquals(null, iconFmt.getThresholds()[3].getValue()); assertEquals(null, iconFmt.getThresholds()[3].getValue());
} }
public void testCreateColorScaleFormatting() {
// TODO Implement then test
}
public void testCreateDataBarFormatting() {
// TODO Implement then test
}
public void testBug55380() { public void testBug55380() {
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet(); Sheet sheet = wb.createSheet();