1 /*************************************************************************
3 * $RCSfile: ObjectTransformationDemo.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:23:56 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.lang
.XComponent
;
46 import com
.sun
.star
.awt
.Point
;
47 import com
.sun
.star
.awt
.Size
;
49 import com
.sun
.star
.beans
.PropertyValue
;
50 import com
.sun
.star
.beans
.XPropertySet
;
52 import com
.sun
.star
.drawing
.XShape
;
53 import com
.sun
.star
.drawing
.XShapes
;
54 import com
.sun
.star
.drawing
.XDrawPage
;
55 import com
.sun
.star
.drawing
.HomogenMatrix3
;
57 import java
.awt
.geom
.AffineTransform
;
59 // __________ Implementation __________
61 /** ObjectTransformationDemo
65 public class ObjectTransformationDemo
67 public static void main( String args
[] )
69 XComponent xDrawDoc
= null;
72 // get the remote office context of a running office (a new office
73 // instance is started if necessary)
74 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
76 // suppress Presentation Autopilot when opening the document
77 // properties are the same as described for
78 // com.sun.star.document.MediaDescriptor
79 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
80 pPropValues
[ 0 ] = new PropertyValue();
81 pPropValues
[ 0 ].Name
= "Silent";
82 pPropValues
[ 0 ].Value
= new Boolean( true );
84 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
85 "private:factory/simpress", "_blank", 0, pPropValues
);
87 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
88 XPropertySet xPagePropSet
= (XPropertySet
)
89 UnoRuntime
.queryInterface( XPropertySet
.class, xPage
);
91 XShapes xShapes
= (XShapes
)
92 UnoRuntime
.queryInterface( XShapes
.class, xPage
);
95 XShape xShape
= ShapeHelper
.createShape( xDrawDoc
,
96 new Point( 0, 0 ), new Size( 10000, 2500 ),
97 "com.sun.star.drawing.RectangleShape" );
98 xShapes
.add( xShape
);
100 XPropertySet xPropSet
= (XPropertySet
)
101 UnoRuntime
.queryInterface( XPropertySet
.class, xShape
);
103 HomogenMatrix3 aHomogenMatrix3
= (HomogenMatrix3
)
104 xPropSet
.getPropertyValue( "Transformation" );
106 java
.awt
.geom
.AffineTransform aOriginalMatrix
=
107 new java
.awt
.geom
.AffineTransform(
108 aHomogenMatrix3
.Line1
.Column1
, aHomogenMatrix3
.Line2
.Column1
,
109 aHomogenMatrix3
.Line1
.Column2
, aHomogenMatrix3
.Line2
.Column2
,
110 aHomogenMatrix3
.Line1
.Column3
, aHomogenMatrix3
.Line2
.Column3
);
113 AffineTransform aNewMatrix1
= new AffineTransform();
114 aNewMatrix1
.setToRotation( Math
.PI
/180 * 15 );
115 aNewMatrix1
.concatenate( aOriginalMatrix
);
117 AffineTransform aNewMatrix2
= new AffineTransform();
118 aNewMatrix2
.setToTranslation( 2000, 2000 );
119 aNewMatrix2
.concatenate( aNewMatrix1
);
121 double aFlatMatrix
[] = new double[ 6 ];
122 aNewMatrix2
.getMatrix( aFlatMatrix
);
123 aHomogenMatrix3
.Line1
.Column1
= aFlatMatrix
[ 0 ];
124 aHomogenMatrix3
.Line2
.Column1
= aFlatMatrix
[ 1 ];
125 aHomogenMatrix3
.Line1
.Column2
= aFlatMatrix
[ 2 ];
126 aHomogenMatrix3
.Line2
.Column2
= aFlatMatrix
[ 3 ];
127 aHomogenMatrix3
.Line1
.Column3
= aFlatMatrix
[ 4 ];
128 aHomogenMatrix3
.Line2
.Column3
= aFlatMatrix
[ 5 ];
129 xPropSet
.setPropertyValue( "Transformation", aHomogenMatrix3
);
133 catch( Exception ex
)
135 System
.out
.println( ex
);