1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sch; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.SOfficeFactory; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 35cdf0e10cSrcweir import com.sun.star.chart.XChartDataArray; 36cdf0e10cSrcweir import com.sun.star.chart.XChartDocument; 37cdf0e10cSrcweir import com.sun.star.chart.XDiagram; 38cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 39cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 40cdf0e10cSrcweir import com.sun.star.document.XEmbeddedObjectSupplier; 41cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 42cdf0e10cSrcweir import com.sun.star.sheet.XCellRangeAddressable; 43cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 44cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 45cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets; 46cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress; 47cdf0e10cSrcweir import com.sun.star.table.XCell; 48cdf0e10cSrcweir import com.sun.star.table.XCellRange; 49cdf0e10cSrcweir import com.sun.star.table.XTableChart; 50cdf0e10cSrcweir import com.sun.star.table.XTableCharts; 51cdf0e10cSrcweir import com.sun.star.table.XTableChartsSupplier; 52cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 53cdf0e10cSrcweir import com.sun.star.uno.Type; 54cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 55cdf0e10cSrcweir import com.sun.star.uno.XInterface; 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** 58cdf0e10cSrcweir * Test for object which is represented by the following services: 59cdf0e10cSrcweir * <ul> 60cdf0e10cSrcweir * <li> <code>com.sun.star.chart.Dim3DDiagram</code> </li> 61cdf0e10cSrcweir * <li> <code>com.sun.star.chart.StockDiagram</code> </li> 62cdf0e10cSrcweir * <li> <code>com.sun.star.chart.LineDiagram</code> </li> 63cdf0e10cSrcweir * <li> <code>com.sun.star.chart.BarDiagram</code> </li> 64cdf0e10cSrcweir * <li> <code>com.sun.star.chart.StackableDiagram</code> </li> 65cdf0e10cSrcweir * </ul> 66cdf0e10cSrcweir * <p> 67cdf0e10cSrcweir * Object implements the following interfaces : 68cdf0e10cSrcweir * <ul> 69cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XDiagram</code></li> 70cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartAxisXSupplier</code></li> 71cdf0e10cSrcweir * <li> <code>com::sun::star::chart::Dim3DDiagram</code></li> 72cdf0e10cSrcweir * <li> <code>com::sun::star::chart::StockDiagram</code></li> 73cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartAxisZSupplier</code></li> 74cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XTwoAxisXSupplier</code></li> 75cdf0e10cSrcweir * <li> <code>com::sun::star::chart::LineDiagram</code></li> 76cdf0e10cSrcweir * <li> <code>com::sun::star::chart::BarDiagram</code></li> 77cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XAxisYSupplier</code></li> 78cdf0e10cSrcweir * <li> <code>com::sun::star::chart::Diagram</code></li> 79cdf0e10cSrcweir * <li> <code>com::sun::star::chart::X3DDisplay</code></li> 80cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartTwoAxisYSupplier</code></li> 81cdf0e10cSrcweir * <li> <code>com::sun::star::chart::StackableDiagram</code></li> 82cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartAxisYSupplier</code></li> 83cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XAxisXSupplier</code></li> 84cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartTwoAxisXSupplier</code></li> 85cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XShape</code></li> 86cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XTwoAxisYSupplier</code></li> 87cdf0e10cSrcweir * <li> <code>com::sun::star::chart::ChartStatistics</code></li> 88cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 89cdf0e10cSrcweir * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 90cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XAxisZSupplier</code></li> 91cdf0e10cSrcweir * <li> <code>com::sun::star::chart::XStatisticDisplay</code></li> 92cdf0e10cSrcweir * </ul> 93cdf0e10cSrcweir * @see com.sun.star.chart.XDiagram 94cdf0e10cSrcweir * @see com.sun.star.chart.ChartAxisXSupplier 95cdf0e10cSrcweir * @see com.sun.star.chart.Dim3DDiagram 96cdf0e10cSrcweir * @see com.sun.star.chart.StockDiagram 97cdf0e10cSrcweir * @see com.sun.star.chart.ChartAxisZSupplier 98cdf0e10cSrcweir * @see com.sun.star.chart.XTwoAxisXSupplier 99cdf0e10cSrcweir * @see com.sun.star.chart.LineDiagram 100cdf0e10cSrcweir * @see com.sun.star.chart.BarDiagram 101cdf0e10cSrcweir * @see com.sun.star.chart.XAxisYSupplier 102cdf0e10cSrcweir * @see com.sun.star.chart.Diagram 103cdf0e10cSrcweir * @see com.sun.star.chart.X3DDisplay 104cdf0e10cSrcweir * @see com.sun.star.chart.ChartTwoAxisYSupplier 105cdf0e10cSrcweir * @see com.sun.star.chart.StackableDiagram 106cdf0e10cSrcweir * @see com.sun.star.chart.ChartAxisYSupplier 107cdf0e10cSrcweir * @see com.sun.star.chart.XAxisXSupplier 108cdf0e10cSrcweir * @see com.sun.star.chart.ChartTwoAxisXSupplier 109cdf0e10cSrcweir * @see com.sun.star.drawing.XShape 110cdf0e10cSrcweir * @see com.sun.star.chart.XTwoAxisYSupplier 111cdf0e10cSrcweir * @see com.sun.star.chart.ChartStatistics 112cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 113cdf0e10cSrcweir * @see com.sun.star.drawing.XShapeDescriptor 114cdf0e10cSrcweir * @see com.sun.star.chart.XAxisZSupplier 115cdf0e10cSrcweir * @see com.sun.star.chart.XStatisticDisplay 116cdf0e10cSrcweir * @see ifc.chart._XDiagram 117cdf0e10cSrcweir * @see ifc.chart._ChartAxisXSupplier 118cdf0e10cSrcweir * @see ifc.chart._Dim3DDiagram 119cdf0e10cSrcweir * @see ifc.chart._StockDiagram 120cdf0e10cSrcweir * @see ifc.chart._ChartAxisZSupplier 121cdf0e10cSrcweir * @see ifc.chart._XTwoAxisXSupplier 122cdf0e10cSrcweir * @see ifc.chart._LineDiagram 123cdf0e10cSrcweir * @see ifc.chart._BarDiagram 124cdf0e10cSrcweir * @see ifc.chart._XAxisYSupplier 125cdf0e10cSrcweir * @see ifc.chart._Diagram 126cdf0e10cSrcweir * @see ifc.chart._X3DDisplay 127cdf0e10cSrcweir * @see ifc.chart._ChartTwoAxisYSupplier 128cdf0e10cSrcweir * @see ifc.chart._StackableDiagram 129cdf0e10cSrcweir * @see ifc.chart._ChartAxisYSupplier 130cdf0e10cSrcweir * @see ifc.chart._XAxisXSupplier 131cdf0e10cSrcweir * @see ifc.chart._ChartTwoAxisXSupplier 132cdf0e10cSrcweir * @see ifc.drawing._XShape 133cdf0e10cSrcweir * @see ifc.chart._XTwoAxisYSupplier 134cdf0e10cSrcweir * @see ifc.chart._ChartStatistics 135cdf0e10cSrcweir * @see ifc.beans._XPropertySet 136cdf0e10cSrcweir * @see ifc.drawing._XShapeDescriptor 137cdf0e10cSrcweir * @see ifc.chart._XAxisZSupplier 138cdf0e10cSrcweir * @see ifc.chart._XStatisticDisplay 139cdf0e10cSrcweir */ 140cdf0e10cSrcweir public class ChXDiagram extends TestCase { 141cdf0e10cSrcweir XSpreadsheetDocument xSheetDoc = null; 142cdf0e10cSrcweir 143cdf0e10cSrcweir /** 144cdf0e10cSrcweir * Creates Spreadsheet document. 145cdf0e10cSrcweir */ 146cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 147cdf0e10cSrcweir // get a soffice factory object 148cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 149cdf0e10cSrcweir 150cdf0e10cSrcweir try { 151cdf0e10cSrcweir log.println( "creating a sheetdocument" ); 152cdf0e10cSrcweir xSheetDoc = SOF.createCalcDoc(null);; 153cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 154cdf0e10cSrcweir // Some exception occures.FAILED 155cdf0e10cSrcweir e.printStackTrace( log ); 156cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir /** 161cdf0e10cSrcweir * Disposes Spreadsheet document. 162cdf0e10cSrcweir */ 163cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 164cdf0e10cSrcweir log.println( " closing xSheetDoc " ); 165cdf0e10cSrcweir util.DesktopTools.closeDoc(xSheetDoc); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir /** 169cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 170cdf0e10cSrcweir * Retrieves a collection of spreadsheets from a document 171cdf0e10cSrcweir * and takes one of them. Inserts some values into the cells of the some cell 172cdf0e10cSrcweir * range address. Adds and retrieves the chart that using the data from 173cdf0e10cSrcweir * the cells of this cell range address. Obtains the chart document which is 174cdf0e10cSrcweir * embedded into the retrieved chart using the interface 175cdf0e10cSrcweir * <code>XEmbeddedObjectSupplier</code>. Retrieves the diagram from 176cdf0e10cSrcweir * the obtained chart document. The retrieved diagram is the instance of 177cdf0e10cSrcweir * the service <code>com.sun.star.chart.Diagram</code>. 178cdf0e10cSrcweir * Obtains the data source of the chart from the chart document. 179cdf0e10cSrcweir * Creates a stock-diagram, a bar-diagram, a XY-diagram and line-diagram 180cdf0e10cSrcweir * that are the instances of the following services: 181cdf0e10cSrcweir * <ul> 182cdf0e10cSrcweir * <li> <code>com.sun.star.chart.StockDiagram</code> </li> 183cdf0e10cSrcweir * <li> <code>com.sun.star.chart.BarDiagram</code> </li> 184cdf0e10cSrcweir * <li> <code>com.sun.star.chart.LineDiagram</code> </li> 185cdf0e10cSrcweir * <li> <code>com.sun.star.chart.StackableDiagram</code> </li> 186cdf0e10cSrcweir * </ul>. 187cdf0e10cSrcweir * Object relations created : 188cdf0e10cSrcweir * <ul> 189cdf0e10cSrcweir * <li> <code>'CHARTDOC'</code> for 190cdf0e10cSrcweir * {@link ifc.chart._Dim3DDiagram}, {@link ifc.chart._StockDiagram}, 191cdf0e10cSrcweir * {@link ifc.chart._ChartAxisZSupplier}, {@link _LineDiagram}, 192cdf0e10cSrcweir * {@link ifc.chart._BarDiagram}, {@link ifc.chart._Diagram}, 193cdf0e10cSrcweir * {@link ifc.chart._ChartTwoAxisYSupplier}, 194cdf0e10cSrcweir * {@link ifc.chart._StackableDiagram}, {@link ifc.chart._Diagram}, 195cdf0e10cSrcweir * {@link ifc.chart._ChartAxisYSupplier}, 196cdf0e10cSrcweir * {@link ifc.chart._ChartTwoAxisXSupplier}, 197cdf0e10cSrcweir * {@link ifc.chart._ChartStatistics} (the obtained chart document)</li> 198cdf0e10cSrcweir * <li> <code>'ROWAMOUNT', 'COLAMOUNT'</code> for 199cdf0e10cSrcweir * {@link ifc.chart._XDiagram}(the number of chart columns and 200cdf0e10cSrcweir * the number of chart rows) </li> 201cdf0e10cSrcweir * <li> <code>'STOCK'</code> for 202cdf0e10cSrcweir * {@link ifc.chart._StockDiagram}(the created stock-diagram) </li> 203cdf0e10cSrcweir * <li> <code>'BAR'</code> for 204cdf0e10cSrcweir * {@link ifc.chart._BarDiagram}, {@link ifc.chart._ChartAxisZSupplier}, 205cdf0e10cSrcweir * {@link ifc.chart._ChartTwoAxisXSupplier}, 206cdf0e10cSrcweir * {@link ifc.chart._ChartTwoAxisYSupplier}(the created bar-diagram)</li> 207cdf0e10cSrcweir * <li> <code>'LINE'</code> for 208cdf0e10cSrcweir * {@link ifc.chart._LineDiagram}(the created XY-diagram) </li> 209cdf0e10cSrcweir * <li> <code>'STACK'</code> for 210cdf0e10cSrcweir * {@link ifc.chart._StackableDiagram}(the created Line-diagram) </li> 211cdf0e10cSrcweir * </ul> 212cdf0e10cSrcweir * @see com.sun.star.document.XEmbeddedObjectSupplier 213cdf0e10cSrcweir * @see com.sun.star.chart.Diagram 214cdf0e10cSrcweir * @see com.sun.star.chart.StockDiagram 215cdf0e10cSrcweir */ 216cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment 217cdf0e10cSrcweir (TestParameters Param, PrintWriter log) { 218cdf0e10cSrcweir 219cdf0e10cSrcweir XSpreadsheet oSheet=null; 220cdf0e10cSrcweir XChartDocument xChartDoc=null; 221cdf0e10cSrcweir XDiagram oObj = null; 222cdf0e10cSrcweir 223cdf0e10cSrcweir System.out.println("Getting spreadsheet") ; 224cdf0e10cSrcweir XSpreadsheets oSheets = xSheetDoc.getSheets() ; 225cdf0e10cSrcweir XIndexAccess oIndexSheets = (XIndexAccess) 226cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class, oSheets); 227cdf0e10cSrcweir try { 228cdf0e10cSrcweir oSheet = (XSpreadsheet) AnyConverter.toObject( 229cdf0e10cSrcweir new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0)); 230cdf0e10cSrcweir } catch(com.sun.star.lang.WrappedTargetException e) { 231cdf0e10cSrcweir e.printStackTrace(log); 232cdf0e10cSrcweir throw new StatusException("Couldn't get sheet", e); 233cdf0e10cSrcweir } catch(com.sun.star.lang.IndexOutOfBoundsException e) { 234cdf0e10cSrcweir e.printStackTrace(log); 235cdf0e10cSrcweir throw new StatusException("Couldn't get sheet", e); 236cdf0e10cSrcweir } catch(com.sun.star.lang.IllegalArgumentException e) { 237cdf0e10cSrcweir e.printStackTrace(log); 238cdf0e10cSrcweir throw new StatusException("Couldn't get sheet", e); 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir log.println("Creating the Header") ; 242cdf0e10cSrcweir 243cdf0e10cSrcweir insertIntoCell(1,0,"JAN",oSheet,""); 244cdf0e10cSrcweir insertIntoCell(2,0,"FEB",oSheet,""); 245cdf0e10cSrcweir insertIntoCell(3,0,"MAR",oSheet,""); 246cdf0e10cSrcweir insertIntoCell(4,0,"APR",oSheet,""); 247cdf0e10cSrcweir insertIntoCell(5,0,"MAI",oSheet,""); 248cdf0e10cSrcweir insertIntoCell(6,0,"JUN",oSheet,""); 249cdf0e10cSrcweir insertIntoCell(7,0,"JUL",oSheet,""); 250cdf0e10cSrcweir insertIntoCell(8,0,"AUG",oSheet,""); 251cdf0e10cSrcweir insertIntoCell(9,0,"SEP",oSheet,""); 252cdf0e10cSrcweir insertIntoCell(10,0,"OCT",oSheet,""); 253cdf0e10cSrcweir insertIntoCell(11,0,"NOV",oSheet,""); 254cdf0e10cSrcweir insertIntoCell(12,0,"DEC",oSheet,""); 255cdf0e10cSrcweir insertIntoCell(13,0,"SUM",oSheet,""); 256cdf0e10cSrcweir 257cdf0e10cSrcweir log.println("Fill the lines"); 258cdf0e10cSrcweir 259cdf0e10cSrcweir insertIntoCell(0,1,"Smith",oSheet,""); 260cdf0e10cSrcweir insertIntoCell(1,1,"42",oSheet,"V"); 261cdf0e10cSrcweir insertIntoCell(2,1,"58.9",oSheet,"V"); 262cdf0e10cSrcweir insertIntoCell(3,1,"-66.5",oSheet,"V"); 263cdf0e10cSrcweir insertIntoCell(4,1,"43.4",oSheet,"V"); 264cdf0e10cSrcweir insertIntoCell(5,1,"44.5",oSheet,"V"); 265cdf0e10cSrcweir insertIntoCell(6,1,"45.3",oSheet,"V"); 266cdf0e10cSrcweir insertIntoCell(7,1,"-67.3",oSheet,"V"); 267cdf0e10cSrcweir insertIntoCell(8,1,"30.5",oSheet,"V"); 268cdf0e10cSrcweir insertIntoCell(9,1,"23.2",oSheet,"V"); 269cdf0e10cSrcweir insertIntoCell(10,1,"-97.3",oSheet,"V"); 270cdf0e10cSrcweir insertIntoCell(11,1,"22.4",oSheet,"V"); 271cdf0e10cSrcweir insertIntoCell(12,1,"23.5",oSheet,"V"); 272cdf0e10cSrcweir insertIntoCell(13,1,"=SUM(B2:M2)",oSheet,""); 273cdf0e10cSrcweir 274cdf0e10cSrcweir insertIntoCell(0,2,"Jones",oSheet,""); 275cdf0e10cSrcweir insertIntoCell(1,2,"21",oSheet,"V"); 276cdf0e10cSrcweir insertIntoCell(2,2,"40.9",oSheet,"V"); 277cdf0e10cSrcweir insertIntoCell(3,2,"-57.5",oSheet,"V"); 278cdf0e10cSrcweir insertIntoCell(4,2,"-23.4",oSheet,"V"); 279cdf0e10cSrcweir insertIntoCell(5,2,"34.5",oSheet,"V"); 280cdf0e10cSrcweir insertIntoCell(6,2,"59.3",oSheet,"V"); 281cdf0e10cSrcweir insertIntoCell(7,2,"27.3",oSheet,"V"); 282cdf0e10cSrcweir insertIntoCell(8,2,"-38.5",oSheet,"V"); 283cdf0e10cSrcweir insertIntoCell(9,2,"43.2",oSheet,"V"); 284cdf0e10cSrcweir insertIntoCell(10,2,"57.3",oSheet,"V"); 285cdf0e10cSrcweir insertIntoCell(11,2,"25.4",oSheet,"V"); 286cdf0e10cSrcweir insertIntoCell(12,2,"28.5",oSheet,"V"); 287cdf0e10cSrcweir insertIntoCell(13,2,"=SUM(B3:M3)",oSheet,""); 288cdf0e10cSrcweir 289cdf0e10cSrcweir insertIntoCell(0,3,"Brown",oSheet,""); 290cdf0e10cSrcweir insertIntoCell(1,3,"31.45",oSheet,"V"); 291cdf0e10cSrcweir insertIntoCell(2,3,"-20.9",oSheet,"V"); 292cdf0e10cSrcweir insertIntoCell(3,3,"-117.5",oSheet,"V"); 293cdf0e10cSrcweir insertIntoCell(4,3,"23.4",oSheet,"V"); 294cdf0e10cSrcweir insertIntoCell(5,3,"-114.5",oSheet,"V"); 295cdf0e10cSrcweir insertIntoCell(6,3,"115.3",oSheet,"V"); 296cdf0e10cSrcweir insertIntoCell(7,3,"-171.3",oSheet,"V"); 297cdf0e10cSrcweir insertIntoCell(8,3,"89.5",oSheet,"V"); 298cdf0e10cSrcweir insertIntoCell(9,3,"41.2",oSheet,"V"); 299cdf0e10cSrcweir insertIntoCell(10,3,"71.3",oSheet,"V"); 300cdf0e10cSrcweir insertIntoCell(11,3,"25.4",oSheet,"V"); 301cdf0e10cSrcweir insertIntoCell(12,3,"38.5",oSheet,"V"); 302cdf0e10cSrcweir insertIntoCell(13,3,"=SUM(A4:L4)",oSheet,""); 303cdf0e10cSrcweir 304cdf0e10cSrcweir // insert a chart 305cdf0e10cSrcweir Rectangle oRect = new Rectangle(500, 3000, 25000, 11000); 306cdf0e10cSrcweir 307cdf0e10cSrcweir XCellRange oRange = (XCellRange) 308cdf0e10cSrcweir UnoRuntime.queryInterface(XCellRange.class, oSheet); 309cdf0e10cSrcweir XCellRange myRange = oRange.getCellRangeByName("A1:N4"); 310cdf0e10cSrcweir XCellRangeAddressable oRangeAddr = (XCellRangeAddressable) 311cdf0e10cSrcweir UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange); 312cdf0e10cSrcweir CellRangeAddress myAddr = oRangeAddr.getRangeAddress(); 313cdf0e10cSrcweir 314cdf0e10cSrcweir CellRangeAddress[] oAddr = new CellRangeAddress[1]; 315cdf0e10cSrcweir oAddr[0] = myAddr; 316cdf0e10cSrcweir XTableChartsSupplier oSupp = (XTableChartsSupplier) 317cdf0e10cSrcweir UnoRuntime.queryInterface(XTableChartsSupplier.class, oSheet); 318cdf0e10cSrcweir 319cdf0e10cSrcweir log.println("Insert Chart"); 320cdf0e10cSrcweir XTableCharts oCharts = oSupp.getCharts(); 321cdf0e10cSrcweir 322cdf0e10cSrcweir 323cdf0e10cSrcweir if (!oCharts.hasByName("ChXDiagram")) { 324cdf0e10cSrcweir oCharts.addNewByName("ChXDiagram", oRect, oAddr, true, true); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir // get the TableChart 328cdf0e10cSrcweir XTableChart oChart = null; 329cdf0e10cSrcweir try { 330cdf0e10cSrcweir oChart = (XTableChart) AnyConverter.toObject( 331cdf0e10cSrcweir new Type(XTableChart.class),((XNameAccess) 332cdf0e10cSrcweir UnoRuntime.queryInterface( 333cdf0e10cSrcweir XNameAccess.class, oCharts)).getByName("ChXDiagram")); 334cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 335cdf0e10cSrcweir e.printStackTrace(log); 336cdf0e10cSrcweir throw new StatusException("Couldn't get TableChart", e); 337cdf0e10cSrcweir } catch (com.sun.star.container.NoSuchElementException e) { 338cdf0e10cSrcweir e.printStackTrace(log); 339cdf0e10cSrcweir throw new StatusException("Couldn't get TableChart", e); 340cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 341cdf0e10cSrcweir e.printStackTrace(log); 342cdf0e10cSrcweir throw new StatusException("Couldn't get TableChart", e); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir XEmbeddedObjectSupplier oEOS = (XEmbeddedObjectSupplier) 346cdf0e10cSrcweir UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart); 347cdf0e10cSrcweir XInterface oInt = oEOS.getEmbeddedObject(); 348cdf0e10cSrcweir xChartDoc = (XChartDocument) 349cdf0e10cSrcweir UnoRuntime.queryInterface(XChartDocument.class,oInt); 350cdf0e10cSrcweir oObj = (XDiagram) xChartDoc.getDiagram(); 351cdf0e10cSrcweir 352cdf0e10cSrcweir log.println( "creating a new environment for chartdocument object" ); 353cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 354cdf0e10cSrcweir 355cdf0e10cSrcweir log.println( "adding ChartDocument as mod relation to environment" ); 356cdf0e10cSrcweir tEnv.addObjRelation("CHARTDOC", xChartDoc); 357cdf0e10cSrcweir 358cdf0e10cSrcweir XChartDataArray da = (XChartDataArray) 359cdf0e10cSrcweir UnoRuntime.queryInterface(XChartDataArray.class, xChartDoc.getData()); 360cdf0e10cSrcweir int cols = da.getColumnDescriptions().length; 361cdf0e10cSrcweir int rows = da.getRowDescriptions().length; 362cdf0e10cSrcweir 363cdf0e10cSrcweir tEnv.addObjRelation("ROWAMOUNT", new Integer(rows)); 364cdf0e10cSrcweir tEnv.addObjRelation("COLAMOUNT", new Integer(cols)); 365cdf0e10cSrcweir 366cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 367cdf0e10cSrcweir Object stock = SOF.createDiagram(xChartDoc,"StockDiagram"); 368cdf0e10cSrcweir tEnv.addObjRelation("STOCK",stock); 369cdf0e10cSrcweir 370cdf0e10cSrcweir Object bar = SOF.createDiagram(xChartDoc,"BarDiagram"); 371cdf0e10cSrcweir tEnv.addObjRelation("BAR",bar); 372cdf0e10cSrcweir 373cdf0e10cSrcweir Object line = SOF.createDiagram(xChartDoc,"XYDiagram"); 374cdf0e10cSrcweir tEnv.addObjRelation("LINE",line); 375cdf0e10cSrcweir 376cdf0e10cSrcweir Object stack = SOF.createDiagram(xChartDoc,"LineDiagram"); 377cdf0e10cSrcweir tEnv.addObjRelation("STACK",stack); 378cdf0e10cSrcweir 379cdf0e10cSrcweir return tEnv; 380cdf0e10cSrcweir } // finish method getTestEnvironment 381cdf0e10cSrcweir 382cdf0e10cSrcweir /** 383cdf0e10cSrcweir * Inserts a value or a formula in the cell of the spreasheet. 384cdf0e10cSrcweir * @param CellX is the column index of the cell 385cdf0e10cSrcweir * @param CellY is the row index of the cell 386cdf0e10cSrcweir * @param theValue string representation of the value 387cdf0e10cSrcweir * @param TT1 specify the spreadsheet, the interface 388cdf0e10cSrcweir * <code>com.sun.star.sheet.XSpreadsheet</code> 389cdf0e10cSrcweir * @param flag if it's equal to <code>'V'</code> then the method inserts 390cdf0e10cSrcweir * a double-value in the cell else it inserts a formula in the cell 391cdf0e10cSrcweir */ 392cdf0e10cSrcweir public static void insertIntoCell( 393cdf0e10cSrcweir int CellX, int CellY, String theValue, XSpreadsheet TT1, String flag) { 394cdf0e10cSrcweir 395cdf0e10cSrcweir XCell oCell = null; 396cdf0e10cSrcweir 397cdf0e10cSrcweir try { 398cdf0e10cSrcweir oCell = TT1.getCellByPosition(CellX, CellY); 399cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { 400cdf0e10cSrcweir System.out.println("Could not get Cell"); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir if (flag.equals("V")) {oCell.setValue((new Float(theValue)).floatValue());} 403cdf0e10cSrcweir else {oCell.setFormula(theValue);} 404cdf0e10cSrcweir 405cdf0e10cSrcweir } // end of insertIntoCell 406cdf0e10cSrcweir 407cdf0e10cSrcweir 408cdf0e10cSrcweir } // finish class ChXDiagram 409cdf0e10cSrcweir 410