2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.FormTools
;
27 import util
.SOfficeFactory
;
28 import util
.WriterTools
;
30 import com
.sun
.star
.awt
.XControlModel
;
31 import com
.sun
.star
.awt
.XDevice
;
32 import com
.sun
.star
.awt
.XGraphics
;
33 import com
.sun
.star
.awt
.XTextComponent
;
34 import com
.sun
.star
.awt
.XToolkit
;
35 import com
.sun
.star
.awt
.XWindow
;
36 import com
.sun
.star
.awt
.XWindowPeer
;
37 import com
.sun
.star
.drawing
.XControlShape
;
38 import com
.sun
.star
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
41 import com
.sun
.star
.util
.XCloseable
;
42 import com
.sun
.star
.view
.XControlAccess
;
46 * Test for object which is represented by default controller
47 * of the <code>com.sun.star.form.component.FormattedField</code>
50 * Object implements the following interfaces :
52 * <li> <code>com::sun::star::awt::XView</code></li>
53 * <li> <code>com::sun::star::form::XBoundControl</code></li>
54 * <li> <code>com::sun::star::awt::XControl</code></li>
55 * <li> <code>com::sun::star::awt::XTextComponent</code></li>
56 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
57 * <li> <code>com::sun::star::awt::XTextListener</code></li>
58 * <li> <code>com::sun::star::awt::XWindow</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::awt::XTextLayoutConstrains</code></li>
61 * <li> <code>com::sun::star::lang::XEventListener</code></li>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurently.
66 * @see com.sun.star.awt.XView
67 * @see com.sun.star.form.XBoundControl
68 * @see com.sun.star.awt.XControl
69 * @see com.sun.star.awt.XTextComponent
70 * @see com.sun.star.awt.XLayoutConstrains
71 * @see com.sun.star.awt.XTextListener
72 * @see com.sun.star.awt.XWindow
73 * @see com.sun.star.lang.XComponent
74 * @see com.sun.star.awt.XTextLayoutConstrains
75 * @see com.sun.star.lang.XEventListener
77 * @see ifc.form._XBoundControl
78 * @see ifc.awt._XControl
79 * @see ifc.awt._XTextComponent
80 * @see ifc.awt._XLayoutConstrains
81 * @see ifc.awt._XTextListener
82 * @see ifc.awt._XWindow
83 * @see ifc.lang._XComponent
84 * @see ifc.awt._XTextLayoutConstrains
85 * @see ifc.lang._XEventListener
87 public class OFormattedControl
extends TestCase
{
88 XTextDocument xTextDoc
;
91 * Creates a new text document.
94 protected void initialize(TestParameters Param
, PrintWriter log
) {
95 SOfficeFactory SOF
= SOfficeFactory
.getFactory((Param
.getMSF()));
98 log
.println("creating a textdocument");
99 xTextDoc
= SOF
.createTextDoc(null);
100 } catch (com
.sun
.star
.uno
.Exception e
) {
101 // Some exception occurs.FAILED
102 e
.printStackTrace(log
);
103 throw new StatusException("Couldn't create document", e
);
108 * Disposes the text document created before
111 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
112 log
.println(" disposing xTextDoc ");
115 XCloseable closer
= UnoRuntime
.queryInterface(
116 XCloseable
.class, xTextDoc
);
118 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
119 log
.println("couldn't close document");
120 } catch (com
.sun
.star
.lang
.DisposedException e
) {
121 log
.println("couldn't close document");
126 * Creates two components and inserts them to the form of
127 * text document. One component
128 * (<code>com.sun.star.form.component.FormattedField</code>) is created
129 * for testing, another to be passed as relation. Using a controller
130 * of the text document the controller of the first component is
131 * obtained and returned in environment as a test object. <p>
133 * Object relations created :
135 * <li> <code>'GRAPHICS'</code> for
136 * {@link ifc.awt._XView} : a graphics component
137 * created using screen device of the window peer of
138 * the controller tested. </li>
139 * <li> <code>'CONTEXT'</code> for
140 * {@link ifc.awt._XControl} : the text document
141 * where the component is inserted. </li>
142 * <li> <code>'WINPEER'</code> for
143 * {@link ifc.awt._XControl} : Window peer of the
144 * controller tested. </li>
145 * <li> <code>'TOOLKIT'</code> for
146 * {@link ifc.awt._XControl} : toolkit of the component.</li>
147 * <li> <code>'MODEL'</code> for
148 * {@link ifc.awt._XControl} : the model of the controller.</li>
149 * <li> <code>'XWindow.AnotherWindow'</code> for
150 * {@link ifc.awt._XWindow} : the controller of another
155 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
157 XInterface oObj
= null;
158 Object anotherCtrl
= null;
159 XWindowPeer the_win
= null;
160 XToolkit the_kit
= null;
161 XDevice aDevice
= null;
162 XGraphics aGraphic
= null;
164 //Insert a ControlShape and get the ControlModel
165 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
169 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
171 XControlModel the_Model
= aShape
.getControl();
173 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
177 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
179 XControlModel the_Model2
= aShape2
.getControl();
181 //Try to query XControlAccess
182 XControlAccess the_access
= UnoRuntime
.queryInterface(
183 XControlAccess
.class,
184 xTextDoc
.getCurrentController());
186 //now get the OFormattedControl
188 oObj
= the_access
.getControl(the_Model
);
189 anotherCtrl
= the_access
.getControl(the_Model2
);
190 the_win
= the_access
.getControl(the_Model
).getPeer();
191 the_kit
= the_win
.getToolkit();
192 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
193 aGraphic
= aDevice
.createGraphics();
194 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
195 log
.println("Couldn't get OFormattedControl");
196 e
.printStackTrace(log
);
197 throw new StatusException("Couldn't get OFormattedControl", e
);
200 log
.println("creating a new environment for OFormattedControl object");
202 TestEnvironment tEnv
= new TestEnvironment(oObj
);
205 //Adding ObjRelation for XView
206 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
209 //Adding ObjRelation for XControl
210 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
211 tEnv
.addObjRelation("WINPEER", the_win
);
212 tEnv
.addObjRelation("TOOLKIT", the_kit
);
213 tEnv
.addObjRelation("MODEL", the_Model
);
215 // Adding relation for XWindow
216 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
219 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
220 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
222 // Adding relation for XTextListener
223 ifc
.awt
._XTextListener
.TestTextListener listener
=
224 new ifc
.awt
._XTextListener
.TestTextListener();
225 XTextComponent textComp
= UnoRuntime
.queryInterface(
226 XTextComponent
.class, oObj
);
227 textComp
.addTextListener(listener
);
228 tEnv
.addObjRelation("TestTextListener", listener
);
231 } // finish method getTestEnvironment
232 } // finish class OFormattedControl