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