#58138 Color object support for HSSF CF borders

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-14 20:52:07 +00:00
parent 6dc77bc7b3
commit d7e781d349
1 changed files with 65 additions and 6 deletions

View File

@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.record.CFRuleBase; import org.apache.poi.hssf.record.CFRuleBase;
import org.apache.poi.hssf.record.cf.BorderFormatting; import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Color;
/** /**
* High level representation for Border Formatting component * High level representation for Border Formatting component
@ -72,23 +73,42 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
public short getDiagonalBorderColor() { public short getDiagonalBorderColor() {
return (short)borderFormatting.getDiagonalBorderColor(); return (short)borderFormatting.getDiagonalBorderColor();
} }
public HSSFColor getDiagonalBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getDiagonalBorderColor()
);
}
public short getLeftBorderColor() { public short getLeftBorderColor() {
return (short)borderFormatting.getLeftBorderColor(); return (short)borderFormatting.getLeftBorderColor();
} }
public HSSFColor getLeftBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getLeftBorderColor()
);
}
public short getRightBorderColor() { public short getRightBorderColor() {
return (short)borderFormatting.getRightBorderColor(); return (short)borderFormatting.getRightBorderColor();
} }
public HSSFColor getRightBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getRightBorderColor()
);
}
public short getTopBorderColor() { public short getTopBorderColor() {
return (short)borderFormatting.getTopBorderColor(); return (short)borderFormatting.getTopBorderColor();
} }
public HSSFColor getTopBorderColorColor() {
return workbook.getCustomPalette().getColor(
borderFormatting.getTopBorderColor()
);
}
public boolean isBackwardDiagonalOn() { public boolean isBackwardDiagonalOn() {
return borderFormatting.isBackwardDiagonalOn(); return borderFormatting.isBackwardDiagonalOn();
} }
public boolean isForwardDiagonalOn() { public boolean isForwardDiagonalOn() {
return borderFormatting.isForwardDiagonalOn(); return borderFormatting.isForwardDiagonalOn();
} }
@ -99,6 +119,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(on); cfRuleRecord.setTopLeftBottomRightBorderModified(on);
} }
} }
public void setForwardDiagonalOn(boolean on) {
borderFormatting.setForwardDiagonalOn(on);
if (on) {
cfRuleRecord.setBottomLeftTopRightBorderModified(on);
}
}
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
borderFormatting.setBorderBottom(border); borderFormatting.setBorderBottom(border);
@ -155,6 +181,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setBottomBorderModified(false); cfRuleRecord.setBottomBorderModified(false);
} }
} }
public void setBottomBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
setBottomBorderColor((short)0);
} else {
setBottomBorderColor(hcolor.getIndex());
}
}
public void setDiagonalBorderColor(short color) { public void setDiagonalBorderColor(short color) {
borderFormatting.setDiagonalBorderColor(color); borderFormatting.setDiagonalBorderColor(color);
@ -166,11 +200,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopLeftBottomRightBorderModified(false); cfRuleRecord.setTopLeftBottomRightBorderModified(false);
} }
} }
public void setDiagonalBorderColor(Color color) {
public void setForwardDiagonalOn(boolean on) { HSSFColor hcolor = HSSFColor.toHSSFColor(color);
borderFormatting.setForwardDiagonalOn(on); if (hcolor == null) {
if (on) { setDiagonalBorderColor((short)0);
cfRuleRecord.setBottomLeftTopRightBorderModified(on); } else {
setDiagonalBorderColor(hcolor.getIndex());
} }
} }
@ -182,6 +217,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setLeftBorderModified(false); cfRuleRecord.setLeftBorderModified(false);
} }
} }
public void setLeftBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
setLeftBorderColor((short)0);
} else {
setLeftBorderColor(hcolor.getIndex());
}
}
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
borderFormatting.setRightBorderColor(color); borderFormatting.setRightBorderColor(color);
@ -191,6 +234,14 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setRightBorderModified(false); cfRuleRecord.setRightBorderModified(false);
} }
} }
public void setRightBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
setRightBorderColor((short)0);
} else {
setRightBorderColor(hcolor.getIndex());
}
}
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
borderFormatting.setTopBorderColor(color); borderFormatting.setTopBorderColor(color);
@ -200,4 +251,12 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
cfRuleRecord.setTopBorderModified(false); cfRuleRecord.setTopBorderModified(false);
} }
} }
public void setTopBorderColor(Color color) {
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
if (hcolor == null) {
setTopBorderColor((short)0);
} else {
setTopBorderColor(hcolor.getIndex());
}
}
} }