poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1241395 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
Date Tue, 07 Feb 2012 09:45:21 GMT
Author: yegor
Date: Tue Feb  7 09:45:20 2012
New Revision: 1241395

URL: http://svn.apache.org/viewvc?rev=1241395&view=rev
Log:
Bugzilla 52568: added methods to set/get an XWPFRun's text color

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1241395&r1=1241394&r2=1241395&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Feb  7 09:45:20 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">52568 - Added methods to set/get
an XWPFRun's text color</action>
            <action dev="poi-developers" type="add">52566 - Added methods to set/get
vertical alignment and color in XWPFTableCell</action>
            <action dev="poi-developers" type="add">52562 - Added methods to get/set
a table row's Can't Split and Repeat Header attributes  in XWPF</action>
            <action dev="poi-developers" type="add">52561 - Added methods to set table
inside borders and cell margins in XWPF</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1241395&r1=1241394&r2=1241395&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Tue Feb  7 09:45:20
2012
@@ -48,6 +48,7 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
 import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
@@ -74,6 +75,8 @@ import org.openxmlformats.schemas.drawin
  * XWPFRun object defines a region of text with a common set of properties
  *
  * @author Yegor Kozlov
+ * @author Gregg Morris (gregg dot morris at gmail dot com) - added getColor(), setColor()
+ *
  */
 public class XWPFRun {
     private CTR run;
@@ -245,6 +248,31 @@ public class XWPFRun {
     }
 
     /**
+     * Get text color. The returned value is a string in the hex form "RRGGBB".
+     */
+    public String getColor() {
+    	String color = null;
+        if (run.isSetRPr()) {
+        	CTRPr pr = run.getRPr();
+        	if (pr.isSetColor()) {
+        		CTColor clr = pr.getColor();
+        		color = clr.xgetVal().getStringValue();
+        	}
+        }
+    	return color;
+    }
+
+    /**
+     * Set text color.
+     * @param rgbStr - the desired color, in the hex form "RRGGBB".
+     */
+    public void setColor(String rgbStr) {
+        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
+        CTColor color = pr.isSetColor() ? pr.getColor() : pr.addNewColor();
+        color.setVal(rgbStr);
+    }
+
+    /**
      * Return the string content of this text run
      *
      * @return the text of this text run or <code>null</code> if not set

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1241395&r1=1241394&r2=1241395&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Tue Feb 
7 09:45:20 2012
@@ -161,6 +161,13 @@ public class TestXWPFRun extends TestCas
         assertEquals(2400, rpr.getPosition().getVal().longValue());
     }
 
+    public void testSetGetColor() {
+        XWPFRun run = new XWPFRun(ctRun, p);
+        run.setColor("0F0F0F");
+        String clr = run.getColor();
+        assertEquals("0F0F0F", clr);
+    }
+
     public void testAddCarriageReturn() {
 	
 	ctRun.addNewT().setStringValue("TEST STRING");



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


Mime
View raw message