You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractXSSFChartSeries.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel.charts;
  16. import org.apache.poi.ss.usermodel.charts.ChartSeries;
  17. import org.apache.poi.ss.usermodel.charts.TitleType;
  18. import org.apache.poi.ss.util.CellReference;
  19. import org.apache.poi.util.Removal;
  20. import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
  21. import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerTx;
  22. /**
  23. * Base of all XSSF Chart Series
  24. *
  25. * @deprecated use {@link XDDFChartData.Series} instead
  26. */
  27. @Deprecated
  28. @Removal(version="4.2")
  29. public abstract class AbstractXSSFChartSeries implements ChartSeries {
  30. private String titleValue;
  31. private CellReference titleRef;
  32. private TitleType titleType;
  33. @Override
  34. public void setTitle(CellReference titleReference) {
  35. titleType = TitleType.CELL_REFERENCE;
  36. titleRef = titleReference;
  37. }
  38. @Override
  39. public void setTitle(String title) {
  40. titleType = TitleType.STRING;
  41. titleValue = title;
  42. }
  43. @Override
  44. public CellReference getTitleCellReference() {
  45. if (TitleType.CELL_REFERENCE.equals(titleType)) {
  46. return titleRef;
  47. }
  48. throw new IllegalStateException("Title type is not CellReference.");
  49. }
  50. @Override
  51. public String getTitleString() {
  52. if (TitleType.STRING.equals(titleType)) {
  53. return titleValue;
  54. }
  55. throw new IllegalStateException("Title type is not String.");
  56. }
  57. @Override
  58. public TitleType getTitleType() {
  59. return titleType;
  60. }
  61. protected boolean isTitleSet() {
  62. return titleType != null;
  63. }
  64. protected CTSerTx getCTSerTx() {
  65. CTSerTx tx = CTSerTx.Factory.newInstance();
  66. switch (titleType) {
  67. case CELL_REFERENCE:
  68. tx.addNewStrRef().setF(titleRef.formatAsString());
  69. return tx;
  70. case STRING:
  71. tx.setV(titleValue);
  72. return tx;
  73. default:
  74. throw new IllegalStateException("Unkown title type: " + titleType);
  75. }
  76. }
  77. }