Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2011 IBM. All rights reserved. Use is subject to license terms. Licensed 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. You can also obtain a copy of the License at http://odftoolkit.org/docs/license.txt 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.odftoolkit.simple.chart;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
AbstractChartContainer is an abstract implementation of the ChartContainer interface, with a default implementation for every method defined in ChartContainer.

Since:
0.6
 
 public abstract class AbstractChartContainer implements ChartContainer {
 	private Document mDocument;
 	private Map<StringChartmCharts;
 	private String ROOT_STRING = "./";

The constructor to create a chart container

Parameters:
doc - the onwer document
 
 	protected AbstractChartContainer(Document doc) {
 		try {
 			 = doc;
 			// init chart container by searching the embeded document
 			 = new HashMap<StringChart>();
 			for (Document chartDoc : charts) {
 				OdfContentDom contentDom = chartDoc.getContentDom();
 				ChartChartElement chartEle = (ChartChartElementcontentDom.getXPath().evaluate("//chart:chart[1]",
 						contentDom.);
 				String documentPath = chartDoc.getDocumentPath();
 				.put(documentPathnew Chart(chartEledocumentPath));
 			}
 		} catch (Exception ex) {
 			Logger.getLogger(AbstractChartContainer.class.getName()).log(.nullex);
 		}
 	}

Returns the <draw:frame> element which can contain a chart image object.

Returns:
the draw:frame element
 
 	protected abstract DrawFrameElement getChartFrame() throws Exception;
 
 	public Chart createChart(String titleDataSet datasetRectangle rect) {
 		try {
 			String sName = .getDocumentPath() + "/" + title + "_" + System.currentTimeMillis();
 			// embed this chart document
 			ChartDocument newChartDocument = ChartDocument.newChartDocument();
 			.insertDocument(newChartDocumentsName);
 			OdfContentDom contentDom = newChartDocument.getContentDom();
 			ChartChartElement chartEle = (ChartChartElement) (contentDom.getXPath().evaluate("//chart:chart[1]",
 					contentDom.));
			Chart chart = new Chart(chartElesName);
			chart.setChartTitle(title);
			chart.setUseLegend(true);
			chart.setChartData(dataset);
			if (rect != null) {
				drawFrame.setSvgXAttribute(new Integer(rect.x).toString());
				drawFrame.setSvgYAttribute(new Integer(rect.y).toString());
				drawFrame.setSvgWidthAttribute(new Integer(rect.width).toString());
				drawFrame.setSvgHeightAttribute(new Integer(rect.height).toString());
			}
			DrawObjectElement drawObject = OdfElement.findFirstChildNode(DrawObjectElement.classdrawFrame);
			if(drawObject == null){
				drawObject = drawFrame.newDrawObjectElement();
			}
			if (dataset.getCellRangeAddress() != null){
			}
			drawObject.setXlinkHrefAttribute( + sName);
			drawObject.setXlinkTypeAttribute("simple");
			drawObject.setXlinkShowAttribute("embed");
			drawObject.setXlinkActuateAttribute("onLoad");
			.put(sNamechart);
			return chart;
catch (Exception ex) {
			return null;
		}
	}
	public Chart createChart(String titleSpreadsheetDocument documentCellRangeAddressList cellRangeAddr,
			boolean firstRowAsLabelboolean firstColumnAsLabelboolean rowAsDataSeriesRectangle rect) {
		DataSet dataset = new DataSet(cellRangeAddrdocumentfirstRowAsLabelfirstColumnAsLabelrowAsDataSeries);
		return createChart(titledatasetrect);
	}
	public Chart createChart(String titleString[] labelsString[] legendsdouble[][] dataRectangle rect) {
		DataSet dataset = new DataSet(labelslegendsdata);
		return createChart(titledatasetrect);
	}
	public void deleteChartById(String chartId) {
		try {
			// 1.remove from the container
			.remove(chartId);
			// 2.remove the embedded document
			// 3.remove the draw:frame element in main document
			NodeList frameObjects;
					"object");
			for (int i = 0; i < frameObjects.getLength(); i++) {
				DrawObjectElement object = (DrawObjectElementframeObjects.item(i);
				if (object.getXlinkHrefAttribute().toString().endsWith(chartId)) {
					frame.getParentNode().removeChild(frame);
				}
			}
catch (Exception ex) {
		}
	}
	public void deleteChartByTitle(String title) {
		List<StringdelChartIDList = new ArrayList<String>();
		Set<StringchartSet = .keySet();
		for (String chartIter : chartSet) {
			Chart chart = .get(chartIter);
			if (chart.getChartTitle().equals(title)) {
				delChartIDList.add(chartIter);
			}
		}
		for (int i = 0; i < delChartIDList.size(); i++) {
			deleteChartById(delChartIDList.get(i));
		}
	}
	public Chart getChartById(String chartId) {
		try {
			Document embedChartDoc = .getEmbeddedDocument(chartId);
			if (embedChartDoc != null) {
				OdfContentDom contentDom = embedChartDoc.getContentDom();
				ChartChartElement chartEle = (ChartChartElementcontentDom.getXPath().evaluate("//chart:chart[1]",
						contentDom.);
				Chart chart = new Chart(chartElechartId);
				if (.get(chartId) != null) {
					return chart;
				}
			}
catch (Exception ex) {
		}
		return null;
	}
	public List<ChartgetChartByTitle(String title) {
		List<ChartchartList = new ArrayList<Chart>();
		Set<StringchartSet = .keySet();
		for (String chartIter : chartSet) {
			Chart chart = .get(chartIter);
			if (chart.getChartTitle().equals(title)) {
				chartList.add(chart);
			}
		}
		return chartList;
	}
	public int getChartCount() {
		return cnt;
	}
New to GrepCode? Check out our FAQ X