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) {
|
public void setFontColor(Color color) {
|
||||||
if (color != null && !(color instanceof HSSFColor)) {
|
HSSFColor hcolor = HSSFColor.toHSSFColor(color);
|
||||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
HSSFColor hcolor = (HSSFColor)color;
|
|
||||||
if (hcolor == null) {
|
if (hcolor == null) {
|
||||||
fontFormatting.setFontColorIndex((short)0);
|
fontFormatting.setFontColorIndex((short)0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,10 +74,7 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFillBackgroundColor(Color bg) {
|
public void setFillBackgroundColor(Color bg) {
|
||||||
if (bg != null && !(bg instanceof HSSFColor)) {
|
HSSFColor hcolor = HSSFColor.toHSSFColor(bg);
|
||||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
HSSFColor hcolor = (HSSFColor)bg;
|
|
||||||
if (hcolor == null) {
|
if (hcolor == null) {
|
||||||
setFillBackgroundColor((short)0);
|
setFillBackgroundColor((short)0);
|
||||||
} else {
|
} else {
|
||||||
@ -86,10 +83,7 @@ public class HSSFPatternFormatting implements org.apache.poi.ss.usermodel.Patter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFillForegroundColor(Color fg) {
|
public void setFillForegroundColor(Color fg) {
|
||||||
if (fg != null && !(fg instanceof HSSFColor)) {
|
HSSFColor hcolor = HSSFColor.toHSSFColor(fg);
|
||||||
throw new IllegalArgumentException("Only HSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
HSSFColor hcolor = (HSSFColor)fg;
|
|
||||||
if (hcolor == null) {
|
if (hcolor == null) {
|
||||||
setFillForegroundColor((short)0);
|
setFillForegroundColor((short)0);
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,6 +204,13 @@ public class HSSFColor implements Color {
|
|||||||
{
|
{
|
||||||
return BLACK.hexString;
|
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
|
* Class BLACK
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dmitriy Kumshayev
|
* High level representation for Border Formatting component
|
||||||
* @author Yegor Kozlov
|
* of Conditional Formatting settings
|
||||||
*/
|
*/
|
||||||
public interface BorderFormatting {
|
public interface BorderFormatting {
|
||||||
/** No border */
|
/** No border */
|
||||||
|
@ -316,6 +316,13 @@ public class XSSFColor implements Color {
|
|||||||
return ctColor;
|
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(){
|
public int hashCode(){
|
||||||
return ctColor.toString().hashCode();
|
return ctColor.toString().hashCode();
|
||||||
}
|
}
|
||||||
|
@ -97,11 +97,7 @@ public class XSSFFontFormatting implements FontFormatting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFontColor(Color color) {
|
public void setFontColor(Color color) {
|
||||||
if (color != null && !(color instanceof XSSFColor)) {
|
XSSFColor xcolor = XSSFColor.toXSSFColor(color);
|
||||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
XSSFColor xcolor = (XSSFColor)color;
|
|
||||||
if (xcolor == null) {
|
if (xcolor == null) {
|
||||||
_font.getColorList().clear();
|
_font.getColorList().clear();
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,10 +63,7 @@ public class XSSFPatternFormatting implements PatternFormatting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFillBackgroundColor(Color bg) {
|
public void setFillBackgroundColor(Color bg) {
|
||||||
if (bg != null && !(bg instanceof XSSFColor)) {
|
XSSFColor xcolor = XSSFColor.toXSSFColor(bg);
|
||||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
XSSFColor xcolor = (XSSFColor)bg;
|
|
||||||
setFillBackgroundColor(xcolor.getCTColor());
|
setFillBackgroundColor(xcolor.getCTColor());
|
||||||
}
|
}
|
||||||
public void setFillBackgroundColor(short bg) {
|
public void setFillBackgroundColor(short bg) {
|
||||||
@ -80,10 +77,7 @@ public class XSSFPatternFormatting implements PatternFormatting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setFillForegroundColor(Color fg) {
|
public void setFillForegroundColor(Color fg) {
|
||||||
if (fg != null && !(fg instanceof XSSFColor)) {
|
XSSFColor xcolor = XSSFColor.toXSSFColor(fg);
|
||||||
throw new IllegalArgumentException("Only XSSFColor objects are supported");
|
|
||||||
}
|
|
||||||
XSSFColor xcolor = (XSSFColor)fg;
|
|
||||||
setFillForegroundColor(xcolor.getCTColor());
|
setFillForegroundColor(xcolor.getCTColor());
|
||||||
}
|
}
|
||||||
public void setFillForegroundColor(short fg) {
|
public void setFillForegroundColor(short fg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user