Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / odk / examples / DevelopersGuide / Charts / ChartInWriter.java
blobb84404d8be9e64b0e26992f60d4d29a887907a79
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // __________ Imports __________
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.lang.*;
41 // property access
42 import com.sun.star.beans.*;
44 // application specific classes
45 import com.sun.star.chart.*;
46 import com.sun.star.drawing.*;
47 import com.sun.star.frame.XModel;
48 // base graphics things
49 import com.sun.star.awt.Point;
50 import com.sun.star.awt.Size;
51 // Exceptions
52 import com.sun.star.uno.Exception;
53 import com.sun.star.uno.RuntimeException;
54 import com.sun.star.beans.UnknownPropertyException;
57 // __________ Implementation __________
59 /** Test to create a writer document and insert an OLE Chart.
61 Be careful! This does not really work. The Writer currently has no
62 interface for dealing with OLE objects. You can add an OLE shape to the
63 Writer's drawing layer, but it is not treated correctly as OLE object.
64 Thus, you can not activate the chart by double-clicking. The office may
65 also crash when the document is closed!
68 public class ChartInWriter
72 public static void main( String args[] )
74 Helper aHelper = new Helper( args );
76 ChartHelper aChartHelper = new ChartHelper(
77 UnoRuntime.queryInterface( XModel.class,
78 aHelper.createTextDocument()));
80 // the unit for measures is 1/100th of a millimeter
81 // position at (1cm, 1cm)
82 Point aPos = new Point( 1000, 1000 );
84 // size of the chart is 15cm x 12cm
85 Size aExtent = new Size( 15000, 13000 );
87 // insert a new chart into the "Chart" sheet of the
88 // spreadsheet document
89 XChartDocument aChartDoc = aChartHelper.insertOLEChartInWriter(
90 aPos,
91 aExtent,
92 "com.sun.star.chart.AreaDiagram" );
94 // instantiate test class with newly created chart
95 ChartInWriter aTest = new ChartInWriter( aChartDoc );
97 try
99 aTest.lockControllers();
101 // do tests here
102 aTest.testWall();
104 aTest.unlockControllers();
106 catch( Exception ex )
108 System.out.println( "UNO Exception caught: " + ex );
109 System.out.println( "Message: " + ex.getMessage() );
112 System.exit( 0 );
118 public ChartInWriter( XChartDocument aChartDoc )
120 maChartDocument = aChartDoc;
121 maDiagram = maChartDocument.getDiagram();
126 public void lockControllers()
127 throws RuntimeException
129 UnoRuntime.queryInterface( XModel.class, maChartDocument ).lockControllers();
134 public void unlockControllers()
135 throws RuntimeException
137 UnoRuntime.queryInterface( XModel.class, maChartDocument ).unlockControllers();
142 public void testWall()
143 throws RuntimeException, UnknownPropertyException, PropertyVetoException,
144 com.sun.star.lang.IllegalArgumentException, WrappedTargetException
146 XPropertySet aWall = UnoRuntime.queryInterface(
147 X3DDisplay.class, maDiagram ).getWall();
149 // change background color of area
150 aWall.setPropertyValue( "FillColor", Integer.valueOf( 0xeecc99 ));
151 aWall.setPropertyValue( "FillStyle", FillStyle.SOLID );
156 // private members
159 private final XChartDocument maChartDocument;
160 private final XDiagram maDiagram;
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */