You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/10/05 15:56:29 UTC

svn commit: r701797 [1/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/...

Author: yegor
Date: Sun Oct  5 06:56:28 2008
New Revision: 701797

URL: http://svn.apache.org/viewvc?rev=701797&view=rev
Log:
applied patch #45492 submitted by Gisella Bronzetti,also performed major cleanup of StylesTable and its components, the goal was to ensure that StylesTable works as a cache of styling components, not just a regular store of fill patterns and cell styles.

Added:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java   (with props)
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java   (with props)
Modified:
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CellStyle.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFColor.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFCellFill.java

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java Sun Oct  5 06:56:28 2008
@@ -68,6 +68,11 @@
         cell.setCellValue(new Date());
         cell.setCellStyle(style);
 
+        //hyperlink
+        row.createCell(7).setCellFormula("SUM(A1:B1)");
+        cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
+
+
         // Write the output to a file
         FileOutputStream fileOut = new FileOutputStream("ooxml-cell.xlsx");
         wb.write(fileOut);

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java Sun Oct  5 06:56:28 2008
@@ -32,34 +32,72 @@
 public class WorkingWithFonts {
     public static void main(String[] args) throws Exception {
         Workbook wb = new XSSFWorkbook();
-        Sheet sheet = wb.createSheet("new sheet");
+        Sheet sheet = wb.createSheet("Fonts");
 
-        // Create a row and put some cells in it. Rows are 0 based.
-        Row row = sheet.createRow((short) 1);
-
-        // Create a new font and alter it.
-        Font font = wb.createFont();
-        font.setFontHeightInPoints((short)24);
-        font.setFontName("Courier New");
-
-        font.setColor(IndexedColors.RED.getIndex());
-
-        font.setItalic(true);
-        font.setStrikeout(true);
-
-        // Fonts are set into a style so create a new one to use.
-        CellStyle style = wb.createCellStyle();
-        style.setFont(font);
-
-        // Create a cell and put a value in it.
-        Cell cell = row.createCell((short) 1);
-        cell.setCellValue(1974);
-        //cell.setCellValue(new XSSFRichTextString("This is a test of fonts"));
-        cell.setCellStyle(style);
+        Font font0 = wb.createFont();
+        font0.setColor(IndexedColors.BROWN.getIndex());
+        CellStyle style0 = wb.createCellStyle();
+        style0.setFont(font0);
+
+        Font font1 = wb.createFont();
+        font1.setFontHeightInPoints((short)14);
+        font1.setFontName("Courier New");
+        font1.setColor(IndexedColors.RED.getIndex());
+        CellStyle style1 = wb.createCellStyle();
+        style1.setFont(font1);
+
+        Font font2 = wb.createFont();
+        font2.setFontHeightInPoints((short)16);
+        font2.setFontName("Arial");
+        font2.setColor(IndexedColors.GREEN.getIndex());
+        CellStyle style2 = wb.createCellStyle();
+        style2.setFont(font2);
+
+        Font font3 = wb.createFont();
+        font3.setFontHeightInPoints((short)18);
+        font3.setFontName("Times New Roman");
+        font3.setColor(IndexedColors.LAVENDER.getIndex());
+        CellStyle style3 = wb.createCellStyle();
+        style3.setFont(font3);
+
+        Font font4 = wb.createFont();
+        font4.setFontHeightInPoints((short)18);
+        font4.setFontName("Wingdings");
+        font4.setColor(IndexedColors.GOLD.getIndex());
+        CellStyle style4 = wb.createCellStyle();
+        style4.setFont(font4);
+
+        Font font5 = wb.createFont();
+        font5.setFontName("Symbol");
+        CellStyle style5 = wb.createCellStyle();
+        style5.setFont(font5);
+
+        Cell cell0 = sheet.createRow(0).createCell(1);
+        cell0.setCellValue("Default");
+        cell0.setCellStyle(style0);
+
+        Cell cell1 = sheet.createRow(1).createCell(1);
+        cell1.setCellValue("Courier");
+        cell1.setCellStyle(style1);
+
+        Cell cell2 = sheet.createRow(2).createCell(1);
+        cell2.setCellValue("Arial");
+        cell2.setCellStyle(style2);
+
+        Cell cell3 = sheet.createRow(3).createCell(1);
+        cell3.setCellValue("Times New Roman");
+        cell3.setCellStyle(style3);
+
+        Cell cell4 = sheet.createRow(4).createCell(1);
+        cell4.setCellValue("Wingdings");
+        cell4.setCellStyle(style4);
+
+        Cell cell5 = sheet.createRow(5).createCell(1);
+        cell5.setCellValue("Symbol");
+        cell5.setCellStyle(style5);
 
         // Write the output to a file
-
-        FileOutputStream fileOut = new FileOutputStream("fonts.xlsx");
+        FileOutputStream fileOut = new FileOutputStream("xssf-fonts.xlsx");
         wb.write(fileOut);
         fileOut.close();
     }

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CellStyle.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/CellStyle.java Sun Oct  5 06:56:28 2008
@@ -277,14 +277,6 @@
     short getFontIndex();
 
     /**
-     * gets the font for this style
-     * @param parentWorkbook The HSSFWorkbook that this style belongs to
-     * @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIndex()
-     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
-     */
-    Font getFont(Workbook parentWorkbook);
-
-    /**
      * set the cell's using this style to be hidden
      * @param hidden - whether the cell using this style should be hidden
      */

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Font.java Sun Oct  5 06:56:28 2008
@@ -270,6 +270,17 @@
      */
     void setCharSet(byte charset);
 
-    String toString();
+    /**
+     * get the index within the XSSFWorkbook (sequence within the collection of Font objects)
+     * 
+     * @return unique index number of the underlying record this Font represents (probably you don't care
+     *  unless you're comparing which one is which)
+     */
+    public short getIndex();
+
+    public void setBoldweight(short boldweight);
+
+    public short getBoldweight();
+
 
 }
\ No newline at end of file

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Sun Oct  5 06:56:28 2008
@@ -66,9 +66,9 @@
  */
 public class StylesTable extends POIXMLDocumentPart implements StylesSource, XSSFModel {
 	private final Hashtable<Long,String> numberFormats = new Hashtable<Long,String>();
-	private final List<CTFont> fonts = new ArrayList<CTFont>();
-	private final List<CTFill> fills = new LinkedList<CTFill>();
-	private final List<CTBorder> borders = new LinkedList<CTBorder>();
+	private final List<XSSFFont> fonts = new ArrayList<XSSFFont>();
+	private final List<XSSFCellFill> fills = new ArrayList<XSSFCellFill>();
+	private final List<XSSFCellBorder> borders = new ArrayList<XSSFCellBorder>();
 	private final List<CTXf> styleXfs = new LinkedList<CTXf>();
 	private final List<CTXf> xfs = new LinkedList<CTXf>();
 
@@ -122,17 +122,21 @@
 			for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtArray()) {
 				numberFormats.put(nfmt.getNumFmtId(), nfmt.getFormatCode());
 			}
-			if(doc.getStyleSheet().getFonts() != null)
-			for (CTFont font : doc.getStyleSheet().getFonts().getFontArray()) {
-				fonts.add(font);
-			}
+			if(doc.getStyleSheet().getFonts() != null){
+                int idx = 0;
+                for (CTFont font : doc.getStyleSheet().getFonts().getFontArray()) {
+                    XSSFFont f = new XSSFFont(font, idx);
+                    fonts.add(f);
+                    idx++;
+                }
+            }
 			if(doc.getStyleSheet().getFills() != null)
 			for (CTFill fill : doc.getStyleSheet().getFills().getFillArray()) {
-				fills.add(fill);
+				fills.add(new XSSFCellFill(fill));
 			}
 			if(doc.getStyleSheet().getBorders() != null)
 			for (CTBorder border : doc.getStyleSheet().getBorders().getBorderArray()) {
-				borders.add(border);
+				borders.add(new XSSFCellBorder(border));
 			}
 			if(doc.getStyleSheet().getCellXfs() != null)
 			for (CTXf xf : doc.getStyleSheet().getCellXfs().getXfArray()) {
@@ -181,12 +185,17 @@
 		return newKey;
 	}
 
-	public Font getFontAt(long idx) {
-		return new XSSFFont(fonts.get((int) idx));
+	public XSSFFont getFontAt(long idx) {
+		return fonts.get((int)idx);
 	}
 
-	public synchronized long putFont(Font font) {
-		return putFont((XSSFFont)font, fonts);
+	public long putFont(Font font) {
+        int idx = fonts.indexOf(font);
+        if (idx != -1) {
+            return idx;
+        }
+        fonts.add((XSSFFont)font);
+        return fonts.size() - 1;
 	}
 
 	public XSSFCellStyle getStyleAt(long idx) {
@@ -209,24 +218,44 @@
 		return xfs.indexOf(mainXF);
 	}
 
-	public XSSFCellBorder getBorderAt(long idx) {
-		return new XSSFCellBorder(borders.get((int)idx));
+	public XSSFCellBorder getBorderAt(int idx) {
+		return borders.get(idx);
 	}
-	public long putBorder(XSSFCellBorder border) {
-		return putBorder(border, borders);
+
+    public int putBorder(XSSFCellBorder border) {
+        int idx = borders.indexOf(border);
+        if (idx != -1) {
+            return idx;
+        }
+        borders.add(border);
+        return borders.size() - 1;
 	}
 
-	public XSSFCellFill getFillAt(long idx) {
-		return new XSSFCellFill(fills.get((int) idx));
+    public List<XSSFCellBorder> getBorders(){
+        return borders;
+    }
+
+	public XSSFCellFill getFillAt(int idx) {
+		return fills.get(idx);
 	}
-	public long putFill(XSSFCellFill fill) {
-		return fill.putFill(fills);
+
+    public List<XSSFCellFill> getFills(){
+        return fills;
+    }
+
+    public int putFill(XSSFCellFill fill) {
+        int idx = fills.indexOf(fill);
+        if (idx != -1) {
+            return idx;
+        }
+        fills.add(fill);
+        return fills.size() - 1;
 	}
 
 	public CTXf getCellXfAt(long idx) {
 		return xfs.get((int) idx);
 	}
-	public long putCellXf(CTXf cellXf) {
+	public int putCellXf(CTXf cellXf) {
 		xfs.add(cellXf);
 		return xfs.size();
 	}
@@ -234,7 +263,7 @@
 	public CTXf getCellStyleXfAt(long idx) {
 		return styleXfs.get((int) idx);
 	}
-	public long putCellStyleXf(CTXf cellStyleXf) {
+	public int putCellStyleXf(CTXf cellStyleXf) {
 		styleXfs.add(cellStyleXf);
 		return styleXfs.size();
 	}
@@ -323,24 +352,32 @@
 		}
 		doc.getStyleSheet().setNumFmts(formats);
 
+        int idx = 0;
 		// Fonts
 		CTFonts ctFonts = CTFonts.Factory.newInstance();
 		ctFonts.setCount(fonts.size());
-		ctFonts.setFontArray(
-				fonts.toArray(new CTFont[fonts.size()])
-		);
+        CTFont[] ctfnt = new CTFont[fonts.size()];
+        idx = 0;
+        for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
+        ctFonts.setFontArray(ctfnt);
 		doc.getStyleSheet().setFonts(ctFonts);
 
 		// Fills
 		CTFills ctFills = CTFills.Factory.newInstance();
 		ctFills.setCount(fills.size());
-		ctFills.setFillArray(fills.toArray(new CTFill[fills.size()]));
+        CTFill[] ctf = new CTFill[fills.size()];
+        idx = 0;
+        for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill();
+        ctFills.setFillArray(ctf);
 		doc.getStyleSheet().setFills(ctFills);
 
 		// Borders
 		CTBorders ctBorders = CTBorders.Factory.newInstance();
 		ctBorders.setCount(borders.size());
-		ctBorders.setBorderArray(borders.toArray(new CTBorder[borders.size()]));
+        CTBorder[] ctb = new CTBorder[borders.size()];
+        idx = 0;
+        for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder();
+		ctBorders.setBorderArray(ctb);
 		doc.getStyleSheet().setBorders(ctBorders);
 
 		// Xfs
@@ -384,25 +421,17 @@
         out.close();
     }
 
-	private long putBorder(XSSFCellBorder border, List<CTBorder> borders) {
-		return border.putBorder((LinkedList<CTBorder>) borders); // TODO - use List instead of LinkedList
-	}
-
-	private long putFont(XSSFFont font, List<CTFont> fonts) {
-		return font.putFont((ArrayList<CTFont>) fonts); // TODO - use List instead of ArrayList
-	}
-
 	private void initialize() {
 		//CTFont ctFont = createDefaultFont();
 		XSSFFont xssfFont = createDefaultFont();
-		fonts.add(xssfFont.getCTFont());
+		fonts.add(xssfFont);
 
 		CTFill[] ctFill = createDefaultFills();
-		fills.add(ctFill[0]);
-		fills.add(ctFill[1]);
+		fills.add(new XSSFCellFill(ctFill[0]));
+		fills.add(new XSSFCellFill(ctFill[1]));
 
 		CTBorder ctBorder = createDefaultBorder();
-		borders.add(ctBorder);
+		borders.add(new XSSFCellBorder(ctBorder));
 
 		CTXf styleXf = createDefaultXf();
 		styleXfs.add(styleXf);
@@ -439,7 +468,7 @@
 
 	private XSSFFont createDefaultFont() {
 		CTFont ctFont = CTFont.Factory.newInstance();
-		XSSFFont xssfFont=new XSSFFont(ctFont);
+		XSSFFont xssfFont=new XSSFFont(ctFont, 0);
 		xssfFont.setFontHeightInPoints(XSSFFont.DEFAULT_FONT_SIZE);
 		xssfFont.setColor(XSSFFont.DEFAULT_FONT_COLOR);//setTheme
 		xssfFont.setFontName(XSSFFont.DEFAULT_FONT_NAME);

Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java?rev=701797&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java Sun Oct  5 06:56:28 2008
@@ -0,0 +1,113 @@
+/* ====================================================================
+   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;
+
+/**
+ * The enumeration value indicating the line style of a border in a cell,
+ * i.e., whether it is borded dash dot, dash dot dot, dashed, dotted, double, hair, medium, 
+ * medium dash dot, medium dash dot dot, medium dashed, none, slant dash dot, thick or thin.
+ */
+
+
+public enum BorderStyle {
+
+    /**
+     * No border
+     */
+
+    NONE,
+
+    /**
+     * Thin border
+     */
+
+    THIN,
+
+    /**
+     * Medium border
+     */
+
+    MEDIUM,
+
+    /**
+     * dash border
+     */
+
+    DASHED,
+
+    /**
+     * dot border
+     */
+
+    HAIR,
+
+    /**
+     * Thick border
+     */
+
+    THICK,
+
+    /**
+     * double-line border
+     */
+
+    DOUBLE,
+
+    /**
+     * hair-line border
+     */
+
+    DOTTED,
+
+    /**
+     * Medium dashed border
+     */
+
+    MEDIUM_DASHED,
+
+    /**
+     * dash-dot border
+     */
+
+    DASH_DOT,
+
+    /**
+     * medium dash-dot border
+     */
+
+    MEDIUM_DASH_DOT,
+
+    /**
+     * dash-dot-dot border
+     */
+
+    DASH_DOT_DOT,
+
+    /**
+     * medium dash-dot-dot border
+     */
+
+    MEDIUM_DASH_DOT_DOTC,
+
+    /**
+     * slanted dash-dot border
+     */
+
+    SLANTED_DASH_DOT;
+
+}

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java?rev=701797&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java Sun Oct  5 06:56:28 2008
@@ -0,0 +1,85 @@
+/* ====================================================================
+   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;
+
+/**
+ * The enumeration value indicating the style of fill pattern being used for a cell format.
+ * 
+ */
+
+
+public enum FillPatternType {
+    
+    /**  No background */
+     NO_FILL,
+
+    /**  Solidly filled */
+     SOLID_FOREGROUND,
+
+    /**  Small fine dots */
+     FINE_DOTS,
+
+    /**  Wide dots */
+     ALT_BARS,
+
+    /**  Sparse dots */
+     SPARSE_DOTS,
+
+    /**  Thick horizontal bands */
+     THICK_HORZ_BANDS,
+
+    /**  Thick vertical bands */
+     THICK_VERT_BANDS,
+
+    /**  Thick backward facing diagonals */
+     THICK_BACKWARD_DIAG,
+
+    /**  Thick forward facing diagonals */
+     THICK_FORWARD_DIAG,
+
+    /**  Large spots */
+     BIG_SPOTS,
+
+    /**  Brick-like layout */
+     BRICKS,
+
+    /**  Thin horizontal bands */
+     THIN_HORZ_BANDS,
+
+    /**  Thin vertical bands */
+     THIN_VERT_BANDS,
+
+    /**  Thin backward diagonal */
+     THIN_BACKWARD_DIAG,
+
+    /**  Thin forward diagonal */
+     THIN_FORWARD_DIAG,
+
+    /**  Squares */
+     SQUARES,
+
+    /**  Diamonds */
+     DIAMONDS,
+
+    /**  Less Dots */
+     LESS_DOTS,
+
+    /**  Least Dots */
+     LEAST_DOTS;
+
+}

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sun Oct  5 06:56:28 2008
@@ -20,44 +20,44 @@
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.StylesSource;
-import org.apache.poi.ss.usermodel.Workbook;
 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.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;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 
-public class XSSFCellStyle implements CellStyle {
+/**
+ *
+ * High level representation of the the possible formatting information for the contents of the cells on a sheet in a
+ * SpreadsheetML document.
+ *
+ * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createCellStyle()
+ * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getCellStyleAt(short)
+ * @see org.apache.poi.xssf.usermodel.XSSFCell#setCellStyle(org.apache.poi.ss.usermodel.CellStyle)
+ */
+public class XSSFCellStyle implements CellStyle, Cloneable {
 
     private int cellXfId;
-    private int cellStyleXfId;
-    private StylesSource stylesSource;
+    private StylesTable stylesSource;
     private CTXf cellXf;
     private CTXf cellStyleXf;
-    private XSSFCellBorder cellBorder;
-    private XSSFCellFill cellFill;
     private XSSFFont font;
     private XSSFCellAlignment cellAlignment;
 
     /**
      * Creates a Cell Style from the supplied parts
-     * @param cellXf The main XF for the cell
-     * @param cellStyleXf Optional, style xf
+     * @param cellXfId The main XF for the cell
+     * @param cellStyleXfId Optional, style xf
      * @param stylesSource Styles Source to work off
      */
     public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource) {
         this.cellXfId = cellXfId;
-        this.cellStyleXfId = cellStyleXfId;
         this.stylesSource = stylesSource;
         this.cellXf = stylesSource.getCellXfAt(this.cellXfId);
-        this.cellStyleXf = stylesSource.getCellStyleXfAt(this.cellStyleXfId);
+        this.cellStyleXf = stylesSource.getCellStyleXfAt(cellStyleXfId);
     }
 
     /**
@@ -66,6 +66,7 @@
     public CTXf getCoreXf() {
         return cellXf;
     }
+
     /**
      * Used so that StylesSource can figure out our location
      */
@@ -77,13 +78,13 @@
      * Creates an empty Cell Style
      */
     public XSSFCellStyle(StylesSource stylesSource) {
-        this.stylesSource = stylesSource;
+        this.stylesSource = (StylesTable)stylesSource;
         // We need a new CTXf for the main styles
         // TODO decide on a style ctxf
         cellXf = CTXf.Factory.newInstance();
         cellStyleXf = null;
     }
-    
+
     /**
      * Verifies that this style belongs to the supplied Workbook
      *  Styles Source.
@@ -117,426 +118,1168 @@
         }
         throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
     }
+
     public void cloneStyleFrom(XSSFCellStyle source) {
         throw new IllegalStateException("TODO");
     }
 
+    /**
+     * Get the type of horizontal alignment for the cell
+     *
+     * @return short - the type of alignment
+     * @see #ALIGN_GENERAL
+     * @see #ALIGN_LEFT
+     * @see #ALIGN_CENTER
+     * @see #ALIGN_RIGHT
+     * @see #ALIGN_FILL
+     * @see #ALIGN_JUSTIFY
+     * @see #ALIGN_CENTER_SELECTION
+     */
     public short getAlignment() {
         return (short)(getAlignmentEnum().ordinal());
     }
 
+    /**
+     * Get the type of horizontal alignment for the cell
+     *
+     * @return HorizontalAlignment - the type of alignment
+     */
     public HorizontalAlignment getAlignmentEnum() {
         return getCellAlignment().getHorizontal();
     }
 
+    /**
+     * Get the type of border to use for the bottom border of the cell
+     *
+     * @return short - border type
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public short getBorderBottom() {
-        return getBorderStyleAsShort(BorderSide.BOTTOM);
+        if(!cellXf.getApplyBorder()) return BORDER_NONE;
+
+        int idx = (int)cellXf.getBorderId();
+        CTBorder ct = stylesSource.getBorderAt(idx).getCTBorder();
+        STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null;
+        return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
     }
 
-    public String getBorderBottomAsString() {
-        return getBorderStyleAsString(BorderSide.BOTTOM);
+    /**
+     * Get the type of border to use for the bottom border of the cell
+     *
+     * @return border type as Java enum
+     * @see BorderStyle
+     */
+    public BorderStyle getBorderBottomEnum() {
+        int style  = getBorderBottom();
+        return BorderStyle.values()[style];
     }
 
+    /**
+     * Get the type of border to use for the left border of the cell
+     *
+     * @return short - border type, default value is {@link #BORDER_NONE}
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public short getBorderLeft() {
-        return getBorderStyleAsShort(BorderSide.LEFT);
+        if(!cellXf.getApplyBorder()) return BORDER_NONE;
+
+        int idx = (int)cellXf.getBorderId();
+        CTBorder ct = stylesSource.getBorderAt(idx).getCTBorder();
+        STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null;
+        return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
     }
 
-    public String getBorderLeftAsString() {
-        return getBorderStyleAsString(BorderSide.LEFT);
+    /**
+     * Get the type of border to use for the left border of the cell
+     *
+     * @return border type, default value is {@link BorderStyle.NONE}
+     */
+    public BorderStyle getBorderLeftEnum() {
+        int style  = getBorderLeft();
+        return BorderStyle.values()[style];
     }
 
+    /**
+     * Get the type of border to use for the right border of the cell
+     *
+     * @return short - border type, default value is {@link #BORDER_NONE}
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public short getBorderRight() {
-        return getBorderStyleAsShort(BorderSide.RIGHT);
+        if(!cellXf.getApplyBorder()) return BORDER_NONE;
+
+        int idx = (int)cellXf.getBorderId();
+        CTBorder ct = stylesSource.getBorderAt(idx).getCTBorder();
+        STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null;
+        return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
     }
 
-    public String getBorderRightAsString() {
-        return getBorderStyleAsString(BorderSide.RIGHT);
+    /**
+     * Get the type of border to use for the right border of the cell
+     *
+     * @return border type, default value is {@link BorderStyle.NONE}
+     */
+    public BorderStyle getBorderRightEnum() {
+        int style  = getBorderRight();
+        return BorderStyle.values()[style];
     }
 
+    /**
+     * Get the type of border to use for the top border of the cell
+     *
+     * @return short - border type, default value is {@link #BORDER_NONE}
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public short getBorderTop() {
-        return getBorderStyleAsShort(BorderSide.TOP);
+        if(!cellXf.getApplyBorder()) return BORDER_NONE;
+
+        int idx = (int)cellXf.getBorderId();
+        CTBorder ct = stylesSource.getBorderAt(idx).getCTBorder();
+        STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
+        return ptrn == null ? BORDER_NONE : (short)(ptrn.intValue() - 1);
     }
 
-    public String getBorderTopAsString() {
-        return getBorderStyleAsString(BorderSide.TOP);
+     /**
+     * Get the type of border to use for the top border of the cell
+     *
+     * @return border type, default value is {@link BorderStyle.NONE}
+     */
+    public BorderStyle getBorderTopEnum() {
+         int style  = getBorderTop();
+         return BorderStyle.values()[style];
     }
 
+    /**
+     * Get the color to use for the bottom border
+     * <br/>
+     * Color is optional. When missing, IndexedColors.AUTOMATIC is implied.
+     * @return the index of the color definition, default value is {@link IndexedColors.AUTOMATIC}
+     * @see IndexedColors
+     */
     public short getBottomBorderColor() {
-        return getBorderColorIndexed(BorderSide.BOTTOM);
+        XSSFColor clr = getBottomBorderRgbColor();
+        return clr == null ? IndexedColors.BLACK.getIndex() : (short)clr.getIndexed();
+    }
+
+    /**
+     * Get the color to use for the bottom border as a {@link XSSFColor}
+     *
+     * @return the used color or <code>null</code> if not set
+     */
+    public XSSFColor getBottomBorderRgbColor() {
+        if(!cellXf.getApplyBorder()) return null;
+
+        int idx = (int)cellXf.getBorderId();
+        XSSFCellBorder border = stylesSource.getBorderAt(idx);
+
+        return border.getBorderColor(BorderSide.BOTTOM);
     }
 
+    /**
+     * Get the index of the number format (numFmt) record used by this cell format.
+     *
+     * @return the index of the number format
+     */
     public short getDataFormat() {
         return (short)cellXf.getNumFmtId();
     }
+
+    /**
+     * Get the contents of the format string, by looking up
+     * the StylesSource
+     *
+     * @return the number format string
+     */
     public String getDataFormatString() {
         return stylesSource.getNumberFormatAt(getDataFormat());
     }
 
+    /**
+     * Get the background fill color.
+     * <p>
+     * Note - many cells are actually filled with a foreground
+     *  fill, not a background fill - see {@link #getFillForegroundColor()}
+     * </p>
+     * @return fill color, default value is {@link IndexedColors.AUTOMATIC}
+     * @see IndexedColors
+     */
     public short getFillBackgroundColor() {
-        return (short) getCellFill().getFillBackgroundColor().getIndexed();
+        XSSFColor clr = getFillBackgroundRgbColor();
+        return clr == null ? IndexedColors.AUTOMATIC.getIndex() : (short)clr.getIndexed();
     }
 
+    /**
+     * Get the background fill color.
+     * <p>
+     * Note - many cells are actually filled with a foreground
+     *  fill, not a background fill - see {@link #getFillForegroundColor()}
+     * </p>
+     * @see org.apache.poi.xssf.usermodel.extensions.XSSFColor#getRgb()
+     * @return XSSFColor - fill color or <code>null</code> if not set
+     */
     public XSSFColor getFillBackgroundRgbColor() {
-        return getCellFill().getFillBackgroundColor();
+        if(!cellXf.getApplyFill()) return null;
+
+        int fillIndex = (int)cellXf.getFillId();
+        XSSFCellFill fg = stylesSource.getFillAt(fillIndex);
+
+        return fg.getFillBackgroundColor();
     }
 
+    /**
+     * Get the foreground fill color.
+     * <p>
+     * Many cells are filled with this, instead of a
+     *  background color ({@link #getFillBackgroundColor()})
+     * </p>
+     * @see IndexedColors
+     * @return fill color, default value is {@link IndexedColors.AUTOMATIC}
+     */
     public short getFillForegroundColor() {
-        return (short) getCellFill().getFillForegroundColor().getIndexed();
+        XSSFColor clr = getFillForegroundRgbColor();
+        return clr == null ? IndexedColors.AUTOMATIC.getIndex() : (short)clr.getIndexed();
     }
 
+    /**
+     * Get the foreground fill color.
+     *
+     * @return XSSFColor - fill color or <code>null</code> if not set
+     */
     public XSSFColor getFillForegroundRgbColor() {
-        return  getCellFill().getFillForegroundColor();
+        if(!cellXf.getApplyFill()) return null;
+
+        int fillIndex = (int)cellXf.getFillId();
+        XSSFCellFill fg = stylesSource.getFillAt(fillIndex);
+
+        return fg.getFillForegroundColor();
     }
 
+    /**
+     * Get the fill pattern
+     * @return fill pattern, default value is {@link #NO_FILL}
+     *
+     * @see #NO_FILL
+     * @see #SOLID_FOREGROUND
+     * @see #FINE_DOTS
+     * @see #ALT_BARS
+     * @see #SPARSE_DOTS
+     * @see #THICK_HORZ_BANDS
+     * @see #THICK_VERT_BANDS
+     * @see #THICK_BACKWARD_DIAG
+     * @see #THICK_FORWARD_DIAG
+     * @see #BIG_SPOTS
+     * @see #BRICKS
+     * @see #THIN_HORZ_BANDS
+     * @see #THIN_VERT_BANDS
+     * @see #THIN_BACKWARD_DIAG
+     * @see #THIN_FORWARD_DIAG
+     * @see #SQUARES
+     * @see #DIAMONDS
+     */
     public short getFillPattern() {
-	int fp= getCellFill().getPatternType().intValue();
-	switch (fp) {
-	case STPatternType.INT_NONE:
-		return CellStyle.NO_FILL;
-	case STPatternType.INT_SOLID: 
-	    return CellStyle.SOLID_FOREGROUND;
-	case STPatternType.INT_LIGHT_GRAY:
-	    return CellStyle.FINE_DOTS;
-	case STPatternType.INT_DARK_GRID:
-		return CellStyle.ALT_BARS;
-	case STPatternType.INT_DARK_GRAY:
-	    return CellStyle.SPARSE_DOTS;
-	case STPatternType.INT_DARK_HORIZONTAL: 
-	    return CellStyle.THICK_HORZ_BANDS;
-	case STPatternType.INT_DARK_VERTICAL:
-	    return CellStyle.THICK_VERT_BANDS;
-	case STPatternType.INT_DARK_UP:
-		return CellStyle.THICK_BACKWARD_DIAG;
-	case STPatternType.INT_DARK_DOWN:
-		return CellStyle.THICK_FORWARD_DIAG;
-	case STPatternType.INT_GRAY_0625:
-		return CellStyle.BIG_SPOTS;
-	case STPatternType.INT_DARK_TRELLIS:
-		return CellStyle.BRICKS;
-	case STPatternType.INT_LIGHT_HORIZONTAL:
-		return CellStyle.THIN_HORZ_BANDS;
-	case STPatternType.INT_LIGHT_VERTICAL:
-		return CellStyle.THIN_VERT_BANDS;
-	case STPatternType.INT_LIGHT_UP:
-		return CellStyle.THIN_BACKWARD_DIAG;
-	case STPatternType.INT_LIGHT_DOWN:
-		return CellStyle.THIN_FORWARD_DIAG;
-	case STPatternType.INT_LIGHT_GRID:
-		return CellStyle.SQUARES;
-	case STPatternType.INT_LIGHT_TRELLIS:
-		return CellStyle.DIAMONDS;
-	case STPatternType.INT_GRAY_125:
-		return CellStyle.LESS_DOTS;
-/*		
-	case STPatternType.INT_GRAY_0625:
-		return CellStyle.LEAST_DOTS;
-*/		
-	default:
-	    	return CellStyle.NO_FILL;
-	}
-    //    return (short) getCellFill().getPatternType().intValue();
+        if(!cellXf.getApplyFill()) return 0;
+
+        int fillIndex = (int)cellXf.getFillId();
+        XSSFCellFill fill = stylesSource.getFillAt(fillIndex);
+
+        STPatternType.Enum ptrn = fill.getPatternType();
+        if(ptrn == null) return CellStyle.NO_FILL;
+        return (short)(ptrn.intValue() - 1);
     }
 
-    public Font getFont(Workbook parentWorkbook) {
-        return getFont();
+    /**
+     * Get the fill pattern
+     *
+     * @return the fill pattern, default value is {@link FillPatternType.NO_FILL}
+     */
+    public FillPatternType getFillPatternEnum() {
+        int style  = getFillPattern();
+        return FillPatternType.values()[style];
     }
 
-    public Font getFont() {
+    /**
+    * Gets the font for this style
+    * @return Font - font
+    */
+    public XSSFFont getFont() {
         if (font == null) {
-            font = (XSSFFont) ((StylesTable)stylesSource).getFontAt(getFontId());
+            font = stylesSource.getFontAt(getFontId());
         }
         return font;
     }
 
+    /**
+     * Gets the index of the font for this style
+     *
+     * @return short - font index
+     * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
+     */
     public short getFontIndex() {
         return (short) getFontId();
     }
 
+    /**
+     * Get whether the cell's using this style are to be hidden
+     *
+     * @return boolean -  whether the cell using this style is hidden
+     */
     public boolean getHidden() {
         return getCellProtection().getHidden();
     }
 
+    /**
+     * Get the number of spaces to indent the text in the cell
+     *
+     * @return indent - number of spaces
+     */
     public short getIndention() {
         return (short) getCellAlignment().getIndent();
     }
 
+    /**
+     * Get the index within the StylesTable (sequence within the collection of CTXf elements)
+     *
+     * @return unique index number of the underlying record this style represents
+     */
     public short getIndex() {
-        return (short) this.cellXfId;
+        return (short)this.cellXfId;
     }
 
+    /**
+     * Get the color to use for the left border
+     *
+     * @return the index of the color definition, default value is {@link IndexedColors.BLACK}
+     * @see IndexedColors
+     */
     public short getLeftBorderColor() {
-        return getBorderColorIndexed(BorderSide.LEFT);
+        XSSFColor clr = getLeftBorderRgbColor();
+        return clr == null ? IndexedColors.BLACK.getIndex() : (short)clr.getIndexed();
     }
 
+    /**
+     * Get the color to use for the left border
+     *
+     * @return the index of the color definition or <code>null</code> if not set
+     * @see IndexedColors
+     */
+    public XSSFColor getLeftBorderRgbColor() {
+        if(!cellXf.getApplyBorder()) return null;
+
+        int idx = (int)cellXf.getBorderId();
+        XSSFCellBorder border = stylesSource.getBorderAt(idx);
+
+        return border.getBorderColor(BorderSide.LEFT);
+    }
+
+    /**
+     * Get whether the cell's using this style are locked
+     *
+     * @return whether the cell using this style are locked
+     */
     public boolean getLocked() {
         return getCellProtection().getLocked();
     }
 
+    /**
+     * Get the color to use for the right border
+     *
+     * @return the index of the color definition, default value is {@link IndexedColors.BLACK}
+     * @see IndexedColors
+     */
     public short getRightBorderColor() {
-        return getBorderColorIndexed(BorderSide.RIGHT);
+        XSSFColor clr = getRightBorderRgbColor();
+        return clr == null ? IndexedColors.BLACK.getIndex() : (short)clr.getIndexed();
     }
+    /**
+     * Get the color to use for the right border
+     *
+     * @return the used color or <code>null</code> if not set
+     */
+    public XSSFColor getRightBorderRgbColor() {
+        if(!cellXf.getApplyBorder()) return null;
 
+        int idx = (int)cellXf.getBorderId();
+        XSSFCellBorder border = stylesSource.getBorderAt(idx);
+
+        return border.getBorderColor(BorderSide.RIGHT);
+    }
+
+    /**
+     * Get the degree of rotation for the text in the cell
+     * <p>
+     * Expressed in degrees. Values range from 0 to 180. The first letter of
+     * the text is considered the center-point of the arc.
+     * <br/>
+     * For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the
+     * horizon is calculated as:
+     * <br/>
+     * <code>[degrees below horizon] = 90 - textRotation.</code>
+     * </p>
+     *
+     * @return rotation degrees (between 0 and 180 degrees)
+     */
     public short getRotation() {
         return (short) getCellAlignment().getTextRotation();
     }
 
+    /**
+     * Get the color to use for the top border
+     *
+     * @return the index of the color definition, default value is {@link IndexedColors.BLACK}
+     * @see IndexedColors
+     */
     public short getTopBorderColor() {
-        return getBorderColorIndexed(BorderSide.TOP);
+        XSSFColor clr = getTopBorderRgbColor();
+        return clr == null ? IndexedColors.BLACK.getIndex() : (short)clr.getIndexed();
+    }
+
+    /**
+     * Get the color to use for the top border
+     *
+     * @return the used color or <code>null</code> if not set
+     */
+    public XSSFColor getTopBorderRgbColor() {
+        if(!cellXf.getApplyBorder()) return null;
+
+        int idx = (int)cellXf.getBorderId();
+        XSSFCellBorder border = stylesSource.getBorderAt(idx);
+
+        return border.getBorderColor(BorderSide.TOP);
     }
 
+    /**
+     * Get the type of vertical alignment for the cell
+     *
+     * @return align the type of alignment, default value is {@link #VERTICAL_BOTTOM}
+     * @see #VERTICAL_TOP
+     * @see #VERTICAL_CENTER
+     * @see #VERTICAL_BOTTOM
+     * @see #VERTICAL_JUSTIFY
+     */
     public short getVerticalAlignment() {
         return (short) (getVerticalAlignmentEnum().ordinal());
     }
 
+    /**
+     * Get the type of vertical alignment for the cell
+     *
+     * @return the type of alignment, default value is {@link VerticalAlignment.BOTTOM}
+     * @see VerticalAlignment
+     */
     public VerticalAlignment getVerticalAlignmentEnum() {
         return getCellAlignment().getVertical();
     }
 
+    /**
+     * Whether the text should be wrapped
+     *
+     * @return  a boolean value indicating if the text in a cell should be line-wrapped within the cell.
+     */
     public boolean getWrapText() {
         return getCellAlignment().getWrapText();
     }
 
+    /**
+     * Set the type of horizontal alignment for the cell
+     *
+     * @param align - the type of alignment
+     * @see #ALIGN_GENERAL
+     * @see #ALIGN_LEFT
+     * @see #ALIGN_CENTER
+     * @see #ALIGN_RIGHT
+     * @see #ALIGN_FILL
+     * @see #ALIGN_JUSTIFY
+     * @see #ALIGN_CENTER_SELECTION
+     */
     public void setAlignment(short align) {
         getCellAlignment().setHorizontal(HorizontalAlignment.values()[align]);
     }
 
+    /**
+     * Set the type of horizontal alignment for the cell
+     *
+     * @param align - the type of alignment
+     * @see HorizontalAlignment
+     */
     public void setAlignment(HorizontalAlignment align) {
         setAlignment((short)align.ordinal());
     }
 
+    /**
+     * Set the type of border to use for the bottom border of the cell
+     *
+     * @param border the type of border to use
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public void setBorderBottom(short border) {
-        setBorderBottomEnum(STBorderStyle.Enum.forInt(border));
+        CTBorder ct = getCTBorder();
+        CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
+        if(border == BORDER_NONE) ct.unsetBottom();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
     }
 
-    public void setBorderBottomEnum(STBorderStyle.Enum style) {
-        getCellBorder().setBorderStyle(BorderSide.BOTTOM, style);
+    /**
+     * Set the type of border to use for the bottom border of the cell
+     *
+     * @param border - type of border to use
+     * @see BorderStyle
+     */
+    public void setBorderBottom(BorderStyle border) {
+	    setBorderBottom((short)border.ordinal());
     }
 
+    /**
+     * Set the type of border to use for the left border of the cell
+     * @param border the type of border to use
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
     public void setBorderLeft(short border) {
-        setBorderLeftEnum(STBorderStyle.Enum.forInt(border));
-    }
+        CTBorder ct = getCTBorder();
+        CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
+        if(border == BORDER_NONE) ct.unsetLeft();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
 
-    public void setBorderLeftEnum(STBorderStyle.Enum style) {
-        getCellBorder().setBorderStyle(BorderSide.LEFT, style);
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
     }
 
-    public void setBorderRight(short border) {
-        setBorderRightEnum(STBorderStyle.Enum.forInt(border));
+     /**
+     * Set the type of border to use for the left border of the cell
+      *
+     * @param border the type of border to use
+     */
+    public void setBorderLeft(BorderStyle border) {
+	    setBorderLeft((short)border.ordinal());
     }
 
-    public void setBorderRightEnum(STBorderStyle.Enum style) {
-        getCellBorder().setBorderStyle(BorderSide.RIGHT, style);
+    /**
+     * Set the type of border to use for the right border of the cell
+     *
+     * @param border the type of border to use
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
+   public void setBorderRight(short border) {
+        CTBorder ct = getCTBorder();
+        CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
+        if(border == BORDER_NONE) ct.unsetRight();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
+    }
+
+     /**
+     * Set the type of border to use for the right border of the cell
+      *
+     * @param border the type of border to use
+     */
+    public void setBorderRight(BorderStyle border) {
+	    setBorderRight((short)border.ordinal());
     }
 
-    public void setBorderTop(short border) {
-        setBorderTopEnum(STBorderStyle.Enum.forInt(border));
+    /**
+     * Set the type of border to use for the top border of the cell
+     *
+     * @param border the type of border to use
+     * @see #BORDER_NONE
+     * @see #BORDER_THIN
+     * @see #BORDER_MEDIUM
+     * @see #BORDER_DASHED
+     * @see #BORDER_DOTTED
+     * @see #BORDER_THICK
+     * @see #BORDER_DOUBLE
+     * @see #BORDER_HAIR
+     * @see #BORDER_MEDIUM_DASHED
+     * @see #BORDER_DASH_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT
+     * @see #BORDER_DASH_DOT_DOT
+     * @see #BORDER_MEDIUM_DASH_DOT_DOT
+     * @see #BORDER_SLANTED_DASH_DOT
+     */
+   public void setBorderTop(short border) {
+        CTBorder ct = getCTBorder();
+        CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
+        if(border == BORDER_NONE) ct.unsetTop();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
     }
 
-    public void setBorderTopEnum(STBorderStyle.Enum style) {
-        getCellBorder().setBorderStyle(BorderSide.TOP, style);
+    /**
+     * Set the type of border to use for the top border of the cell
+     *
+     * @param border the type of border to use
+     */
+    public void setBorderTopEnum(BorderStyle border) {
+	    setBorderTop((short)border.ordinal());
     }
 
+    /**
+     * Set the color to use for the bottom border
+     * @param color the index of the color definition
+     * @see IndexedColors
+     */
     public void setBottomBorderColor(short color) {
-        setBorderColorIndexed(BorderSide.BOTTOM, color);
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(color);
+        setBottomBorderColor(clr);
     }
 
+    /**
+     * Set the color to use for the bottom border
+     *
+     * @param color the color to use, null means no color
+     */
+    public void setBottomBorderColor(XSSFColor color) {
+        CTBorder ct = getCTBorder();
+        if(color == null && !ct.isSetBottom()) return;
+
+        CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
+        if(color != null)  pr.setColor(color.getCTColor());
+        else pr.unsetColor();
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
+    }
+
+    /**
+     * Set the index of a data format
+     *
+     * @param fmt the index of a data format
+     */
     public void setDataFormat(short fmt) {
         cellXf.setNumFmtId((long)fmt);
     }
 
-    public void setFillBackgroundRgbColor(XSSFColor color) {
-        cellFill=getCellFill();
-        cellFill.setFillBackgroundRgbColor(color);
+    /**
+     * Set the background fill color represented as a {@link XSSFColor} value.
+     * <p>
+     * For example:
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
+     * cs.setFillBackgroundRgbColor(new XSSFColor(java.awt.Color.RED));
+     * </pre>
+     * optionally a Foreground and background fill can be applied:
+     * <i>Note: Ensure Foreground color is set prior to background</i>
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
+     * cs.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE));
+     * cs.setFillBackgroundColor(new XSSFColor(java.awt.Color.GREEN));
+     * </pre>
+     * or, for the special case of SOLID_FILL:
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND );
+     * cs.setFillForegroundColor(new XSSFColor(java.awt.Color.GREEN));
+     * </pre>
+     * It is necessary to set the fill style in order
+     * for the color to be shown in the cell.
+     *
+     * @param color - the color to use
+     */
+    public void setFillBackgroundColor(XSSFColor color) {
+        CTFill ct = getCTFill();
+        CTPatternFill ptrn = ct.getPatternFill();
+        if(color == null) {
+            if(ptrn != null) ptrn.unsetBgColor();
+        } else {
+            if(ptrn == null) ptrn = ct.addNewPatternFill();
+            ptrn.setBgColor(color.getCTColor());
+        }
+
+        int idx = stylesSource.putFill(new XSSFCellFill(ct));
+
+        cellXf.setFillId(idx);
+        cellXf.setApplyFill(true);
     }
 
+    /**
+     * Set the background fill color represented as a indexed color value.
+     * <p>
+     * For example:
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
+     * cs.setFillBackgroundRgbColor(IndexedColors.RED.getIndex());
+     * </pre>
+     * optionally a Foreground and background fill can be applied:
+     * <i>Note: Ensure Foreground color is set prior to background</i>
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.FINE_DOTS );
+     * cs.setFillForegroundColor(IndexedColors.BLUE.getIndex());
+     * cs.setFillBackgroundColor(IndexedColors.RED.getIndex());
+     * </pre>
+     * or, for the special case of SOLID_FILL:
+     * <pre>
+     * cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND );
+     * cs.setFillForegroundColor(IndexedColors.RED.getIndex());
+     * </pre>
+     * It is necessary to set the fill style in order
+     * for the color to be shown in the cell.
+     *
+     * @param bg - the color to use
+     * @see IndexedColors
+     */
     public void setFillBackgroundColor(short bg) {
-        getCellFill().setFillBackgroundColor(bg);
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(bg);
+        setFillBackgroundColor(clr);
     }
 
-    public void setFillForegroundRgbColor(XSSFColor color) {
-        getCellFill().setFillForegroundRgbColor(color);
+    /**
+    * Set the foreground fill color represented as a {@link XSSFColor} value.
+     * <br/>
+    * <i>Note: Ensure Foreground color is set prior to background color.</i>
+    * @param color the color to use
+    * @see #setFillBackgroundColor(org.apache.poi.xssf.usermodel.extensions.XSSFColor) )
+    */
+    public void setFillForegroundColor(XSSFColor color) {
+        CTFill ct = getCTFill();
+
+        CTPatternFill ptrn = ct.getPatternFill();
+        if(color == null) {
+            if(ptrn != null) ptrn.unsetFgColor();
+        } else {
+            if(ptrn == null) ptrn = ct.addNewPatternFill();
+            ptrn.setFgColor(color.getCTColor());
+        }
+
+        int idx = stylesSource.putFill(new XSSFCellFill(ct));
+
+        cellXf.setFillId(idx);
+        cellXf.setApplyFill(true);
+    }
+
+    /**
+     * Set the foreground fill color as a indexed color value
+     * <br/>
+     * <i>Note: Ensure Foreground color is set prior to background color.</i>
+     * @param fg the color to use
+     * @see IndexedColors
+     */
+    public void setFillForegroundColor(short fg) {
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(fg);
+        setFillForegroundColor(clr);
+    }
+
+    /**
+     * Get a <b>copy</b> of the currently used CTFill, if none is used, return a new instance.
+     */
+    private CTFill getCTFill(){
+        CTFill ct;
+        if(cellXf.getApplyFill()) {
+            int fillIndex = (int)cellXf.getFillId();
+            XSSFCellFill cf = stylesSource.getFillAt(fillIndex);
+
+            ct = (CTFill)cf.getCTFill().copy();
+        } else {
+            ct = CTFill.Factory.newInstance();
+        }
+        return ct;
+    }
+
+    /**
+     * Get a <b>copy</b> of the currently used CTBorder, if none is used, return a new instance.
+     */
+    private CTBorder getCTBorder(){
+        CTBorder ct;
+        if(cellXf.getApplyBorder()) {
+            int idx = (int)cellXf.getBorderId();
+            XSSFCellBorder cf = stylesSource.getBorderAt(idx);
+
+            ct = (CTBorder)cf.getCTBorder().copy();
+        } else {
+            ct = CTBorder.Factory.newInstance();
+        }
+        return ct;
     }
 
-    public void setFillForegroundColor(short bg) {
-	getCellFill().setFillForegroundColor(bg);
-    }
-
-    public void setFillPattern(short fp) {
-	cellFill=getCellFill();
-	switch (fp) {
-	case CellStyle.NO_FILL:
-		cellFill.setPatternType(STPatternType.NONE);
-	    break;
-	case CellStyle.SOLID_FOREGROUND:
-		cellFill.setPatternType(STPatternType.SOLID);
-		    break;
-	case CellStyle.FINE_DOTS:
-		cellFill.setPatternType(STPatternType.LIGHT_GRAY);
-		    break;
-	case CellStyle.ALT_BARS:
-		cellFill.setPatternType(STPatternType.DARK_GRID);
-		    break;
-	case CellStyle.SPARSE_DOTS:
-		cellFill.setPatternType(STPatternType.DARK_GRAY);
-		    break;
-	case CellStyle.THICK_HORZ_BANDS:
-		cellFill.setPatternType(STPatternType.DARK_HORIZONTAL);
-		    break;
-	case CellStyle.THICK_VERT_BANDS:
-		cellFill.setPatternType(STPatternType.DARK_VERTICAL);
-		    break;
-	case CellStyle.THICK_BACKWARD_DIAG:
-		cellFill.setPatternType(STPatternType.DARK_UP);
-		    break;
-	case CellStyle.THICK_FORWARD_DIAG:
-		cellFill.setPatternType(STPatternType.DARK_DOWN);
-		    break;
-	case CellStyle.BIG_SPOTS:
-		cellFill.setPatternType(STPatternType.GRAY_0625);
-		    break;
-	case CellStyle.BRICKS:
-		cellFill.setPatternType(STPatternType.DARK_TRELLIS);
-		    break;
-	case CellStyle.THIN_HORZ_BANDS:
-		cellFill.setPatternType(STPatternType.LIGHT_HORIZONTAL);
-		    break;
-	case CellStyle.THIN_VERT_BANDS:
-		cellFill.setPatternType(STPatternType.LIGHT_VERTICAL);
-		    break;
-	case CellStyle.THIN_BACKWARD_DIAG:
-		cellFill.setPatternType(STPatternType.LIGHT_UP);
-		    break;
-	case CellStyle.THIN_FORWARD_DIAG:
-		cellFill.setPatternType(STPatternType.LIGHT_DOWN);
-		    break;
-	case CellStyle.SQUARES:
-		cellFill.setPatternType(STPatternType.LIGHT_GRID);
-		    break;
-	case CellStyle.DIAMONDS:
-		cellFill.setPatternType(STPatternType.LIGHT_TRELLIS);
-		    break;
-	case CellStyle.LESS_DOTS:
-		cellFill.setPatternType(STPatternType.GRAY_125);
-		    break;
-	case CellStyle.LEAST_DOTS:
-		cellFill.setPatternType(STPatternType.GRAY_0625);
-		    break;
-	default: throw new RuntimeException("Fill type ["+fp+"] not accepted");
-	}
+    /**
+     * This element is used to specify cell fill information for pattern and solid color cell fills.
+     * For solid cell fills (no pattern),  foregorund color is used.
+     * For cell fills with patterns specified, then the cell fill color is specified by the background color.
+     *
+     * @see #NO_FILL
+     * @see #SOLID_FOREGROUND
+     * @see #FINE_DOTS
+     * @see #ALT_BARS
+     * @see #SPARSE_DOTS
+     * @see #THICK_HORZ_BANDS
+     * @see #THICK_VERT_BANDS
+     * @see #THICK_BACKWARD_DIAG
+     * @see #THICK_FORWARD_DIAG
+     * @see #BIG_SPOTS
+     * @see #BRICKS
+     * @see #THIN_HORZ_BANDS
+     * @see #THIN_VERT_BANDS
+     * @see #THIN_BACKWARD_DIAG
+     * @see #THIN_FORWARD_DIAG
+     * @see #SQUARES
+     * @see #DIAMONDS
+     * @see #setFillBackgroundColor(short)
+     * @see #setFillForegroundColor(short)
+     * @param fp  fill pattern (set to {@link #SOLID_FOREGROUND} to fill w/foreground color)
+     */
+   public void setFillPattern(short fp) {
+        CTFill ct = getCTFill();
+        CTPatternFill ptrn = ct.isSetPatternFill() ? ct.getPatternFill() : ct.addNewPatternFill();
+        if(fp == NO_FILL && ptrn.isSetPatternType()) ptrn.unsetPatternType();
+        else ptrn.setPatternType(STPatternType.Enum.forInt(fp + 1));
+
+        int idx = stylesSource.putFill(new XSSFCellFill(ct));
+
+        cellXf.setFillId(idx);
+        cellXf.setApplyFill(true);
+    }
+
+    /**
+     * This element is used to specify cell fill information for pattern and solid color cell fills. For solid cell fills (no pattern),
+     * foreground color is used is used. For cell fills with patterns specified, then the cell fill color is specified by the background color element.
+     *
+     * @param ptrn the fill pattern to use
+     * @see #setFillBackgroundColor(short)
+     * @see #setFillForegroundColor(short)
+     * @see FillPatternType
+     */
+    public void setFillPattern(FillPatternType ptrn) {
+	    setFillPattern((short)ptrn.ordinal());
     }
 
+    /**
+     * Set the font for this style
+     *
+     * @param font  a font object created or retreived from the XSSFWorkbook object
+     * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createFont()
+     * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#getFontAt(short)
+     */
     public void setFont(Font font) {
-        if(font!=null){
-            long index=this.stylesSource.putFont(font);
+        if(font != null){
+            long index = font.getIndex();
             this.cellXf.setFontId(index);
+            this.cellXf.setApplyFont(true);
+        } else {
+            this.cellXf.setApplyFont(false);
         }
-        this.cellXf.setApplyFont(true);
     }
 
+    /**
+     * Set the cell's using this style to be hidden
+     *
+     * @param hidden - whether the cell using this style should be hidden
+     */
     public void setHidden(boolean hidden) {
         getCellProtection().setHidden(hidden);
     }
 
+    /**
+     * Set the number of spaces to indent the text in the cell
+     *
+     * @param indent - number of spaces
+     */
     public void setIndention(short indent) {
         getCellAlignment().setIndent(indent);
     }
 
+    /**
+     * Set the color to use for the left border as a indexed color value
+     *
+     * @param color the index of the color definition
+     * @see IndexedColors
+     */
     public void setLeftBorderColor(short color) {
-        setBorderColorIndexed(BorderSide.LEFT, color);
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(color);
+        setLeftBorderColor(clr);
     }
 
-	
-	private void setBorderColorIndexed(BorderSide side, XSSFColor color) {
-		this.cellBorder.setBorderColor(side, color);
-	}
+    /**
+     * Set the color to use for the left border as a {@link XSSFColor} value
+     *
+     * @param color the color to use
+     */
+    public void setLeftBorderColor(XSSFColor color) {
+        CTBorder ct = getCTBorder();
+        if(color == null && !ct.isSetLeft()) return;
+
+        CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
+        if(color != null)  pr.setColor(color.getCTColor());
+        else pr.unsetColor();
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
 
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
+    }
 
+    /**
+     * Set the cell's using this style to be locked
+     *
+     * @param locked -  whether the cell using this style should be locked
+     */
     public void setLocked(boolean locked) {
         getCellProtection().setLocked(locked);
     }
 
-
+    /**
+     * Set the color to use for the right border
+     *
+     * @param color the index of the color definition
+     * @see IndexedColors
+     */
     public void setRightBorderColor(short color) {
-        setBorderColorIndexed(BorderSide.RIGHT, color);
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(color);
+        setRightBorderColor(clr);
     }
 
+    /**
+     * Set the color to use for the right border as a {@link XSSFColor} value
+     *
+     * @param color the color to use
+     */
+    public void setRightBorderColor(XSSFColor color) {
+        CTBorder ct = getCTBorder();
+        if(color == null && !ct.isSetRight()) return;
+
+        CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
+        if(color != null)  pr.setColor(color.getCTColor());
+        else pr.unsetColor();
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
+    }
+
+    /**
+     * Set the degree of rotation for the text in the cell
+     * <p>
+     * Expressed in degrees. Values range from 0 to 180. The first letter of
+     * the text is considered the center-point of the arc.
+     * <br/>
+     * For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the
+     * horizon is calculated as:
+     * <br/>
+     * <code>[degrees below horizon] = 90 - textRotation.</code>
+     * </p>
+     *
+     * @param rotation - the rotation degrees (between 0 and 180 degrees)
+     */
     public void setRotation(short rotation) {
         getCellAlignment().setTextRotation(rotation);
     }
 
+
+    /**
+     * Set the color to use for the top border
+     *
+     * @param color the index of the color definition
+     * @see IndexedColors
+     */
     public void setTopBorderColor(short color) {
-        setBorderColorIndexed(BorderSide.TOP, color);
+        XSSFColor clr = new XSSFColor();
+        clr.setIndexed(color);
+        setTopBorderColor(clr);
+    }
+
+    /**
+     * Set the color to use for the top border as a {@link XSSFColor} value
+     *
+     * @param color the color to use
+     */
+    public void setTopBorderColor(XSSFColor color) {
+        CTBorder ct = getCTBorder();
+        if(color == null && !ct.isSetTop()) return;
+
+        CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
+        if(color != null)  pr.setColor(color.getCTColor());
+        else pr.unsetColor();
+
+        int idx = stylesSource.putBorder(new XSSFCellBorder(ct));
+
+        cellXf.setBorderId(idx);
+        cellXf.setApplyBorder(true);
     }
 
+    /**
+     * Set the type of vertical alignment for the cell
+     *
+     * @param align - align the type of alignment
+     * @see #VERTICAL_TOP
+     * @see #VERTICAL_CENTER
+     * @see #VERTICAL_BOTTOM
+     * @see #VERTICAL_JUSTIFY
+     * @see VerticalAlignment
+     */
     public void setVerticalAlignment(short align) {
         getCellAlignment().setVertical(VerticalAlignment.values()[align]);
     }
 
+    /**
+     * Set the type of vertical alignment for the cell
+     *
+     * @param align - the type of alignment
+     */
     public void setVerticalAlignment(VerticalAlignment align) {
         getCellAlignment().setVertical(align);
     }
 
+    /**
+     * Set whether the text should be wrapped
+     *
+     * @param wrapped a boolean value indicating if the text in a cell should be line-wrapped within the cell.
+     */
     public void setWrapText(boolean wrapped) {
         getCellAlignment().setWrapText(wrapped);
     }
 
+    /**
+     * Gets border color
+     *
+     * @param side the border side
+     * @return the used color
+     */
     public XSSFColor getBorderColor(BorderSide side) {
-        return getCellBorder().getBorderColor(side);
+        switch(side){
+            case BOTTOM:
+                return getBottomBorderRgbColor();
+            case RIGHT:
+                return getRightBorderRgbColor();
+            case TOP:
+                return getTopBorderRgbColor();
+            case LEFT:
+                return getLeftBorderRgbColor();
+            default:
+                throw new IllegalArgumentException("Unknown border: " + side);
+        }
     }
 
+    /**
+     * Set the color to use for the selected border
+     *
+     * @param side - where to apply the color definition
+     * @param color - the color to use
+     */
     public void setBorderColor(BorderSide side, XSSFColor color) {
-        getCellBorder().setBorderColor(side, color);
-    }
-    
-    private XSSFCellBorder getCellBorder() {
-        if (cellBorder == null) {
-            // TODO make a common Cell Border object
-            int borderId=getBorderId();
-            if(borderId==-1){
-        	cellBorder=new XSSFCellBorder();
-		long index=((StylesTable)stylesSource).putBorder(cellBorder);
-		this.cellXf.setBorderId(index);
-		this.cellXf.setApplyBorder(true);
-            }
-            else{
-        	cellBorder = ((StylesTable)stylesSource).getBorderAt(borderId);
-            }
-        }
-        return cellBorder;
-    }
-
-    private int getBorderId() {
-        if (cellXf.isSetBorderId() && cellXf.getBorderId()>0) {
-            return (int) cellXf.getBorderId();
-        }
-        return -1;
-      //  return (int) cellStyleXf.getBorderId();
-    }
-    
-    private XSSFCellFill getCellFill() {
-	if (cellFill == null) {
-	    int fillId=getFillId();
-	    if(fillId == -1) {
-		cellFill=new XSSFCellFill();
-		long index=((StylesTable)stylesSource).putFill(cellFill);
-		this.cellXf.setFillId(index);
-		this.cellXf.setApplyFill(true);
-	    }
-	    else{
-		cellFill=((StylesTable)stylesSource).getFillAt(fillId);
-	    }
-	}
-	return cellFill;
-    }
-
-    private int getFillId() {
-        if (cellXf.isSetFillId() && cellXf.getFillId()>0) {
-            return (int) cellXf.getFillId();
+        switch(side){
+            case BOTTOM:
+                setBottomBorderColor(color);
+                break;
+            case RIGHT:
+                setRightBorderColor(color);
+                break;
+            case TOP:
+                setTopBorderColor(color);
+                break;
+            case LEFT:
+                setLeftBorderColor(color);
+                break;
         }
-        //return (int) cellStyleXf.getFillId();
-        return -1; 
     }
-
     private int getFontId() {
         if (cellXf.isSetFontId()) {
             return (int) cellXf.getFontId();
@@ -544,6 +1287,10 @@
         return (int) cellStyleXf.getFontId();
     }
 
+    /**
+     * get a cellProtection from the supplied XML definition
+     * @return CTCellProtection
+     */
     private CTCellProtection getCellProtection() {
         if (cellXf.getProtection() == null) {
             cellXf.addNewProtection();
@@ -551,13 +1298,22 @@
         return cellXf.getProtection();
     }
 
-    public XSSFCellAlignment getCellAlignment() {
+    /**
+     * get the cellAlignment object to use for manage alignment
+     * @return XSSFCellAlignment - cell alignment
+     */
+    protected XSSFCellAlignment getCellAlignment() {
         if (this.cellAlignment == null) {
             this.cellAlignment = new XSSFCellAlignment(getCTCellAlignment());
         }
         return this.cellAlignment;
     }
 
+    /**
+     * Return the CTCellAlignment instance for alignment
+     *
+     * @return CTCellAlignment
+     */
     private CTCellAlignment getCTCellAlignment() {
         if (cellXf.getAlignment() == null) {
             cellXf.setAlignment(CTCellAlignment.Factory.newInstance());
@@ -565,24 +1321,40 @@
         return cellXf.getAlignment();
     }
 
-    private short getBorderColorIndexed(BorderSide side) {
-        return (short) getBorderColor(side).getIndexed();
+    /**
+     * Returns a hash code value for the object. The hash is derived from the underlying CTXf bean.
+     *
+     * @return the hash code value for this style
+     */
+    public int hashCode(){
+        return cellXf.toString().hashCode();
     }
 
-    private void setBorderColorIndexed(BorderSide side, int color) {
-        getBorderColor(side).setIndexed(color);
-    }
+    /**
+     * Checks is the supplied style is equal to this style
+     *
+     * @param o the style to check
+     * @return true if the supplied style is equal to this style
+     */
+    public boolean equals(Object o){
+        if(o == null || !(o instanceof XSSFCellStyle)) return false;
 
-    private short getBorderStyleAsShort(BorderSide side) {
-        return (short) (getBorderStyle(side).intValue() - 1);
+        XSSFCellStyle cf = (XSSFCellStyle)o;
+        return cellXf.toString().equals(cf.getCoreXf().toString());
     }
 
-    private String getBorderStyleAsString(BorderSide side) {
-        return getBorderStyle(side).toString();
-    }
+    /**
+     * Make a copy of this style. The underlying CTXf bean is cloned,
+     * the references to fills and borders remain.
+     *
+     * @return a copy of this style
+     */
+    public Object clone(){
+        CTXf xf = (CTXf)cellXf.copy();
 
-    private STBorderStyle.Enum getBorderStyle(BorderSide side) {
-        return getCellBorder().getBorderStyle(side);
+        int xfSize = stylesSource._getStyleXfsSize();
+        int indexXf = stylesSource.putCellXf(xf);
+        return new XSSFCellStyle(indexXf-1, xfSize-1, stylesSource);
     }
 
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Sun Oct  5 06:56:28 2008
@@ -20,6 +20,7 @@
 
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
+import org.apache.poi.xssf.model.StylesTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
@@ -54,6 +55,7 @@
     public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex();
 
     private CTFont ctFont;
+    private short index;
 
     /**
      * Create a new XSSFFont
@@ -62,6 +64,12 @@
      */
     public XSSFFont(CTFont font) {
         this.ctFont = font;
+        this.index = 0;
+    }
+
+    public XSSFFont(CTFont font, int index) {
+        this.ctFont = font;
+        this.index = (short)index;
     }
 
     /**
@@ -69,6 +77,8 @@
      */
     protected XSSFFont() {
         this.ctFont = CTFont.Factory.newInstance();
+        setFontName(DEFAULT_FONT_NAME);
+        setFontHeight(DEFAULT_FONT_SIZE);
     }
 
     /**
@@ -130,8 +140,7 @@
      */
     public XSSFColor getRgbColor() {
         CTColor ctColor = ctFont.sizeOfColorArray() == 0 ? null : ctFont.getColorArray(0);
-        XSSFColor color = new XSSFColor(ctColor);
-        return color;
+        return ctColor == null ? null : new XSSFColor(ctColor);
     }
 
 
@@ -180,7 +189,7 @@
      */
     public String getFontName() {
         CTFontName name = ctFont.sizeOfNameArray() == 0 ? null : ctFont.getNameArray(0);
-        return name == null ? null : name.getVal();
+        return name == null ? DEFAULT_FONT_NAME : name.getVal();
     }
 
     /**
@@ -265,8 +274,29 @@
      * @param bold - boldness to use
      */
     public void setBold(boolean bold) {
-        CTBooleanProperty ctBold = ctFont.sizeOfBArray() == 0 ? ctFont.addNewB() : ctFont.getBArray(0);
-        ctBold.setVal(true);
+        if(bold){
+            CTBooleanProperty ctBold = ctFont.sizeOfBArray() == 0 ? ctFont.addNewB() : ctFont.getBArray(0);
+            ctBold.setVal(bold);
+        } else {
+            ctFont.setBArray(null);
+        }
+    }
+
+    public void setBoldweight(short boldweight)
+    {
+        setBold(boldweight == BOLDWEIGHT_BOLD);
+    }
+
+    /**
+     * get the boldness to use
+     * @return boldweight
+     * @see #BOLDWEIGHT_NORMAL
+     * @see #BOLDWEIGHT_BOLD
+     */
+
+    public short getBoldweight()
+    {
+        return getBold() ? BOLDWEIGHT_BOLD : BOLDWEIGHT_NORMAL;
     }
 
     /**
@@ -323,6 +353,10 @@
                 ctColor.setIndexed(color);
         }
     }
+    public void setColor(XSSFColor color) {
+        if(color == null) ctFont.setColorArray(null);
+        else ctFont.setColorArray(new CTColor[]{color.getCTColor()});
+    }
 
     /**
      * set the font height in points.
@@ -385,7 +419,7 @@
      */
     public void setFontName(String name) {
         CTFontName fontName = ctFont.sizeOfNameArray() == 0 ? ctFont.addNewName() : ctFont.getNameArray(0);
-        fontName.setVal(name);
+        fontName.setVal(name == null ? DEFAULT_FONT_NAME : name);
     }
 
 
@@ -396,8 +430,12 @@
      * @param italic - value for italics or not
      */
     public void setItalic(boolean italic) {
-        CTBooleanProperty bool = ctFont.sizeOfIArray() == 0 ? ctFont.addNewI() : ctFont.getIArray(0);
-        bool.setVal(italic);
+        if(italic){
+            CTBooleanProperty bool = ctFont.sizeOfIArray() == 0 ? ctFont.addNewI() : ctFont.getIArray(0);
+            bool.setVal(italic);
+        } else {
+            ctFont.setIArray(null);
+        }
     }
 
 
@@ -408,8 +446,11 @@
      * @param strikeout - value for strikeout or not
      */
     public void setStrikeout(boolean strikeout) {
-        CTBooleanProperty strike = ctFont.sizeOfStrikeArray() == 0 ? ctFont.addNewStrike() : ctFont.getStrikeArray(0);
-        strike.setVal(strikeout);
+        if(!strikeout) ctFont.setStrikeArray(null);
+        else {
+            CTBooleanProperty strike = ctFont.sizeOfStrikeArray() == 0 ? ctFont.addNewStrike() : ctFont.getStrikeArray(0);
+            strike.setVal(strikeout);
+        }
     }
 
     /**
@@ -423,17 +464,21 @@
      * @see #SS_SUB
      */
     public void setTypeOffset(short offset) {
-        CTVerticalAlignFontProperty offsetProperty = ctFont.sizeOfVertAlignArray() == 0 ? ctFont.addNewVertAlign() : ctFont.getVertAlignArray(0);
-        switch (offset) {
-            case Font.SS_NONE:
-                offsetProperty.setVal(STVerticalAlignRun.BASELINE);
-                break;
-            case Font.SS_SUB:
-                offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
-                break;
-            case Font.SS_SUPER:
-                offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
-                break;
+        if(offset == Font.SS_NONE){
+            ctFont.setVertAlignArray(null);
+        } else {
+            CTVerticalAlignFontProperty offsetProperty = ctFont.sizeOfVertAlignArray() == 0 ? ctFont.addNewVertAlign() : ctFont.getVertAlignArray(0);
+            switch (offset) {
+                case Font.SS_NONE:
+                    offsetProperty.setVal(STVerticalAlignRun.BASELINE);
+                    break;
+                case Font.SS_SUB:
+                    offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
+                    break;
+                case Font.SS_SUPER:
+                    offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
+                    break;
+            }
         }
     }
 
@@ -445,24 +490,25 @@
      * @see FontUnderline
      */
     public void setUnderline(byte underline) {
-        CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
-        switch (underline) {
-            case Font.U_DOUBLE:
-                ctUnderline.setVal(FontUnderline.DOUBLE.getValue());
-                break;
-            case Font.U_DOUBLE_ACCOUNTING:
-                ctUnderline.setVal(FontUnderline.DOUBLE_ACCOUNTING.getValue());
-                break;
-            case Font.U_SINGLE_ACCOUNTING:
-                ctUnderline.setVal(FontUnderline.SINGLE_ACCOUNTING.getValue());
-                break;
-            case Font.U_NONE:
-                ctUnderline.setVal(FontUnderline.NONE.getValue());
-                break;
-            case Font.U_SINGLE:
-            default:
-                ctUnderline.setVal(FontUnderline.SINGLE.getValue());
-                break;
+        if(underline == Font.U_NONE) {
+            ctFont.setUArray(null);
+        } else {
+            CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
+            switch (underline) {
+                case Font.U_DOUBLE:
+                    ctUnderline.setVal(FontUnderline.DOUBLE.getValue());
+                    break;
+                case Font.U_DOUBLE_ACCOUNTING:
+                    ctUnderline.setVal(FontUnderline.DOUBLE_ACCOUNTING.getValue());
+                    break;
+                case Font.U_SINGLE_ACCOUNTING:
+                    ctUnderline.setVal(FontUnderline.SINGLE_ACCOUNTING.getValue());
+                    break;
+                case Font.U_SINGLE:
+                default:
+                    ctUnderline.setVal(FontUnderline.NONE.getValue());
+                    break;
+            }
         }
     }
 
@@ -486,18 +532,13 @@
     }
 
 
-    public long putFont(ArrayList<CTFont> fonts) {
-        //TODO
-        /*
-           * we need to implement a method equals to check that 2 instances of CTFont
-           * are different by comparison of all font attributes.
-           * NB: take a look to findFont method in XSSFWorkbook
-           */
-        if (fonts.contains(ctFont)) {
-            return fonts.indexOf(ctFont);
-        }
-        fonts.add(ctFont);
-        return fonts.size() - 1;
+    /**
+     * Register ourselfs in the style table
+     */
+    public long putFont(StylesTable styles) {
+        short idx = (short)styles.putFont(this);
+        this.index = idx;
+        return idx;
     }
 
     /**
@@ -558,5 +599,26 @@
         setFamily(family.getValue());
     }
 
+    /**
+     * get the index within the XSSFWorkbook (sequence within the collection of Font objects)
+     * @return unique index number of the underlying record this Font represents (probably you don't care
+     *  unless you're comparing which one is which)
+     */
+
+    public short getIndex()
+    {
+        return index;
+    }
+
+    public int hashCode(){
+        return ctFont.toString().hashCode();
+    }
+
+    public boolean equals(Object o){
+        if(!(o instanceof XSSFFont)) return false;
+
+        XSSFFont cf = (XSSFFont)o;
+        return ctFont.toString().equals(cf.getCTFont().toString());
+    }
 
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=701797&r1=701796&r2=701797&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun Oct  5 06:56:28 2008
@@ -30,7 +30,6 @@
 import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.StylesSource;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
 import org.apache.poi.util.POILogFactory;
@@ -77,7 +76,7 @@
      * A collection of shared objects used for styling content,
      * e.g. fonts, cell styles, colors, etc.
      */
-    private StylesSource stylesSource;
+    private StylesTable stylesSource;
 
     /**
      * Used to keep track of the data formatter so that all
@@ -160,7 +159,7 @@
             HashMap<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
             for(POIXMLDocumentPart p : getRelations()){
                 if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
-                else if(p instanceof StylesSource) stylesSource = (StylesSource)p;
+                else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
                 else if (p instanceof XSSFSheet) {
                     shIdMap.put(p.getPackageRelationship().getId(), (XSSFSheet)p);
                 }
@@ -300,9 +299,9 @@
         xf.setFillId(0);
         xf.setBorderId(0);
         xf.setXfId(0);
-        int xfSize=((StylesTable)stylesSource)._getStyleXfsSize();
-        long indexXf=((StylesTable)stylesSource).putCellXf(xf);
-        XSSFCellStyle style = new XSSFCellStyle(new Long(indexXf-1).intValue(), xfSize-1, (StylesTable)stylesSource);
+        int xfSize=(stylesSource)._getStyleXfsSize();
+        long indexXf=(stylesSource).putCellXf(xf);
+        XSSFCellStyle style = new XSSFCellStyle(new Long(indexXf-1).intValue(), xfSize-1, stylesSource);
         return style;
     }
 
@@ -324,8 +323,8 @@
      * @return new font object
      */
     public XSSFFont createFont() {
-        XSSFFont font= new XSSFFont();
-        stylesSource.putFont(font);
+        XSSFFont font = new XSSFFont();
+        font.putFont(stylesSource);
         return font;
     }
 
@@ -394,7 +393,7 @@
      * Finds a font that matches the one with the supplied attributes
      */
     public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
-        short fontNum=getNumberOfFonts();
+        short fontNum = getNumberOfFonts();
         for (short i = 0; i < fontNum; i++) {
             XSSFFont xssfFont = getFontAt(i);
 
@@ -471,7 +470,7 @@
     }
 
     public XSSFCellStyle getCellStyleAt(short idx) {
-        return (XSSFCellStyle)stylesSource.getStyleAt(idx);
+        return stylesSource.getStyleAt(idx);
     }
 
     public Palette getCustomPalette() {
@@ -536,7 +535,7 @@
      * @return count of cell styles
      */
     public short getNumCellStyles() {
-        return (short) ((StylesTable)stylesSource).getNumCellStyles();
+        return (short) (stylesSource).getNumCellStyles();
     }
 
     /**
@@ -545,7 +544,7 @@
      * @return number of fonts
      */
     public short getNumberOfFonts() {
-        return (short)((StylesTable)stylesSource).getNumberOfFonts();
+        return (short)(stylesSource).getNumberOfFonts();
     }
 
     /**
@@ -921,11 +920,11 @@
      * Return a object representing a collection of shared objects used for styling content,
      * e.g. fonts, cell styles, colors, etc.
      */
-    public StylesSource getStylesSource() {
+    public StylesTable getStylesSource() {
         return this.stylesSource;
     }
     //TODO do we really need setStylesSource?
-    protected void setStylesSource(StylesSource stylesSource) {
+    protected void setStylesSource(StylesTable stylesSource) {
         this.stylesSource = stylesSource;
     }
 



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