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