summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-02-21 11:34:25 +0000
committerNick Burch <nick@apache.org>2008-02-21 11:34:25 +0000
commit862657ef40a6dcad654c119d7d6b030fbc28f143 (patch)
tree12287a046557ce8c208c55c307ebbaf06a269678 /src
parentd561e7b60ac0b1d939e654c49722f9dc92d0663e (diff)
downloadpoi-862657ef40a6dcad654c119d7d6b030fbc28f143.tar.gz
poi-862657ef40a6dcad654c119d7d6b030fbc28f143.zip
Fix bug 38921, where HSSFPalette.findSimilar() wasn't working properly, and add tests for it
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@629755 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java43
4 files changed, 48 insertions, 1 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 46fdb22acd..eea475fd2c 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -36,6 +36,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">38921 - Have HSSFPalette.findSimilar() work properly</action>
<action dev="POI-DEVELOPERS" type="fix">44456 - Fix the contrib SViewer / SViewerPanel to not fail on sheets with missing rows</action>
<action dev="POI-DEVELOPERS" type="fix">44403 - Further support for unusual, but valid, arguments to the Mid function</action>
<action dev="POI-DEVELOPERS" type="fix">44410 - Support for whole-column ranges, such as C:C, in formula strings and the formula evaluator</action>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index fec81a1e1c..2d176896f5 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -33,6 +33,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta1" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">38921 - Have HSSFPalette.findSimilar() work properly</action>
<action dev="POI-DEVELOPERS" type="fix">44456 - Fix the contrib SViewer / SViewerPanel to not fail on sheets with missing rows</action>
<action dev="POI-DEVELOPERS" type="fix">44403 - Further support for unusual, but valid, arguments to the Mid function</action>
<action dev="POI-DEVELOPERS" type="fix">44410 - Support for whole-column ranges, such as C:C, in formula strings and the formula evaluator</action>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
index 7fc5525950..8674904d0c 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
@@ -99,9 +99,11 @@ public class HSSFPalette
for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null;
b = palette.getColor(++i))
{
- int colorDistance = red - b[0] + green - b[1] + blue - b[2];
+ int colorDistance = Math.abs(red - b[0]) +
+ Math.abs(green - b[1]) + Math.abs(blue - b[2]);
if (colorDistance < minColorDistance)
{
+ minColorDistance = colorDistance;
result = getColor(i);
}
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
index c5674b9e76..a0f09696b5 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java
@@ -160,6 +160,49 @@ public class TestHSSFPalette extends TestCase
assertEquals("FFFF:0:FFFF", p.getColor((short)14).getHexString());
}
+ public void testFindSimilar() throws Exception {
+ HSSFWorkbook book = new HSSFWorkbook();
+ HSSFPalette p = book.getCustomPalette();
+
+
+ // Add a few edge colours in
+ p.setColorAtIndex((short)8, (byte)-1, (byte)0, (byte)0);
+ p.setColorAtIndex((short)9, (byte)0, (byte)-1, (byte)0);
+ p.setColorAtIndex((short)10, (byte)0, (byte)0, (byte)-1);
+
+ // And some near a few of them
+ p.setColorAtIndex((short)11, (byte)-1, (byte)2, (byte)2);
+ p.setColorAtIndex((short)12, (byte)-2, (byte)2, (byte)10);
+ p.setColorAtIndex((short)13, (byte)-4, (byte)0, (byte)0);
+ p.setColorAtIndex((short)14, (byte)-8, (byte)0, (byte)0);
+
+ assertEquals(
+ "FFFF:0:0", p.getColor((short)8).getHexString()
+ );
+
+ // Now check we get the right stuff back
+ assertEquals(
+ p.getColor((short)8).getHexString(),
+ p.findSimilarColor((byte)-1, (byte)0, (byte)0).getHexString()
+ );
+ assertEquals(
+ p.getColor((short)8).getHexString(),
+ p.findSimilarColor((byte)-2, (byte)0, (byte)0).getHexString()
+ );
+ assertEquals(
+ p.getColor((short)8).getHexString(),
+ p.findSimilarColor((byte)-1, (byte)1, (byte)0).getHexString()
+ );
+ assertEquals(
+ p.getColor((short)11).getHexString(),
+ p.findSimilarColor((byte)-1, (byte)2, (byte)1).getHexString()
+ );
+ assertEquals(
+ p.getColor((short)12).getHexString(),
+ p.findSimilarColor((byte)-1, (byte)2, (byte)10).getHexString()
+ );
+ }
+
/**
* Verifies that the generated gnumeric-format string values match the
* hardcoded values in the HSSFColor default color palette