1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
35 // __________ Imports __________
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.lang
.*;
41 import com
.sun
.star
.beans
.*;
43 // application specific classes
44 import com
.sun
.star
.chart
.*;
45 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
;
52 import com
.sun
.star
.uno
.Exception
;
53 import com
.sun
.star
.uno
.RuntimeException
;
54 import com
.sun
.star
.beans
.UnknownPropertyException
;
57 // __________ Implementation __________
59 // Create a spreadsheet add some data and add a chart
61 public class ChartInDraw
63 // ____________________
65 public static void main( String args
[] )
67 Helper aHelper
= new Helper( args
);
69 ChartHelper aChartHelper
= new ChartHelper( aHelper
.createDrawingDocument());
71 // the unit for measures is 1/100th of a millimeter
72 // position at (1cm, 1cm)
73 Point aPos
= new Point( 1000, 1000 );
75 // size of the chart is 15cm x 12cm
76 Size aExtent
= new Size( 15000, 13000 );
78 // insert a new chart into the "Chart" sheet of the
79 // spreadsheet document
80 XChartDocument aChartDoc
= aChartHelper
.insertOLEChartInDraw(
84 "com.sun.star.chart.BarDiagram" );
86 // instantiate test class with newly created chart
87 ChartInDraw aTest
= new ChartInDraw( aChartDoc
);
91 aTest
.lockControllers();
99 aTest
.unlockControllers();
101 catch( Exception ex
)
103 System
.out
.println( "UNO Exception caught: " + ex
);
104 System
.out
.println( "Message: " + ex
.getMessage() );
111 // ________________________________________
113 public ChartInDraw( XChartDocument aChartDoc
)
115 maChartDocument
= aChartDoc
;
116 maDiagram
= maChartDocument
.getDiagram();
119 // ____________________
121 public void lockControllers()
122 throws RuntimeException
124 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).lockControllers();
127 // ____________________
129 public void unlockControllers()
130 throws RuntimeException
132 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).unlockControllers();
135 // ____________________
137 public void testArea()
138 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
139 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
141 XPropertySet aArea
= maChartDocument
.getArea();
145 // change background color of entire chart
146 aArea
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
147 aArea
.setPropertyValue( "FillColor", new Integer( 0xeeeeee ));
151 // ____________________
153 public void testWall()
154 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
155 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
157 XPropertySet aWall
= UnoRuntime
.queryInterface(
158 X3DDisplay
.class, maDiagram
).getWall();
160 // change background color of area
161 aWall
.setPropertyValue( "FillColor", new Integer( 0xcccccc ));
162 aWall
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
165 // ____________________
167 public void testTitle()
168 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
169 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
172 XPropertySet aDocProp
= UnoRuntime
.queryInterface(
173 XPropertySet
.class, maChartDocument
);
174 aDocProp
.setPropertyValue( "HasMainTitle", new Boolean( true ));
176 XShape aTitle
= maChartDocument
.getTitle();
177 XPropertySet aTitleProp
= UnoRuntime
.queryInterface( XPropertySet
.class, aTitle
);
180 if( aTitleProp
!= null )
182 aTitleProp
.setPropertyValue( "String", "Bar Chart in a Draw Document" );
186 // ____________________
188 public void testLegend()
189 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
190 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
192 XShape aLegend
= maChartDocument
.getLegend();
193 XPropertySet aLegendProp
= UnoRuntime
.queryInterface( XPropertySet
.class, aLegend
);
195 aLegendProp
.setPropertyValue( "Alignment", ChartLegendPosition
.LEFT
);
196 aLegendProp
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
197 aLegendProp
.setPropertyValue( "FillColor", new Integer( 0xeeddee ));
200 // ____________________
202 public void testThreeD()
203 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
204 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
,
205 com
.sun
.star
.lang
.IndexOutOfBoundsException
207 XPropertySet aDiaProp
= UnoRuntime
.queryInterface( XPropertySet
.class, maDiagram
);
208 Boolean aTrue
= new Boolean( true );
210 aDiaProp
.setPropertyValue( "Dim3D", aTrue
);
211 aDiaProp
.setPropertyValue( "Deep", aTrue
);
212 // from Chart3DBarProperties:
213 aDiaProp
.setPropertyValue( "SolidType", new Integer( ChartSolidType
.CYLINDER
));
215 // change floor color to Magenta6
216 XPropertySet aFloor
= UnoRuntime
.queryInterface(
217 X3DDisplay
.class, maDiagram
).getFloor();
218 aFloor
.setPropertyValue( "FillColor", new Integer( 0x6b2394 ));
220 // apply changes to get a 3d scene
225 // rotate scene to a different angle
226 HomogenMatrix aMatrix
= new HomogenMatrix();
227 HomogenMatrixLine aLines
[] = new HomogenMatrixLine
[]
229 new HomogenMatrixLine( 1.0, 0.0, 0.0, 0.0 ),
230 new HomogenMatrixLine( 0.0, 1.0, 0.0, 0.0 ),
231 new HomogenMatrixLine( 0.0, 0.0, 1.0, 0.0 ),
232 new HomogenMatrixLine( 0.0, 0.0, 0.0, 1.0 )
235 aMatrix
.Line1
= aLines
[ 0 ];
236 aMatrix
.Line2
= aLines
[ 1 ];
237 aMatrix
.Line3
= aLines
[ 2 ];
238 aMatrix
.Line4
= aLines
[ 3 ];
240 // rotate 10 degrees along the x axis
241 double fAngle
= 10.0;
242 double fCosX
= java
.lang
.Math
.cos( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
243 double fSinX
= java
.lang
.Math
.sin( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
245 // rotate -20 degrees along the y axis
247 double fCosY
= java
.lang
.Math
.cos( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
248 double fSinY
= java
.lang
.Math
.sin( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
250 // rotate -5 degrees along the z axis
252 double fCosZ
= java
.lang
.Math
.cos( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
253 double fSinZ
= java
.lang
.Math
.sin( java
.lang
.Math
.PI
/ 180.0 * fAngle
);
255 aMatrix
.Line1
.Column1
= fCosY
* fCosZ
;
256 aMatrix
.Line1
.Column2
= fCosY
* -fSinZ
;
257 aMatrix
.Line1
.Column3
= fSinY
;
259 aMatrix
.Line2
.Column1
= fSinX
* fSinY
* fCosZ
+ fCosX
* fSinZ
;
260 aMatrix
.Line2
.Column2
= -fSinX
* fSinY
* fSinZ
+ fCosX
* fCosZ
;
261 aMatrix
.Line2
.Column3
= -fSinX
* fCosY
;
263 aMatrix
.Line3
.Column1
= -fCosX
* fSinY
* fCosZ
+ fSinX
* fSinZ
;
264 aMatrix
.Line3
.Column2
= fCosX
* fSinY
* fSinZ
+ fSinX
* fCosZ
;
265 aMatrix
.Line3
.Column3
= fCosX
* fCosY
;
267 aDiaProp
.setPropertyValue( "D3DTransformMatrix", aMatrix
);
269 // add a red light source
271 // in a chart by default only the second (non-specular) light source is switched on
272 // light source 1 is a specular light source
273 aDiaProp
.setPropertyValue( "D3DSceneLightColor1", new Integer( 0xff3333 ));
276 com
.sun
.star
.drawing
.Direction3D aDirection
= new com
.sun
.star
.drawing
.Direction3D();
278 aDirection
.DirectionX
= -0.75;
279 aDirection
.DirectionY
= 0.5;
280 aDirection
.DirectionZ
= 0.5;
282 aDiaProp
.setPropertyValue( "D3DSceneLightDirection1", aDirection
);
283 aDiaProp
.setPropertyValue( "D3DSceneLightOn1", new Boolean( true ));
286 // ______________________________
289 // ______________________________
291 private XChartDocument maChartDocument
;
292 private XDiagram maDiagram
;