1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 // __________ Imports __________
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.awt
.Point
;
42 import com
.sun
.star
.awt
.Size
;
44 import com
.sun
.star
.beans
.PropertyValue
;
45 import com
.sun
.star
.beans
.XPropertySet
;
47 import com
.sun
.star
.drawing
.XShape
;
48 import com
.sun
.star
.drawing
.XShapes
;
49 import com
.sun
.star
.drawing
.XDrawPage
;
50 import com
.sun
.star
.drawing
.HomogenMatrix3
;
52 import java
.awt
.geom
.AffineTransform
;
54 // __________ Implementation __________
56 // ObjectTransformationDemo
58 public class ObjectTransformationDemo
60 public static void main( String args
[] )
62 XComponent xDrawDoc
= null;
65 // get the remote office context of a running office (a new office
66 // instance is started if necessary)
67 com
.sun
.star
.uno
.XComponentContext xOfficeContext
= Helper
.connect();
69 // suppress Presentation Autopilot when opening the document
70 // properties are the same as described for
71 // com.sun.star.document.MediaDescriptor
72 PropertyValue
[] pPropValues
= new PropertyValue
[ 1 ];
73 pPropValues
[ 0 ] = new PropertyValue();
74 pPropValues
[ 0 ].Name
= "Silent";
75 pPropValues
[ 0 ].Value
= Boolean
.TRUE
;
77 xDrawDoc
= Helper
.createDocument( xOfficeContext
,
78 "private:factory/simpress", "_blank", 0, pPropValues
);
80 XDrawPage xPage
= PageHelper
.getDrawPageByIndex( xDrawDoc
, 0 );
81 XPropertySet xPagePropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, xPage
);
83 XShapes xShapes
= UnoRuntime
.queryInterface( XShapes
.class, xPage
);
86 XShape xShape
= ShapeHelper
.createShape( xDrawDoc
,
87 new Point( 0, 0 ), new Size( 10000, 2500 ),
88 "com.sun.star.drawing.RectangleShape" );
89 xShapes
.add( xShape
);
91 XPropertySet xPropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, xShape
);
93 HomogenMatrix3 aHomogenMatrix3
= (HomogenMatrix3
)
94 xPropSet
.getPropertyValue( "Transformation" );
96 java
.awt
.geom
.AffineTransform aOriginalMatrix
=
97 new java
.awt
.geom
.AffineTransform(
98 aHomogenMatrix3
.Line1
.Column1
, aHomogenMatrix3
.Line2
.Column1
,
99 aHomogenMatrix3
.Line1
.Column2
, aHomogenMatrix3
.Line2
.Column2
,
100 aHomogenMatrix3
.Line1
.Column3
, aHomogenMatrix3
.Line2
.Column3
);
103 AffineTransform aNewMatrix1
= new AffineTransform();
104 aNewMatrix1
.setToRotation( Math
.PI
/180 * 15 );
105 aNewMatrix1
.concatenate( aOriginalMatrix
);
107 AffineTransform aNewMatrix2
= new AffineTransform();
108 aNewMatrix2
.setToTranslation( 2000, 2000 );
109 aNewMatrix2
.concatenate( aNewMatrix1
);
111 double aFlatMatrix
[] = new double[ 6 ];
112 aNewMatrix2
.getMatrix( aFlatMatrix
);
113 aHomogenMatrix3
.Line1
.Column1
= aFlatMatrix
[ 0 ];
114 aHomogenMatrix3
.Line2
.Column1
= aFlatMatrix
[ 1 ];
115 aHomogenMatrix3
.Line1
.Column2
= aFlatMatrix
[ 2 ];
116 aHomogenMatrix3
.Line2
.Column2
= aFlatMatrix
[ 3 ];
117 aHomogenMatrix3
.Line1
.Column3
= aFlatMatrix
[ 4 ];
118 aHomogenMatrix3
.Line2
.Column3
= aFlatMatrix
[ 5 ];
119 xPropSet
.setPropertyValue( "Transformation", aHomogenMatrix3
);
123 catch( Exception ex
)
125 System
.out
.println( ex
);
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */