aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2019-03-10 16:12:57 +0000
committerDominik Stadler <centic@apache.org>2019-03-10 16:12:57 +0000
commitef369931e246d8d8dd180077bd162119e8991e70 (patch)
tree97e04824777ea4ae0f05fde2f66fb9e7e2fc00ed
parent5329f25b0a8ebe88c6049b0abc292824489d2193 (diff)
downloadpoi-ef369931e246d8d8dd180077bd162119e8991e70.tar.gz
poi-ef369931e246d8d8dd180077bd162119e8991e70.zip
Bug 63221: Add margin-settings for top, bottom, left and right to XSSFPrintSetup
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1855154 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java101
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java112
2 files changed, 161 insertions, 52 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
index 55c4d2787f..e626790d88 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
@@ -115,10 +115,10 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* Set whether to go left to right or top down in ordering
*
- * @param ltor left to right
+ * @param leftToRight left to right
*/
- public void setLeftToRight(boolean ltor) {
- if (ltor)
+ public void setLeftToRight(boolean leftToRight) {
+ if (leftToRight)
setPageOrder(PageOrder.OVER_THEN_DOWN);
else
setPageOrder(PageOrder.DOWN_THEN_OVER);
@@ -139,7 +139,7 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* Use the printer's defaults settings for page setup values and don't use the default values
* specified in the schema. For example, if dpi is not present or specified in the XML, the
- * a plication shall not assume 600dpi as specified in the schema as a default and instead
+ * application shall not assume 600dpi as specified in the schema as a default and instead
* shall let the printer specify the default dpi.
*
* @param valid Valid
@@ -169,10 +169,10 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* Print the include notes
*
- * @param printnotes print the notes
+ * @param printNotes print the notes
*/
- public void setNotes(boolean printnotes) {
- if (printnotes){
+ public void setNotes(boolean printNotes) {
+ if (printNotes){
pageSetup.setCellComments(STCellComments.AS_DISPLAYED);
}
}
@@ -218,19 +218,19 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* Sets the header margin.
*
- * @param headermargin header margin
+ * @param headerMargin header margin
*/
- public void setHeaderMargin(double headermargin) {
- pageMargins.setHeader(headermargin);
+ public void setHeaderMargin(double headerMargin) {
+ pageMargins.setHeader(headerMargin);
}
/**
* Sets the footer margin.
*
- * @param footermargin footer margin
+ * @param footerMargin footer margin
*/
- public void setFooterMargin(double footermargin) {
- pageMargins.setFooter(footermargin);
+ public void setFooterMargin(double footerMargin) {
+ pageMargins.setFooter(footerMargin);
}
/**
@@ -273,7 +273,7 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* Set print page order.
*
- * @param pageOrder
+ * @param pageOrder An enum indicating the wanted ordering of printed pages
*/
public void setPageOrder(PageOrder pageOrder) {
STPageOrder.Enum v = STPageOrder.Enum.forInt(pageOrder.getValue());
@@ -283,7 +283,7 @@ public class XSSFPrintSetup implements PrintSetup {
/**
* get print page order.
*
- * @return PageOrder
+ * @return The currently set ordering of printed pages
*/
public PageOrder getPageOrder() {
return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder().intValue());
@@ -465,4 +465,75 @@ public class XSSFPrintSetup implements PrintSetup {
return (short) pageSetup.getCopies();
}
+ /**
+ * Sets the top margin.
+ *
+ * @param topMargin top margin
+ */
+ public void setTopMargin(double topMargin) {
+ pageMargins.setTop(topMargin);
+ }
+
+ /**
+ * Returns the top margin.
+ *
+ * @return top margin
+ */
+ public double getTopMargin() {
+ return pageMargins.getTop();
+ }
+
+ /**
+ * Sets the bottom margin.
+ *
+ * @param bottomMargin bottom margin
+ */
+ public void setBottomMargin(double bottomMargin) {
+ pageMargins.setBottom(bottomMargin);
+ }
+
+ /**
+ * Returns the bottom margin.
+ *
+ * @return bottom margin
+ */
+ public double getBottomMargin() {
+ return pageMargins.getBottom();
+ }
+
+ /**
+ * Sets the left margin.
+ *
+ * @param leftMargin left margin
+ */
+ public void setLeftMargin(double leftMargin) {
+ pageMargins.setLeft(leftMargin);
+ }
+
+ /**
+ * Returns the left margin.
+ *
+ * @return left margin
+ */
+ public double getLeftMargin() {
+ return pageMargins.getLeft();
+ }
+
+ /**
+ * Sets the right margin.
+ *
+ * @param rightMargin right margin
+ */
+ public void setRightMargin(double rightMargin) {
+ pageMargins.setRight(rightMargin);
+ }
+
+ /**
+ * Returns the right margin.
+ *
+ * @return right margin
+ */
+ public double getRightMargin() {
+ return pageMargins.getRight();
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
index 6cda3aff29..db700a9054 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPrintSetup.java
@@ -17,8 +17,6 @@
package org.apache.poi.xssf.usermodel;
-import junit.framework.TestCase;
-
import org.apache.poi.ss.usermodel.PageOrder;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.ss.usermodel.PrintCellComments;
@@ -32,10 +30,15 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Tests for {@link XSSFPrintSetup}
*/
-public class TestXSSFPrintSetup extends TestCase {
+public class TestXSSFPrintSetup {
+ @Test
public void testSetGetPaperSize() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -48,7 +51,7 @@ public class TestXSSFPrintSetup extends TestCase {
assertEquals(8, pSetup.getPaperSize());
}
-
+ @Test
public void testSetGetScale() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -60,6 +63,7 @@ public class TestXSSFPrintSetup extends TestCase {
assertEquals(100, pSetup.getScale());
}
+ @Test
public void testSetGetPageStart() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -71,7 +75,7 @@ public class TestXSSFPrintSetup extends TestCase {
assertEquals(1, pSetup.getFirstPageNumber());
}
-
+ @Test
public void testSetGetFitWidthHeight() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -88,89 +92,95 @@ public class TestXSSFPrintSetup extends TestCase {
}
+ @Test
public void testSetGetLeftToRight() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getLeftToRight());
+ assertFalse(printSetup.getLeftToRight());
printSetup.setLeftToRight(true);
assertEquals(PageOrder.OVER_THEN_DOWN.getValue(), pSetup.getPageOrder().intValue());
}
+ @Test
public void testSetGetOrientation() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setOrientation(STOrientation.PORTRAIT);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
assertEquals(PrintOrientation.PORTRAIT, printSetup.getOrientation());
- assertEquals(false, printSetup.getLandscape());
- assertEquals(false, printSetup.getNoOrientation());
+ assertFalse(printSetup.getLandscape());
+ assertFalse(printSetup.getNoOrientation());
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
assertEquals(pSetup.getOrientation().intValue(), printSetup.getOrientation().getValue());
- assertEquals(true, printSetup.getLandscape());
- assertEquals(false, printSetup.getNoOrientation());
+ assertTrue(printSetup.getLandscape());
+ assertFalse(printSetup.getNoOrientation());
}
-
+ @Test
public void testSetGetValidSettings() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setUsePrinterDefaults(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getValidSettings());
+ assertFalse(printSetup.getValidSettings());
printSetup.setValidSettings(true);
- assertEquals(true, pSetup.getUsePrinterDefaults());
+ assertTrue(pSetup.getUsePrinterDefaults());
}
+ @Test
public void testSetGetNoColor() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setBlackAndWhite(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getNoColor());
+ assertFalse(printSetup.getNoColor());
printSetup.setNoColor(true);
- assertEquals(true, pSetup.getBlackAndWhite());
+ assertTrue(pSetup.getBlackAndWhite());
}
+ @Test
public void testSetGetDraft() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setDraft(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getDraft());
+ assertFalse(printSetup.getDraft());
printSetup.setDraft(true);
- assertEquals(true, pSetup.getDraft());
+ assertTrue(pSetup.getDraft());
}
+ @Test
public void testSetGetNotes() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setCellComments(STCellComments.NONE);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getNotes());
+ assertFalse(printSetup.getNotes());
printSetup.setNotes(true);
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(), pSetup.getCellComments().intValue());
}
-
+ @Test
public void testSetGetUsePage() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
pSetup.setUseFirstPageNumber(false);
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
- assertEquals(false, printSetup.getUsePage());
+ assertFalse(printSetup.getUsePage());
printSetup.setUsePage(true);
- assertEquals(true, pSetup.getUseFirstPageNumber());
+ assertTrue(pSetup.getUseFirstPageNumber());
}
+ @Test
public void testSetGetHVResolution() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -186,6 +196,7 @@ public class TestXSSFPrintSetup extends TestCase {
assertEquals(130, pSetup.getVerticalDpi());
}
+ @Test
public void testSetGetHeaderFooterMargin() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageMargins pMargins = worksheet.addNewPageMargins();
@@ -201,6 +212,31 @@ public class TestXSSFPrintSetup extends TestCase {
assertEquals(3.5, pMargins.getFooter(), 0.0);
}
+ @Test
+ public void testSetGetMargins() {
+ CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
+ CTPageMargins pMargins = worksheet.addNewPageMargins();
+ pMargins.setTop(5.3);
+ pMargins.setBottom(1.5);
+ pMargins.setLeft(2);
+ pMargins.setRight(3.2);
+ XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
+ assertEquals(5.3, printSetup.getTopMargin(), 0.0);
+ assertEquals(1.5, printSetup.getBottomMargin(), 0.0);
+ assertEquals(2, printSetup.getLeftMargin(), 0.0);
+ assertEquals(3.2, printSetup.getRightMargin(), 0.0);
+
+ printSetup.setTopMargin(9);
+ printSetup.setBottomMargin(6.4);
+ printSetup.setLeftMargin(7.8);
+ printSetup.setRightMargin(8.1);
+ assertEquals(9, pMargins.getTop(), 0.0);
+ assertEquals(6.4, pMargins.getBottom(), 0.0);
+ assertEquals(7.8, pMargins.getLeft(), 0.0);
+ assertEquals(8.1, pMargins.getRight(), 0.0);
+ }
+
+ @Test
public void testSetGetCopies() {
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTPageSetup pSetup = worksheet.addNewPageSetup();
@@ -211,40 +247,41 @@ public class TestXSSFPrintSetup extends TestCase {
printSetup.setCopies((short) 15);
assertEquals(15, pSetup.getCopies());
}
-
+
+ @Test
public void testSetSaveRead() throws Exception {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s1 = wb.createSheet();
- assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+ assertFalse(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
XSSFPrintSetup print = s1.getPrintSetup();
- assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
+ assertTrue(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
print.setCopies((short)3);
print.setLandscape(true);
assertEquals(3, print.getCopies());
- assertEquals(true, print.getLandscape());
+ assertTrue(print.getLandscape());
XSSFSheet s2 = wb.createSheet();
- assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+ assertFalse(s2.getCTWorksheet().isSetPageSetup());
+ assertTrue(s2.getCTWorksheet().isSetPageMargins());
// Round trip and check
XSSFWorkbook wbBack = XSSFITestDataProvider.instance.writeOutAndReadBack(wb);
s1 = wbBack.getSheetAt(0);
s2 = wbBack.getSheetAt(1);
-
- assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
- assertEquals(false, s2.getCTWorksheet().isSetPageSetup());
- assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
+
+ assertTrue(s1.getCTWorksheet().isSetPageSetup());
+ assertTrue(s1.getCTWorksheet().isSetPageMargins());
+ assertFalse(s2.getCTWorksheet().isSetPageSetup());
+ assertTrue(s2.getCTWorksheet().isSetPageMargins());
print = s1.getPrintSetup();
assertEquals(3, print.getCopies());
- assertEquals(true, print.getLandscape());
+ assertTrue(print.getLandscape());
wb.close();
}
@@ -253,12 +290,13 @@ public class TestXSSFPrintSetup extends TestCase {
* Open a file with print settings, save and check.
* Then, change, save, read, check
*/
+ @Test
public void testRoundTrip() {
// TODO
}
@Test
- public void testSetLandscapeFalse() throws Exception {
+ public void testSetLandscapeFalse() {
XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance());
assertFalse(ps.getLandscape());
@@ -271,7 +309,7 @@ public class TestXSSFPrintSetup extends TestCase {
}
@Test
- public void testSetLeftToRight() throws Exception {
+ public void testSetLeftToRight() {
XSSFPrintSetup ps = new XSSFPrintSetup(CTWorksheet.Factory.newInstance());
assertFalse(ps.getLeftToRight());