1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // __________ Imports __________
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // base classes
27cdf0e10cSrcweir import com.sun.star.uno.XInterface;
28cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
29cdf0e10cSrcweir import com.sun.star.lang.*;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // property access
32cdf0e10cSrcweir import com.sun.star.beans.*;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // application specific classes
35cdf0e10cSrcweir import com.sun.star.chart.*;
36cdf0e10cSrcweir import com.sun.star.drawing.*;
37cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir import com.sun.star.table.CellRangeAddress;
40cdf0e10cSrcweir import com.sun.star.frame.XModel;
41cdf0e10cSrcweir import com.sun.star.frame.XController;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir import com.sun.star.util.XNumberFormatsSupplier;
44cdf0e10cSrcweir import com.sun.star.util.XNumberFormats;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // base graphics things
47cdf0e10cSrcweir import com.sun.star.awt.Point;
48cdf0e10cSrcweir import com.sun.star.awt.Size;
49cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
50cdf0e10cSrcweir import com.sun.star.awt.FontWeight;
51cdf0e10cSrcweir import com.sun.star.awt.FontRelief;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // Exceptions
54cdf0e10cSrcweir import com.sun.star.uno.Exception;
55cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
56cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException;
57cdf0e10cSrcweir import com.sun.star.lang.IndexOutOfBoundsException;
58cdf0e10cSrcweir import com.sun.star.util.MalformedNumberFormatException;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // __________ Implementation __________
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /** Test to create a writer document and insert an OLE Chart.
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     Be careful!  This does not really work.  The Writer currently has no
66cdf0e10cSrcweir     interface for dealing with OLE objects.  You can add an OLE shape to the
67cdf0e10cSrcweir     Writer's drawing layer, but it is not treated correctly as OLE object.
68cdf0e10cSrcweir     Thus, you can not activate the chart by double-clicking.  The office may
69cdf0e10cSrcweir     also crash when the document is closed!
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     @author Björn Milcke
72cdf0e10cSrcweir  */
73cdf0e10cSrcweir public class ChartInWriter
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     // ____________________
76cdf0e10cSrcweir 
main( String args[] )77cdf0e10cSrcweir     public static void main( String args[] )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         Helper aHelper = new Helper( args );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         ChartHelper aChartHelper = new ChartHelper(
82cdf0e10cSrcweir             (XModel) UnoRuntime.queryInterface( XModel.class,
83cdf0e10cSrcweir                                                 aHelper.createTextDocument()));
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         // the unit for measures is 1/100th of a millimeter
86cdf0e10cSrcweir         // position at (1cm, 1cm)
87cdf0e10cSrcweir         Point aPos    = new Point( 1000, 1000 );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         // size of the chart is 15cm x 12cm
90cdf0e10cSrcweir         Size  aExtent = new Size( 15000, 13000 );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         // insert a new chart into the "Chart" sheet of the
93cdf0e10cSrcweir         // spreadsheet document
94cdf0e10cSrcweir         XChartDocument aChartDoc = aChartHelper.insertOLEChartInWriter(
95cdf0e10cSrcweir             "BarChart",
96cdf0e10cSrcweir             aPos,
97cdf0e10cSrcweir             aExtent,
98cdf0e10cSrcweir             "com.sun.star.chart.AreaDiagram" );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         // instantiate test class with newly created chart
101cdf0e10cSrcweir         ChartInWriter aTest   = new ChartInWriter( aChartDoc );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         try
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir              aTest.lockControllers();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             // do tests here
108cdf0e10cSrcweir              aTest.testWall();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir              aTest.unlockControllers();
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir         catch( Exception ex )
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             System.out.println( "UNO Exception caught: " + ex );
115cdf0e10cSrcweir             System.out.println( "Message: " + ex.getMessage() );
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         System.exit( 0 );
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     // ________________________________________
123cdf0e10cSrcweir 
ChartInWriter( XChartDocument aChartDoc )124cdf0e10cSrcweir     public ChartInWriter( XChartDocument aChartDoc )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         maChartDocument = aChartDoc;
127cdf0e10cSrcweir         maDiagram       = maChartDocument.getDiagram();
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     // ____________________
131cdf0e10cSrcweir 
lockControllers()132cdf0e10cSrcweir     public void lockControllers()
133cdf0e10cSrcweir         throws RuntimeException
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers();
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     // ____________________
139cdf0e10cSrcweir 
unlockControllers()140cdf0e10cSrcweir     public void unlockControllers()
141cdf0e10cSrcweir         throws RuntimeException
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers();
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // ____________________
147cdf0e10cSrcweir 
testWall()148cdf0e10cSrcweir     public void testWall()
149cdf0e10cSrcweir         throws RuntimeException, UnknownPropertyException, PropertyVetoException,
150cdf0e10cSrcweir                com.sun.star.lang.IllegalArgumentException, WrappedTargetException
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface(
153cdf0e10cSrcweir                                   X3DDisplay.class, maDiagram )).getWall();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         // change background color of area
156cdf0e10cSrcweir         aWall.setPropertyValue( "FillColor", new Integer( 0xeecc99 ));
157cdf0e10cSrcweir         aWall.setPropertyValue( "FillStyle",  FillStyle.SOLID );
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     // ______________________________
161cdf0e10cSrcweir     //
162cdf0e10cSrcweir     // private members
163cdf0e10cSrcweir     // ______________________________
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     private XChartDocument maChartDocument;
166cdf0e10cSrcweir     private XDiagram       maDiagram;
167cdf0e10cSrcweir }
168