#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 8a62462905
commit e0f6ff5ca1
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,149 +17,230 @@
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;
/*package*/ XSSFBorderFormatting(CTBorder border){ /*package*/ XSSFBorderFormatting(CTBorder border) {
_border = border; _border = border;
} }
public short getBorderBottom(){ public short getBorderBottom() {
STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
public short getBorderDiagonal(){ public short getBorderDiagonal() {
STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
public short getBorderLeft(){ public short getBorderLeft() {
STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
public short getBorderRight(){ public short getBorderRight() {
STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null;
return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1); return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
} }
public short getBorderTop(){ public short getBorderTop() {
STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null; STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
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) {
CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom(); CTBorderPr pr = _border.isSetBottom() ? _border.getBottom() : _border.addNewBottom();
if(border == BORDER_NONE) _border.unsetBottom(); if(border == BORDER_NONE) _border.unsetBottom();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBorderDiagonal(short border){ public void setBorderDiagonal(short border) {
CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal(); CTBorderPr pr = _border.isSetDiagonal() ? _border.getDiagonal() : _border.addNewDiagonal();
if(border == BORDER_NONE) _border.unsetDiagonal(); if(border == BORDER_NONE) _border.unsetDiagonal();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBorderLeft(short border){ public void setBorderLeft(short border) {
CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft(); CTBorderPr pr = _border.isSetLeft() ? _border.getLeft() : _border.addNewLeft();
if(border == BORDER_NONE) _border.unsetLeft(); if(border == BORDER_NONE) _border.unsetLeft();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBorderRight(short border){ public void setBorderRight(short border) {
CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight(); CTBorderPr pr = _border.isSetRight() ? _border.getRight() : _border.addNewRight();
if(border == BORDER_NONE) _border.unsetRight(); if(border == BORDER_NONE) _border.unsetRight();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBorderTop(short border){ public void setBorderTop(short border) {
CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop(); CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop();
if(border == BORDER_NONE) _border.unsetTop(); if(border == BORDER_NONE) _border.unsetTop();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
} }
public void setBottomBorderColor(short color){ 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) {
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(short 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) {
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(short 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) {
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(short 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) {
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(short 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) {
CTColor ctColor = CTColor.Factory.newInstance();
ctColor.setIndexed(color);
setTopBorderColor(ctColor);
}
public void setTopBorderColor(CTColor color) {
CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop(); CTBorderPr pr = _border.isSetTop() ? _border.getTop() : _border.addNewTop();
if (color == null) {
CTColor ctColor = CTColor.Factory.newInstance(); pr.unsetColor();
ctColor.setIndexed(color); } else {
pr.setColor(ctColor); pr.setColor(color);
}
} }
} }