From: PJ Fanning Date: Sat, 27 Jun 2020 13:43:36 +0000 (+0000) Subject: remove some deprecated classes X-Git-Tag: before_ooxml_3rd_edition~218 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c3ed1acbc746ab61851cc5f807b6f63ed8b839b5;p=poi.git remove some deprecated classes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879272 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/AbstractXSSFChartSeries.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/AbstractXSSFChartSeries.java deleted file mode 100644 index e053c7eea7..0000000000 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/AbstractXSSFChartSeries.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ==================================================================== - 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.xssf.usermodel.charts; - -import org.apache.poi.ss.usermodel.charts.ChartSeries; -import org.apache.poi.ss.usermodel.charts.TitleType; -import org.apache.poi.ss.util.CellReference; -import org.apache.poi.util.Removal; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx; -import org.apache.poi.xddf.usermodel.chart.XDDFChartData.Series; - -/** - * Base of all XSSF Chart Series - * - * @deprecated use {@link Series} instead - */ -@Deprecated -@Removal(version="4.2") -public abstract class AbstractXSSFChartSeries implements ChartSeries { - - private String titleValue; - private CellReference titleRef; - private TitleType titleType; - - @Override - public void setTitle(CellReference titleReference) { - titleType = TitleType.CELL_REFERENCE; - titleRef = titleReference; - } - - @Override - public void setTitle(String title) { - titleType = TitleType.STRING; - titleValue = title; - } - - @Override - public CellReference getTitleCellReference() { - if (TitleType.CELL_REFERENCE.equals(titleType)) { - return titleRef; - } - throw new IllegalStateException("Title type is not CellReference."); - } - - @Override - public String getTitleString() { - if (TitleType.STRING.equals(titleType)) { - return titleValue; - } - throw new IllegalStateException("Title type is not String."); - } - - @Override - public TitleType getTitleType() { - return titleType; - } - - protected boolean isTitleSet() { - return titleType != null; - } - - protected CTSerTx getCTSerTx() { - CTSerTx tx = CTSerTx.Factory.newInstance(); - switch (titleType) { - case CELL_REFERENCE: - tx.addNewStrRef().setF(titleRef.formatAsString()); - return tx; - case STRING: - tx.setV(titleValue); - return tx; - default: - throw new IllegalStateException("Unkown title type: " + titleType); - } - } -} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFManualLayout.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFManualLayout.java deleted file mode 100644 index 1f5b66b43c..0000000000 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFManualLayout.java +++ /dev/null @@ -1,267 +0,0 @@ -/* ==================================================================== - 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.xssf.usermodel.charts; - -import org.apache.poi.ss.usermodel.charts.LayoutMode; -import org.apache.poi.ss.usermodel.charts.LayoutTarget; -import org.apache.poi.ss.usermodel.charts.ManualLayout; -import org.apache.poi.util.Internal; -import org.apache.poi.util.Removal; -import org.apache.poi.xddf.usermodel.chart.XDDFManualLayout; -import org.apache.poi.xssf.usermodel.XSSFChart; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayoutMode; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayoutTarget; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTManualLayout; -import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea; -import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutMode; -import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutTarget; - -/** - * Represents a SpreadsheetML manual layout. - * @deprecated use {@link XDDFManualLayout instead} - */ -@Deprecated -@Removal(version="4.2") -public final class XSSFManualLayout implements ManualLayout { - - /** - * Underlaying CTManualLayout bean. - */ - private CTManualLayout layout; - - private static final LayoutMode defaultLayoutMode = LayoutMode.EDGE; - private static final LayoutTarget defaultLayoutTarget = LayoutTarget.INNER; - - /** - * Create a new SpreadsheetML manual layout. - * @param ctLayout a Spreadsheet ML layout that should be used as base. - */ - public XSSFManualLayout(CTLayout ctLayout) { - initLayout(ctLayout); - } - - /** - * Create a new SpreadsheetML manual layout for chart. - * @param chart a chart to create layout for. - */ - public XSSFManualLayout(XSSFChart chart) { - CTPlotArea ctPlotArea = chart.getCTChart().getPlotArea(); - CTLayout ctLayout = ctPlotArea.isSetLayout() ? - ctPlotArea.getLayout() : ctPlotArea.addNewLayout(); - - initLayout(ctLayout); - } - - /** - * Return the underlying CTManualLayout bean. - * - * @return the underlying CTManualLayout bean. - */ - @Internal public CTManualLayout getCTManualLayout(){ - return layout; - } - - @Override - public void setWidthRatio(double ratio) { - if (!layout.isSetW()) { - layout.addNewW(); - } - layout.getW().setVal(ratio); - } - - @Override - public double getWidthRatio() { - if (!layout.isSetW()) { - return 0.0; - } - return layout.getW().getVal(); - } - - @Override - public void setHeightRatio(double ratio) { - if (!layout.isSetH()) { - layout.addNewH(); - } - layout.getH().setVal(ratio); - } - - @Override - public double getHeightRatio() { - if (!layout.isSetH()) { - return 0.0; - } - return layout.getH().getVal(); - } - - @Override - public LayoutTarget getTarget() { - if (!layout.isSetLayoutTarget()) { - return defaultLayoutTarget; - } - return toLayoutTarget(layout.getLayoutTarget()); - } - - @Override - public void setTarget(LayoutTarget target) { - if (!layout.isSetLayoutTarget()) { - layout.addNewLayoutTarget(); - } - layout.getLayoutTarget().setVal(fromLayoutTarget(target)); - } - - @Override - public LayoutMode getXMode() { - if (!layout.isSetXMode()) { - return defaultLayoutMode; - } - return toLayoutMode(layout.getXMode()); - } - - @Override - public void setXMode(LayoutMode mode) { - if (!layout.isSetXMode()) { - layout.addNewXMode(); - } - layout.getXMode().setVal(fromLayoutMode(mode)); - } - - @Override - public LayoutMode getYMode() { - if (!layout.isSetYMode()) { - return defaultLayoutMode; - } - return toLayoutMode(layout.getYMode()); - } - - @Override - public void setYMode(LayoutMode mode) { - if (!layout.isSetYMode()) { - layout.addNewYMode(); - } - layout.getYMode().setVal(fromLayoutMode(mode)); - } - - @Override - public double getX() { - if (!layout.isSetX()) { - return 0.0; - } - return layout.getX().getVal(); - } - - @Override - public void setX(double x) { - if (!layout.isSetX()) { - layout.addNewX(); - } - layout.getX().setVal(x); - } - - @Override - public double getY() { - if (!layout.isSetY()) { - return 0.0; - } - return layout.getY().getVal(); - } - - @Override - public void setY(double y) { - if (!layout.isSetY()) { - layout.addNewY(); - } - layout.getY().setVal(y); - } - - @Override - public LayoutMode getWidthMode() { - if (!layout.isSetWMode()) { - return defaultLayoutMode; - } - return toLayoutMode(layout.getWMode()); - } - - @Override - public void setWidthMode(LayoutMode mode) { - if (!layout.isSetWMode()) { - layout.addNewWMode(); - } - layout.getWMode().setVal(fromLayoutMode(mode)); - } - - @Override - public LayoutMode getHeightMode() { - if (!layout.isSetHMode()) { - return defaultLayoutMode; - } - return toLayoutMode(layout.getHMode()); - } - - @Override - public void setHeightMode(LayoutMode mode) { - if (!layout.isSetHMode()) { - layout.addNewHMode(); - } - layout.getHMode().setVal(fromLayoutMode(mode)); - } - - private void initLayout(CTLayout ctLayout) { - if (ctLayout.isSetManualLayout()) { - this.layout = ctLayout.getManualLayout(); - } else { - this.layout = ctLayout.addNewManualLayout(); - } - } - - private STLayoutMode.Enum fromLayoutMode(LayoutMode mode) { - switch (mode) { - case EDGE: return STLayoutMode.EDGE; - case FACTOR: return STLayoutMode.FACTOR; - default: - throw new IllegalArgumentException(); - } - } - - private LayoutMode toLayoutMode(CTLayoutMode ctLayoutMode) { - switch (ctLayoutMode.getVal().intValue()) { - case STLayoutMode.INT_EDGE: return LayoutMode.EDGE; - case STLayoutMode.INT_FACTOR: return LayoutMode.FACTOR; - default: - throw new IllegalArgumentException(); - } - } - - private STLayoutTarget.Enum fromLayoutTarget(LayoutTarget target) { - switch (target) { - case INNER: return STLayoutTarget.INNER; - case OUTER: return STLayoutTarget.OUTER; - default: - throw new IllegalArgumentException(); - } - } - - private LayoutTarget toLayoutTarget(CTLayoutTarget ctLayoutTarget) { - switch (ctLayoutTarget.getVal().intValue()) { - case STLayoutTarget.INT_INNER: return LayoutTarget.INNER; - case STLayoutTarget.INT_OUTER: return LayoutTarget.OUTER; - default: - throw new IllegalArgumentException(); - } - } -} diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXDDFManualLayout.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXDDFManualLayout.java new file mode 100644 index 0000000000..243169f3cd --- /dev/null +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXDDFManualLayout.java @@ -0,0 +1,118 @@ +/* ==================================================================== + 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.xssf.usermodel.charts; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.poi.xddf.usermodel.chart.LayoutMode; +import org.apache.poi.xddf.usermodel.chart.LayoutTarget; +import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend; +import org.apache.poi.xddf.usermodel.chart.XDDFManualLayout; +import org.apache.poi.xssf.usermodel.XSSFChart; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; +import org.apache.poi.xssf.usermodel.XSSFDrawing; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public final class TestXDDFManualLayout { + + private XSSFWorkbook wb; + private XDDFManualLayout layout; + + @Before + public void createEmptyLayout() { + wb = new XSSFWorkbook(); + XSSFSheet sheet = wb.createSheet(); + XSSFDrawing drawing = sheet.createDrawingPatriarch(); + XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); + XSSFChart chart = drawing.createChart(anchor); + XDDFChartLegend legend = chart.getOrAddLegend(); + layout = legend.getOrAddManualLayout(); + } + + @After + public void closeWB() throws IOException { + wb.close(); + } + + /* + * Accessor methods are not trivial. They use lazy underlying bean + * initialization so there can be some errors (NPE, for example). + */ + @Test + public void testAccessorMethods() { + final double newRatio = 1.1; + final double newCoordinate = 0.3; + final LayoutMode nonDefaultMode = LayoutMode.FACTOR; + final LayoutTarget nonDefaultTarget = LayoutTarget.OUTER; + + layout.setWidthRatio(newRatio); + assertEquals(layout.getWidthRatio(), newRatio, 0.0); + + layout.setHeightRatio(newRatio); + assertEquals(layout.getHeightRatio(), newRatio, 0.0); + + layout.setX(newCoordinate); + assertEquals(layout.getX(), newCoordinate, 0.0); + + layout.setY(newCoordinate); + assertEquals(layout.getY(), newCoordinate, 0.0); + + layout.setXMode(nonDefaultMode); + assertSame(layout.getXMode(), nonDefaultMode); + + layout.setYMode(nonDefaultMode); + assertSame(layout.getYMode(), nonDefaultMode); + + layout.setWidthMode(nonDefaultMode); + assertSame(layout.getWidthMode(), nonDefaultMode); + + layout.setHeightMode(nonDefaultMode); + assertSame(layout.getHeightMode(), nonDefaultMode); + + layout.setTarget(nonDefaultTarget); + assertSame(layout.getTarget(), nonDefaultTarget); + + } + + /* + * Layout must have reasonable default values and must not throw + * any exceptions. + */ + @Test + public void testDefaultValues() { + assertNotNull(layout.getTarget()); + assertNotNull(layout.getXMode()); + assertNotNull(layout.getYMode()); + assertNotNull(layout.getHeightMode()); + assertNotNull(layout.getWidthMode()); + /* + * According to interface, 0.0 should be returned for + * uninitialized double properties. + */ + assertEquals(0.0, layout.getX(), 0.0); + assertEquals(0.0, layout.getY(), 0.0); + assertEquals(0.0, layout.getWidthRatio(), 0.0); + assertEquals(0.0, layout.getHeightRatio(), 0.0); + } +} diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java deleted file mode 100644 index 6cfe2f14a0..0000000000 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFManualLayout.java +++ /dev/null @@ -1,121 +0,0 @@ -/* ==================================================================== - 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.xssf.usermodel.charts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.apache.poi.xddf.usermodel.chart.LayoutMode; -import org.apache.poi.xddf.usermodel.chart.LayoutTarget; -import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend; -import org.apache.poi.xddf.usermodel.chart.XDDFManualLayout; -import org.apache.poi.xssf.usermodel.XSSFChart; -import org.apache.poi.xssf.usermodel.XSSFClientAnchor; -import org.apache.poi.xssf.usermodel.XSSFDrawing; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public final class TestXSSFManualLayout { - - private XSSFWorkbook wb; - private XDDFManualLayout layout; - - @Before - public void createEmptyLayout() { - wb = new XSSFWorkbook(); - XSSFSheet sheet = wb.createSheet(); - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30); - XSSFChart chart = drawing.createChart(anchor); - XDDFChartLegend legend = chart.getOrAddLegend(); - layout = legend.getOrAddManualLayout(); - } - - @After - public void closeWB() throws IOException { - wb.close(); - } - - /* - * Accessor methods are not trivial. They use lazy underlying bean - * initialization so there can be some errors (NPE, for example). - */ - @Test - public void testAccessorMethods() { - final double newRatio = 1.1; - final double newCoordinate = 0.3; - final LayoutMode nonDefaultMode = LayoutMode.FACTOR; - final LayoutTarget nonDefaultTarget = LayoutTarget.OUTER; - - layout.setWidthRatio(newRatio); - assertEquals(layout.getWidthRatio(), newRatio, 0.0); - - layout.setHeightRatio(newRatio); - assertEquals(layout.getHeightRatio(), newRatio, 0.0); - - layout.setX(newCoordinate); - assertEquals(layout.getX(), newCoordinate, 0.0); - - layout.setY(newCoordinate); - assertEquals(layout.getY(), newCoordinate, 0.0); - - layout.setXMode(nonDefaultMode); - assertSame(layout.getXMode(), nonDefaultMode); - - layout.setYMode(nonDefaultMode); - assertSame(layout.getYMode(), nonDefaultMode); - - layout.setWidthMode(nonDefaultMode); - assertSame(layout.getWidthMode(), nonDefaultMode); - - layout.setHeightMode(nonDefaultMode); - assertSame(layout.getHeightMode(), nonDefaultMode); - - layout.setTarget(nonDefaultTarget); - assertSame(layout.getTarget(), nonDefaultTarget); - - } - - /* - * Layout must have reasonable default values and must not throw - * any exceptions. - */ - @Test - public void testDefaultValues() { - assertNotNull(layout.getTarget()); - assertNotNull(layout.getXMode()); - assertNotNull(layout.getYMode()); - assertNotNull(layout.getHeightMode()); - assertNotNull(layout.getWidthMode()); - /* - * According to interface, 0.0 should be returned for - * uninitialized double properties. - */ - assertEquals(0.0, layout.getX(), 0.0); - assertEquals(0.0, layout.getY(), 0.0); - assertEquals(0.0, layout.getWidthRatio(), 0.0); - assertEquals(0.0, layout.getHeightRatio(), 0.0); - } -}