]> source.dussan.org Git - poi.git/commitdiff
Fix bug #50846 - XSSFCellBorder needs a theme table too, but as it gets created early...
authorNick Burch <nick@apache.org>
Fri, 18 Mar 2011 15:18:45 +0000 (15:18 +0000)
committerNick Burch <nick@apache.org>
Fri, 18 Mar 2011 15:18:45 +0000 (15:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1082946 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
test-data/spreadsheet/50846-border_colours.xlsx [new file with mode: 0644]

index 5410a7fab4c8fefc6913a18dcb97cd933bed8d45..e2e772a3c2440f41feb95b88da19f24da877a820 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta2" date="2011-??-??">
+           <action dev="poi-developers" type="fix">50846 - More XSSFColor theme improvements, this time for Cell Borders</action>
            <action dev="poi-developers" type="fix">50939 - ChartEndObjectRecord is supposed to have 6 bytes at the end, but handle it not</action>
            <action dev="poi-developers" type="add">HMEF - New component which supports TNEF (Transport Neutral Encoding Format), aka winmail.dat</action>
            <action dev="poi-developers" type="fix">50313 - support for getting HWPFDocument fields</action>
index 60dad91b0b151f80ac952f1292a1f13c7d7bbbc9..e643f9fa1fcc8f58c1cd88998db821638c4d5de3 100644 (file)
@@ -98,9 +98,15 @@ public class StylesTable extends POIXMLDocumentPart {
 
     public void setTheme(ThemesTable theme) {
         this.theme = theme;
+        
+        // Pass the themes table along to things which need to 
+        //  know about it, but have already been created by now
         for(XSSFFont font : fonts) {
            font.setThemesTable(theme);
         }
+        for(XSSFCellBorder border : borders) {
+           border.setThemesTable(theme);
+        }
     }
 
        /**
@@ -144,7 +150,7 @@ public class StylesTable extends POIXMLDocumentPart {
             CTBorders ctborders = styleSheet.getBorders();
             if(ctborders != null) {
                 for (CTBorder border : ctborders.getBorderArray()) {
-                    borders.add(new XSSFCellBorder(border, theme));
+                    borders.add(new XSSFCellBorder(border));
                 }
             }
 
@@ -251,6 +257,7 @@ public class StylesTable extends POIXMLDocumentPart {
                        return idx;
                }
                borders.add(border);
+               border.setThemesTable(theme);
                return borders.size() - 1;
        }
 
@@ -437,7 +444,7 @@ public class StylesTable extends POIXMLDocumentPart {
                fills.add(new XSSFCellFill(ctFill[1]));
 
                CTBorder ctBorder = createDefaultBorder();
-               borders.add(new XSSFCellBorder(ctBorder, theme));
+               borders.add(new XSSFCellBorder(ctBorder));
 
                CTXf styleXf = createDefaultXf();
                styleXfs.add(styleXf);
index adc695b0956634cd25866991d7c2ed0ef14a9398..b100bc210158670d6c29bbfa334bcdf932c0dccd 100644 (file)
@@ -38,19 +38,34 @@ public class XSSFCellBorder {
      * Creates a Cell Border from the supplied XML definition
      */
     public XSSFCellBorder(CTBorder border, ThemesTable theme) {
-        this.border = border;
+        this(border);
         this._theme = theme;
     }
 
+    /**
+     * Creates a Cell Border from the supplied XML definition
+     */
+    public XSSFCellBorder(CTBorder border) {
+        this.border = border;
+    }
+
     /**
      * Creates a new, empty Cell Border.
      * You need to attach this to the Styles Table
      */
-    public XSSFCellBorder(ThemesTable theme) {
+    public XSSFCellBorder() {
         border = CTBorder.Factory.newInstance();
-        this._theme = theme;
     }
 
+    /**
+     * Records the Themes Table that is associated with
+     *  the current font, used when looking up theme
+     *  based colours and properties.
+     */
+    public void setThemesTable(ThemesTable themes) {
+       this._theme = themes;
+    }
+    
     /**
      * The enumeration value indicating the side being used for a cell border.
      */
index eaeb01faab7cfb1b457ce8baa0209c95c7345120..710ba2c01f4ff949a7dda582848dae6587345b4f 100644 (file)
@@ -742,12 +742,26 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
      *  should still be able to get colours
      */
     public void test50846() throws Exception {
-       // TODO Get file and test
-       //Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50846.xlsx");
+       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50846-border_colours.xlsx");
        
-       // Check the style that is theme based
+       XSSFSheet sheet = wb.getSheetAt(0);
+       XSSFRow row = sheet.getRow(0);
+       
+       // Border from a theme, brown
+       XSSFCell cellT = row.getCell(0);
+       XSSFCellStyle styleT = cellT.getCellStyle();
+       XSSFColor colorT = styleT.getBottomBorderXSSFColor();
+       
+       assertEquals(5, colorT.getTheme());
+       assertEquals("FFC0504D", colorT.getARGBHex());
+       
+       // Border from a style direct, red
+       XSSFCell cellS = row.getCell(1);
+       XSSFCellStyle styleS = cellS.getCellStyle();
+       XSSFColor colorS = styleS.getBottomBorderXSSFColor();
        
-       // Check the one that isn't
+       assertEquals(0, colorS.getTheme());
+       assertEquals("FFFF0000", colorS.getARGBHex());
     }
     
     /**
index 83edc8f2f45a86e5849160e1dbd444264d15bf57..02b34ae85ef2dd4ba42414a94229aff710a9e1a2 100644 (file)
@@ -59,11 +59,11 @@ public class TestXSSFCellStyle extends TestCase {
                ctStylesheet = stylesTable.getCTStylesheet();
 
                ctBorderA = CTBorder.Factory.newInstance();
-               XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA, null);
+               XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
                long borderId = stylesTable.putBorder(borderA);
                assertEquals(1, borderId);
 
-               XSSFCellBorder borderB = new XSSFCellBorder(null);
+               XSSFCellBorder borderB = new XSSFCellBorder();
                assertEquals(1, stylesTable.putBorder(borderB));
 
                ctFill = CTFill.Factory.newInstance();
index 46af27d59d440fac418409d8c1e08c0cf56579a9..e7233c227e6b3d464703639ceaccd9958f8e45b6 100644 (file)
@@ -40,7 +40,7 @@ public class TestXSSFBorder extends TestCase {
                right.setStyle(STBorderStyle.NONE);
                bottom.setStyle(STBorderStyle.THIN);
                
-               XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border, null);
+               XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
                assertEquals("DASH_DOT", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString());
                
                assertEquals("NONE", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString());
diff --git a/test-data/spreadsheet/50846-border_colours.xlsx b/test-data/spreadsheet/50846-border_colours.xlsx
new file mode 100644 (file)
index 0000000..49ec532
Binary files /dev/null and b/test-data/spreadsheet/50846-border_colours.xlsx differ