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.XSSFCellAlignment;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder; import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill; 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.CTCellAlignment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
@ -90,39 +91,39 @@ public class XSSFCellStyle implements CellStyle {
} }
public short getBorderBottom() { public short getBorderBottom() {
return (short) (getBorderStyle(BorderSides.BOTTOM).intValue() - 1); return getBorderStyleAsShort(BorderSide.BOTTOM);
} }
public String getBorderBottomAsString() { public String getBorderBottomAsString() {
return getBorderStyle(BorderSides.BOTTOM).toString(); return getBorderStyleAsString(BorderSide.BOTTOM);
} }
public short getBorderLeft() { public short getBorderLeft() {
return (short) (getBorderStyle(BorderSides.LEFT).intValue() - 1); return getBorderStyleAsShort(BorderSide.LEFT);
} }
public String getBorderLeftAsString() { public String getBorderLeftAsString() {
return getBorderStyle(BorderSides.LEFT).toString(); return getBorderStyleAsString(BorderSide.LEFT);
} }
public short getBorderRight() { public short getBorderRight() {
return (short) (getBorderStyle(BorderSides.RIGHT).intValue() - 1); return getBorderStyleAsShort(BorderSide.RIGHT);
} }
public String getBorderRightAsString() { public String getBorderRightAsString() {
return getBorderStyle(BorderSides.RIGHT).toString(); return getBorderStyleAsString(BorderSide.RIGHT);
} }
public short getBorderTop() { public short getBorderTop() {
return (short) (getBorderStyle(BorderSides.TOP).intValue() - 1); return getBorderStyleAsShort(BorderSide.TOP);
} }
public String getBorderTopAsString() { public String getBorderTopAsString() {
return getBorderStyle(BorderSides.TOP).toString(); return getBorderStyleAsString(BorderSide.TOP);
} }
public short getBottomBorderColor() { public short getBottomBorderColor() {
return getBorderColorBySide(BorderSides.BOTTOM); return getBorderColorIndexed(BorderSide.BOTTOM);
} }
public short getDataFormat() { public short getDataFormat() {
@ -173,7 +174,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public short getLeftBorderColor() { public short getLeftBorderColor() {
return getBorderColorBySide(BorderSides.LEFT); return getBorderColorIndexed(BorderSide.LEFT);
} }
public boolean getLocked() { public boolean getLocked() {
@ -181,7 +182,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public short getRightBorderColor() { public short getRightBorderColor() {
return getBorderColorBySide(BorderSides.RIGHT); return getBorderColorIndexed(BorderSide.RIGHT);
} }
public short getRotation() { public short getRotation() {
@ -189,7 +190,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public short getTopBorderColor() { public short getTopBorderColor() {
return getBorderColorBySide(BorderSides.TOP); return getBorderColorIndexed(BorderSide.TOP);
} }
public short getVerticalAlignment() { public short getVerticalAlignment() {
@ -213,28 +214,39 @@ public class XSSFCellStyle implements CellStyle {
} }
public void setBorderBottom(short border) { 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) { 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) { 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) { 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) { public void setBottomBorderColor(short color) {
// TODO Auto-generated method stub setBorderColorIndexed(BorderSide.BOTTOM, color);
} }
public void setDataFormat(short fmt) { public void setDataFormat(short fmt) {
@ -270,8 +282,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public void setLeftBorderColor(short color) { public void setLeftBorderColor(short color) {
// TODO Auto-generated method stub setBorderColorIndexed(BorderSide.LEFT, color);
} }
public void setLocked(boolean locked) { public void setLocked(boolean locked) {
@ -279,8 +290,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public void setRightBorderColor(short color) { public void setRightBorderColor(short color) {
// TODO Auto-generated method stub setBorderColorIndexed(BorderSide.RIGHT, color);
} }
public void setRotation(short rotation) { public void setRotation(short rotation) {
@ -288,8 +298,7 @@ public class XSSFCellStyle implements CellStyle {
} }
public void setTopBorderColor(short color) { public void setTopBorderColor(short color) {
// TODO Auto-generated method stub setBorderColorIndexed(BorderSide.TOP, color);
} }
public void setVerticalAlignment(short align) { public void setVerticalAlignment(short align) {
@ -332,14 +341,6 @@ public class XSSFCellStyle implements CellStyle {
} }
return (int) cellStyleXf.getFillId(); 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() { private int getFontId() {
if (cellXf.isSetFontId()) { if (cellXf.isSetFontId()) {
@ -368,5 +369,29 @@ public class XSSFCellStyle implements CellStyle {
} }
return cellXf.getAlignment(); 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.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr; 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; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle.Enum;
@ -41,7 +42,7 @@ public class XSSFCellBorder {
border = CTBorder.Factory.newInstance(); border = CTBorder.Factory.newInstance();
} }
public static enum BorderSides { public static enum BorderSide {
TOP, RIGHT, BOTTOM, LEFT TOP, RIGHT, BOTTOM, LEFT
} }
@ -53,11 +54,15 @@ public class XSSFCellBorder {
return borders.size() - 1; 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(); 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); CTBorderPr borderPr = getBorder(side);
if (!borderPr.isSetColor()) { if (!borderPr.isSetColor()) {
borderPr.addNewColor(); borderPr.addNewColor();
@ -65,7 +70,7 @@ public class XSSFCellBorder {
return new XSSFColor(getBorder(side).getColor()); return new XSSFColor(getBorder(side).getColor());
} }
private CTBorderPr getBorder(BorderSides side) { private CTBorderPr getBorder(BorderSide side) {
switch (side) { switch (side) {
case TOP: return border.getTop(); case TOP: return border.getTop();
case RIGHT: return border.getRight(); case RIGHT: return border.getRight();

View File

@ -80,9 +80,13 @@ public class TestXSSFCellStyle extends TestCase {
cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable); cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
} }
public void testGetBorderBottom() { public void testGetSetBorderBottom() {
ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN); ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
assertEquals((short)1, cellStyle.getBorderBottom()); 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() { public void testGetBorderBottomAsString() {
@ -90,9 +94,13 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("thin", cellStyle.getBorderBottomAsString()); assertEquals("thin", cellStyle.getBorderBottomAsString());
} }
public void testGetBorderRight() { public void testGetSetBorderRight() {
ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM); ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
assertEquals((short)2, cellStyle.getBorderRight()); 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() { public void testGetBorderRightAsString() {
@ -100,9 +108,13 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("medium", cellStyle.getBorderRightAsString()); assertEquals("medium", cellStyle.getBorderRightAsString());
} }
public void testGetBorderLeft() { public void testGetSetBorderLeft() {
ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED); ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
assertEquals((short)3, cellStyle.getBorderLeft()); 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() { public void testGetBorderLeftAsString() {
@ -110,12 +122,16 @@ public class TestXSSFCellStyle extends TestCase {
assertEquals("dashed", cellStyle.getBorderLeftAsString()); assertEquals("dashed", cellStyle.getBorderLeftAsString());
} }
public void testGetBorderTop() { public void testGetSetBorderTop() {
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR); ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals((short)7, cellStyle.getBorderTop()); 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); ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
assertEquals("hair", cellStyle.getBorderTopAsString()); assertEquals("hair", cellStyle.getBorderTopAsString());
} }

View File

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