Author: jmarkmurphy
Date: Mon Feb 12 04:12:06 2018
New Revision: 1823920
URL: http://svn.apache.org/viewvc?rev=1823920&view=rev
Log:
#55953 Added methods to position a table
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
(with props)
Modified:
poi/site/src/documentation/content/xdocs/status.xml
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
Modified: poi/site/src/documentation/content/xdocs/status.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1823920&r1=1823919&r2=1823920&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Mon Feb 12 04:12:06 2018
@@ -68,6 +68,7 @@
<summary-item>Provide new ooxml-schemas-1.4.jar</summary-item>
</summary>
<actions>
+ <action dev="PD" type="add" fixes-bug="55954" module="XWPF">Added
methods to position table</action>
<action dev="PD" type="add" fixes-bug="61947" module="POI
Overall">Remove deprecated classes (POI 4.0.0)</action>
<action dev="PD" type="add" fixes-bug="55954" module="XWPF">Add
functions to get, set, remove outer borders for tables</action>
<action dev="PD" type="add" fixes-bug="github-72" module="XDDF">Define
XDDF user model for shape properties to be shared between XSLF, XSSF and
XWPF</action>
Added: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java?rev=1823920&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
(added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
Mon Feb 12 04:12:06 2018
@@ -0,0 +1,54 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xwpf.usermodel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Sets alignment values allowed for Tables and Table Rows
+ */
+public enum TableRowAlign {
+
+ LEFT(1),
+ CENTER(2),
+ RIGHT(3);
+
+ private static Map<Integer, TableRowAlign> imap = new HashMap<>();
+
+ static {
+ for (TableRowAlign p : values()) {
+ imap.put(p.getValue(), p);
+ }
+ }
+
+ private final int value;
+
+ private TableRowAlign(int val) {
+ value = val;
+ }
+
+ public static TableRowAlign valueOf(int type) {
+ TableRowAlign err = imap.get(type);
+ if (err == null) throw new IllegalArgumentException("Unknown table row
alignment: " + type);
+ return err;
+ }
+
+ public int getValue() {
+ return value;
+ }
+}
Propchange:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/TableRowAlign.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java?rev=1823920&r1=1823919&r2=1823920&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java Mon
Feb 12 04:12:06 2018
@@ -29,6 +29,7 @@ import org.apache.poi.util.NotImplemente
import org.apache.poi.util.Removal;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
@@ -39,6 +40,7 @@ import org.openxmlformats.schemas.wordpr
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
/**
@@ -410,6 +412,39 @@ public class XWPFTable implements IBodyE
: null;
}
+ /**
+ * Returns the current table alignment or NULL
+ *
+ * @return Table Alignment as a {@link TableRowAlign} enum
+ */
+ public TableRowAlign getTableAlignment() {
+ CTTblPr tPr = getTblPr(false);
+ return tPr == null ? null
+ : tPr.isSetJc() ?
TableRowAlign.valueOf(tPr.getJc().getVal().intValue())
+ : null;
+ }
+
+ /**
+ * Set table alignment to specified {@link TableRowAlign}
+ *
+ * @param ha {@link TableRowAlign} to set
+ */
+ public void setTableAlignment(TableRowAlign tra) {
+ CTTblPr tPr = getTblPr(true);
+ CTJc jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
+ jc.setVal(STJc.Enum.forInt(tra.getValue()));
+ }
+
+ /**
+ * Removes the table alignment attribute from a table
+ */
+ public void removeTableAlignment() {
+ CTTblPr tPr = getTblPr(false);
+ if (tPr != null && tPr.isSetJc()) {
+ tPr.unsetJc();
+ }
+ }
+
private void addColumn(XWPFTableRow tabRow, int sizeCol) {
if (sizeCol > 0) {
for (int i = 0; i < sizeCol; i++) {
@@ -1172,6 +1207,6 @@ public class XWPFTable implements IBodyE
THIN_THICK_MEDIUM_GAP, THICK_THIN_MEDIUM_GAP,
THIN_THICK_THIN_MEDIUM_GAP,
THIN_THICK_LARGE_GAP, THICK_THIN_LARGE_GAP, THIN_THICK_THIN_LARGE_GAP,
WAVE, DOUBLE_WAVE, DASH_SMALL_GAP, DASH_DOT_STROKED, THREE_D_EMBOSS,
THREE_D_ENGRAVE,
- OUTSET, INSET
+ OUTSET, INSET;
}
}
Modified:
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java?rev=1823920&r1=1823919&r2=1823920&view=diff
==============================================================================
---
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
(original)
+++
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
Mon Feb 12 04:12:06 2018
@@ -16,13 +16,18 @@
==================================================================== */
package org.apache.poi.xwpf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
-import junit.framework.TestCase;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;
+import org.junit.Test;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
@@ -34,20 +39,13 @@ import org.openxmlformats.schemas.wordpr
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+
/**
* Tests for XWPF Tables
*/
-public class TestXWPFTable extends TestCase {
- @Override
- protected void setUp() {
- /*
- XWPFDocument doc = new XWPFDocument();
- p = doc.createParagraph();
-
- this.ctRun = CTR.Factory.newInstance();
- */
- }
+public class TestXWPFTable {
+ @Test
public void testConstructor() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -70,6 +68,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testTblGrid() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -87,6 +86,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testGetText() {
XWPFDocument doc = new XWPFDocument();
CTTbl table = CTTbl.Factory.newInstance();
@@ -106,7 +106,7 @@ public class TestXWPFTable extends TestC
}
}
-
+ @Test
public void testCreateRow() {
XWPFDocument doc = new XWPFDocument();
@@ -142,7 +142,7 @@ public class TestXWPFTable extends TestC
}
}
-
+ @Test
public void testSetGetWidth() {
XWPFDocument doc = new XWPFDocument();
@@ -162,6 +162,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetHeight() {
XWPFDocument doc = new XWPFDocument();
@@ -178,6 +179,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetMargins() {
// instantiate the following class so it'll get picked up by
// the XmlBean process and added to the jar file. it's required
@@ -206,6 +208,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetHBorders() {
// instantiate the following classes so they'll get picked up by
// the XmlBean process and added to the jar file. they are required
@@ -278,6 +281,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetVBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
@@ -347,6 +351,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetTopBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
@@ -389,6 +394,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetBottomBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
@@ -431,6 +437,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetLeftBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
@@ -473,6 +480,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetRightBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
@@ -515,6 +523,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetRowBandSize() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -529,6 +538,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testSetGetColBandSize() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -543,6 +553,7 @@ public class TestXWPFTable extends TestC
}
}
+ @Test
public void testCreateTable() throws Exception {
// open an empty document
XWPFDocument doc =
XWPFTestDataSamples.openSampleDocument("sample.docx");
@@ -569,6 +580,25 @@ public class TestXWPFTable extends TestC
try {
doc.close();
} catch (IOException e) {
+ fail("Unable to close doc");
+ }
+ }
+
+ @Test
+ public void testSetGetTableAlignment() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFTable tbl = doc.createTable(1, 1);
+ tbl.setTableAlignment(TableRowAlign.LEFT);
+ assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.CENTER);
+ assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.RIGHT);
+ assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
+ tbl.removeTableAlignment();
+ assertNull(tbl.getTableAlignment());
+ try {
+ doc.close();
+ } catch (IOException e) {
fail("Unable to close doc");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]