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 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.lang.XComponent;
28 
29 import com.sun.star.awt.Point;
30 import com.sun.star.awt.Size;
31 
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.beans.XPropertySet;
34 
35 import com.sun.star.drawing.XShape;
36 import com.sun.star.drawing.XShapes;
37 import com.sun.star.drawing.XDrawPage;
38 import com.sun.star.drawing.HomogenMatrix3;
39 
40 import java.awt.geom.AffineTransform;
41 
42 // __________ Implementation __________
43 
44 /** ObjectTransformationDemo
45     @author Sven Jacobi
46  */
47 
48 public class ObjectTransformationDemo
49 {
main( String args[] )50     public static void main( String args[] )
51     {
52 		XComponent xDrawDoc = null;
53 		try
54 		{
55             // get the remote office context of a running office (a new office
56             // instance is started if necessary)
57 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
58 
59 			// suppress Presentation Autopilot when opening the document
60 			// properties are the same as described for
61 			// com.sun.star.document.MediaDescriptor
62 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
63 			pPropValues[ 0 ] = new PropertyValue();
64 			pPropValues[ 0 ].Name = "Silent";
65 			pPropValues[ 0 ].Value = new Boolean( true );
66 
67 			xDrawDoc = Helper.createDocument( xOfficeContext,
68 				"private:factory/simpress", "_blank", 0, pPropValues );
69 
70 			XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
71 			XPropertySet xPagePropSet= (XPropertySet)
72 					UnoRuntime.queryInterface( XPropertySet.class, xPage );
73 
74 			XShapes xShapes = (XShapes)
75 					UnoRuntime.queryInterface( XShapes.class, xPage );
76 
77 
78 			XShape xShape = ShapeHelper.createShape( xDrawDoc,
79 				new Point( 0, 0 ), new Size( 10000, 2500 ),
80 					"com.sun.star.drawing.RectangleShape" );
81 			xShapes.add( xShape );
82 
83 			XPropertySet xPropSet = (XPropertySet)
84 					UnoRuntime.queryInterface( XPropertySet.class, xShape );
85 
86 			HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3)
87                 xPropSet.getPropertyValue( "Transformation" );
88 
89 			java.awt.geom.AffineTransform aOriginalMatrix =
90                 new java.awt.geom.AffineTransform(
91                     aHomogenMatrix3.Line1.Column1, aHomogenMatrix3.Line2.Column1,
92 					aHomogenMatrix3.Line1.Column2, aHomogenMatrix3.Line2.Column2,
93                     aHomogenMatrix3.Line1.Column3, aHomogenMatrix3.Line2.Column3 );
94 
95 
96 			AffineTransform aNewMatrix1 = new AffineTransform();
97 			aNewMatrix1.setToRotation( Math.PI /180 * 15 );
98 			aNewMatrix1.concatenate( aOriginalMatrix );
99 
100 			AffineTransform aNewMatrix2 = new AffineTransform();
101 			aNewMatrix2.setToTranslation( 2000, 2000 );
102 			aNewMatrix2.concatenate( aNewMatrix1 );
103 
104 			double aFlatMatrix[] = new double[ 6 ];
105 			aNewMatrix2.getMatrix( aFlatMatrix );
106 			aHomogenMatrix3.Line1.Column1 = aFlatMatrix[ 0 ];
107 			aHomogenMatrix3.Line2.Column1 = aFlatMatrix[ 1 ];
108 			aHomogenMatrix3.Line1.Column2 = aFlatMatrix[ 2 ];
109 			aHomogenMatrix3.Line2.Column2 = aFlatMatrix[ 3 ];
110 			aHomogenMatrix3.Line1.Column3 = aFlatMatrix[ 4 ];
111 			aHomogenMatrix3.Line2.Column3 = aFlatMatrix[ 5 ];
112 			xPropSet.setPropertyValue( "Transformation", aHomogenMatrix3 );
113 
114 
115 		}
116 		catch( Exception ex )
117 		{
118             System.out.println( ex );
119 		}
120 		System.exit( 0 );
121     }
122 }
123