poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r701797 [2/2] - in /poi/branches/ooxml/src: examples/src/org/apache/poi/xssf/usermodel/examples/ ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/model/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/java/...
Date Sun, 05 Oct 2008 13:56:29 GMT
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java Sun Oct  5 06:56:28 2008
@@ -22,76 +22,96 @@
 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.apache.poi.xssf.usermodel.BorderStyle;
 
 
 public class XSSFCellBorder {
-	private CTBorder border;
-	
-	/**
-	 * Creates a Cell Border from the supplied XML definition
-	 */
-	public XSSFCellBorder(CTBorder border) {
-		this.border = border;
-	}
-	/**
-	 * Creates a new, empty Cell Border, on the
-	 *  given Styles Table
-	 */
-	public XSSFCellBorder() {
-		border = CTBorder.Factory.newInstance();
-	}
-	
-	public static enum BorderSide {
-		TOP, RIGHT, BOTTOM, LEFT
-	}
-	
-	public long putBorder(LinkedList<CTBorder> borders) {
-		if(borders.contains(border)) {
-			return borders.indexOf(border);
-		}
-		borders.add(border);
-		return borders.size() - 1;
-	}
-	
-	public STBorderStyle.Enum getBorderStyle(BorderSide side) {
-		return getBorder(side).getStyle();
-	}
-	
-	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();
-		}
-		return new XSSFColor(getBorder(side).getColor());
-	}
-
-	public void setBorderColor(BorderSide side, XSSFColor color) {
-		getBorder(side).setColor(color.getCTColor());
-	}
-	
-	private CTBorderPr getBorder(BorderSide side) {
-		switch (side) {
-		case TOP: {
-		    CTBorderPr borderPr = border.isSetTop() ? border.getTop() : border.addNewTop();
-		    return borderPr;
-		}
-		case RIGHT: {
-			    CTBorderPr borderPr = border.isSetRight() ? border.getRight() : border.addNewRight();
-			    return borderPr;
-		}
-		case BOTTOM:{
-			    CTBorderPr borderPr = border.isSetBottom() ? border.getBottom() : border.addNewBottom();
-			    return borderPr;
-		}
-		case LEFT:{
-			    CTBorderPr borderPr = border.isSetLeft() ? border.getLeft() : border.addNewLeft();
-			    return borderPr;
-			}
-		default: throw new IllegalArgumentException("No suitable side specified for the border");
-		}
-	}
+
+    private CTBorder border;
+
+    /**
+     * Creates a Cell Border from the supplied XML definition
+     */
+    public XSSFCellBorder(CTBorder border) {
+        this.border = border;
+    }
+    /**
+     * Creates a new, empty Cell Border, on the
+     *  given Styles Table
+     */
+    public XSSFCellBorder() {
+        border = CTBorder.Factory.newInstance();
+    }
+
+    public static enum BorderSide {
+        TOP, RIGHT, BOTTOM, LEFT
+    }
+
+    public CTBorder getCTBorder() {
+        return border;
+    }
+
+    public BorderStyle getBorderStyle(BorderSide side) {
+        CTBorderPr ctBorder = getBorder(side);
+        STBorderStyle.Enum border = ctBorder == null ? STBorderStyle.NONE : ctBorder.getStyle();
+        return BorderStyle.values()[border.intValue() - 1];
+    }
+
+    public void setBorderStyle(BorderSide side, BorderStyle style) {
+        getBorder(side, true).setStyle(STBorderStyle.Enum.forInt(style.ordinal() + 1));
+    }
+
+    public XSSFColor getBorderColor(BorderSide side) {
+        CTBorderPr borderPr = getBorder(side);
+        return borderPr != null && borderPr.isSetColor() ?
+                new XSSFColor(borderPr.getColor()) : null;
+    }
+
+    public void setBorderColor(BorderSide side, XSSFColor color) {
+        CTBorderPr borderPr = getBorder(side, true);
+        if(color == null) borderPr.unsetColor();
+        else borderPr.setColor(color.getCTColor());
+    }
+
+    private CTBorderPr getBorder(BorderSide side) {
+        return getBorder(side, false);
+    }
+
+    private CTBorderPr getBorder(BorderSide side, boolean ensure) {
+        CTBorderPr borderPr;
+        switch (side) {
+            case TOP:
+                borderPr = border.getTop();
+                if(ensure && borderPr == null) borderPr = border.addNewTop();
+                break;
+            case RIGHT:
+                borderPr = border.getRight();
+                if(ensure && borderPr == null) borderPr = border.addNewRight();
+                break;
+            case BOTTOM:
+                borderPr = border.getBottom();
+                if(ensure && borderPr == null) borderPr = border.addNewBottom();
+                break;
+            case LEFT:
+                borderPr = border.getLeft();
+                if(ensure && borderPr == null) borderPr = border.addNewLeft();
+                break;
+            default:
+                throw new IllegalArgumentException("No suitable side specified for the border");
+        }
+        return borderPr;
+    }
+
+
+    public int hashCode(){
+        return border.toString().hashCode();
+    }
+
+    public boolean equals(Object o){
+        if(!(o instanceof XSSFCellBorder)) return false;
+
+        XSSFCellBorder cf = (XSSFCellBorder)o;
+        return border.toString().equals(cf.getCTBorder().toString());
+    }
+
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java Sun Oct  5 06:56:28 2008
@@ -22,6 +22,7 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType.Enum;
 
 public final class XSSFCellFill {
@@ -37,41 +38,54 @@
 	}
 	
 	public XSSFColor getFillBackgroundColor() {
-		CTColor ctColor = getPatternFill().getBgColor();
-		if (ctColor == null) {
-			XSSFColor result = new XSSFColor();
-			result.setIndexed(IndexedColors.AUTOMATIC.getIndex());
-			return result;
-		}
-		return new XSSFColor(ctColor);
-	}
+        CTPatternFill ptrn = _fill.getPatternFill();
+        if(ptrn == null) return null;
 
-	public XSSFColor getFillForegroundColor() {
-		CTColor ctColor = getPatternFill().getFgColor();
-		if (ctColor == null) {
-			XSSFColor result = new XSSFColor();
-			result.setIndexed(IndexedColors.AUTOMATIC.getIndex());
-			return result;
-		}
-		return new XSSFColor(ctColor);
+        CTColor ctColor = ptrn.getBgColor();
+		return ctColor == null ? null : new XSSFColor(ctColor);
 	}
 
-	public Enum getPatternType() {
-		return getPatternFill().getPatternType();
-	}
-	
-	/**
-	 * @return the index of the just added fill
-	 */
-	public int putFill(List<CTFill> fills) {
-		if (fills.contains(_fill)) {
-			return fills.indexOf(_fill);
-		}
-		fills.add(_fill);
-		return fills.size() - 1;
-	}
+    public void setFillBackgroundColor(int index) {
+        CTPatternFill ptrn = ensureCTPatternFill();
+        CTColor ctColor = ptrn.isSetBgColor() ? ptrn.getBgColor() : ptrn.addNewBgColor();
+        ctColor.setIndexed(index);
+    }
+
+    public void setFillBackgroundColor(XSSFColor color) {
+        CTPatternFill ptrn = ensureCTPatternFill();
+        ptrn.setBgColor(color.getCTColor());
+    }
+
+    public XSSFColor getFillForegroundColor() {
+        CTPatternFill ptrn = _fill.getPatternFill();
+        if(ptrn == null) return null;
+
+        CTColor ctColor = ptrn.getFgColor();
+        return ctColor == null ? null : new XSSFColor(ctColor);
+    }
+
+    public void setFillForegroundColor(int index) {
+        CTPatternFill ptrn = ensureCTPatternFill();
+        CTColor ctColor = ptrn.isSetFgColor() ? ptrn.getFgColor() : ptrn.addNewFgColor();
+        ctColor.setIndexed(index);
+    }
+
+    public void setFillForegroundColor(XSSFColor color) {
+        CTPatternFill ptrn = ensureCTPatternFill();
+        ptrn.setFgColor(color.getCTColor());
+    }
+
+	public STPatternType.Enum getPatternType() {
+        CTPatternFill ptrn = _fill.getPatternFill();
+		return ptrn == null ? null : ptrn.getPatternType();
+	}
+
+    public void setPatternType(STPatternType.Enum patternType) {
+        CTPatternFill ptrn = ensureCTPatternFill();
+        ptrn.setPatternType(patternType);
+    }
 
-	private CTPatternFill getPatternFill() {
+	private CTPatternFill ensureCTPatternFill() {
 		CTPatternFill patternFill = _fill.getPatternFill();
 		if (patternFill == null) {
 			patternFill = _fill.addNewPatternFill();
@@ -83,27 +97,14 @@
 		return _fill;
 	}
 	
-	public void setFillBackgroundColor(long index) {
-		CTColor ctColor=getPatternFill().addNewBgColor();
-		ctColor.setIndexed(index);
-		_fill.getPatternFill().setBgColor(ctColor);
-	}
-
-	public void setFillForegroundColor(long index) {
-		CTColor ctColor=getPatternFill().addNewFgColor();
-		ctColor.setIndexed(index);
-		_fill.getPatternFill().setFgColor(ctColor);
-	}
-	
-	public void setFillBackgroundRgbColor(XSSFColor color) {
-		_fill.getPatternFill().setBgColor(color.getCTColor());
-	}
-
-	public void setFillForegroundRgbColor(XSSFColor color) {
-		_fill.getPatternFill().setFgColor(color.getCTColor());
-	}
-	
-	public void setPatternType(Enum patternType) {
-		getPatternFill().setPatternType(patternType);
-	}
+    public int hashCode(){
+        return _fill.toString().hashCode();
+    }
+
+    public boolean equals(Object o){
+        if(!(o instanceof XSSFCellFill)) return false;
+
+        XSSFCellFill cf = (XSSFCellFill)o;
+        return _fill.toString().equals(cf.getCTFill().toString());
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java Sun Oct  5 06:56:28 2008
@@ -39,6 +39,11 @@
         this.ctColor = CTColor.Factory.newInstance();
     }
 
+    public XSSFColor(java.awt.Color clr) {
+        this();
+        ctColor.setRgb(new byte[]{(byte)clr.getRed(), (byte)clr.getGreen(), (byte)clr.getBlue()});
+    }
+
     /**
      * A boolean value indicating the ctColor is automatic and system ctColor dependent.
      */
@@ -56,8 +61,8 @@
     /**
      * Indexed ctColor value. Only used for backwards compatibility. References a ctColor in indexedColors.
      */
-    public int getIndexed() {
-		return (int)ctColor.getIndexed();
+    public short getIndexed() {
+		return (short)ctColor.getIndexed();
 	}
 	
     /**
@@ -195,4 +200,16 @@
     public CTColor getCTColor(){
         return ctColor;
     }
+
+    public int hashCode(){
+        return ctColor.toString().hashCode();
+    }
+
+    public boolean equals(Object o){
+        if(!(o instanceof XSSFColor)) return false;
+
+        XSSFColor cf = (XSSFColor)o;
+        return ctColor.toString().equals(cf.getCTColor().toString());
+    }
+
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java Sun Oct  5 06:56:28 2008
@@ -26,12 +26,13 @@
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 
 public class TestXSSFCellStyle extends TestCase {
 
-	private static final int AUTO_COLOR_INDEX = 64;
 	private StylesTable stylesTable;
 	private CTBorder ctBorderA;
 	private CTFill ctFill;
@@ -48,14 +49,13 @@
 		
 		ctStylesheet = stylesTable._getRawStylesheet();
 		
-		// Until we do XSSFBorder properly, cheat
 		ctBorderA = CTBorder.Factory.newInstance();
 		XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
 		long borderId = stylesTable.putBorder(borderA);
 		assertEquals(1, borderId);
 
 		XSSFCellBorder borderB = new XSSFCellBorder();
-		assertEquals(2, stylesTable.putBorder(borderB));
+		assertEquals(1, stylesTable.putBorder(borderB));
 
 		ctFill = CTFill.Factory.newInstance();
 		XSSFCellFill fill = new XSSFCellFill(ctFill);
@@ -84,225 +84,430 @@
 	}
 
 	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() {
-		ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
-		assertEquals("thin", cellStyle.getBorderBottomAsString());
-	}
-
-	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() {
-		ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
-		assertEquals("medium", cellStyle.getBorderRightAsString());
-	}
+        //default values
+        assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderBottom());
+
+        int num = stylesTable.getBorders().size();
+        cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
+        assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom());
+        //a new border has been added
+        assertEquals(num + 1, stylesTable.getBorders().size());
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(STBorderStyle.MEDIUM, ctBorder.getBottom().getStyle());
+
+        num = stylesTable.getBorders().size();
+        //setting the same border multiple times should not change borderId
+        for (int i = 0; i < 3; i++) {
+            cellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
+            assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderBottom());
+        }
+        assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
+        assertEquals(num, stylesTable.getBorders().size());
+        assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
+
+        //setting border to none removes the <bottom> element
+        cellStyle.setBorderBottom(CellStyle.BORDER_NONE);
+        assertEquals(num, stylesTable.getBorders().size());
+        borderId = (int)cellStyle.getCoreXf().getBorderId();
+        ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertFalse(ctBorder.isSetBottom());
+    }
+
+    public void testGetSetBorderRight() {
+        //default values
+        assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderRight());
+
+        int num = stylesTable.getBorders().size();
+        cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
+        assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight());
+        //a new border has been added
+        assertEquals(num + 1, stylesTable.getBorders().size());
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());
+
+        num = stylesTable.getBorders().size();
+        //setting the same border multiple times should not change borderId
+        for (int i = 0; i < 3; i++) {
+            cellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
+            assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderRight());
+        }
+        assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
+        assertEquals(num, stylesTable.getBorders().size());
+        assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
+
+        //setting border to none removes the <right> element
+        cellStyle.setBorderRight(CellStyle.BORDER_NONE);
+        assertEquals(num, stylesTable.getBorders().size());
+        borderId = (int)cellStyle.getCoreXf().getBorderId();
+        ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertFalse(ctBorder.isSetRight());
+    }
 
 	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());
-	}
+        //default values
+        assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderLeft());
 
-	public void testGetBorderLeftAsString() {
-		ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
-		assertEquals("dashed", cellStyle.getBorderLeftAsString());
+        int num = stylesTable.getBorders().size();
+        cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
+        assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft());
+        //a new border has been added
+        assertEquals(num + 1, stylesTable.getBorders().size());
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());
+
+        num = stylesTable.getBorders().size();
+        //setting the same border multiple times should not change borderId
+        for (int i = 0; i < 3; i++) {
+            cellStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
+            assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderLeft());
+        }
+        assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
+        assertEquals(num, stylesTable.getBorders().size());
+        assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
+
+        //setting border to none removes the <left> element
+        cellStyle.setBorderLeft(CellStyle.BORDER_NONE);
+        assertEquals(num, stylesTable.getBorders().size());
+        borderId = (int)cellStyle.getCoreXf().getBorderId();
+        ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertFalse(ctBorder.isSetLeft());
 	}
 
 	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());
-	}
+        //default values
+        assertEquals(CellStyle.BORDER_NONE, cellStyle.getBorderTop());
 
-	public void testGetBorderTopAsString() {
-		ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
-		assertEquals("hair", cellStyle.getBorderTopAsString());
+        int num = stylesTable.getBorders().size();
+        cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
+        assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop());
+        //a new border has been added
+        assertEquals(num + 1, stylesTable.getBorders().size());
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
+
+        num = stylesTable.getBorders().size();
+        //setting the same border multiple times should not change borderId
+        for (int i = 0; i < 3; i++) {
+            cellStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
+            assertEquals(CellStyle.BORDER_MEDIUM, cellStyle.getBorderTop());
+        }
+        assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
+        assertEquals(num, stylesTable.getBorders().size());
+        assertSame(ctBorder, stylesTable.getBorderAt(borderId).getCTBorder());
+
+        //setting border to none removes the <top> element
+        cellStyle.setBorderTop(CellStyle.BORDER_NONE);
+        assertEquals(num, stylesTable.getBorders().size());
+        borderId = (int)cellStyle.getCoreXf().getBorderId();
+        ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertFalse(ctBorder.isSetTop());
 	}
 
 	public void testGetSetBottomBorderColor() {
-		CTColor ctColor = ctBorderA.addNewBottom().addNewColor();
-		ctColor.setIndexed(2);
-		assertEquals((short)2, cellStyle.getBottomBorderColor());
-		CTColor anotherCtColor = CTColor.Factory.newInstance();
-		anotherCtColor.setIndexed(4);
-		anotherCtColor.setTheme(3);
-		anotherCtColor.setRgb("1234".getBytes());
-		XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-		cellStyle.setBorderColor(BorderSide.BOTTOM, anotherColor);
-		assertEquals((short)4, cellStyle.getBottomBorderColor());
-		assertEquals("1234", new String(cellStyle.getBorderColor(BorderSide.BOTTOM).getRgb()));
-	}
+        //defaults
+        assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getBottomBorderColor());
+        assertNull(cellStyle.getBottomBorderRgbColor());
+
+        int num = stylesTable.getBorders().size();
+
+        XSSFColor clr;
+
+        //setting indexed color
+        cellStyle.setBottomBorderColor(IndexedColors.BLUE_GREY.getIndex());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), cellStyle.getBottomBorderColor());
+        clr = cellStyle.getBottomBorderRgbColor();
+        assertTrue(clr.getCTColor().isSetIndexed());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), clr.getIndexed());
+        //a new border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), ctBorder.getBottom().getColor().getIndexed());
+
+        //setting XSSFColor
+        num = stylesTable.getBorders().size();
+        clr = new XSSFColor(java.awt.Color.CYAN);
+        cellStyle.setBottomBorderColor(clr);
+        assertEquals(clr.getCTColor().toString(), cellStyle.getBottomBorderRgbColor().getCTColor().toString());
+        byte[] rgb = cellStyle.getBottomBorderRgbColor().getRgb();
+        assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
+        //another border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //passing null unsets the color
+        cellStyle.setBottomBorderColor(null);
+        assertNull(cellStyle.getBottomBorderRgbColor());
+    }
 
 	public void testGetSetTopBorderColor() {
-		CTColor ctColor = ctBorderA.addNewTop().addNewColor();
-		ctColor.setIndexed(5);
-		assertEquals((short)5, cellStyle.getTopBorderColor());
-		CTColor anotherCtColor = CTColor.Factory.newInstance();
-		anotherCtColor.setIndexed(7);
-		anotherCtColor.setTheme(3);
-		anotherCtColor.setRgb("abcd".getBytes());
-		XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-		cellStyle.setBorderColor(BorderSide.TOP, anotherColor);
-		assertEquals((short)7, cellStyle.getTopBorderColor());
-		assertEquals("abcd", new String(cellStyle.getBorderColor(BorderSide.TOP).getRgb()));
+        //defaults
+        assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getTopBorderColor());
+        assertNull(cellStyle.getTopBorderRgbColor());
+
+        int num = stylesTable.getBorders().size();
+
+        XSSFColor clr;
+
+        //setting indexed color
+        cellStyle.setTopBorderColor(IndexedColors.BLUE_GREY.getIndex());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), cellStyle.getTopBorderColor());
+        clr = cellStyle.getTopBorderRgbColor();
+        assertTrue(clr.getCTColor().isSetIndexed());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), clr.getIndexed());
+        //a new border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), ctBorder.getTop().getColor().getIndexed());
+
+        //setting XSSFColor
+        num = stylesTable.getBorders().size();
+        clr = new XSSFColor(java.awt.Color.CYAN);
+        cellStyle.setTopBorderColor(clr);
+        assertEquals(clr.getCTColor().toString(), cellStyle.getTopBorderRgbColor().getCTColor().toString());
+        byte[] rgb = cellStyle.getTopBorderRgbColor().getRgb();
+        assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
+        //another border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //passing null unsets the color
+        cellStyle.setTopBorderColor(null);
+        assertNull(cellStyle.getTopBorderRgbColor());
 	}
 
 	public void testGetSetLeftBorderColor() {
-		CTColor ctColor = ctBorderA.addNewLeft().addNewColor();
-		ctColor.setIndexed(2);
-		assertEquals((short)2, cellStyle.getLeftBorderColor());
-		CTColor anotherCtColor = CTColor.Factory.newInstance();
-		anotherCtColor.setIndexed(4);
-		anotherCtColor.setTheme(3);
-		anotherCtColor.setRgb("1234".getBytes());
-		XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-		cellStyle.setBorderColor(BorderSide.LEFT, anotherColor);
-		assertEquals((short)4, cellStyle.getLeftBorderColor());
-		assertEquals("1234", new String(cellStyle.getBorderColor(BorderSide.LEFT).getRgb()));
+        //defaults
+        assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getLeftBorderColor());
+        assertNull(cellStyle.getLeftBorderRgbColor());
+
+        int num = stylesTable.getBorders().size();
+
+        XSSFColor clr;
+
+        //setting indexed color
+        cellStyle.setLeftBorderColor(IndexedColors.BLUE_GREY.getIndex());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), cellStyle.getLeftBorderColor());
+        clr = cellStyle.getLeftBorderRgbColor();
+        assertTrue(clr.getCTColor().isSetIndexed());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), clr.getIndexed());
+        //a new border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), ctBorder.getLeft().getColor().getIndexed());
+
+        //setting XSSFColor
+        num = stylesTable.getBorders().size();
+        clr = new XSSFColor(java.awt.Color.CYAN);
+        cellStyle.setLeftBorderColor(clr);
+        assertEquals(clr.getCTColor().toString(), cellStyle.getLeftBorderRgbColor().getCTColor().toString());
+        byte[] rgb = cellStyle.getLeftBorderRgbColor().getRgb();
+        assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
+        //another border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //passing null unsets the color
+        cellStyle.setLeftBorderColor(null);
+        assertNull(cellStyle.getLeftBorderRgbColor());
 	}
 
 	public void testGetSetRightBorderColor() {
-		CTColor ctColor = ctBorderA.addNewRight().addNewColor();
-		ctColor.setIndexed(8);
-		assertEquals((short)8, cellStyle.getRightBorderColor());
-		CTColor anotherCtColor = CTColor.Factory.newInstance();
-		anotherCtColor.setIndexed(14);
-		anotherCtColor.setTheme(3);
-		anotherCtColor.setRgb("af67".getBytes());
-		XSSFColor anotherColor = new XSSFColor(anotherCtColor);
-		cellStyle.setBorderColor(BorderSide.RIGHT, anotherColor);
-		assertEquals((short)14, cellStyle.getRightBorderColor());
-		assertEquals("af67", new String(cellStyle.getBorderColor(BorderSide.RIGHT).getRgb()));
-	}
-
-	public void testGetFillBackgroundColor() {
-
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		CTColor ctBgColor = ctPatternFill.addNewBgColor();
-		ctBgColor.setIndexed(IndexedColors.BRIGHT_GREEN.getIndex());
-		ctPatternFill.setBgColor(ctBgColor);
-
-		XSSFCellFill cellFill=new XSSFCellFill(ctFill);
-		long index=stylesTable.putFill(cellFill);
-		cellStyle.getCoreXf().setFillId(index);
-
-		assertEquals(2,cellStyle.getCoreXf().getFillId());
-		assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), cellStyle.getFillBackgroundColor());
-		
-		cellStyle.setFillBackgroundColor(IndexedColors.BLUE.getIndex());
-		assertEquals(IndexedColors.BLUE.getIndex(), ctFill.getPatternFill().getBgColor().getIndexed());
-		
-		//test rgb color - XSSFColor
-		CTColor ctColor=CTColor.Factory.newInstance();
-		ctColor.setRgb("FFFFFF".getBytes());
-		ctPatternFill.setBgColor(ctColor);
-		assertEquals(ctColor.toString(), cellStyle.getFillBackgroundRgbColor().getCTColor().toString());
-		
-		cellStyle.setFillBackgroundRgbColor(new XSSFColor(ctColor));
-		assertEquals(ctColor.getRgb()[0], ctPatternFill.getBgColor().getRgb()[0]);
-		assertEquals(ctColor.getRgb()[1], ctPatternFill.getBgColor().getRgb()[1]);
-		assertEquals(ctColor.getRgb()[2], ctPatternFill.getBgColor().getRgb()[2]);
-		assertEquals(ctColor.getRgb()[3], ctPatternFill.getBgColor().getRgb()[3]);
+        //defaults
+        assertEquals(IndexedColors.BLACK.getIndex(), cellStyle.getRightBorderColor());
+        assertNull(cellStyle.getRightBorderRgbColor());
+
+        int num = stylesTable.getBorders().size();
+
+        XSSFColor clr;
+
+        //setting indexed color
+        cellStyle.setRightBorderColor(IndexedColors.BLUE_GREY.getIndex());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), cellStyle.getRightBorderColor());
+        clr = cellStyle.getRightBorderRgbColor();
+        assertTrue(clr.getCTColor().isSetIndexed());
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), clr.getIndexed());
+        //a new border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //id of the created border
+        int borderId = (int)cellStyle.getCoreXf().getBorderId();
+        assertTrue(borderId > 0);
+        //check changes in the underlying xml bean
+        CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
+        assertEquals(IndexedColors.BLUE_GREY.getIndex(), ctBorder.getRight().getColor().getIndexed());
+
+        //setting XSSFColor
+        num = stylesTable.getBorders().size();
+        clr = new XSSFColor(java.awt.Color.CYAN);
+        cellStyle.setRightBorderColor(clr);
+        assertEquals(clr.getCTColor().toString(), cellStyle.getRightBorderRgbColor().getCTColor().toString());
+        byte[] rgb = cellStyle.getRightBorderRgbColor().getRgb();
+        assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
+        //another border was added to the styles table
+        assertEquals(num + 1, stylesTable.getBorders().size());
+
+        //passing null unsets the color
+        cellStyle.setRightBorderColor(null);
+        assertNull(cellStyle.getRightBorderRgbColor());
+	}
+
+	public void testGetSetFillBackgroundColor() {
+
+        assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor());
+        assertNull(cellStyle.getFillBackgroundRgbColor());
+
+        XSSFColor clr;
+
+        int num = stylesTable.getFills().size();
+
+        //setting indexed color
+        cellStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
+        assertEquals(IndexedColors.RED.getIndex(), cellStyle.getFillBackgroundColor());
+        clr = cellStyle.getFillBackgroundRgbColor();
+        assertTrue(clr.getCTColor().isSetIndexed());
+        assertEquals(IndexedColors.RED.getIndex(), clr.getIndexed());
+        //a new fill was added to the styles table
+        assertEquals(num + 1, stylesTable.getFills().size());
+
+        //id of the created border
+        int fillId = (int)cellStyle.getCoreXf().getFillId();
+        assertTrue(fillId > 0);
+        //check changes in the underlying xml bean
+        CTFill ctFill = stylesTable.getFillAt(fillId).getCTFill();
+        assertEquals(IndexedColors.RED.getIndex(), ctFill.getPatternFill().getBgColor().getIndexed());
+
+        //setting XSSFColor
+        num = stylesTable.getFills().size();
+        clr = new XSSFColor(java.awt.Color.CYAN);
+        cellStyle.setFillBackgroundColor(clr);
+        assertEquals(clr.getCTColor().toString(), cellStyle.getFillBackgroundRgbColor().getCTColor().toString());
+        byte[] rgb = cellStyle.getFillBackgroundRgbColor().getRgb();
+        assertEquals(java.awt.Color.CYAN, new java.awt.Color(rgb[0] & 0xFF, rgb[1] & 0xFF, rgb[2] & 0xFF));
+        //another border was added to the styles table
+        assertEquals(num + 1, stylesTable.getFills().size());
+
+        //passing null unsets the color
+        cellStyle.setFillBackgroundColor(null);
+        assertNull(cellStyle.getFillBackgroundRgbColor());
+        assertEquals(IndexedColors.AUTOMATIC.getIndex(), cellStyle.getFillBackgroundColor());
 	}
 	
-	public void testGetFillBackgroundColor_default() {
+	public void testDefaultStyles() {
 
-		XSSFWorkbook wb = new XSSFWorkbook();
+		XSSFWorkbook wb1 = new XSSFWorkbook();
 
-		XSSFCellStyle style = wb.createCellStyle();
-
-		short color;
-		try {
-			color = style.getFillBackgroundColor();
-		} catch (NullPointerException e) {
-			throw new AssertionFailedError("Identified bug 45898");
-		}
-		assertEquals(AUTO_COLOR_INDEX, color);
-		XSSFColor xcolor=style.getFillBackgroundRgbColor();
-		assertEquals(xcolor.getIndexed(), AUTO_COLOR_INDEX);
+		XSSFCellStyle style1 = wb1.createCellStyle();
+        assertEquals(IndexedColors.AUTOMATIC.getIndex(), style1.getFillBackgroundColor());
+        assertNull(style1.getFillBackgroundRgbColor());
+
+        //compatibility with HSSF
+        HSSFWorkbook wb2 = new HSSFWorkbook();
+        HSSFCellStyle style2 = wb2.createCellStyle();
+        assertEquals(style2.getFillBackgroundColor(), style1.getFillBackgroundColor());
+        assertEquals(style2.getFillForegroundColor(), style1.getFillForegroundColor());
+        assertEquals(style2.getFillPattern(), style1.getFillPattern());
+
+        assertEquals(style2.getLeftBorderColor(), style1.getLeftBorderColor());
+        assertEquals(style2.getTopBorderColor(), style1.getTopBorderColor());
+        assertEquals(style2.getRightBorderColor(), style1.getRightBorderColor());
+        assertEquals(style2.getBottomBorderColor(), style1.getBottomBorderColor());
+
+        assertEquals(style2.getBorderBottom(), style1.getBorderBottom());
+        assertEquals(style2.getBorderLeft(), style1.getBorderLeft());
+        assertEquals(style2.getBorderRight(), style1.getBorderRight());
+        assertEquals(style2.getBorderTop(), style1.getBorderTop());
 	}
 	
 
 	public void testGetFillForegroundColor() {
 
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		CTColor ctFgColor = ctPatternFill.addNewFgColor();
-		ctFgColor.setIndexed(IndexedColors.BRIGHT_GREEN.getIndex());
-		ctPatternFill.setFgColor(ctFgColor);
-
-		XSSFCellFill cellFill=new XSSFCellFill(ctFill);
-		long index=stylesTable.putFill(cellFill);
-		cellStyle.getCoreXf().setFillId(index);
-
-		assertEquals(2,cellStyle.getCoreXf().getFillId());
-		assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), cellStyle.getFillForegroundColor());
-		
-		cellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
-		assertEquals(IndexedColors.BLUE.getIndex(), ctFill.getPatternFill().getFgColor().getIndexed());
-		
-		//test rgb color - XSSFColor
-		CTColor ctColor=CTColor.Factory.newInstance();
-		ctColor.setRgb("FFFFFF".getBytes());
-		ctPatternFill.setFgColor(ctColor);
-		assertEquals(ctColor.toString(), cellStyle.getFillForegroundRgbColor().getCTColor().toString());
-		
-		cellStyle.setFillForegroundRgbColor(new XSSFColor(ctColor));
-		assertEquals(ctColor.getRgb()[0], ctPatternFill.getFgColor().getRgb()[0]);
-		assertEquals(ctColor.getRgb()[1], ctPatternFill.getFgColor().getRgb()[1]);
-		assertEquals(ctColor.getRgb()[2], ctPatternFill.getFgColor().getRgb()[2]);
-		assertEquals(ctColor.getRgb()[3], ctPatternFill.getFgColor().getRgb()[3]);
+        XSSFWorkbook wb = new XSSFWorkbook();
+        StylesTable styles = wb.getStylesSource();
+        assertEquals(1, wb.getNumCellStyles());
+        assertEquals(2, styles.getFills().size());
+
+        XSSFCellStyle defaultStyle = wb.getCellStyleAt((short)0);
+        assertEquals(IndexedColors.AUTOMATIC.getIndex(), defaultStyle.getFillForegroundColor());
+        assertEquals(null, defaultStyle.getFillForegroundRgbColor());
+        assertEquals(CellStyle.NO_FILL, defaultStyle.getFillPattern());
+
+        XSSFCellStyle customStyle = wb.createCellStyle();
+
+        customStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        assertEquals(CellStyle.SOLID_FOREGROUND, customStyle.getFillPattern());
+        assertEquals(3, styles.getFills().size());
+
+        customStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
+        assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), customStyle.getFillForegroundColor());
+        assertEquals(4, styles.getFills().size());
+
+        for (int i = 0; i < 3; i++) {
+            XSSFCellStyle style = wb.createCellStyle();
+
+            style.setFillPattern(CellStyle.SOLID_FOREGROUND);
+            assertEquals(CellStyle.SOLID_FOREGROUND, style.getFillPattern());
+            assertEquals(4, styles.getFills().size());
+
+            style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
+            assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), style.getFillForegroundColor());
+            assertEquals(4, styles.getFills().size());
+        }
 	}
 	
-	public void testGetFillForegroundColor_default() {
+	public void testGetFillPattern() {
 
-		XSSFWorkbook wb = new XSSFWorkbook();
+        assertEquals(CellStyle.NO_FILL, cellStyle.getFillPattern());
 
-		XSSFCellStyle style = wb.createCellStyle();
+        int num = stylesTable.getFills().size();
+        cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        assertEquals(CellStyle.SOLID_FOREGROUND, cellStyle.getFillPattern());
+        assertEquals(num + 1, stylesTable.getFills().size());
+        int fillId = (int)cellStyle.getCoreXf().getFillId();
+        assertTrue(fillId > 0);
+        //check changes in the underlying xml bean
+        CTFill ctFill = stylesTable.getFillAt(fillId).getCTFill();
+        assertEquals(STPatternType.SOLID, ctFill.getPatternFill().getPatternType());
+
+        //setting the same fill multiple time does not update the styles table
+        for (int i = 0; i < 3; i++) {
+            cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
+        }
+        assertEquals(num + 1, stylesTable.getFills().size());
+
+        cellStyle.setFillPattern(CellStyle.NO_FILL);
+        assertEquals(CellStyle.NO_FILL, cellStyle.getFillPattern());
+        fillId = (int)cellStyle.getCoreXf().getFillId();
+        ctFill = stylesTable.getFillAt(fillId).getCTFill();
+        assertFalse(ctFill.getPatternFill().isSetPatternType());
 
-		short color;
-		try {
-			color = style.getFillForegroundColor();
-		} catch (NullPointerException e) {
-			throw new AssertionFailedError("Identified bug 45898");
-		}
-		assertEquals(AUTO_COLOR_INDEX, color);
-		XSSFColor xcolor=style.getFillForegroundRgbColor();
-		assertEquals(xcolor.getIndexed(), AUTO_COLOR_INDEX);
-	}
-	
-
-	public void testGetFillPattern() {
-
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
-		XSSFCellFill cellFill=new XSSFCellFill(ctFill);
-		long index=stylesTable.putFill(cellFill);
-		cellStyle.getCoreXf().setFillId(index);
-	
-		assertEquals(CellStyle.THICK_FORWARD_DIAG, cellStyle.getFillPattern());
-		
-		cellStyle.setFillPattern(CellStyle.BRICKS);
-		assertEquals(STPatternType.INT_DARK_TRELLIS,ctPatternFill.getPatternType().intValue());
 	}
 
 	public void testGetFont() {

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java Sun Oct  5 06:56:28 2008
@@ -255,9 +255,11 @@
 		s1 = wb.getSheetAt(0);
 
 		assertEquals(2, wb.getNumberOfFonts());
-		assertNotNull(s1.getRow(0).getCell(0).getCellStyle().getFont(wb));
-		assertEquals(IndexedColors.YELLOW.getIndex(), s1.getRow(0).getCell(0).getCellStyle().getFont(wb).getColor());
-		assertEquals("Courier", s1.getRow(0).getCell(0).getCellStyle().getFont(wb).getFontName());
+        short idx = s1.getRow(0).getCell(0).getCellStyle().getFontIndex();
+        Font fnt = wb.getFontAt(idx);
+        assertNotNull(fnt);
+		assertEquals(IndexedColors.YELLOW.getIndex(), fnt.getColor());
+		assertEquals("Courier", fnt.getFontName());
 
 		// Now add an orphaned one
 		XSSFFont font2 = wb.createFont();
@@ -342,4 +344,92 @@
 
 		XSSFTestDataSamples.writeOutAndReadBack(workbook);
 	}
+
+    /**
+     * Test that fonts get added properly
+     * 
+     * @see org.apache.poi.hssf.usermodel.TestBugs#test45338()
+     */
+    public void test45338() {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        assertEquals(1, wb.getNumberOfFonts());
+
+        XSSFSheet s = wb.createSheet();
+        s.createRow(0);
+        s.createRow(1);
+        XSSFCell c1 = s.getRow(0).createCell(0);
+        XSSFCell c2 = s.getRow(1).createCell(0);
+
+        assertEquals(1, wb.getNumberOfFonts());
+
+        XSSFFont f1 = wb.getFontAt((short)0);
+        assertEquals(XSSFFont.BOLDWEIGHT_NORMAL, f1.getBoldweight());
+
+        // Check that asking for the same font
+        //  multiple times gives you the same thing.
+        // Otherwise, our tests wouldn't work!
+        assertEquals(
+                wb.getFontAt((short)0),
+                wb.getFontAt((short)0)
+        );
+
+        // Look for a new font we have
+        //  yet to add
+        assertNull(
+            wb.findFont(
+                (short)11, (short)123, (short)22,
+                "Thingy", false, true, (short)2, (byte)2
+            )
+        );
+
+        XSSFFont nf = wb.createFont();
+        assertEquals(2, wb.getNumberOfFonts());
+
+        assertEquals(1, nf.getIndex());
+        assertEquals(nf, wb.getFontAt((short)1));
+
+        nf.setBoldweight((short)11);
+        nf.setColor((short)123);
+        nf.setFontHeight((short)22);
+        nf.setFontName("Thingy");
+        nf.setItalic(false);
+        nf.setStrikeout(true);
+        nf.setTypeOffset((short)2);
+        nf.setUnderline((byte)2);
+
+        assertEquals(2, wb.getNumberOfFonts());
+        assertEquals(nf, wb.getFontAt((short)1));
+
+        assertEquals(
+                wb.getFontAt((short)1),
+                wb.getFontAt((short)1)
+        );
+        assertTrue(
+                wb.getFontAt((short)0)
+                !=
+                wb.getFontAt((short)1)
+        );
+
+        // Find it now
+        assertNotNull(
+            wb.findFont(
+                (short)11, (short)123, (short)22,
+                "Thingy", false, true, (short)2, (byte)2
+            )
+        );
+        assertEquals(
+            1,
+            wb.findFont(
+                   (short)11, (short)123, (short)22,
+                   "Thingy", false, true, (short)2, (byte)2
+               ).getIndex()
+        );
+        assertEquals(nf,
+               wb.findFont(
+                   (short)11, (short)123, (short)22,
+                   "Thingy", false, true, (short)2, (byte)2
+               )
+        );
+    }
+
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Sun Oct  5 06:56:28 2008
@@ -256,7 +256,7 @@
 		Font font=workbook.createFont();
 		((XSSFFont)font).setBold(true);
 		font.setUnderline(Font.U_DOUBLE);
-		StylesSource styleSource=new StylesTable();
+		StylesTable styleSource=new StylesTable();
 		long index=styleSource.putFont(font);
 		System.out.println("index="+index);
 		workbook.setStylesSource(styleSource);

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java Sun Oct  5 06:56:28 2008
@@ -17,14 +17,15 @@
 
 package org.apache.poi.xssf.usermodel.extensions;
 
+import junit.framework.TestCase;
+
+import org.apache.poi.xssf.usermodel.BorderStyle;
 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;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
 
-import junit.framework.TestCase;
-
 
 public class TestXSSFBorder extends TestCase {
 	
@@ -34,15 +35,20 @@
 		CTBorderPr top = border.addNewTop();
 		CTBorderPr right = border.addNewRight();
 		CTBorderPr bottom = border.addNewBottom();
+		
 		top.setStyle(STBorderStyle.DASH_DOT);
 		right.setStyle(STBorderStyle.NONE);
 		bottom.setStyle(STBorderStyle.THIN);
+		
 		XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
-		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());
+		assertEquals("DASH_DOT", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString());
+		
+		assertEquals("NONE", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString());
+		assertEquals(BorderStyle.NONE.ordinal(), cellBorderStyle.getBorderStyle(BorderSide.RIGHT).ordinal());
+		
+		assertEquals("THIN", cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).toString());
+		
+		assertEquals(BorderStyle.THIN.ordinal(), cellBorderStyle.getBorderStyle(BorderSide.BOTTOM).ordinal());
 	}
 	
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java Sun Oct  5 06:56:28 2008
@@ -1,58 +1,67 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.xssf.usermodel.extensions;
-
-
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
-
-import junit.framework.TestCase;
-
-
-public class TestXSSFCellFill extends TestCase {
-	
-	public void testGetFillBackgroundColor() {
-		CTFill ctFill = CTFill.Factory.newInstance();
-		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		CTColor bgColor = ctPatternFill.addNewBgColor();
-		assertNotNull(cellFill.getFillBackgroundColor());
-		bgColor.setIndexed(2);
-		assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
-	}
-	
-	public void testGetFillForegroundColor() {
-		CTFill ctFill = CTFill.Factory.newInstance();
-		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		CTColor fgColor = ctPatternFill.addNewFgColor();
-		assertNotNull(cellFill.getFillForegroundColor());
-		fgColor.setIndexed(8);
-		assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
-	}
-	
-	public void testGetPatternType() {
-		CTFill ctFill = CTFill.Factory.newInstance();
-		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
-		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
-		ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
-		assertEquals(8, cellFill.getPatternType().intValue());
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel.extensions;
+
+
+import org.apache.poi.xssf.usermodel.FillPatternType;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
+
+import junit.framework.TestCase;
+
+
+public class TestXSSFCellFill extends TestCase {
+	
+	public void testGetFillBackgroundColor() {
+		CTFill ctFill = CTFill.Factory.newInstance();
+		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+		CTColor bgColor = ctPatternFill.addNewBgColor();
+		assertNotNull(cellFill.getFillBackgroundColor());
+		bgColor.setIndexed(2);
+		assertEquals(2, cellFill.getFillBackgroundColor().getIndexed());
+	}
+	
+	public void testGetFillForegroundColor() {
+		CTFill ctFill = CTFill.Factory.newInstance();
+		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+		CTColor fgColor = ctPatternFill.addNewFgColor();
+		assertNotNull(cellFill.getFillForegroundColor());
+		fgColor.setIndexed(8);
+		assertEquals(8, cellFill.getFillForegroundColor().getIndexed());
+	}
+	
+	public void testGetSetPatternType() {
+		CTFill ctFill = CTFill.Factory.newInstance();
+		XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+		CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+		ctPatternFill.setPatternType(STPatternType.SOLID);
+		//assertEquals(FillPatternType.SOLID_FOREGROUND.ordinal(), cellFill.getPatternType().ordinal());
+	}
+
+    public void testGetNotModifies() {
+        CTFill ctFill = CTFill.Factory.newInstance();
+        XSSFCellFill cellFill = new XSSFCellFill(ctFill);
+        CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+        ctPatternFill.setPatternType(STPatternType.DARK_DOWN);
+        assertEquals(8, cellFill.getPatternType().intValue());
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message