Index: src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java =================================================================== --- src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java (revision 704016) +++ src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java (working copy) @@ -17,14 +17,16 @@ package org.apache.poi.xssf.usermodel.extensions; -import java.util.LinkedList; - +import org.apache.poi.xssf.usermodel.BorderStyle; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle; -import org.apache.poi.xssf.usermodel.BorderStyle; - +/** + * This element contains border formatting information, specifying border definition formats (left, right, top, bottom, diagonal) + * for cells in the workbook. + * Color is optional. + */ public class XSSFCellBorder { private CTBorder border; @@ -33,85 +35,115 @@ * Creates a Cell Border from the supplied XML definition */ public XSSFCellBorder(CTBorder border) { - this.border = border; + this.border = border; } /** * Creates a new, empty Cell Border, on the * given Styles Table */ public XSSFCellBorder() { - border = CTBorder.Factory.newInstance(); + border = CTBorder.Factory.newInstance(); } - + +/** + * The enumeration value indicating the side being used for a cell border. + * + */ public static enum BorderSide { - TOP, RIGHT, BOTTOM, LEFT + TOP, RIGHT, BOTTOM, LEFT } + /** + * Returns the underlying XML bean. + * @return CTBorder + */ public CTBorder getCTBorder() { - return border; + return border; } + /** + * Get the type of border to use for the selected border + * @param side - - where to apply the color definition + * @see BorderStyle + * @return borderstyle - the type of border to use. default value is NONE if border style is not set. + */ public BorderStyle getBorderStyle(BorderSide side) { - CTBorderPr ctBorder = getBorder(side); - STBorderStyle.Enum border = ctBorder == null ? STBorderStyle.NONE : ctBorder.getStyle(); - return BorderStyle.values()[border.intValue() - 1]; + CTBorderPr ctBorder = getBorder(side); + STBorderStyle.Enum border = ctBorder == null ? STBorderStyle.NONE : ctBorder.getStyle(); + return BorderStyle.values()[border.intValue() - 1]; } + /** + * Set the type of border to use for the selected border + * @param side - - where to apply the color definition + * @param style - border style + * @see BorderStyle + */ public void setBorderStyle(BorderSide side, BorderStyle style) { - getBorder(side, true).setStyle(STBorderStyle.Enum.forInt(style.ordinal() + 1)); + getBorder(side, true).setStyle(STBorderStyle.Enum.forInt(style.ordinal() + 1)); } - + /** + * Get the color to use for the selected border + * @param side - where to apply the color definition + * @return color - color to use as XSSFColor. null if color is not set + */ public XSSFColor getBorderColor(BorderSide side) { - CTBorderPr borderPr = getBorder(side); - return borderPr != null && borderPr.isSetColor() ? - new XSSFColor(borderPr.getColor()) : null; + CTBorderPr borderPr = getBorder(side); + return borderPr != null && borderPr.isSetColor() ? + new XSSFColor(borderPr.getColor()) : null; } - + /** + * 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) { - CTBorderPr borderPr = getBorder(side, true); - if(color == null) borderPr.unsetColor(); - else borderPr.setColor(color.getCTColor()); + CTBorderPr borderPr = getBorder(side, true); + if(color == null) borderPr.unsetColor(); + else borderPr.setColor(color.getCTColor()); } private CTBorderPr getBorder(BorderSide side) { - return getBorder(side, false); + return getBorder(side, false); } + private CTBorderPr getBorder(BorderSide side, boolean ensure) { - CTBorderPr borderPr; - switch (side) { - case TOP: - borderPr = border.getTop(); - if(ensure && borderPr == null) borderPr = border.addNewTop(); - break; - case RIGHT: - borderPr = border.getRight(); - if(ensure && borderPr == null) borderPr = border.addNewRight(); - break; - case BOTTOM: - borderPr = border.getBottom(); - if(ensure && borderPr == null) borderPr = border.addNewBottom(); - break; - case LEFT: - borderPr = border.getLeft(); - if(ensure && borderPr == null) borderPr = border.addNewLeft(); - break; - default: - throw new IllegalArgumentException("No suitable side specified for the border"); - } - return borderPr; + CTBorderPr borderPr; + switch (side) { + case TOP: + borderPr = border.getTop(); + if(ensure && borderPr == null) borderPr = border.addNewTop(); + break; + case RIGHT: + borderPr = border.getRight(); + if(ensure && borderPr == null) borderPr = border.addNewRight(); + break; + case BOTTOM: + borderPr = border.getBottom(); + if(ensure && borderPr == null) borderPr = border.addNewBottom(); + break; + case LEFT: + borderPr = border.getLeft(); + if(ensure && borderPr == null) borderPr = border.addNewLeft(); + break; + default: + throw new IllegalArgumentException("No suitable side specified for the border"); + } + return borderPr; } public int hashCode(){ - return border.toString().hashCode(); + return border.toString().hashCode(); } public boolean equals(Object o){ - if(!(o instanceof XSSFCellBorder)) return false; + if(!(o instanceof XSSFCellBorder)) return false; - XSSFCellBorder cf = (XSSFCellBorder)o; - return border.toString().equals(cf.getCTBorder().toString()); + XSSFCellBorder cf = (XSSFCellBorder)o; + return border.toString().equals(cf.getCTBorder().toString()); } } \ No newline at end of file Index: src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java =================================================================== --- src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java (revision 704016) +++ src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellAlignment.java (working copy) @@ -30,60 +30,124 @@ private CTCellAlignment cellAlignement; + /** + * Creates a Cell Alignment from the supplied XML definition + * @param cellAlignment + */ public XSSFCellAlignment(CTCellAlignment cellAlignment) { - this.cellAlignement = cellAlignment; + this.cellAlignement = cellAlignment; } + /** + * Get the type of vertical alignment for the cell + * @see VerticalAlignment + * @return the type of aligment + */ public VerticalAlignment getVertical() { - STVerticalAlignment.Enum align = cellAlignement.getVertical(); - if(align == null) align = STVerticalAlignment.BOTTOM; + STVerticalAlignment.Enum align = cellAlignement.getVertical(); + if(align == null) align = STVerticalAlignment.BOTTOM; - return VerticalAlignment.values()[align.intValue() - 1]; + return VerticalAlignment.values()[align.intValue() - 1]; } - + /** + * Set the type of vertical alignment for the cell + * @see VerticalAlignment + * @param align - the type of alignment + */ public void setVertical(VerticalAlignment vertical) { - cellAlignement.setVertical(STVerticalAlignment.Enum.forInt(vertical.ordinal() + 1)); + cellAlignement.setVertical(STVerticalAlignment.Enum.forInt(vertical.ordinal() + 1)); } - + /** + * Get the type of horizontal alignment for the cell + * @see HorizontalAlignment + * @return the type of aligment + */ public HorizontalAlignment getHorizontal() { - STHorizontalAlignment.Enum align = cellAlignement.getHorizontal(); - if(align == null) align = STHorizontalAlignment.GENERAL; + STHorizontalAlignment.Enum align = cellAlignement.getHorizontal(); + if(align == null) align = STHorizontalAlignment.GENERAL; - return HorizontalAlignment.values()[align.intValue() - 1]; + return HorizontalAlignment.values()[align.intValue() - 1]; } - + /** + * Set the type of horizontal alignment for the cell + * @see HorizontalAlignment + * @param align - the type of alignment + */ public void setHorizontal(HorizontalAlignment align) { - cellAlignement.setHorizontal(STHorizontalAlignment.Enum.forInt(align.ordinal() + 1)); + cellAlignement.setHorizontal(STHorizontalAlignment.Enum.forInt(align.ordinal() + 1)); } - + /** + * Get the number of spaces to indent the text in the cell + * + * @return indent - number of spaces + */ public long getIndent() { - return cellAlignement.getIndent(); + return cellAlignement.getIndent(); } - + /** + * Set the number of spaces to indent the text in the cell + * + * @param indent - number of spaces + */ public void setIndent(long indent) { - cellAlignement.setIndent(indent); + cellAlignement.setIndent(indent); } - + /** + * Get the degree of rotation for the text in the cell + *
+ * Expressed in degrees. Values range from 0 to 180. The first letter of
+ * the text is considered the center-point of the arc.
+ *
+ * For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the
+ * horizon is calculated as:
+ *
+ * [degrees below horizon] = 90 - textRotation.
+ *
+ * Expressed in degrees. Values range from 0 to 180. The first letter of
+ * the text is considered the center-point of the arc.
+ *
+ * For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the
+ * horizon is calculated as:
+ *
+ * [degrees below horizon] = 90 - textRotation.
+ *