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
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(
83 "com.sun.star.chart.BarDiagram" );
85 // instantiate test class with newly created chart
86 ChartInDraw aTest
= new ChartInDraw( aChartDoc
);
90 aTest
.lockControllers();
98 aTest
.unlockControllers();
100 catch( Exception ex
)
102 System
.out
.println( "UNO Exception caught: " + ex
);
103 System
.out
.println( "Message: " + ex
.getMessage() );
112 public ChartInDraw( XChartDocument aChartDoc
)
114 maChartDocument
= aChartDoc
;
115 maDiagram
= maChartDocument
.getDiagram();
120 public void lockControllers()
121 throws RuntimeException
123 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).lockControllers();
128 public void unlockControllers()
129 throws RuntimeException
131 UnoRuntime
.queryInterface( XModel
.class, maChartDocument
).unlockControllers();
136 public void testArea()
137 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
138 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
140 XPropertySet aArea
= maChartDocument
.getArea();
144 // change background color of entire chart
145 aArea
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
146 aArea
.setPropertyValue( "FillColor", Integer
.valueOf( 0xeeeeee ));
152 public void testWall()
153 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
154 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
156 XPropertySet aWall
= UnoRuntime
.queryInterface(
157 X3DDisplay
.class, maDiagram
).getWall();
159 // change background color of area
160 aWall
.setPropertyValue( "FillColor", Integer
.valueOf( 0xcccccc ));
161 aWall
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
166 public void testTitle()
167 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
168 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
171 XPropertySet aDocProp
= UnoRuntime
.queryInterface(
172 XPropertySet
.class, maChartDocument
);
173 aDocProp
.setPropertyValue( "HasMainTitle", Boolean
.TRUE
);
175 XShape aTitle
= maChartDocument
.getTitle();
176 XPropertySet aTitleProp
= UnoRuntime
.queryInterface( XPropertySet
.class, aTitle
);
179 if( aTitleProp
!= null )
181 aTitleProp
.setPropertyValue( "String", "Bar Chart in a Draw Document" );
187 public void testLegend()
188 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
189 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
191 XShape aLegend
= maChartDocument
.getLegend();
192 XPropertySet aLegendProp
= UnoRuntime
.queryInterface( XPropertySet
.class, aLegend
);
194 aLegendProp
.setPropertyValue( "Alignment", ChartLegendPosition
.LEFT
);
195 aLegendProp
.setPropertyValue( "FillStyle", FillStyle
.SOLID
);
196 aLegendProp
.setPropertyValue( "FillColor", Integer
.valueOf( 0xeeddee ));
201 public void testThreeD()
202 throws RuntimeException
, UnknownPropertyException
, PropertyVetoException
,
203 com
.sun
.star
.lang
.IllegalArgumentException
, WrappedTargetException
205 XPropertySet aDiaProp
= UnoRuntime
.queryInterface( XPropertySet
.class, maDiagram
);
206 Boolean aTrue
= Boolean
.TRUE
;
208 aDiaProp
.setPropertyValue( "Dim3D", aTrue
);
209 aDiaProp
.setPropertyValue( "Deep", aTrue
);
210 // from Chart3DBarProperties:
211 aDiaProp
.setPropertyValue( "SolidType", Integer
.valueOf( ChartSolidType
.CYLINDER
));
213 // change floor color to Magenta6
214 XPropertySet aFloor
= UnoRuntime
.queryInterface(
215 X3DDisplay
.class, maDiagram
).getFloor();
216 aFloor
.setPropertyValue( "FillColor", Integer
.valueOf( 0x6b2394 ));
218 // apply changes to get a 3d scene
223 // rotate scene to a different angle
224 HomogenMatrix aMatrix
= new HomogenMatrix();
225 HomogenMatrixLine aLines
[] = new HomogenMatrixLine
[]
227 new HomogenMatrixLine( 1.0, 0.0, 0.0, 0.0 ),
228 new HomogenMatrixLine( 0.0, 1.0, 0.0, 0.0 ),
229 new HomogenMatrixLine( 0.0, 0.0, 1.0, 0.0 ),
230 new HomogenMatrixLine( 0.0, 0.0, 0.0, 1.0 )
233 aMatrix
.Line1
= aLines
[ 0 ];
234 aMatrix
.Line2
= aLines
[ 1 ];
235 aMatrix
.Line3
= aLines
[ 2 ];
236 aMatrix
.Line4
= aLines
[ 3 ];
238 // rotate 10 degrees along the x axis
239 double fAngle
= 10.0;
240 double fCosX
= Math
.cos( Math
.PI
/ 180.0 * fAngle
);
241 double fSinX
= Math
.sin( Math
.PI
/ 180.0 * fAngle
);
243 // rotate -20 degrees along the y axis
245 double fCosY
= Math
.cos( Math
.PI
/ 180.0 * fAngle
);
246 double fSinY
= Math
.sin( Math
.PI
/ 180.0 * fAngle
);
248 // rotate -5 degrees along the z axis
250 double fCosZ
= Math
.cos( Math
.PI
/ 180.0 * fAngle
);
251 double fSinZ
= Math
.sin( Math
.PI
/ 180.0 * fAngle
);
253 aMatrix
.Line1
.Column1
= fCosY
* fCosZ
;
254 aMatrix
.Line1
.Column2
= fCosY
* -fSinZ
;
255 aMatrix
.Line1
.Column3
= fSinY
;
257 aMatrix
.Line2
.Column1
= fSinX
* fSinY
* fCosZ
+ fCosX
* fSinZ
;
258 aMatrix
.Line2
.Column2
= -fSinX
* fSinY
* fSinZ
+ fCosX
* fCosZ
;
259 aMatrix
.Line2
.Column3
= -fSinX
* fCosY
;
261 aMatrix
.Line3
.Column1
= -fCosX
* fSinY
* fCosZ
+ fSinX
* fSinZ
;
262 aMatrix
.Line3
.Column2
= fCosX
* fSinY
* fSinZ
+ fSinX
* fCosZ
;
263 aMatrix
.Line3
.Column3
= fCosX
* fCosY
;
265 aDiaProp
.setPropertyValue( "D3DTransformMatrix", aMatrix
);
267 // add a red light source
269 // in a chart by default only the second (non-specular) light source is switched on
270 // light source 1 is a specular light source
271 aDiaProp
.setPropertyValue( "D3DSceneLightColor1", Integer
.valueOf( 0xff3333 ));
274 com
.sun
.star
.drawing
.Direction3D aDirection
= new com
.sun
.star
.drawing
.Direction3D();
276 aDirection
.DirectionX
= -0.75;
277 aDirection
.DirectionY
= 0.5;
278 aDirection
.DirectionZ
= 0.5;
280 aDiaProp
.setPropertyValue( "D3DSceneLightDirection1", aDirection
);
281 aDiaProp
.setPropertyValue( "D3DSceneLightOn1", Boolean
.TRUE
);
289 private final XChartDocument maChartDocument
;
290 private final XDiagram maDiagram
;