You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ab...@apache.org on 2018/10/05 09:59:32 UTC
svn commit: r1842876 - in /poi/trunk/src:
examples/src/org/apache/poi/xslf/usermodel/
examples/src/org/apache/poi/xssf/usermodel/examples/
examples/src/org/apache/poi/xwpf/usermodel/examples/
ooxml/java/org/apache/poi/xddf/usermodel/chart/ ooxml/java/o...
Author: abearez
Date: Fri Oct 5 09:59:32 2018
New Revision: 1842876
URL: http://svn.apache.org/viewvc?rev=1842876&view=rev
Log:
more XDDF improvements based on SO examples
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFTitle.java
Modified:
poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java
poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
Modified: poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java Fri Oct 5 09:59:32 2018
@@ -115,6 +115,8 @@ public class BarChartDemo {
series2.setTitle(series[1], chart.setSheetTitle(series[1], 1));
chart.plot(bar);
+ chart.setTitleText(chartTitle); // https://stackoverflow.com/questions/30532612
+ // chart.setTitleOverlay(overlay);
}
private static void setColumnData(XSLFChart chart, String chartTitle) {
Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BarChart.java Fri Oct 5 09:59:32 2018
@@ -76,7 +76,9 @@ public class BarChart {
// Use a category axis for the bottom axis.
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+ leftAxis.setTitle("f(x)");
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java Fri Oct 5 09:59:32 2018
@@ -77,7 +77,9 @@ public class LineChart {
// Use a category axis for the bottom axis.
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+ leftAxis.setTitle("f(x)");
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java Fri Oct 5 09:59:32 2018
@@ -77,7 +77,9 @@ public class ScatterChart {
legend.setPosition(LegendPosition.TOP_RIGHT);
XDDFValueAxis bottomAxis = chart.createValueAxis(AxisPosition.BOTTOM);
+ bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+ leftAxis.setTitle("f(x)");
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
Modified: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java Fri Oct 5 09:59:32 2018
@@ -117,6 +117,8 @@ public class BarChartExample {
series2.setTitle(series[1], chart.setSheetTitle(series[1], 1));
chart.plot(bar);
+ chart.setTitleText(chartTitle); // https://stackoverflow.com/questions/30532612
+ // chart.setTitleOverlay(overlay);
}
private static void setColumnData(XWPFChart chart, String chartTitle) {
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFCategoryAxis.java Fri Oct 5 09:59:32 2018
@@ -79,6 +79,19 @@ public class XDDFCategoryAxis extends XD
return new XDDFShapeProperties(properties);
}
+ /**
+ * @since 4.0.1
+ */
+ @Override
+ public void setTitle(String text) {
+ if (!ctCatAx.isSetTitle()) {
+ ctCatAx.addNewTitle();
+ }
+ XDDFTitle title = new XDDFTitle(null, ctCatAx.getTitle());
+ title.setOverlay(false);
+ title.setText(text);
+ }
+
@Override
public boolean isSetMinorUnit() {
return false;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java Fri Oct 5 09:59:32 2018
@@ -70,7 +70,6 @@ import org.openxmlformats.schemas.drawin
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
@@ -252,11 +251,27 @@ public abstract class XDDFChart extends
if (!chart.isSetTitle()) {
chart.addNewTitle();
}
- CTTitle title = chart.getTitle();
- if (title.isSetOverlay()) {
- title.getOverlay().setVal(overlay);
+ new XDDFTitle(this, chart.getTitle()).setOverlay(overlay);
+ }
+
+ /**
+ * @since 4.0.1
+ */
+ public void setTitleText(String text) {
+ if (!chart.isSetTitle()) {
+ chart.addNewTitle();
+ }
+ new XDDFTitle(this, chart.getTitle()).setText(text);
+ }
+
+ /**
+ * @since 4.0.1
+ */
+ public XDDFTitle getTitle() {
+ if (chart.isSetTitle()) {
+ return new XDDFTitle(this, chart.getTitle());
} else {
- title.addNewOverlay().setVal(overlay);
+ return null;
}
}
@@ -271,15 +286,7 @@ public abstract class XDDFChart extends
if (!chart.isSetTitle()) {
return null;
}
- CTTitle title = chart.getTitle();
- if (!title.isSetTx()) {
- return null;
- }
- CTTx tx = title.getTx();
- if (!tx.isSetRich()) {
- return null;
- }
- return new XDDFTextBody(this, tx.getRich());
+ return new XDDFTitle(this, chart.getTitle()).getBody();
}
@Override
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChartAxis.java Fri Oct 5 09:59:32 2018
@@ -57,6 +57,11 @@ public abstract class XDDFChartAxis impl
public abstract XDDFShapeProperties getOrAddMinorGridProperties();
/**
+ * @since 4.0.1
+ */
+ public abstract void setTitle(String text);
+
+ /**
* @return true if minor unit value is defined, false otherwise
*/
public abstract boolean isSetMinorUnit();
Added: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFTitle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFTitle.java?rev=1842876&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFTitle.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFTitle.java Fri Oct 5 09:59:32 2018
@@ -0,0 +1,79 @@
+/*
+ * ====================================================================
+ * 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.xddf.usermodel.chart;
+
+import org.apache.poi.util.Beta;
+import org.apache.poi.xddf.usermodel.text.TextContainer;
+import org.apache.poi.xddf.usermodel.text.XDDFTextBody;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx;
+
+/**
+ * @since 4.0.1
+ */
+@Beta
+public class XDDFTitle {
+ private final CTTitle title;
+ private final TextContainer parent;
+
+ public XDDFTitle(TextContainer parent, CTTitle title) {
+ this.parent = parent;
+ this.title = title;
+ }
+
+ public XDDFTextBody getBody() {
+ XDDFTextBody body;
+ if (title.isSetTxPr()) {
+ body = new XDDFTextBody(parent, title.getTxPr());
+ } else {
+ if (!title.isSetTx()) {
+ title.addNewTx();
+ }
+ CTTx tx = title.getTx();
+ if (!tx.isSetRich()) {
+ tx.addNewRich();
+ }
+ body = new XDDFTextBody(parent, tx.getRich());
+ }
+ return body;
+ }
+
+ public void setText(String text) {
+ if (!title.isSetLayout()) {
+ title.addNewLayout();
+ }
+ getBody().setText(text);
+ }
+
+ public void setOverlay(Boolean overlay) {
+ if (overlay == null) {
+ if (title.isSetOverlay()) {
+ title.unsetOverlay();
+ }
+ } else {
+ if (title.isSetOverlay()) {
+ title.getOverlay().setVal(overlay);
+ } else {
+ title.addNewOverlay().setVal(overlay);
+ }
+ }
+ }
+
+}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFValueAxis.java Fri Oct 5 09:59:32 2018
@@ -78,6 +78,19 @@ public class XDDFValueAxis extends XDDFC
return new XDDFShapeProperties(properties);
}
+ /**
+ * @since 4.0.1
+ */
+ @Override
+ public void setTitle(String text) {
+ if (!ctValAx.isSetTitle()) {
+ ctValAx.addNewTitle();
+ }
+ XDDFTitle title = new XDDFTitle(null, ctValAx.getTitle());
+ title.setOverlay(false);
+ title.setText(text);
+ }
+
@Override
public boolean isSetMinorUnit() {
return ctValAx.isSetMinorUnit();
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphProperties.java Fri Oct 5 09:59:32 2018
@@ -67,6 +67,16 @@ public class XDDFParagraphProperties {
}
}
+ /**
+ * @since 4.0.1
+ */
+ public XDDFRunProperties addDefaultRunProperties() {
+ if (!props.isSetDefRPr()) {
+ props.addNewDefRPr();
+ }
+ return getDefaultRunProperties();
+ }
+
public XDDFRunProperties getDefaultRunProperties() {
if (props.isSetDefRPr()) {
return new XDDFRunProperties(props.getDefRPr());
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextBody.java Fri Oct 5 09:59:32 2018
@@ -70,6 +70,19 @@ public class XDDFTextBody {
return p;
}
+ public void setText(String text) {
+ if (_body.sizeOfPArray() > 0) {
+ // remove all but first paragraph
+ for (int i = _body.sizeOfPArray() - 1; i > 0; i--) {
+ _body.removeP(i);
+ }
+ getParagraph(0).setText(text);
+ } else {
+ // as there were no paragraphs yet, initialize the text body
+ initialize().setText(text);
+ }
+ }
+
public XDDFTextParagraph addNewParagraph() {
return new XDDFTextParagraph(_body.addNewP(), this);
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java?rev=1842876&r1=1842875&r2=1842876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java Fri Oct 5 09:59:32 2018
@@ -69,6 +69,24 @@ public class XDDFTextParagraph {
_runs.add(new XDDFTextRun((CTRegularTextRun) xo, this));
}
}
+
+ addDefaultRunProperties();
+ addAfterLastRunProperties();
+ }
+
+ public void setText(String text) {
+ // remove all runs
+ for (int i = _p.sizeOfBrArray() - 1; i >= 0; i--) {
+ _p.removeBr(i);
+ }
+ for (int i = _p.sizeOfFldArray() - 1; i >= 0; i--) {
+ _p.removeFld(i);
+ }
+ for (int i = _p.sizeOfRArray() - 1; i >= 0; i--) {
+ _p.removeR(i);
+ }
+ _runs.clear();
+ appendRegularRun(text);
}
public String getText() {
@@ -662,6 +680,13 @@ public class XDDFTextParagraph {
}
}
+ /**
+ * @since 4.0.1
+ */
+ public XDDFRunProperties addDefaultRunProperties() {
+ return getOrCreateProperties().addDefaultRunProperties();
+ }
+
public XDDFRunProperties getDefaultRunProperties() {
if (_p.isSetPPr()) {
return getProperties().getDefaultRunProperties();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org