Return-Path: Delivered-To: apmail-poi-commits-archive@locus.apache.org Received: (qmail 20799 invoked from network); 21 Feb 2008 11:35:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Feb 2008 11:35:11 -0000 Received: (qmail 87244 invoked by uid 500); 21 Feb 2008 11:35:06 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 87201 invoked by uid 500); 21 Feb 2008 11:35:06 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 87192 invoked by uid 99); 21 Feb 2008 11:35:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2008 03:35:05 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2008 11:34:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B68BC1A9832; Thu, 21 Feb 2008 03:34:49 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r629755 - in /poi/trunk/src: documentation/content/xdocs/changes.xml documentation/content/xdocs/status.xml java/org/apache/poi/hssf/usermodel/HSSFPalette.java testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java Date: Thu, 21 Feb 2008 11:34:46 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080221113449.B68BC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Thu Feb 21 03:34:25 2008 New Revision: 629755 URL: http://svn.apache.org/viewvc?rev=629755&view=rev Log: Fix bug 38921, where HSSFPalette.findSimilar() wasn't working properly, and add tests for it Modified: poi/trunk/src/documentation/content/xdocs/changes.xml poi/trunk/src/documentation/content/xdocs/status.xml poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java Modified: poi/trunk/src/documentation/content/xdocs/changes.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=629755&r1=629754&r2=629755&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/changes.xml (original) +++ poi/trunk/src/documentation/content/xdocs/changes.xml Thu Feb 21 03:34:25 2008 @@ -36,6 +36,7 @@ + 38921 - Have HSSFPalette.findSimilar() work properly 44456 - Fix the contrib SViewer / SViewerPanel to not fail on sheets with missing rows 44403 - Further support for unusual, but valid, arguments to the Mid function 44410 - Support for whole-column ranges, such as C:C, in formula strings and the formula evaluator Modified: poi/trunk/src/documentation/content/xdocs/status.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=629755&r1=629754&r2=629755&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/status.xml (original) +++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Feb 21 03:34:25 2008 @@ -33,6 +33,7 @@ + 38921 - Have HSSFPalette.findSimilar() work properly 44456 - Fix the contrib SViewer / SViewerPanel to not fail on sheets with missing rows 44403 - Further support for unusual, but valid, arguments to the Mid function 44410 - Support for whole-column ranges, such as C:C, in formula strings and the formula evaluator Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java?rev=629755&r1=629754&r2=629755&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java (original) +++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java Thu Feb 21 03:34:25 2008 @@ -99,9 +99,11 @@ 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); } } Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java?rev=629755&r1=629754&r2=629755&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java Thu Feb 21 03:34:25 2008 @@ -160,6 +160,49 @@ 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 --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org