123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /* ====================================================================
- 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.ChartLegend;
- import org.apache.poi.ss.usermodel.charts.LegendPosition;
- import org.apache.poi.util.Internal;
- import org.apache.poi.util.Removal;
- import org.apache.poi.xddf.usermodel.chart.XDDFChartLegend;
- import org.apache.poi.xssf.usermodel.XSSFChart;
- import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
- import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegend;
- import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegendPos;
- import org.openxmlformats.schemas.drawingml.x2006.chart.STLegendPos;
-
- /**
- * Represents a SpreadsheetML chart legend
- * @deprecated use {@link XDDFChartLegend} instead
- */
- @Deprecated
- @Removal(version="4.2")
- public final class XSSFChartLegend implements ChartLegend {
-
- /**
- * Underlaying CTLagend bean
- */
- private CTLegend legend;
-
- /**
- * Create a new SpreadsheetML chart legend
- */
- public XSSFChartLegend(XSSFChart chart) {
- CTChart ctChart = chart.getCTChart();
- this.legend = (ctChart.isSetLegend()) ?
- ctChart.getLegend() :
- ctChart.addNewLegend();
-
- setDefaults();
- }
-
- /**
- * Set sensible default styling.
- */
- private void setDefaults() {
- if (!legend.isSetOverlay()) {
- legend.addNewOverlay();
- }
- legend.getOverlay().setVal(false);
- }
-
- /**
- * Return the underlying CTLegend bean.
- *
- * @return the underlying CTLegend bean
- */
- @Internal
- public CTLegend getCTLegend(){
- return legend;
- }
-
- @Override
- public void setPosition(LegendPosition position) {
- if (!legend.isSetLegendPos()) {
- legend.addNewLegendPos();
- }
- legend.getLegendPos().setVal(fromLegendPosition(position));
- }
-
- /*
- * According to ECMA-376 default position is RIGHT.
- */
- @Override
- public LegendPosition getPosition() {
- if (legend.isSetLegendPos()) {
- return toLegendPosition(legend.getLegendPos());
- } else {
- return LegendPosition.RIGHT;
- }
- }
-
- @Override
- public XSSFManualLayout getManualLayout() {
- if (!legend.isSetLayout()) {
- legend.addNewLayout();
- }
- return new XSSFManualLayout(legend.getLayout());
- }
-
- @Override
- public boolean isOverlay() {
- return legend.getOverlay().getVal();
- }
-
- @Override
- public void setOverlay(boolean value) {
- legend.getOverlay().setVal(value);
- }
-
- private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
- switch (position) {
- case BOTTOM: return STLegendPos.B;
- case LEFT: return STLegendPos.L;
- case RIGHT: return STLegendPos.R;
- case TOP: return STLegendPos.T;
- case TOP_RIGHT: return STLegendPos.TR;
- default:
- throw new IllegalArgumentException();
- }
- }
-
- private LegendPosition toLegendPosition(CTLegendPos ctLegendPos) {
- switch (ctLegendPos.getVal().intValue()) {
- case STLegendPos.INT_B: return LegendPosition.BOTTOM;
- case STLegendPos.INT_L: return LegendPosition.LEFT;
- case STLegendPos.INT_R: return LegendPosition.RIGHT;
- case STLegendPos.INT_T: return LegendPosition.TOP;
- case STLegendPos.INT_TR: return LegendPosition.TOP_RIGHT;
- default:
- throw new IllegalArgumentException();
- }
- }
- }
|