You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/04/03 17:04:54 UTC
svn commit: r644343 - in /poi/trunk/src:
scratchpad/src/org/apache/poi/hssf/usermodel/
scratchpad/testcases/org/apache/poi/hssf/usermodel/
testcases/org/apache/poi/hssf/data/
Author: nick
Date: Thu Apr 3 08:04:52 2008
New Revision: 644343
URL: http://svn.apache.org/viewvc?rev=644343&view=rev
Log:
Make a bit of a start on being able to edit chart titles, based on the email to user@poi from Russ on the 2nd of April. Not quite there though
Added:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/
poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xls (with props)
poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xlsx (with props)
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java?rev=644343&r1=644342&r2=644343&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java Thu Apr 3 08:04:52 2008
@@ -23,6 +23,7 @@
import org.apache.poi.hssf.record.formula.Area3DPtg;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Stack;
@@ -33,6 +34,15 @@
*/
public class HSSFChart
{
+ private ChartRecord chartRecord;
+ private SeriesRecord seriesRecord;
+
+ private ChartTitleFormatRecord chartTitleFormat;
+ private SeriesTextRecord chartTitleText;
+
+ private HSSFChart(ChartRecord chartRecord) {
+ this.chartRecord = chartRecord;
+ }
/**
* Creates a bar chart. API needs some work. :)
@@ -107,6 +117,74 @@
sheet.insertChartRecords( records );
workbook.insertChartRecord();
}
+
+ /**
+ * Returns all the charts for the given sheet.
+ *
+ * NOTE: Does not yet work... checking it in just so others
+ * can take a look.
+ */
+ public static HSSFChart[] getSheetCharts(HSSFSheet sheet) {
+ List charts = new ArrayList();
+ HSSFChart lastChart = null;
+
+ // Find records of interest
+ List records = sheet.getSheet().getRecords();
+ for(Iterator it = records.iterator(); it.hasNext();) {
+ Record r = (Record)it.next();
+ System.err.println(r);
+
+ if(r instanceof DrawingRecord) {
+ DrawingRecord dr = (DrawingRecord)r;
+ }
+
+ if(r instanceof ChartRecord) {
+ lastChart = new HSSFChart((ChartRecord)r);
+ charts.add(lastChart);
+ }
+ if(r instanceof SeriesRecord) {
+ lastChart.seriesRecord = (SeriesRecord)r;
+ }
+ if(r instanceof ChartTitleFormatRecord) {
+ lastChart.chartTitleFormat =
+ (ChartTitleFormatRecord)r;
+ }
+ if(r instanceof SeriesTextRecord) {
+ lastChart.chartTitleText =
+ (SeriesTextRecord)r;
+ }
+ }
+
+ return (HSSFChart[])
+ charts.toArray( new HSSFChart[charts.size()] );
+ }
+
+
+ /**
+ * Returns the chart's title, if there is one,
+ * or null if not
+ */
+ public String getChartTitle() {
+ if(chartTitleText != null) {
+ return chartTitleText.getText();
+ }
+ return null;
+ }
+
+ /**
+ * Changes the chart's title, but only if there
+ * was one already.
+ * TODO - add in the records if not
+ */
+ public void setChartTitle(String title) {
+ if(chartTitleText != null) {
+ chartTitleText.setText(title);
+ } else {
+ throw new IllegalStateException("No chart title found to change");
+ }
+ }
+
+
private EOFRecord createEOFRecord()
{
Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java?rev=644343&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java Thu Apr 3 08:04:52 2008
@@ -0,0 +1,61 @@
+/* ====================================================================
+ 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.hssf.usermodel;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import junit.framework.TestCase;
+
+public class TestHSSFChart extends TestCase {
+ private String dirName;
+
+ protected void setUp() throws Exception {
+ dirName = System.getProperty("HSSF.testdata.path");
+ }
+
+ public void testSingleChart() throws Exception {
+
+ }
+
+ public void testTwoCharts() throws Exception {
+
+ }
+
+ public void BROKENtestThreeCharts() throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook(
+ new FileInputStream(new File(dirName, "WithThreeCharts.xls"))
+ );
+
+ HSSFSheet s1 = wb.getSheetAt(0);
+ HSSFSheet s2 = wb.getSheetAt(1);
+ HSSFSheet s3 = wb.getSheetAt(2);
+
+ assertEquals(0, HSSFChart.getSheetCharts(s1).length);
+ assertEquals(2, HSSFChart.getSheetCharts(s2).length);
+ assertEquals(1, HSSFChart.getSheetCharts(s3).length);
+
+ HSSFChart[] charts;
+
+ charts = HSSFChart.getSheetCharts(s2);
+ assertNull(charts[0].getChartTitle());
+ assertEquals("Pie Chart Title Thingy", charts[1].getChartTitle());
+
+ charts = HSSFChart.getSheetCharts(s3);
+ assertEquals("Sheet 3 Chart with Title", charts[1].getChartTitle());
+ }
+}
Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestHSSFChart.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xls?rev=644343&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xls
------------------------------------------------------------------------------
svn:executable = *
Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xls
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xlsx?rev=644343&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xlsx
------------------------------------------------------------------------------
svn:executable = *
Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/WithThreeCharts.xlsx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org