Author: cedricwalter
Date: Tue Nov  5 22:35:54 2013
New Revision: 1539169

URL: http://svn.apache.org/r1539169
Log:
Bug 54696: Add overlay setting to ChartLegend

Modified:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java
    
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java?rev=1539169&r1=1539168&r2=1539169&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java Tue 
Nov  5 22:35:54 2013
@@ -23,10 +23,11 @@ import org.apache.poi.util.Beta;
  * High level representation of chart legend.
  *
  * @author Roman Kashitsyn
+ * @author Martin Andersson
  */
 @Beta
 public interface ChartLegend extends ManuallyPositionable {
-       
+
        /**
         * @return legend position
         */
@@ -36,4 +37,19 @@ public interface ChartLegend extends Man
         * @param position new legend position
         */
        void setPosition(LegendPosition position);
+
+       /**
+        * @return overlay value.
+        */
+       boolean isOverlay();
+
+       /**
+        * If true the legend is positioned over the chart area otherwise
+        * the legend is displayed next to it.
+        *
+        * Default is no overlay.
+        *
+        * @param value
+        */
+       void setOverlay(boolean value);
 }

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java?rev=1539169&r1=1539168&r2=1539169&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java
 (original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartLegend.java
 Tue Nov  5 22:35:54 2013
@@ -30,6 +30,7 @@ import org.openxmlformats.schemas.drawin
 /**
  * Represents a SpreadsheetML chart legend
  * @author Roman Kashitsyn
+ * @author Martin Andersson
  */
 @Beta
 public final class XSSFChartLegend implements ChartLegend {
@@ -47,6 +48,18 @@ public final class XSSFChartLegend imple
                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);
        }
 
        /**
@@ -84,6 +97,14 @@ public final class XSSFChartLegend imple
                return new XSSFManualLayout(legend.getLayout());
        }
 
+       public boolean isOverlay() {
+               return legend.getOverlay().getVal();
+       }
+
+       public void setOverlay(boolean value) {
+               legend.getOverlay().setVal(value);
+       }
+
        private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
                switch (position) {
                        case BOTTOM: return STLegendPos.B;

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java?rev=1539169&r1=1539168&r2=1539169&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
 (original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartLegend.java
 Tue Nov  5 22:35:54 2013
@@ -24,8 +24,14 @@ import org.apache.poi.ss.usermodel.chart
 import org.apache.poi.ss.usermodel.charts.LegendPosition;
 import org.apache.poi.xssf.usermodel.*;
 
+/**
+ * Tests ChartLegend
+ *
+ * @author Martin Andersson
+ * @author Cedric dot Walter at gmail dot com
+ */
 public final class TestXSSFChartLegend extends TestCase {
- 
+
        public void testLegendPositionAccessMethods() throws Exception {
                Workbook wb = new XSSFWorkbook();
                Sheet sheet = wb.createSheet();
@@ -37,4 +43,35 @@ public final class TestXSSFChartLegend e
                legend.setPosition(LegendPosition.TOP_RIGHT);
                assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
        }
+
+    public void 
test_setOverlay_defaultChartLegend_expectOverlayInitialValueSetToFalse() {
+        // Arrange
+        Workbook wb = new XSSFWorkbook();
+        Sheet sheet = wb.createSheet();
+        Drawing drawing = sheet.createDrawingPatriarch();
+        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+        Chart chart = drawing.createChart(anchor);
+        ChartLegend legend = chart.getOrCreateLegend();
+
+        // Act
+
+        // Assert
+        assertFalse(legend.isOverlay());
+    }
+
+       public void 
test_setOverlay_chartLegendSetToTrue_expectOverlayInitialValueSetToTrue() {
+        // Arrange
+        Workbook wb = new XSSFWorkbook();
+               Sheet sheet = wb.createSheet();
+               Drawing drawing = sheet.createDrawingPatriarch();
+               ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 
10, 30);
+               Chart chart = drawing.createChart(anchor);
+               ChartLegend legend = chart.getOrCreateLegend();
+
+        // Act
+               legend.setOverlay(true);
+
+        // Assert
+        assertTrue(legend.isOverlay());
+       }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to