1*04813259SLiu Zhe /************************************************************** 2*04813259SLiu Zhe * 3*04813259SLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 4*04813259SLiu Zhe * or more contributor license agreements. See the NOTICE file 5*04813259SLiu Zhe * distributed with this work for additional information 6*04813259SLiu Zhe * regarding copyright ownership. The ASF licenses this file 7*04813259SLiu Zhe * to you under the Apache License, Version 2.0 (the 8*04813259SLiu Zhe * "License"); you may not use this file except in compliance 9*04813259SLiu Zhe * with the License. You may obtain a copy of the License at 10*04813259SLiu Zhe * 11*04813259SLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 12*04813259SLiu Zhe * 13*04813259SLiu Zhe * Unless required by applicable law or agreed to in writing, 14*04813259SLiu Zhe * software distributed under the License is distributed on an 15*04813259SLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*04813259SLiu Zhe * KIND, either express or implied. See the License for the 17*04813259SLiu Zhe * specific language governing permissions and limitations 18*04813259SLiu Zhe * under the License. 19*04813259SLiu Zhe * 20*04813259SLiu Zhe *************************************************************/ 21*04813259SLiu Zhe package testlib.uno; 22*04813259SLiu Zhe 23*04813259SLiu Zhe import com.sun.star.beans.XPropertySet; 24*04813259SLiu Zhe import com.sun.star.chart.XChartDocument; 25*04813259SLiu Zhe import com.sun.star.chart.XDiagram; 26*04813259SLiu Zhe import com.sun.star.drawing.XShape; 27*04813259SLiu Zhe import com.sun.star.lang.XMultiServiceFactory; 28*04813259SLiu Zhe import com.sun.star.uno.UnoRuntime; 29*04813259SLiu Zhe 30*04813259SLiu Zhe public class ChartUtil { 31*04813259SLiu Zhe 32*04813259SLiu Zhe /** 33*04813259SLiu Zhe * Retrieve Chart document as model of the OLE Shape(use to create chart) 34*04813259SLiu Zhe * @param xShape 35*04813259SLiu Zhe * @return 36*04813259SLiu Zhe * @throws Exception 37*04813259SLiu Zhe */ 38*04813259SLiu Zhe public static XChartDocument retrieveChartDocument(XShape xShape)throws Exception{ 39*04813259SLiu Zhe XChartDocument aChartDoc = null; 40*04813259SLiu Zhe final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; 41*04813259SLiu Zhe // make the OLE shape a chart 42*04813259SLiu Zhe XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 43*04813259SLiu Zhe XPropertySet.class, xShape); 44*04813259SLiu Zhe // set the class id for charts 45*04813259SLiu Zhe aShapeProp.setPropertyValue("CLSID", msChartClassID); 46*04813259SLiu Zhe // retrieve the chart document as model of the OLE shape 47*04813259SLiu Zhe aChartDoc = (XChartDocument) UnoRuntime.queryInterface( 48*04813259SLiu Zhe XChartDocument.class, aShapeProp.getPropertyValue("Model")); 49*04813259SLiu Zhe return aChartDoc; 50*04813259SLiu Zhe } 51*04813259SLiu Zhe 52*04813259SLiu Zhe /** 53*04813259SLiu Zhe * Create Chart in ChartDocument. 54*04813259SLiu Zhe * @param aChartDoc 55*04813259SLiu Zhe * @param ChartType 56*04813259SLiu Zhe * @return 57*04813259SLiu Zhe * @throws Exception 58*04813259SLiu Zhe */ 59*04813259SLiu Zhe public static XDiagram createChart(XChartDocument aChartDoc, String ChartType) 60*04813259SLiu Zhe throws Exception { 61*04813259SLiu Zhe 62*04813259SLiu Zhe // let aChartDoc be a valid XChartDocument 63*04813259SLiu Zhe // get the factory that can create diagrams 64*04813259SLiu Zhe XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime 65*04813259SLiu Zhe .queryInterface(XMultiServiceFactory.class, aChartDoc); 66*04813259SLiu Zhe XDiagram aDiagram = (XDiagram) UnoRuntime.queryInterface( 67*04813259SLiu Zhe XDiagram.class, aFact.createInstance(ChartType)); 68*04813259SLiu Zhe return aDiagram; 69*04813259SLiu Zhe } 70*04813259SLiu Zhe 71*04813259SLiu Zhe 72*04813259SLiu Zhe /** 73*04813259SLiu Zhe * Get Chart Doc from a Shape 74*04813259SLiu Zhe * @param xShape 75*04813259SLiu Zhe * @return 76*04813259SLiu Zhe * @throws Exception 77*04813259SLiu Zhe */ 78*04813259SLiu Zhe public static XChartDocument getChartDocument(XShape xShape)throws Exception{ 79*04813259SLiu Zhe XChartDocument aChartDoc = null; 80*04813259SLiu Zhe XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( 81*04813259SLiu Zhe XPropertySet.class, xShape); 82*04813259SLiu Zhe // retrieve the chart document as model of the OLE shape 83*04813259SLiu Zhe aChartDoc = (XChartDocument) UnoRuntime.queryInterface( 84*04813259SLiu Zhe XChartDocument.class, aShapeProp.getPropertyValue("Model")); 85*04813259SLiu Zhe return aChartDoc; 86*04813259SLiu Zhe 87*04813259SLiu Zhe } 88*04813259SLiu Zhe } 89