poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gwool...@apache.org
Subject svn commit: r1796961 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java java/org/apache/poi/ss/usermodel/BorderFormatting.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
Date Wed, 31 May 2017 00:22:58 GMT
Author: gwoolsey
Date: Wed May 31 00:22:58 2017
New Revision: 1796961

URL: http://svn.apache.org/viewvc?rev=1796961&view=rev
Log:
#61085 support table styles

Needed a bit more, to support table/range only border properties for "internal" vertical and
horizontal borders.

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java?rev=1796961&r1=1796960&r2=1796961&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java Wed May 31
00:22:58 2017
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
 import org.apache.poi.hssf.record.CFRuleBase;
 import org.apache.poi.hssf.record.cf.BorderFormatting;
 import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
 import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.usermodel.Color;
 
@@ -364,4 +365,100 @@ public final class HSSFBorderFormatting
             setTopBorderColor(hcolor.getIndex());
         }
     }
+
+    /**
+     * HSSF doesn't support table borders, so always {@link BorderStyle#NONE}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getBorderVerticalEnum()
+     */
+    public BorderStyle getBorderVerticalEnum() {
+        return BorderStyle.NONE;
+    }
+
+    /**
+     * HSSF doesn't support table borders, so always {@link BorderStyle#NONE}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getBorderHorizontalEnum()
+     */
+    public BorderStyle getBorderHorizontalEnum() {
+        return BorderStyle.NONE;
+    }
+
+    /**
+     * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColor()
+     */
+    public short getVerticalBorderColor() {
+        return HSSFColorPredefined.AUTOMATIC.getIndex();
+    }
+
+    /**
+     * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getVerticalBorderColorColor()
+     */
+    public Color getVerticalBorderColorColor() {
+        return HSSFColorPredefined.AUTOMATIC.getColor();
+    }
+
+    /**
+     * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColor()
+     */
+    public short getHorizontalBorderColor() {
+        return HSSFColorPredefined.AUTOMATIC.getIndex();
+    }
+
+    /**
+     * HSSF Doesn't support table borders, so always {@link HSSFColorPredefined#AUTOMATIC}
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#getHorizontalBorderColorColor()
+     */
+    public Color getHorizontalBorderColorColor() {
+        return HSSFColorPredefined.AUTOMATIC.getColor();
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setBorderHorizontal(org.apache.poi.ss.usermodel.BorderStyle)
+     */
+    public void setBorderHorizontal(BorderStyle border) {
+        // nothing
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setBorderVertical(org.apache.poi.ss.usermodel.BorderStyle)
+     */
+    public void setBorderVertical(BorderStyle border) {
+        // nothing
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setHorizontalBorderColor(short)
+     */
+    public void setHorizontalBorderColor(short color) {
+        // nothing
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setHorizontalBorderColor(org.apache.poi.ss.usermodel.Color)
+     */
+    public void setHorizontalBorderColor(Color color) {
+        // nothing
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setVerticalBorderColor(short)
+     */
+    public void setVerticalBorderColor(short color) {
+        // nothing
+    }
+
+    /**
+     * Not available for HSSF.
+     * @see org.apache.poi.ss.usermodel.BorderFormatting#setVerticalBorderColor(org.apache.poi.ss.usermodel.Color)
+     */
+    public void setVerticalBorderColor(Color color) {
+        // nothing
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java?rev=1796961&r1=1796960&r2=1796961&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/BorderFormatting.java Wed May 31 00:22:58
2017
@@ -150,6 +150,18 @@ public interface BorderFormatting {
     /** @since POI 3.15 */
     BorderStyle getBorderTopEnum();
 
+    /**
+     * Only valid for range borders, such as table styles
+     * @since 3.17 beta 1
+     * @return border style
+     */
+    BorderStyle getBorderVerticalEnum();
+    /**
+     * Only valid for range borders, such as table styles
+     * @since 3.17 beta 1
+     * @return border style
+     */
+    BorderStyle getBorderHorizontalEnum();
     
     short getBottomBorderColor();
     Color getBottomBorderColorColor();
@@ -167,6 +179,32 @@ public interface BorderFormatting {
     Color getTopBorderColorColor();
 
     /**
+     * Range internal borders. Only relevant for range styles, such as table formatting
+     * @since  3.17 beta 1
+     * @return color index
+     */
+    short getVerticalBorderColor();
+    /**
+     * Range internal borders. Only relevant for range styles, such as table formatting
+     * @since  3.17 beta 1
+     * @return color
+     */
+    Color getVerticalBorderColorColor();
+    
+    /**
+     * Range internal borders. Only relevant for range styles, such as table formatting
+     * @since  3.17 beta 1
+     * @return color index
+     */
+    short getHorizontalBorderColor();
+    /**
+     * Range internal borders. Only relevant for range styles, such as table formatting
+     * @since  3.17 beta 1
+     * @return color
+     */
+    Color getHorizontalBorderColorColor();
+    
+    /**
      * Set bottom border.
      *
      * @param border  MUST be a BORDER_* constant
@@ -240,6 +278,22 @@ public interface BorderFormatting {
      * @param border
      */
     void setBorderTop(BorderStyle border);
+    
+    /**
+     * Set range internal horizontal borders.
+     *
+     * @since 3.17 beta 1
+     * @param border
+     */
+    void setBorderHorizontal(BorderStyle border);
+    
+    /**
+     * Set range internal vertical borders.
+     *
+     * @since 3.17 beta 1
+     * @param border
+     */
+    void setBorderVertical(BorderStyle border);
 
     void setBottomBorderColor(short color);
     void setBottomBorderColor(Color color);
@@ -255,4 +309,30 @@ public interface BorderFormatting {
 
     void setTopBorderColor(short color);
     void setTopBorderColor(Color color);
+    
+    /**
+     * Range internal border color, such as table styles
+     * @since 3.17 beta 1
+     * @param color index
+     */
+    void setHorizontalBorderColor(short color);
+    /**
+     * Range internal border color, such as table styles
+     * @since 3.17 beta 1
+     * @param color index
+     */
+    void setHorizontalBorderColor(Color color);
+    
+    /**
+     * Range internal border color, such as table styles
+     * @since 3.17 beta 1
+     * @param color index
+     */
+    void setVerticalBorderColor(short color);
+    /**
+     * Range internal border color, such as table styles
+     * @since 3.17 beta 1
+     * @param color index
+     */
+    void setVerticalBorderColor(Color color);
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java?rev=1796961&r1=1796960&r2=1796961&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java Wed May
31 00:22:58 2017
@@ -50,8 +50,7 @@ public class XSSFBorderFormatting implem
      */
     @Override
     public BorderStyle getBorderBottomEnum() {
-        STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle()
: null;
-        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+        return getBorderStyle(_border.getBottom());
     }
 
     /**
@@ -67,8 +66,7 @@ public class XSSFBorderFormatting implem
      */
     @Override
     public BorderStyle getBorderDiagonalEnum() {
-        STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle()
: null;
-        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+        return getBorderStyle(_border.getDiagonal());
     }
 
     /**
@@ -84,8 +82,7 @@ public class XSSFBorderFormatting implem
      */
     @Override
     public BorderStyle getBorderLeftEnum() {
-        STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
-        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+        return getBorderStyle(_border.getLeft());
     }
 
     /**
@@ -101,8 +98,7 @@ public class XSSFBorderFormatting implem
      */
     @Override
     public BorderStyle getBorderRightEnum() {
-        STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() :
null;
-        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+        return getBorderStyle(_border.getRight());
     }
 
     /**
@@ -118,78 +114,52 @@ public class XSSFBorderFormatting implem
      */
     @Override
     public BorderStyle getBorderTopEnum() {
-        STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
-        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+        return getBorderStyle(_border.getTop());
     }
 
     @Override
     public XSSFColor getBottomBorderColorColor() {
-        if(!_border.isSetBottom()) return null;
-
-        CTBorderPr pr = _border.getBottom();
-        return new XSSFColor(pr.getColor(), _colorMap);
+        return getColor(_border.getBottom());
     }
     @Override
     public short getBottomBorderColor() {
-        XSSFColor color = getBottomBorderColorColor();
-        if (color == null) return 0;
-        return color.getIndexed();
+        return getIndexedColor(getBottomBorderColorColor());
     }
 
     @Override
     public XSSFColor getDiagonalBorderColorColor() {
-        if(!_border.isSetDiagonal()) return null;
-
-        CTBorderPr pr = _border.getDiagonal();
-        return new XSSFColor(pr.getColor(), _colorMap);
+        return getColor(_border.getDiagonal());
     }
     @Override
     public short getDiagonalBorderColor() {
-        XSSFColor color = getDiagonalBorderColorColor();
-        if (color == null) return 0;
-        return color.getIndexed();
+        return getIndexedColor(getDiagonalBorderColorColor());
     }
 
     @Override
     public XSSFColor getLeftBorderColorColor() {
-        if(!_border.isSetLeft()) return null;
-
-        CTBorderPr pr = _border.getLeft();
-        return new XSSFColor(pr.getColor(), _colorMap);
+        return getColor(_border.getLeft());
     }
     @Override
     public short getLeftBorderColor() {
-        XSSFColor color = getLeftBorderColorColor();
-        if (color == null) return 0;
-        return color.getIndexed();
+        return getIndexedColor(getLeftBorderColorColor());
     }
 
     @Override
     public XSSFColor getRightBorderColorColor() {
-        if(!_border.isSetRight()) return null;
-
-        CTBorderPr pr = _border.getRight();
-        return new XSSFColor(pr.getColor(), _colorMap);
+        return getColor(_border.getRight());
     }
     @Override
     public short getRightBorderColor() {
-        XSSFColor color = getRightBorderColorColor();
-        if (color == null) return 0;
-        return color.getIndexed();
+        return getIndexedColor(getRightBorderColorColor());
     }
 
     @Override
     public XSSFColor getTopBorderColorColor() {
-        if(!_border.isSetTop()) return null;
-
-        CTBorderPr pr = _border.getTop();
-        return new XSSFColor(pr.getColor(), _colorMap);
+        return getColor(_border.getTop());
     }
     @Override
     public short getTopBorderColor() {
-        XSSFColor color = getRightBorderColorColor();
-        if (color == null) return 0;
-        return color.getIndexed();
+        return getIndexedColor(getRightBorderColorColor());
     }
 
     /**
@@ -366,4 +336,100 @@ public class XSSFBorderFormatting implem
             pr.setColor(color);
         }
     }
+
+    public BorderStyle getBorderVerticalEnum() {
+        return getBorderStyle(_border.getVertical());
+    }
+
+    public BorderStyle getBorderHorizontalEnum() {
+        return getBorderStyle(_border.getHorizontal());
+    }
+
+    public short getVerticalBorderColor() {
+        return getIndexedColor(getVerticalBorderColorColor());
+    }
+
+    public XSSFColor getVerticalBorderColorColor() {
+        return getColor(_border.getVertical());
+    }
+
+    public short getHorizontalBorderColor() {
+        return getIndexedColor(getHorizontalBorderColorColor());
+    }
+
+    public XSSFColor getHorizontalBorderColorColor() {
+        return getColor(_border.getHorizontal());
+    }
+
+    public void setBorderHorizontal(BorderStyle border) {
+        CTBorderPr pr = _border.isSetHorizontal() ? _border.getHorizontal() : _border.addNewHorizontal();
+        if(border == BorderStyle.NONE) _border.unsetHorizontal();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
+    }
+
+    public void setBorderVertical(BorderStyle border) {
+        CTBorderPr pr = _border.isSetVertical() ? _border.getVertical() : _border.addNewVertical();
+        if(border == BorderStyle.NONE) _border.unsetVertical();
+        else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
+    }
+
+    public void setHorizontalBorderColor(short color) {
+        CTColor ctColor = CTColor.Factory.newInstance();
+        ctColor.setIndexed(color);
+        setHorizontalBorderColor(ctColor);
+    }
+
+    public void setHorizontalBorderColor(Color color) {
+        XSSFColor xcolor = XSSFColor.toXSSFColor(color);
+        if (xcolor == null) setBottomBorderColor((CTColor)null);
+        else setHorizontalBorderColor(xcolor.getCTColor());
+    }
+    
+    public void setHorizontalBorderColor(CTColor color) {
+        CTBorderPr pr = _border.isSetHorizontal() ? _border.getHorizontal() : _border.addNewHorizontal();
+        if (color == null) {
+            pr.unsetColor();
+        } else {
+            pr.setColor(color);
+        }
+    }
+
+    public void setVerticalBorderColor(short color) {
+        CTColor ctColor = CTColor.Factory.newInstance();
+        ctColor.setIndexed(color);
+        setVerticalBorderColor(ctColor);
+    }
+
+    public void setVerticalBorderColor(Color color) {
+        XSSFColor xcolor = XSSFColor.toXSSFColor(color);
+        if (xcolor == null) setBottomBorderColor((CTColor)null);
+        else setVerticalBorderColor(xcolor.getCTColor());
+    }
+    
+    public void setVerticalBorderColor(CTColor color) {
+        CTBorderPr pr = _border.isSetVertical() ? _border.getVertical() : _border.addNewVertical();
+        if (color == null) {
+            pr.unsetColor();
+        } else {
+            pr.setColor(color);
+        }
+    }
+    
+    /**
+     * @param borderPr
+     * @return BorderStyle from the given element's style, or NONE if border is null
+     */
+    private BorderStyle getBorderStyle(CTBorderPr borderPr) {
+        if (borderPr == null) return BorderStyle.NONE;
+        STBorderStyle.Enum ptrn = borderPr.getStyle();
+        return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue()
- 1));
+    }
+    
+    private short getIndexedColor(XSSFColor color) {
+        return color == null ? 0 : color.getIndexed();
+    }
+    
+    private XSSFColor getColor(CTBorderPr pr) {
+        return pr == null ? null : new XSSFColor(pr.getColor(), _colorMap);
+    }
 }



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


Mime
View raw message