incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robw...@apache.org
Subject svn commit: r1398965 - in /incubator/odf/trunk: odfdom/src/main/java/org/odftoolkit/odfdom/type/ simple/src/main/java/org/odftoolkit/simple/style/ simple/src/test/java/org/odftoolkit/simple/style/
Date Tue, 16 Oct 2012 20:04:39 GMT
Author: robweir
Date: Tue Oct 16 20:04:38 2012
New Revision: 1398965

URL: http://svn.apache.org/viewvc?rev=1398965&view=rev
Log:
Fix for OFFICE-326
Patch by: Florian Hopf


Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/type/Color.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TableCellProperties.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/TableCellPropertiesTest.java

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/type/Color.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/type/Color.java?rev=1398965&r1=1398964&r2=1398965&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/type/Color.java (original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/type/Color.java Tue Oct
16 20:04:38 2012
@@ -411,4 +411,28 @@ public class Color implements OdfDataTyp
 			return value;
 		}
 	}
+
+        
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        final Color other = (Color) obj;
+        if ((this.mColorAsSixHexRGB == null) ? (other.mColorAsSixHexRGB != null) : !this.mColorAsSixHexRGB.equals(other.mColorAsSixHexRGB))
{
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 3;
+        hash = 97 * hash + (this.mColorAsSixHexRGB != null ? this.mColorAsSixHexRGB.hashCode()
: 0);
+        return hash;
+    }
+        
 }

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TableCellProperties.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TableCellProperties.java?rev=1398965&r1=1398964&r2=1398965&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TableCellProperties.java
(original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/style/TableCellProperties.java
Tue Oct 16 20:04:38 2012
@@ -500,9 +500,11 @@ public class TableCellProperties {
 	 *            - the background color
 	 */
 	public void setBackgroundColor(Color aColor) {
-		if (aColor == null)
-			mElement.removeAttribute(FoBackgroundColorAttribute.ATTRIBUTE_NAME.getQName());
-		mElement.setFoBackgroundColorAttribute(aColor.toString());
+		if (aColor == null) {
+                    mElement.removeAttribute(FoBackgroundColorAttribute.ATTRIBUTE_NAME.getQName());
+                } else {
+                    mElement.setFoBackgroundColorAttribute(aColor.toString());
+                }
 	}
 
 	// //style:cell-protect

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/TableCellPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/TableCellPropertiesTest.java?rev=1398965&r1=1398964&r2=1398965&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/TableCellPropertiesTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/style/TableCellPropertiesTest.java
Tue Oct 16 20:04:38 2012
@@ -184,6 +184,42 @@ public class TableCellPropertiesTest {
 		}
 	}
 	
-	
-	
+        @Test
+	public void testSettingNullBackgroundOnProperties() throws Exception {
+            SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
+            Table table = doc.getTableByName("Sheet1");
+            Cell cell = table.getCellByPosition(1, 1);
+            cell.setCellBackgroundColor(Color.BLACK);
+            // setting null resets the element, see ODFTOOLKIT-326
+            cell.getStyleHandler().getTableCellPropertiesForWrite().setBackgroundColor(null);
+            Assert.assertNull(cell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
+            // defaulting to white when color is null
+            Assert.assertEquals(Color.WHITE, cell.getCellBackgroundColor());
+            Cell newCell = table.appendRow().getCellByIndex(1);
+            Assert.assertNull(newCell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
+            Assert.assertEquals(Color.WHITE, newCell.getCellBackgroundColor());
+        }
+        
+        @Test
+        public void testSettingBlackBackgroundOnProperties() throws Exception {
+            SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
+            Table table = doc.getTableByName("Sheet1");
+            Cell cell = table.getCellByPosition(1, 1);
+            cell.setCellBackgroundColor(Color.BLUE);
+            cell.getStyleHandler().getTableCellPropertiesForWrite().setBackgroundColor(Color.BLACK);
+            Assert.assertEquals(Color.BLACK, cell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
+            Assert.assertEquals(Color.BLACK, cell.getCellBackgroundColor());
+            Cell newCell = table.appendRow().getCellByIndex(1);
+            Assert.assertEquals(Color.BLACK, newCell.getStyleHandler().getBackgroundColor());
+        }
+        
+        @Test
+        public void testSettingNullBackgroundOnCell() throws Exception {
+            SpreadsheetDocument doc = SpreadsheetDocument.newSpreadsheetDocument();
+            Table table = doc.getTableByName("Sheet1");
+            Cell cell = table.getCellByPosition(1, 1);
+            cell.setCellBackgroundColor((Color) null);
+            Assert.assertNull(cell.getStyleHandler().getTableCellPropertiesForRead().getBackgroundColor());
+            Assert.assertEquals(Color.WHITE, cell.getCellBackgroundColor());
+        }
 }



Mime
View raw message