]> source.dussan.org Git - poi.git/commitdiff
XSSFCellStyle borderStyle methods -> TODO: borderColor related methods tests
authorPaolo Mottadelli <paolo@apache.org>
Sat, 5 Apr 2008 17:35:28 +0000 (17:35 +0000)
committerPaolo Mottadelli <paolo@apache.org>
Sat, 5 Apr 2008 17:35:28 +0000 (17:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645141 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java

index c3d148b6ef81be56ec2e5a4c02a8a6563b5fab89..f2a9ddcdeddd24b4e905c63f22eed1923ba8390b 100644 (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);
+       }
        
 }
index 37e67f674384ca2012e828f94f1301d4153dd65a..485814be0991c11d3a328e4d00f0664606402744 100644 (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();
index 378375f7199f51b17554da8d6c9fb2d4139823fd..98ebba8eb5a47ce6719c0bd4320d69bf1f4528f7 100644 (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());
        }
index 83c69fdc4bc0734aed9f1b860dafa76be428b82b..59995a6e78c6235bfda0a34d3773850ebafe3ba7 100644 (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());
        }
        
 }