1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextGraphicObject.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.TextContentAnchorType
;
44 import com
.sun
.star
.text
.XText
;
45 import com
.sun
.star
.text
.XTextContent
;
46 import com
.sun
.star
.text
.XTextCursor
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
51 public class SwXTextGraphicObject
extends TestCase
{
53 XTextDocument xTextDoc
;
56 * in general this method creates a testdocument
58 * @param tParam class which contains additional test parameters
59 * @param log class to log the test state and result
66 protected void initialize( TestParameters tParam
, PrintWriter log
) {
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
69 log
.println( "creating a textdoc" );
70 xTextDoc
= SOF
.createTextDoc( null );;
71 } catch ( Exception e
) {
72 // Some exception occures.FAILED
73 e
.printStackTrace( log
);
74 throw new StatusException( "Couldn't create document", e
);
79 * in general this method disposes the testenvironment and document
81 * @param tParam class which contains additional test parameters
82 * @param log class to log the test state and result
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xDrawDoc " );
91 util
.DesktopTools
.closeDoc(xTextDoc
);
96 * creating a Testenvironment for the interfaces to be tested
98 * @param tParam class which contains additional test parameters
99 * @param log class to log the test state and result
101 * @return Status class
103 * @see TestParameters
106 protected TestEnvironment createTestEnvironment
107 (TestParameters tParam
, PrintWriter log
) {
109 XInterface oObj
= null;
110 Object oGObject
= null;
111 Object xTextFrame
= null;
112 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
114 Object instance
= null;
117 oGObject
= SOF
.createInstance
118 (xTextDoc
,"com.sun.star.text.GraphicObject");
119 instance
= SOF
.createInstance
120 (xTextDoc
,"com.sun.star.text.GraphicObject");
121 xTextFrame
= SOF
.createTextFrame(xTextDoc
, 500, 500);
123 catch (Exception ex
) {
124 log
.println("Couldn't create instance");
125 ex
.printStackTrace(log
);
126 throw new StatusException("Couldn't create instance", ex
);
129 oObj
= (XInterface
) oGObject
;
131 XText the_text
= xTextDoc
.getText();
132 XTextCursor the_cursor
= the_text
.createTextCursor();
133 XTextContent the_content
= (XTextContent
)
134 UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
136 log
.println("inserting Frame");
138 XTextContent Framecontent
= (XTextContent
) UnoRuntime
.queryInterface(
139 XTextContent
.class, xTextFrame
);
140 the_text
.insertTextContent(the_cursor
, Framecontent
, true);
141 } catch (Exception e
) {
142 System
.out
.println("Couldn't insert text frame");
144 throw new StatusException("Couldn't insert text frame", e
);
148 log
.println( "inserting graphic" );
150 the_text
.insertTextContent(the_cursor
,the_content
,true);
151 } catch (Exception e
) {
152 System
.out
.println("Couldn't insert Content");
154 throw new StatusException("Couldn't insert Content", e
);
157 log
.println( "adding graphic" );
158 XPropertySet oProps
= (XPropertySet
)
159 UnoRuntime
.queryInterface(XPropertySet
.class,oObj
);
161 String wat
= util
.utils
.getFullTestURL("space-metal.jpg");
162 oProps
.setPropertyValue("AnchorType",
163 TextContentAnchorType
.AT_PARAGRAPH
);
164 oProps
.setPropertyValue("GraphicURL",wat
);
165 oProps
.setPropertyValue("HoriOrientPosition",new Integer(5500));
166 oProps
.setPropertyValue("VertOrientPosition",new Integer(4200));
167 oProps
.setPropertyValue("Width",new Integer(4400));
168 oProps
.setPropertyValue("Height",new Integer(4000));
169 } catch (Exception e
) {
170 System
.out
.println("Couldn't set property 'GraphicURL'");
172 throw new StatusException
173 ("Couldn't set property 'GraphicURL'", e
);
176 TestEnvironment tEnv
= new TestEnvironment( oObj
);
178 log
.println( "adding ObjRelation for XShape "
179 +"(get/setPosition won't work there)" );
180 tEnv
.addObjRelation("NoPos", "SwXTextGraphicObject");
181 tEnv
.addObjRelation("NoSetSize","SwXTextGraphicObject");
182 Object ImgMap
= null;
183 //creating ObjectRelation for the property
184 // 'ImageMap' of 'TextGraphicObject'
186 XMultiServiceFactory xDocMSF
= (XMultiServiceFactory
)
187 UnoRuntime
.queryInterface
188 (XMultiServiceFactory
.class,xTextDoc
);
189 ImgMap
= xDocMSF
.createInstance
190 ("com.sun.star.image.ImageMapRectangleObject");
192 catch (Exception ex
) {
193 ex
.printStackTrace();
196 tEnv
.addObjRelation("IMGMAP",ImgMap
);
198 tEnv
.addObjRelation("CONTENT", (XTextContent
)
199 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
200 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
202 //object relation for text.BaseFrameProperties
203 tEnv
.addObjRelation("TextFrame", xTextFrame
);
207 } // finish method getTestEnvironment
209 } // finish class SwXTextGraphicObject