update dev300-m58
[ooovba.git] / odk / examples / DevelopersGuide / Charts / ChartInWriter.java
blob5c928031ed7e4947d40f138dba68d3011851980d
1 /*************************************************************************
3 * $RCSfile: ChartInWriter.java,v $
5 * $Revision: 1.4 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:10:28 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
43 // base classes
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.lang.*;
48 // property access
49 import com.sun.star.beans.*;
51 // application specific classes
52 import com.sun.star.chart.*;
53 import com.sun.star.drawing.*;
54 import com.sun.star.text.XTextDocument;
56 import com.sun.star.table.CellRangeAddress;
57 import com.sun.star.frame.XModel;
58 import com.sun.star.frame.XController;
60 import com.sun.star.util.XNumberFormatsSupplier;
61 import com.sun.star.util.XNumberFormats;
63 // base graphics things
64 import com.sun.star.awt.Point;
65 import com.sun.star.awt.Size;
66 import com.sun.star.awt.Rectangle;
67 import com.sun.star.awt.FontWeight;
68 import com.sun.star.awt.FontRelief;
70 // Exceptions
71 import com.sun.star.uno.Exception;
72 import com.sun.star.uno.RuntimeException;
73 import com.sun.star.beans.UnknownPropertyException;
74 import com.sun.star.lang.IndexOutOfBoundsException;
75 import com.sun.star.util.MalformedNumberFormatException;
78 // __________ Implementation __________
80 /** Test to create a writer document and insert an OLE Chart.
82 Be careful! This does not really work. The Writer currently has no
83 interface for dealing with OLE objects. You can add an OLE shape to the
84 Writer's drawing layer, but it is not treated correctly as OLE object.
85 Thus, you can not activate the chart by double-clicking. The office may
86 also crash when the document is closed!
88 @author Björn Milcke
90 public class ChartInWriter
92 // ____________________
94 public static void main( String args[] )
96 Helper aHelper = new Helper( args );
98 ChartHelper aChartHelper = new ChartHelper(
99 (XModel) UnoRuntime.queryInterface( XModel.class,
100 aHelper.createTextDocument()));
102 // the unit for measures is 1/100th of a millimeter
103 // position at (1cm, 1cm)
104 Point aPos = new Point( 1000, 1000 );
106 // size of the chart is 15cm x 12cm
107 Size aExtent = new Size( 15000, 13000 );
109 // insert a new chart into the "Chart" sheet of the
110 // spreadsheet document
111 XChartDocument aChartDoc = aChartHelper.insertOLEChartInWriter(
112 "BarChart",
113 aPos,
114 aExtent,
115 "com.sun.star.chart.AreaDiagram" );
117 // instantiate test class with newly created chart
118 ChartInWriter aTest = new ChartInWriter( aChartDoc );
122 aTest.lockControllers();
124 // do tests here
125 aTest.testWall();
127 aTest.unlockControllers();
129 catch( Exception ex )
131 System.out.println( "UNO Exception caught: " + ex );
132 System.out.println( "Message: " + ex.getMessage() );
135 System.exit( 0 );
139 // ________________________________________
141 public ChartInWriter( XChartDocument aChartDoc )
143 maChartDocument = aChartDoc;
144 maDiagram = maChartDocument.getDiagram();
147 // ____________________
149 public void lockControllers()
150 throws RuntimeException
152 ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers();
155 // ____________________
157 public void unlockControllers()
158 throws RuntimeException
160 ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers();
163 // ____________________
165 public void testWall()
166 throws RuntimeException, UnknownPropertyException, PropertyVetoException,
167 com.sun.star.lang.IllegalArgumentException, WrappedTargetException
169 XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface(
170 X3DDisplay.class, maDiagram )).getWall();
172 // change background color of area
173 aWall.setPropertyValue( "FillColor", new Integer( 0xeecc99 ));
174 aWall.setPropertyValue( "FillStyle", FillStyle.SOLID );
177 // ______________________________
179 // private members
180 // ______________________________
182 private XChartDocument maChartDocument;
183 private XDiagram maDiagram;