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: OImageButtonControl.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 ************************************************************************/
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.FormTools
;
39 import util
.SOfficeFactory
;
40 import util
.WriterTools
;
42 import com
.sun
.star
.awt
.XControlModel
;
43 import com
.sun
.star
.awt
.XDevice
;
44 import com
.sun
.star
.awt
.XGraphics
;
45 import com
.sun
.star
.awt
.XToolkit
;
46 import com
.sun
.star
.awt
.XWindow
;
47 import com
.sun
.star
.awt
.XWindowPeer
;
48 import com
.sun
.star
.drawing
.XControlShape
;
49 import com
.sun
.star
.drawing
.XShape
;
50 import com
.sun
.star
.lang
.XMultiServiceFactory
;
51 import com
.sun
.star
.text
.XTextDocument
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
54 import com
.sun
.star
.util
.XCloseable
;
55 import com
.sun
.star
.view
.XControlAccess
;
59 * Test for object which is represented by default controller
60 * of the <code>com.sun.star.form.component.ImageButton</code>
63 * Object implements the following interfaces :
65 * <li> <code>com::sun::star::lang::XComponent</code></li>
66 * <li> <code>com::sun::star::awt::XWindow</code></li>
67 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li>
68 * <li> <code>com::sun::star::awt::XControl</code></li>
69 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li>
70 * <li> <code>com::sun::star::awt::XView</code></li>
72 * This object test <b> is NOT </b> designed to be run in several
73 * threads concurently.
75 * @see com.sun.star.lang.XComponent
76 * @see com.sun.star.awt.XWindow
77 * @see com.sun.star.form.XApproveActionBroadcaster
78 * @see com.sun.star.awt.XControl
79 * @see com.sun.star.awt.XLayoutConstrains
80 * @see com.sun.star.awt.XView
81 * @see ifc.lang._XComponent
82 * @see ifc.awt._XWindow
83 * @see ifc.form._XApproveActionBroadcaster
84 * @see ifc.awt._XControl
85 * @see ifc.awt._XLayoutConstrains
88 public class OImageButtonControl
extends TestCase
{
89 XTextDocument xTextDoc
;
92 * Creates a new text document.
94 protected void initialize(TestParameters Param
, PrintWriter log
) {
95 SOfficeFactory SOF
= SOfficeFactory
.getFactory(((XMultiServiceFactory
) Param
.getMSF()));
98 log
.println("creating a textdocument");
99 xTextDoc
= SOF
.createTextDoc(null);
100 } catch (com
.sun
.star
.uno
.Exception e
) {
101 // Some exception occures.FAILED
102 e
.printStackTrace(log
);
103 throw new StatusException("Couldn't create document", e
);
108 * Disposes the text document created before
110 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
111 log
.println(" disposing xTextDoc ");
114 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
115 XCloseable
.class, xTextDoc
);
117 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
118 log
.println("couldn't close document");
119 } catch (com
.sun
.star
.lang
.DisposedException e
) {
120 log
.println("couldn't close document");
125 * Creates two components and inserts them to the form of
126 * text document. One component
127 * (<code>com.sun.star.form.component.ImageButton</code>) is created
128 * for testing, another to be passed as relation. Using a controller
129 * of the text document the controller of the first component is
130 * obtained and returned in environment as a test object. <p>
132 * Object relations created :
134 * <li> <code>'GRAPHICS'</code> for
135 * {@link ifc.awt._XView} : a graphics component
136 * created using screen device of the window peer of
137 * the controller tested. </li>
138 * <li> <code>'CONTEXT'</code> for
139 * {@link ifc.awt._XControl} : the text document
140 * where the component is inserted. </li>
141 * <li> <code>'WINPEER'</code> for
142 * {@link ifc.awt._XControl} : Window peer of the
143 * controller tested. </li>
144 * <li> <code>'TOOLKIT'</code> for
145 * {@link ifc.awt._XControl} : toolkit of the component.</li>
146 * <li> <code>'MODEL'</code> for
147 * {@link ifc.awt._XControl} : the model of the controller.</li>
148 * <li> <code>'XWindow.AnotherWindow'</code> for
149 * {@link ifc.awt._XWindow} : the controller of another
153 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
155 XInterface oObj
= null;
156 Object anotherCtrl
= null;
157 XWindowPeer the_win
= null;
158 XToolkit the_kit
= null;
159 XDevice aDevice
= null;
160 XGraphics aGraphic
= null;
162 //Insert a ControlShape and get the ControlModel
163 XControlShape aShape
= FormTools
.createControlShape(xTextDoc
, 3000,
167 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
169 XControlModel the_Model
= aShape
.getControl();
171 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
175 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
177 XControlModel the_Model2
= aShape2
.getControl();
179 //Try to query XControlAccess
180 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
181 XControlAccess
.class,
182 xTextDoc
.getCurrentController());
184 //now get the OImageButtonControl
186 oObj
= the_access
.getControl(the_Model
);
187 anotherCtrl
= the_access
.getControl(the_Model2
);
188 the_win
= the_access
.getControl(the_Model
).getPeer();
189 the_kit
= the_win
.getToolkit();
190 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
191 aGraphic
= aDevice
.createGraphics();
192 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
193 log
.println("Couldn't get OImageButtonControl");
194 e
.printStackTrace(log
);
195 throw new StatusException("Couldn't get OImageButtonControl", e
);
199 "creating a new environment for OImageButtonControl object");
201 TestEnvironment tEnv
= new TestEnvironment(oObj
);
204 //Adding ObjRelation for XView
205 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
208 //Adding ObjRelation for XControl
209 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
210 tEnv
.addObjRelation("WINPEER", the_win
);
211 tEnv
.addObjRelation("TOOLKIT", the_kit
);
212 tEnv
.addObjRelation("MODEL", the_Model
);
214 // Adding relation for XWindow
215 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
218 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
221 } // finish method getTestEnvironment
222 } // finish class OImageButtonControl