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