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
This commit is contained in:
parent
894029a48f
commit
36c3b8d688
@ -77,11 +77,7 @@ public final class HSSFFontFormatting implements org.apache.poi.ss.usermodel.Fon
|
||||
}
|
||||
|
||||
public void setFontColor(Color color) {
|
||||
if (color != null && !(color instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
|
||||
HSSFColor hcolor = (HSSFColor)color;
|
||||
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
|
||||
if (hcolor == null) {
|
||||
fontFormatting.setFontColorIndex((short)0);
|
||||
} else {
|
||||
|
@ -74,10 +74,7 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
||||
}
|
||||
|
||||
public void setFillBackgroundColor(Color bg) {
|
||||
if (bg != null && !(bg instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
HSSFColor hcolor = (HSSFColor)bg;
|
||||
HSSFColor hcolor = HSSFColor.toHSSFColor(bg);
|
||||
if (hcolor == null) {
|
||||
setFillBackgroundColor((short)0);
|
||||
} else {
|
||||
@ -86,10 +83,7 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
||||
}
|
||||
|
||||
public void setFillForegroundColor(Color fg) {
|
||||
if (fg != null && !(fg instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
HSSFColor hcolor = (HSSFColor)fg;
|
||||
HSSFColor hcolor = HSSFColor.toHSSFColor(fg);
|
||||
if (hcolor == null) {
|
||||
setFillForegroundColor((short)0);
|
||||
} else {
|
||||
|
@ -204,6 +204,13 @@ public class HSSFColor implements Color {
|
||||
{
|
||||
return BLACK.hexString;
|
||||
}
|
||||
|
||||
public static HSSFColor toHSSFColor(Color color) {
|
||||
if (color != null && !(color instanceof HSSFColor)) {
|
||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
||||
}
|
||||
return (HSSFColor)color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class BLACK
|
||||
|
@ -20,8 +20,8 @@
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Kumshayev
|
||||
* @author Yegor Kozlov
|
||||
* High level representation for Border Formatting component
|
||||
* of Conditional Formatting settings
|
||||
*/
|
||||
public interface BorderFormatting {
|
||||
/** No border */
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user