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: OCheckBoxControl.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
.FormTools
;
40 import util
.SOfficeFactory
;
41 import util
.WriterTools
;
43 import com
.sun
.star
.awt
.XCheckBox
;
44 import com
.sun
.star
.awt
.XControl
;
45 import com
.sun
.star
.awt
.XControlModel
;
46 import com
.sun
.star
.awt
.XDevice
;
47 import com
.sun
.star
.awt
.XGraphics
;
48 import com
.sun
.star
.awt
.XToolkit
;
49 import com
.sun
.star
.awt
.XWindow
;
50 import com
.sun
.star
.awt
.XWindowPeer
;
51 import com
.sun
.star
.drawing
.XControlShape
;
52 import com
.sun
.star
.drawing
.XShape
;
53 import com
.sun
.star
.lang
.XMultiServiceFactory
;
54 import com
.sun
.star
.text
.XTextDocument
;
55 import com
.sun
.star
.uno
.UnoRuntime
;
56 import com
.sun
.star
.uno
.XInterface
;
57 import com
.sun
.star
.util
.XCloseable
;
58 import com
.sun
.star
.view
.XControlAccess
;
62 * Test for object which is represented by default controller
63 * of the <code>com.sun.star.form.component.CheckBox</code>
66 * Object implements the following interfaces :
68 * <li> <code>com::sun::star::awt::XView</code></li>
69 * <li> <code>com::sun::star::form::XBoundControl</code></li>
70 * <li> <code>com::sun::star::awt::XControl</code></li>
71 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
72 * <li> <code>com::sun::star::awt::XItemListener</code></li>
73 * <li> <code>com::sun::star::awt::XWindow</code></li>
74 * <li> <code>com::sun::star::awt::XCheckBox</code></li>
75 * <li> <code>com::sun::star::lang::XComponent</code></li>
76 * <li> <code>com::sun::star::lang::XEventListener</code></li>
78 * This object test <b> is NOT </b> designed to be run in several
79 * threads concurently.
81 * @see com.sun.star.awt.XView
82 * @see com.sun.star.form.XBoundControl
83 * @see com.sun.star.awt.XControl
84 * @see com.sun.star.awt.XLayoutConstrains
85 * @see com.sun.star.awt.XItemListener
86 * @see com.sun.star.awt.XWindow
87 * @see com.sun.star.awt.XCheckBox
88 * @see com.sun.star.lang.XComponent
89 * @see com.sun.star.lang.XEventListener
91 * @see ifc.form._XBoundControl
92 * @see ifc.awt._XControl
93 * @see ifc.awt._XLayoutConstrains
94 * @see ifc.awt._XItemListener
95 * @see ifc.awt._XWindow
96 * @see ifc.awt._XCheckBox
97 * @see ifc.lang._XComponent
98 * @see ifc.lang._XEventListener
100 public class OCheckBoxControl
extends TestCase
{
102 XTextDocument xTextDoc
;
105 * Creates a new text document.
107 protected void initialize ( TestParameters Param
, PrintWriter log
) {
108 SOfficeFactory SOF
= SOfficeFactory
.getFactory( ((XMultiServiceFactory
)Param
.getMSF()) );
111 log
.println( "creating a textdocument" );
112 xTextDoc
= SOF
.createTextDoc( null );
113 } catch ( com
.sun
.star
.uno
.Exception e
) {
114 // Some exception occures.FAILED
115 e
.printStackTrace( log
);
116 throw new StatusException( "Couldn't create document", e
);
121 * Disposes the text document created before
123 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
124 log
.println(" disposing xTextDoc ");
127 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
128 XCloseable
.class, xTextDoc
);
130 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
131 log
.println("couldn't close document");
132 } catch (com
.sun
.star
.lang
.DisposedException e
) {
133 log
.println("couldn't close document");
138 * Creates two components and inserts them to the form of
139 * text document. One component
140 * (<code>com.sun.star.form.component.CheckBox</code>) is created
141 * for testing, another to be passed as relation. Using a controller
142 * of the text document the controller of the first component is
143 * obtained and returned in environment as a test object. <p>
145 * Object relations created :
147 * <li> <code>'GRAPHICS'</code> for
148 * {@link ifc.awt._XView} : a graphics component
149 * created using screen device of the window peer of
150 * the controller tested. </li>
151 * <li> <code>'CONTEXT'</code> for
152 * {@link ifc.awt._XControl} : the text document
153 * where the component is inserted. </li>
154 * <li> <code>'WINPEER'</code> for
155 * {@link ifc.awt._XControl} : Window peer of the
156 * controller tested. </li>
157 * <li> <code>'TOOLKIT'</code> for
158 * {@link ifc.awt._XControl} : toolkit of the component.</li>
159 * <li> <code>'MODEL'</code> for
160 * {@link ifc.awt._XControl} : the model of the controller.</li>
161 * <li> <code>'XWindow.AnotherWindow'</code> for
162 * {@link ifc.awt._XWindow} : the controller of another
164 * <li> <code>'TestItemListener'</code> for
165 * {@link ifc.awt._XItemListener} : listener implementation is
166 * registered here and passed as relation. </li>
169 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
170 XInterface oObj
= null;
171 XWindowPeer the_win
= null;
172 XToolkit the_kit
= null;
173 XDevice aDevice
= null;
174 XGraphics aGraphic
= null;
175 XControl aControl
= null;
176 //Insert a ControlShape and get the ControlModel
177 XControlShape aShape
= FormTools
.createControlShape(
178 xTextDoc
,3000,4500,15000,10000,"CheckBox");
180 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
182 XControlModel the_Model
= aShape
.getControl();
184 XControlShape aShape2
= FormTools
.createControlShape(
185 xTextDoc
,3000,4500,5000,10000,"TextField");
187 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
189 XControlModel the_Model2
= aShape2
.getControl();
191 //Try to query XControlAccess
192 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
193 XControlAccess
.class,xTextDoc
.getCurrentController());
195 //now get the OButtonControl
197 oObj
= the_access
.getControl(the_Model
);
198 aControl
= the_access
.getControl(the_Model2
);
199 the_win
= the_access
.getControl(the_Model
).getPeer();
200 the_kit
= the_win
.getToolkit();
201 aDevice
= the_kit
.createScreenCompatibleDevice(200,200);
202 aGraphic
= aDevice
.createGraphics();
203 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
204 log
.println("Couldn't get OCheckBoxControl");
205 e
.printStackTrace(log
);
206 throw new StatusException("Couldn't get OCheckBoxControl", e
);
209 log
.println( "creating a new environment for OCheckBoxControl object" );
210 TestEnvironment tEnv
= new TestEnvironment( oObj
);
212 //Adding ObjRelation for XView
213 tEnv
.addObjRelation("GRAPHICS",aGraphic
);
215 //Adding ObjRelation for XControl
216 tEnv
.addObjRelation("CONTEXT",xTextDoc
);
217 tEnv
.addObjRelation("WINPEER",the_win
);
218 tEnv
.addObjRelation("TOOLKIT",the_kit
);
219 tEnv
.addObjRelation("MODEL",the_Model
);
221 // Adding relation for XItemListener
222 ifc
.awt
._XItemListener
.TestItemListener listener
=
223 new ifc
.awt
._XItemListener
.TestItemListener() ;
224 XCheckBox box
= (XCheckBox
) UnoRuntime
.queryInterface
225 (XCheckBox
.class, oObj
) ;
226 box
.addItemListener(listener
) ;
227 tEnv
.addObjRelation("TestItemListener", listener
) ;
229 // Adding relation for XWindow
230 XWindow forObjRel
= (XWindow
)
231 UnoRuntime
.queryInterface(XWindow
.class,aControl
);
233 tEnv
.addObjRelation("XWindow.AnotherWindow",forObjRel
);
236 } // finish method getTestEnvironment
238 } // finish class OButtonControl