Provide format-agnostic conditional formatting patter colour getters and setters
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691047 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e349269fcf
commit
2eb88db1b0
@ -135,13 +135,13 @@ public final class HSSFConditionalFormattingRule implements ConditionalFormattin
|
||||
if ( patternFormatting != null)
|
||||
{
|
||||
cfRuleRecord.setPatternFormatting(patternFormatting);
|
||||
return new HSSFPatternFormatting(cfRuleRecord);
|
||||
return new HSSFPatternFormatting(cfRuleRecord, workbook);
|
||||
}
|
||||
else if( create )
|
||||
{
|
||||
patternFormatting = new PatternFormatting();
|
||||
cfRuleRecord.setPatternFormatting(patternFormatting);
|
||||
return new HSSFPatternFormatting(cfRuleRecord);
|
||||
return new HSSFPatternFormatting(cfRuleRecord, workbook);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -19,17 +19,21 @@ package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.CFRuleBase;
|
||||
import org.apache.poi.hssf.record.cf.PatternFormatting;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.Color;
|
||||
|
||||
/**
|
||||
* High level representation for Conditional Formatting settings
|
||||
*/
|
||||
public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.PatternFormatting
|
||||
{
|
||||
private final HSSFWorkbook workbook;
|
||||
private final CFRuleBase cfRuleRecord;
|
||||
private final PatternFormatting patternFormatting;
|
||||
|
||||
protected HSSFPatternFormatting(CFRuleBase cfRuleRecord)
|
||||
protected HSSFPatternFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook)
|
||||
{
|
||||
this.workbook = workbook;
|
||||
this.cfRuleRecord = cfRuleRecord;
|
||||
this.patternFormatting = cfRuleRecord.getPatternFormatting();
|
||||
}
|
||||
@ -39,7 +43,15 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
||||
return patternFormatting;
|
||||
}
|
||||
|
||||
/**
|
||||
public HSSFColor getFillBackgroundColorColor() {
|
||||
return workbook.getCustomPalette().getColor(getFillBackgroundColor());
|
||||
}
|
||||
|
||||
public HSSFColor getFillForegroundColorColor() {
|
||||
return workbook.getCustomPalette().getColor(getFillForegroundColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.poi.hssf.record.cf.PatternFormatting#getFillBackgroundColor()
|
||||
*/
|
||||
public short getFillBackgroundColor()
|
||||
@ -63,7 +75,31 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
||||
return (short)patternFormatting.getFillPattern();
|
||||
}
|
||||
|
||||
/**
|
||||
public void setFillBackgroundColor(Color bg) {
|
||||
if (bg != null && !(bg instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
HSSFColor hcolor = (HSSFColor)bg;
|
||||
if (hcolor == null) {
|
||||
setFillBackgroundColor((short)0);
|
||||
} else {
|
||||
setFillBackgroundColor(hcolor.getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public void setFillForegroundColor(Color fg) {
|
||||
if (fg != null && !(fg instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
HSSFColor hcolor = (HSSFColor)fg;
|
||||
if (hcolor == null) {
|
||||
setFillForegroundColor((short)0);
|
||||
} else {
|
||||
setFillForegroundColor(hcolor.getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bg
|
||||
* @see org.apache.poi.hssf.record.cf.PatternFormatting#setFillBackgroundColor(int)
|
||||
*/
|
||||
|
@ -63,14 +63,16 @@ public interface PatternFormatting {
|
||||
public final static short LEAST_DOTS = 18 ;
|
||||
|
||||
short getFillBackgroundColor();
|
||||
|
||||
short getFillForegroundColor();
|
||||
Color getFillBackgroundColorColor();
|
||||
Color getFillForegroundColorColor();
|
||||
|
||||
short getFillPattern();
|
||||
|
||||
void setFillBackgroundColor(short bg);
|
||||
|
||||
void setFillForegroundColor(short fg);
|
||||
void setFillBackgroundColor(Color bg);
|
||||
void setFillForegroundColor(Color fg);
|
||||
|
||||
void setFillPattern(short fp);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Color;
|
||||
import org.apache.poi.ss.usermodel.PatternFormatting;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
|
||||
@ -34,37 +35,65 @@ public class XSSFPatternFormatting implements PatternFormatting {
|
||||
_fill = fill;
|
||||
}
|
||||
|
||||
public short getFillBackgroundColor(){
|
||||
if(!_fill.isSetPatternFill()) return 0;
|
||||
|
||||
return (short)_fill.getPatternFill().getBgColor().getIndexed();
|
||||
public XSSFColor getFillBackgroundColorColor() {
|
||||
if(!_fill.isSetPatternFill()) return null;
|
||||
return new XSSFColor(_fill.getPatternFill().getBgColor());
|
||||
}
|
||||
|
||||
public short getFillForegroundColor(){
|
||||
public XSSFColor getFillForegroundColorColor() {
|
||||
if(!_fill.isSetPatternFill() || ! _fill.getPatternFill().isSetFgColor())
|
||||
return 0;
|
||||
|
||||
return (short)_fill.getPatternFill().getFgColor().getIndexed();
|
||||
return null;
|
||||
return new XSSFColor(_fill.getPatternFill().getFgColor());
|
||||
}
|
||||
|
||||
public short getFillPattern(){
|
||||
public short getFillPattern() {
|
||||
if(!_fill.isSetPatternFill() || !_fill.getPatternFill().isSetPatternType()) return NO_FILL;
|
||||
|
||||
return (short)(_fill.getPatternFill().getPatternType().intValue() - 1);
|
||||
}
|
||||
|
||||
public void setFillBackgroundColor(short bg){
|
||||
CTPatternFill ptrn = _fill.isSetPatternFill() ? _fill.getPatternFill() : _fill.addNewPatternFill();
|
||||
CTColor bgColor = CTColor.Factory.newInstance();
|
||||
bgColor.setIndexed(bg);
|
||||
ptrn.setBgColor(bgColor);
|
||||
public short getFillBackgroundColor() {
|
||||
XSSFColor color = getFillBackgroundColorColor();
|
||||
if (color == null) return 0;
|
||||
return color.getIndexed();
|
||||
}
|
||||
public short getFillForegroundColor() {
|
||||
XSSFColor color = getFillForegroundColorColor();
|
||||
if (color == null) return 0;
|
||||
return color.getIndexed();
|
||||
}
|
||||
|
||||
public void setFillForegroundColor(short fg){
|
||||
public void setFillBackgroundColor(Color bg) {
|
||||
if (bg != null && !(bg instanceof XSSFColor)) {
|
||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
||||
}
|
||||
XSSFColor xcolor = (XSSFColor)bg;
|
||||
setFillBackgroundColor(xcolor.getCTColor());
|
||||
}
|
||||
public void setFillBackgroundColor(short bg) {
|
||||
CTColor bgColor = CTColor.Factory.newInstance();
|
||||
bgColor.setIndexed(bg);
|
||||
setFillBackgroundColor(bgColor);
|
||||
}
|
||||
public void setFillBackgroundColor(CTColor color) {
|
||||
CTPatternFill ptrn = _fill.isSetPatternFill() ? _fill.getPatternFill() : _fill.addNewPatternFill();
|
||||
ptrn.setBgColor(color);
|
||||
}
|
||||
|
||||
public void setFillForegroundColor(Color fg) {
|
||||
if (fg != null && !(fg instanceof XSSFColor)) {
|
||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
||||
}
|
||||
XSSFColor xcolor = (XSSFColor)fg;
|
||||
setFillForegroundColor(xcolor.getCTColor());
|
||||
}
|
||||
public void setFillForegroundColor(short fg) {
|
||||
CTColor fgColor = CTColor.Factory.newInstance();
|
||||
fgColor.setIndexed(fg);
|
||||
ptrn.setFgColor(fgColor);
|
||||
setFillForegroundColor(fgColor);
|
||||
}
|
||||
public void setFillForegroundColor(CTColor color) {
|
||||
CTPatternFill ptrn = _fill.isSetPatternFill() ? _fill.getPatternFill() : _fill.addNewPatternFill();
|
||||
ptrn.setFgColor(color);
|
||||
}
|
||||
|
||||
public void setFillPattern(short fp){
|
||||
|
Loading…
Reference in New Issue
Block a user