XSSFCellStyle borderStyle methods -> TODO: borderColor related methods tests

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Paolo Mottadelli 2008-04-05 17:35:28 +00:00
parent 8bc07881fb
commit 0c8605d7b9
4 changed files with 98 additions and 52 deletions

View File

@ -25,7 +25,8 @@ import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
@ -90,39 +91,39 @@ public class XSSFCellStyle implements CellStyle {
}
public short getBorderBottom() {
return (short) (getBorderStyle(BorderSides.BOTTOM).intValue() - 1);
return getBorderStyleAsShort(BorderSide.BOTTOM);
}
public String getBorderBottomAsString() {
return getBorderStyle(BorderSides.BOTTOM).toString();
return getBorderStyleAsString(BorderSide.BOTTOM);
}
public short getBorderLeft() {
return (short) (getBorderStyle(BorderSides.LEFT).intValue() - 1);
return getBorderStyleAsShort(BorderSide.LEFT);
}
public String getBorderLeftAsString() {
return getBorderStyle(BorderSides.LEFT).toString();
return getBorderStyleAsString(BorderSide.LEFT);
}
public short getBorderRight() {
return (short) (getBorderStyle(BorderSides.RIGHT).intValue() - 1);
return getBorderStyleAsShort(BorderSide.RIGHT);
}
public String getBorderRightAsString() {
return getBorderStyle(BorderSides.RIGHT).toString();
return getBorderStyleAsString(BorderSide.RIGHT);
}
public short getBorderTop() {
return (short) (getBorderStyle(BorderSides.TOP).intValue() - 1);
return getBorderStyleAsShort(BorderSide.TOP);
}
public String getBorderTopAsString() {
return getBorderStyle(BorderSides.TOP).toString();
return getBorderStyleAsString(BorderSide.TOP);
}
public short getBottomBorderColor() {
return getBorderColorBySide(BorderSides.BOTTOM);
return getBorderColorIndexed(BorderSide.BOTTOM);
}
public short getDataFormat() {
@ -173,7 +174,7 @@ public class XSSFCellStyle implements CellStyle {
}
public short getLeftBorderColor() {
return getBorderColorBySide(BorderSides.LEFT);
return getBorderColorIndexed(BorderSide.LEFT);
}
public boolean getLocked() {
@ -181,7 +182,7 @@ public class XSSFCellStyle implements CellStyle {
}
public short getRightBorderColor() {
return getBorderColorBySide(BorderSides.RIGHT);
return getBorderColorIndexed(BorderSide.RIGHT);
}
public short getRotation() {
@ -189,7 +190,7 @@ public class XSSFCellStyle implements CellStyle {
}
public short getTopBorderColor() {
return getBorderColorBySide(BorderSides.TOP);
return getBorderColorIndexed(BorderSide.TOP);
}
public short getVerticalAlignment() {
@ -213,28 +214,39 @@ public class XSSFCellStyle implements CellStyle {
}
public void setBorderBottom(short border) {
// TODO Auto-generated method stub
setBorderBottomEnum(STBorderStyle.Enum.forInt(border));
}
public void setBorderBottomEnum(STBorderStyle.Enum style) {
getCellBorder().setBorderStyle(BorderSide.BOTTOM, style);
}
public void setBorderLeft(short border) {
// TODO Auto-generated method stub
setBorderLeftEnum(STBorderStyle.Enum.forInt(border));
}
public void setBorderLeftEnum(STBorderStyle.Enum style) {
getCellBorder().setBorderStyle(BorderSide.LEFT, style);
}
public void setBorderRight(short border) {
// TODO Auto-generated method stub
setBorderRightEnum(STBorderStyle.Enum.forInt(border));
}
public void setBorderRightEnum(STBorderStyle.Enum style) {
getCellBorder().setBorderStyle(BorderSide.RIGHT, style);
}
public void setBorderTop(short border) {
// TODO Auto-generated method stub
setBorderTopEnum(STBorderStyle.Enum.forInt(border));
}
public void setBorderTopEnum(STBorderStyle.Enum style) {
getCellBorder().setBorderStyle(BorderSide.TOP, style);
}
public void setBottomBorderColor(short color) {
// TODO Auto-generated method stub
setBorderColorIndexed(BorderSide.BOTTOM, color);
}
public void setDataFormat(short fmt) {
@ -270,8 +282,7 @@ public class XSSFCellStyle implements CellStyle {
}
public void setLeftBorderColor(short color) {
// TODO Auto-generated method stub
setBorderColorIndexed(BorderSide.LEFT, color);
}
public void setLocked(boolean locked) {
@ -279,8 +290,7 @@ public class XSSFCellStyle implements CellStyle {
}
public void setRightBorderColor(short color) {
// TODO Auto-generated method stub
setBorderColorIndexed(BorderSide.RIGHT, color);
}
public void setRotation(short rotation) {
@ -288,8 +298,7 @@ public class XSSFCellStyle implements CellStyle {
}
public void setTopBorderColor(short color) {
// TODO Auto-generated method stub
setBorderColorIndexed(BorderSide.TOP, color);
}
public void setVerticalAlignment(short align) {
@ -332,14 +341,6 @@ public class XSSFCellStyle implements CellStyle {
}
return (int) cellStyleXf.getFillId();
}
private STBorderStyle.Enum getBorderStyle(BorderSides side) {
return getCellBorder().getBorderStyle(side);
}
private short getBorderColorBySide(BorderSides side) {
return (short) getCellBorder().getBorderColor(side).getIndexed();
}
private int getFontId() {
if (cellXf.isSetFontId()) {
@ -368,5 +369,29 @@ public class XSSFCellStyle implements CellStyle {
}
return cellXf.getAlignment();
}
private short getBorderColorIndexed(BorderSide side) {
return (short) getBorderColor(side).getIndexed();
}
private XSSFColor getBorderColor(BorderSide side) {
return getCellBorder().getBorderColor(side);
}
private void setBorderColorIndexed(BorderSide side, long color) {
getBorderColor(side).setIndexed(color);
}
private short getBorderStyleAsShort(BorderSide side) {
return (short) (getBorderStyle(side).intValue() - 1);
}
private String getBorderStyleAsString(BorderSide side) {
return getBorderStyle(side).toString();
}
private STBorderStyle.Enum getBorderStyle(BorderSide side) {
return getCellBorder().getBorderStyle(side);
}
}

View File

@ -21,6 +21,7 @@ import java.util.LinkedList;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
@ -41,7 +42,7 @@ public class XSSFCellBorder {
border = CTBorder.Factory.newInstance();
}
public static enum BorderSides {
public static enum BorderSide {
TOP, RIGHT, BOTTOM, LEFT
}
@ -53,11 +54,15 @@ public class XSSFCellBorder {
return borders.size() - 1;
}
public org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum getBorderStyle(BorderSides side) {
public STBorderStyle.Enum getBorderStyle(BorderSide side) {
return getBorder(side).getStyle();
}
public XSSFColor getBorderColor(BorderSides side) {
public void setBorderStyle(BorderSide side, STBorderStyle.Enum style) {
getBorder(side).setStyle(style);
}
public XSSFColor getBorderColor(BorderSide side) {
CTBorderPr borderPr = getBorder(side);
if (!borderPr.isSetColor()) {
borderPr.addNewColor();
@ -65,7 +70,7 @@ public class XSSFCellBorder {
return new XSSFColor(getBorder(side).getColor());
}
private CTBorderPr getBorder(BorderSides side) {
private CTBorderPr getBorder(BorderSide side) {
switch (side) {
case TOP: return border.getTop();
case RIGHT: return border.getRight();

View File

@ -80,9 +80,13 @@ public class TestXSSFCellStyle extends TestCase {
cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
}
public void testGetBorderBottom() {
public void testGetSetBorderBottom() {
ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
assertEquals((short)1, cellStyle.getBorderBottom());
cellStyle.setBorderBottom((short) 2);
assertEquals(STBorderStyle.THIN, ctBorderA.getBottom().getStyle());
cellStyle.setBorderBottomEnum(STBorderStyle.THICK);
assertEquals(6, ctBorderA.getBottom().getStyle().intValue());
}
public void testGetBorderBottomAsString() {
@ -90,9 +94,13 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("thin", cellStyle.getBorderBottomAsString());
}
public void testGetBorderRight() {
public void testGetSetBorderRight() {
ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
assertEquals((short)2, cellStyle.getBorderRight());
cellStyle.setBorderRight((short) 2);
assertEquals(STBorderStyle.THIN, ctBorderA.getRight().getStyle());
cellStyle.setBorderRightEnum(STBorderStyle.THICK);
assertEquals(6, ctBorderA.getRight().getStyle().intValue());
}
public void testGetBorderRightAsString() {
@ -100,9 +108,13 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("medium", cellStyle.getBorderRightAsString());
}
public void testGetBorderLeft() {
public void testGetSetBorderLeft() {
ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
assertEquals((short)3, cellStyle.getBorderLeft());
cellStyle.setBorderLeft((short) 2);
assertEquals(STBorderStyle.THIN, ctBorderA.getLeft().getStyle());
cellStyle.setBorderLeftEnum(STBorderStyle.THICK);
assertEquals(6, ctBorderA.getLeft().getStyle().intValue());
}
public void testGetBorderLeftAsString() {
@ -110,12 +122,16 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("dashed", cellStyle.getBorderLeftAsString());
}
public void testGetBorderTop() {
public void testGetSetBorderTop() {
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals((short)7, cellStyle.getBorderTop());
cellStyle.setBorderTop((short) 2);
assertEquals(STBorderStyle.THIN, ctBorderA.getTop().getStyle());
cellStyle.setBorderTopEnum(STBorderStyle.THICK);
assertEquals(6, ctBorderA.getTop().getStyle().intValue());
}
public void testGetTopBottomAsString() {
public void testGetBorderTopAsString() {
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals("hair", cellStyle.getBorderTopAsString());
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.xssf.usermodel.extensions;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSides;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
@ -38,11 +38,11 @@ public class TestXSSFBorder extends TestCase {
right.setStyle(STBorderStyle.NONE);
bottom.setStyle(STBorderStyle.THIN);
XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
assertEquals("dashDot", cellBorderStyle.getBorderStyle(BorderSides.TOP).toString());
assertEquals("none", cellBorderStyle.getBorderStyle(BorderSides.RIGHT).toString());
assertEquals(1, cellBorderStyle.getBorderStyle(BorderSides.RIGHT).intValue());
assertEquals("thin", cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).toString());
assertEquals(2, cellBorderStyle.getBorderStyle(BorderSides.BOTTOM).intValue());
assertEquals("dashDot", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString());
assertEquals("none", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString());
assertEquals(1, cellBorderStyle.getBorderStyle(BorderSide.RIGHT).intValue());
assertEquals("thin", cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).toString());
assertEquals(2, cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).intValue());
}
}