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