poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jhei...@apache.org
Subject svn commit: r425023 - in /jakarta/poi/trunk/src/java/org/apache/poi/hssf: usermodel/HSSFCellStyle.java usermodel/HSSFFont.java usermodel/HSSFPalette.java util/HSSFColor.java
Date Mon, 24 Jul 2006 12:18:49 GMT
Author: jheight
Date: Mon Jul 24 05:18:48 2006
New Revision: 425023

URL: http://svn.apache.org/viewvc?rev=425023&view=rev
Log:
Bug 38486: Added handling of special 0x40 (64 dec) color.

Modified:
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
    jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=425023&r1=425022&r2=425023&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Mon Jul 24
05:18:48 2006
@@ -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 @@
     {
         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 @@
      * 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 void setFillBackgroundColor(short bg)
-    {
+    {    	
         format.setFillBackground(bg);
+        checkDefaultBackgroundFills();
     }
 
     /**
@@ -830,17 +862,24 @@
 
     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();
     }
 
     /**

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java?rev=425023&r1=425022&r2=425023&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java Mon Jul 24 05:18:48
2006
@@ -56,7 +56,7 @@
     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 @@
     /**
      * 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
      */
 

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java?rev=425023&r1=425022&r2=425023&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java Mon Jul 24 05:18:48
2006
@@ -44,11 +44,16 @@
      */
     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;
     }
     

Modified: jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java?rev=425023&r1=425022&r2=425023&view=diff
==============================================================================
--- jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java (original)
+++ jakarta/poi/trunk/src/java/org/apache/poi/hssf/util/HSSFColor.java Mon Jul 24 05:18:48
2006
@@ -1693,4 +1693,38 @@
             return hexString;
         }
     }
+    
+    /**
+     * Special Default/Normal/Automatic color.
+     * <p><i>Note:</i> This class is NOT in the default HashTables returned
by HSSFColor.
+     * The index is a special case which is interpreted in the various setXXXColor calls.
+     * 
+     * @author Jason
+     *
+     */
+    public final static class AUTOMATIC extends HSSFColor
+    {
+    	private static HSSFColor instance = new AUTOMATIC();
+    	
+        public final static short   index     = 0x40;
+
+        public short getIndex()
+        {
+            return index;
+        }
+
+        public short [] getTriplet()
+        {
+            return BLACK.triplet;
+        }
+
+        public String getHexString()
+        {
+            return BLACK.hexString;
+        }
+        
+        public static HSSFColor getInstance() {
+          return instance;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message