diff options
author | Nick Burch <nick@apache.org> | 2015-07-14 19:29:18 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-07-14 19:29:18 +0000 |
commit | 71eeb0c3f810d63379fc8a40e130664cdcc83c7a (patch) | |
tree | 9e3d795e0e266d8a4e0222c9d9017100af86d5e3 /src/ooxml/java/org/apache/poi/xssf/usermodel | |
parent | b13c6bf699f49474552d971f4e750fa410a7e90c (diff) | |
download | poi-71eeb0c3f810d63379fc8a40e130664cdcc83c7a.tar.gz poi-71eeb0c3f810d63379fc8a40e130664cdcc83c7a.zip |
Cleaner code for checking and casting the Color objects
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691064 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel')
3 files changed, 10 insertions, 13 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java index 3082e53878..d2dc28dda7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFColor.java @@ -316,6 +316,13 @@ public class XSSFColor implements Color { return ctColor; } + public static XSSFColor toXSSFColor(Color color) { + if (color != null && !(color instanceof XSSFColor)) { + throw new IllegalArgumentException("Only XSSFColor objects are supported"); + } + return (XSSFColor)color; + } + public int hashCode(){ return ctColor.toString().hashCode(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java index 40ce715f48..e788cf893b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java @@ -97,11 +97,7 @@ public class XSSFFontFormatting implements FontFormatting { }
public void setFontColor(Color color) {
- if (color != null && !(color instanceof XSSFColor)) {
- throw new IllegalArgumentException("Only XSSFColor objects are supported");
- }
-
- XSSFColor xcolor = (XSSFColor)color;
+ XSSFColor xcolor = XSSFColor.toXSSFColor(color);
if (xcolor == null) {
_font.getColorList().clear();
} else {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java index 898fa9b7aa..75989f3e79 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPatternFormatting.java @@ -63,10 +63,7 @@ public class XSSFPatternFormatting implements PatternFormatting { }
public void setFillBackgroundColor(Color bg) {
- if (bg != null && !(bg instanceof XSSFColor)) {
- throw new IllegalArgumentException("Only XSSFColor objects are supported");
- }
- XSSFColor xcolor = (XSSFColor)bg;
+ XSSFColor xcolor = XSSFColor.toXSSFColor(bg);
setFillBackgroundColor(xcolor.getCTColor());
}
public void setFillBackgroundColor(short bg) {
@@ -80,10 +77,7 @@ public class XSSFPatternFormatting implements PatternFormatting { }
public void setFillForegroundColor(Color fg) {
- if (fg != null && !(fg instanceof XSSFColor)) {
- throw new IllegalArgumentException("Only XSSFColor objects are supported");
- }
- XSSFColor xcolor = (XSSFColor)fg;
+ XSSFColor xcolor = XSSFColor.toXSSFColor(fg);
setFillForegroundColor(xcolor.getCTColor());
}
public void setFillForegroundColor(short fg) {
|