diff options
author | Jason Height <jheight@apache.org> | 2006-07-24 12:18:48 +0000 |
---|---|---|
committer | Jason Height <jheight@apache.org> | 2006-07-24 12:18:48 +0000 |
commit | b00b858ade286f5b7edfd9fc7f2515ef469145ba (patch) | |
tree | 0f66255a4dfcd44da86c3e28d87e8e5d79ba9253 /src/java/org/apache/poi/hssf/usermodel | |
parent | b7d6bfa980510ef5fbbe6324f13c94fa4017293e (diff) | |
download | poi-b00b858ade286f5b7edfd9fc7f2515ef469145ba.tar.gz poi-b00b858ade286f5b7edfd9fc7f2515ef469145ba.zip |
Bug 38486: Added handling of special 0x40 (64 dec) color.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@425023 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/usermodel')
3 files changed, 54 insertions, 10 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java index 32a3663629..ea4f3b293e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.hssf.record.ExtendedFormatRecord; +import org.apache.poi.hssf.util.*; /** * High level representation of the style of a cell in a sheet of a workbook. @@ -798,6 +799,29 @@ public class HSSFCellStyle { return format.getAdtlFillPattern(); } + + /** + * Checks if the background and foreground fills are set correctly when one + * or the other is set to the default color. + * <p>Works like the logic table below:</p> + * <p>BACKGROUND FOREGROUND</p> + * <p>NONE AUTOMATIC</p> + * <p>0x41 0x40</p> + * <p>NONE RED/ANYTHING</p> + * <p>0x40 0xSOMETHING</p> + */ + private void checkDefaultBackgroundFills() { + if (format.getFillForeground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) { + //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt + //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the + //background needs to be incremented...... + if (format.getFillBackground() != (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)) + setFillBackgroundColor((short)(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)); + } else if (format.getFillBackground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1) + //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!! + if (format.getFillForeground() != org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) + setFillBackgroundColor(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index); + } /** * set the background fill color. @@ -805,7 +829,14 @@ public class HSSFCellStyle * For example: * <pre> * cs.setFillPattern(HSSFCellStyle.FINE_DOTS ); - * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); + * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); + * </pre> + * optionally a Foreground and background fill can be applied: + * <i>Note: Ensure Foreground color is set prior to background</i> + * <pre> + * cs.setFillPattern(HSSFCellStyle.FINE_DOTS ); + * cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); + * cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); * </pre> * or, for the special case of SOLID_FILL: * <pre> @@ -819,8 +850,9 @@ public class HSSFCellStyle */ public void setFillBackgroundColor(short bg) - { + { format.setFillBackground(bg); + checkDefaultBackgroundFills(); } /** @@ -830,17 +862,24 @@ public class HSSFCellStyle public short getFillBackgroundColor() { - return format.getFillBackground(); + short result = format.getFillBackground(); + //JMH: Do this ridiculous conversion, and let HSSFCellStyle + //internally migrate back and forth + if (result == (HSSFColor.AUTOMATIC.index+1)) + return HSSFColor.AUTOMATIC.index; + else return result; } /** * set the foreground fill color + * <i>Note: Ensure Foreground color is set prior to background color.</i> * @param bg color */ public void setFillForegroundColor(short bg) { format.setFillForeground(bg); + checkDefaultBackgroundFills(); } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java b/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java index 8d502d82ac..c200441d14 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java @@ -56,7 +56,7 @@ public class HSSFFont public final static short BOLDWEIGHT_BOLD = 0x2bc; /** - * normal type of black color + * normal type of black color. */ public final static short COLOR_NORMAL = 0x7fff; @@ -266,7 +266,7 @@ public class HSSFFont /** * set the color for the font * @param color to use - * @see #COLOR_NORMAL + * @see #COLOR_NORMAL Note: Use this rather than HSSFColor.AUTOMATIC for default font color * @see #COLOR_RED */ diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java index c6de0bb6d2..a5a2f49ceb 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java @@ -44,11 +44,16 @@ public class HSSFPalette */ public HSSFColor getColor(short index) { - byte[] b = palette.getColor(index); - if (b != null) - { - return new CustomColor(index, b); - } + //Handle the special AUTOMATIC case + if (index == HSSFColor.AUTOMATIC.index) + return HSSFColor.AUTOMATIC.getInstance(); + else { + byte[] b = palette.getColor(index); + if (b != null) + { + return new CustomColor(index, b); + } + } return null; } |