#58138 CF Border colour getters and setters on Color objects as well as shorts

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-14 21:19:13 +00:00
parent da1abea6b9
commit 13065c6b4c
2 changed files with 144 additions and 53 deletions

View File

@ -64,14 +64,19 @@ public interface BorderFormatting {
short getBorderTop(); short getBorderTop();
short getBottomBorderColor(); short getBottomBorderColor();
Color getBottomBorderColorColor();
short getDiagonalBorderColor(); short getDiagonalBorderColor();
Color getDiagonalBorderColorColor();
short getLeftBorderColor(); short getLeftBorderColor();
Color getLeftBorderColorColor();
short getRightBorderColor(); short getRightBorderColor();
Color getRightBorderColorColor();
short getTopBorderColor(); short getTopBorderColor();
Color getTopBorderColorColor();
void setBorderBottom(short border); void setBorderBottom(short border);
@ -104,12 +109,17 @@ public interface BorderFormatting {
void setBorderTop(short border); void setBorderTop(short border);
void setBottomBorderColor(short color); void setBottomBorderColor(short color);
void setBottomBorderColor(Color color);
void setDiagonalBorderColor(short color); void setDiagonalBorderColor(short color);
void setDiagonalBorderColor(Color color);
void setLeftBorderColor(short color); void setLeftBorderColor(short color);
void setLeftBorderColor(Color color);
void setRightBorderColor(short color); void setRightBorderColor(short color);
void setRightBorderColor(Color color);
void setTopBorderColor(short color); void setTopBorderColor(short color);
void setTopBorderColor(Color color);
} }

View File

@ -17,13 +17,15 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.BorderFormatting; import org.apache.poi.ss.usermodel.BorderFormatting;
import org.apache.poi.ss.usermodel.Color;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
/** /**
* @author Yegor Kozlov * XSSF high level representation for Border Formatting component
* of Conditional Formatting settings
*/ */
public class XSSFBorderFormatting implements BorderFormatting { public class XSSFBorderFormatting implements BorderFormatting {
CTBorder _border; CTBorder _border;
@ -57,39 +59,64 @@ public class XSSFBorderFormatting implements BorderFormatting {
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
public short getBottomBorderColor(){ public XSSFColor getBottomBorderColorColor() {
if(!_border.isSetBottom()) return 0; if(!_border.isSetBottom()) return null;
CTBorderPr pr = _border.getBottom(); CTBorderPr pr = _border.getBottom();
return (short)pr.getColor().getIndexed(); return new XSSFColor(pr.getColor());
}
public short getBottomBorderColor() {
XSSFColor color = getBottomBorderColorColor();
if (color == null) return 0;
return color.getIndexed();
} }
public short getDiagonalBorderColor(){ public XSSFColor getDiagonalBorderColorColor() {
if(!_border.isSetDiagonal()) return 0; if(!_border.isSetDiagonal()) return null;
CTBorderPr pr = _border.getDiagonal(); CTBorderPr pr = _border.getDiagonal();
return (short)pr.getColor().getIndexed(); return new XSSFColor(pr.getColor());
}
public short getDiagonalBorderColor() {
XSSFColor color = getDiagonalBorderColorColor();
if (color == null) return 0;
return color.getIndexed();
} }
public short getLeftBorderColor(){ public XSSFColor getLeftBorderColorColor() {
if(!_border.isSetLeft()) return 0; if(!_border.isSetLeft()) return null;
CTBorderPr pr = _border.getLeft(); CTBorderPr pr = _border.getLeft();
return (short)pr.getColor().getIndexed(); return new XSSFColor(pr.getColor());
}
public short getLeftBorderColor() {
XSSFColor color = getLeftBorderColorColor();
if (color == null) return 0;
return color.getIndexed();
} }
public short getRightBorderColor(){ public XSSFColor getRightBorderColorColor() {
if(!_border.isSetRight()) return 0; if(!_border.isSetRight()) return null;
CTBorderPr pr = _border.getRight(); CTBorderPr pr = _border.getRight();
return (short)pr.getColor().getIndexed(); return new XSSFColor(pr.getColor());
}
public short getRightBorderColor() {
XSSFColor color = getRightBorderColorColor();
if (color == null) return 0;
return color.getIndexed();
} }
public short getTopBorderColor(){ public XSSFColor getTopBorderColorColor() {
if(!_border.isSetTop()) return 0; if(!_border.isSetTop()) return null;
CTBorderPr pr = _border.getTop(); CTBorderPr pr = _border.getTop();
return (short)pr.getColor().getIndexed(); return new XSSFColor(pr.getColor());
}
public short getTopBorderColor() {
XSSFColor color = getRightBorderColorColor();
if (color == null) return 0;
return color.getIndexed();
} }
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
@ -122,44 +149,98 @@ public class XSSFBorderFormatting implements BorderFormatting {
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBottomBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setBottomBorderColor((CTColor)null);
else setBottomBorderColor(xcolor.getCTColor());
}
public void setBottomBorderColor(short color) { public void setBottomBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color);
setBottomBorderColor(ctColor);
}
public void setBottomBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom(); CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom();
if (color == null) {
CTColor ctColor = CTColor.Factory.newInstance(); pr.unsetColor();
ctColor.setIndexed(color); } else {
pr.setColor(ctColor); pr.setColor(color);
}
} }
public void setDiagonalBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setDiagonalBorderColor((CTColor)null);
else setDiagonalBorderColor(xcolor.getCTColor());
}
public void setDiagonalBorderColor(short color) { public void setDiagonalBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color);
setDiagonalBorderColor(ctColor);
}
public void setDiagonalBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal(); CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal();
if (color == null) {
CTColor ctColor = CTColor.Factory.newInstance(); pr.unsetColor();
ctColor.setIndexed(color); } else {
pr.setColor(ctColor); pr.setColor(color);
}
} }
public void setLeftBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setLeftBorderColor((CTColor)null);
else setLeftBorderColor(xcolor.getCTColor());
}
public void setLeftBorderColor(short color) { public void setLeftBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color);
setLeftBorderColor(ctColor);
}
public void setLeftBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft(); CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft();
if (color == null) {
CTColor ctColor = CTColor.Factory.newInstance(); pr.unsetColor();
ctColor.setIndexed(color); } else {
pr.setColor(ctColor); pr.setColor(color);
}
} }
public void setRightBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setRightBorderColor((CTColor)null);
else setRightBorderColor(xcolor.getCTColor());
}
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color);
setRightBorderColor(ctColor);
}
public void setRightBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight(); CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight();
if (color == null) {
CTColor ctColor = CTColor.Factory.newInstance(); pr.unsetColor();
ctColor.setIndexed(color); } else {
pr.setColor(ctColor); pr.setColor(color);
}
} }
public void setTopBorderColor(Color color) {
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) setTopBorderColor((CTColor)null);
else setTopBorderColor(xcolor.getCTColor());
}
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop();
CTColor ctColor = CTColor.Factory.newInstance(); CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color); ctColor.setIndexed(color);
pr.setColor(ctColor); setTopBorderColor(ctColor);
}
public void setTopBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop();
if (color == null) {
pr.unsetColor();
} else {
pr.setColor(color);
}
} }
} }