You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/07/14 20:05:29 UTC

svn commit: r1691045 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/

Author: nick
Date: Tue Jul 14 18:05:28 2015
New Revision: 1691045

URL: http://svn.apache.org/r1691045
Log:
Provide format-agnostic conditional formatting font colour getter and setter

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FontFormatting.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java?rev=1691045&r1=1691044&r2=1691045&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java Tue Jul 14 18:05:28 2015
@@ -62,13 +62,13 @@ public final class HSSFConditionalFormat
 		if ( fontFormatting != null)
 		{
 			cfRuleRecord.setFontFormatting(fontFormatting);
-			return new HSSFFontFormatting(cfRuleRecord);
+			return new HSSFFontFormatting(cfRuleRecord, workbook);
 		}
 		else if( create )
 		{
 			fontFormatting = new FontFormatting();
 			cfRuleRecord.setFontFormatting(fontFormatting);
-			return new HSSFFontFormatting(cfRuleRecord);
+			return new HSSFFontFormatting(cfRuleRecord, workbook);
 		}
 		else
 		{

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java?rev=1691045&r1=1691044&r2=1691045&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java Tue Jul 14 18:05:28 2015
@@ -19,6 +19,8 @@ package org.apache.poi.hssf.usermodel;
 
 import org.apache.poi.hssf.record.CFRuleBase;
 import org.apache.poi.hssf.record.cf.FontFormatting;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.Color;
 /**
  * High level representation for Font Formatting component
  * of Conditional Formatting settings
@@ -37,10 +39,12 @@ public final class HSSFFontFormatting im
 	public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
 
 	private final FontFormatting fontFormatting;
+	private final HSSFWorkbook workbook;
 	
-	protected HSSFFontFormatting(CFRuleBase cfRuleRecord)
+	protected HSSFFontFormatting(CFRuleBase cfRuleRecord, HSSFWorkbook workbook)
 	{
 		this.fontFormatting = cfRuleRecord.getFontFormatting();
+		this.workbook = workbook;
 	}
 	
 	protected FontFormatting getFontFormattingBlock()
@@ -69,7 +73,26 @@ public final class HSSFFontFormatting im
 		return fontFormatting.getFontColorIndex();
 	}
 
-	/**
+	public HSSFColor getFontColor() {
+	    return workbook.getCustomPalette().getColor(
+	            getFontColorIndex()
+        );
+    }
+
+    public void setFontColor(Color color) {
+        if (color != null && !(color instanceof HSSFColor)) {
+            throw new IllegalArgumentException("Only HSSFColor objects are supported");
+        }
+         
+        HSSFColor hcolor = (HSSFColor)color;
+        if (hcolor == null) {
+            fontFormatting.setFontColorIndex((short)0);
+        } else {
+            fontFormatting.setFontColorIndex(hcolor.getIndex());
+        }
+    }
+
+    /**
 	 * gets the height of the font in 1/20th point units
 	 *
 	 * @return fontheight (in points/20); or -1 if not modified

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/FontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/FontFormatting.java?rev=1691045&r1=1691044&r2=1691045&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/FontFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/FontFormatting.java Tue Jul 14 18:05:28 2015
@@ -66,15 +66,26 @@ public interface FontFormatting {
     void setEscapementType(short escapementType);
 
     /**
-     * @return font color index
+     * @return font colour index, or 0 if not indexed (XSSF only)
      */
     short getFontColorIndex();
 
-
     /**
-     * @param color font color index
+     * Sets the indexed colour to use
+     * @param color font colour index
      */
     void setFontColorIndex(short color);
+    
+    /**
+     * @return The colour of the font, or null if no colour applied
+     */
+    Color getFontColor();
+    
+    /**
+     * Sets the colour to use
+     * @param color font colour to use
+     */
+    void setFontColor(Color color);
 
     /**
      * gets the height of the font in 1/20th point units

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java?rev=1691045&r1=1691044&r2=1691045&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFontFormatting.java Tue Jul 14 18:05:28 2015
@@ -80,7 +80,6 @@ public class XSSFFontFormatting implemen
         return (short)idx;
     }
 
-
     /**
      * @param color font color index
      */
@@ -91,16 +90,32 @@ public class XSSFFontFormatting implemen
         }
     }
 
-    /**
-     *
-     * @return xssf color wrapper or null if color info is missing
-     */
-    public XSSFColor getXSSFColor(){
+    public XSSFColor getFontColor() {
         if(_font.sizeOfColorArray() == 0) return null;
 
         return new XSSFColor(_font.getColorArray(0));
     }
 
+    public void setFontColor(Color color) {
+        if (color != null && !(color instanceof XSSFColor)) {
+            throw new IllegalArgumentException("Only XSSFColor objects are supported");
+        }
+         
+        XSSFColor xcolor = (XSSFColor)color;
+        if (xcolor == null) {
+            _font.getColorList().clear();
+        } else {
+            _font.setColorArray(0, xcolor.getCTColor());
+        }
+    }
+
+    /**
+     * @deprecated use {@link #getFontColor()}
+     */
+    public XSSFColor getXSSFColor(){
+        return getFontColor();
+    }
+
     /**
      * gets the height of the font in 1/20th point units
      *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java?rev=1691045&r1=1691044&r2=1691045&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java Tue Jul 14 18:05:28 2015
@@ -40,7 +40,7 @@ import org.openxmlformats.schemas.spread
  */
 public class XSSFSheetConditionalFormatting implements SheetConditionalFormatting {
     /** Office 2010 Conditional Formatting extensions namespace */
-    protected static final CF_EXT_2009_NS_X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
+    protected static final String CF_EXT_2009_NS_X14 = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main";
 
     private final XSSFSheet _sheet;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org