1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package mod._forms; 24 25 import java.io.PrintWriter; 26 27 import lib.StatusException; 28 import lib.TestCase; 29 import lib.TestEnvironment; 30 import lib.TestParameters; 31 import util.FormTools; 32 import util.SOfficeFactory; 33 import util.WriterTools; 34 35 import com.sun.star.awt.XControlModel; 36 import com.sun.star.awt.XDevice; 37 import com.sun.star.awt.XGraphics; 38 import com.sun.star.awt.XToolkit; 39 import com.sun.star.awt.XWindow; 40 import com.sun.star.awt.XWindowPeer; 41 import com.sun.star.drawing.XControlShape; 42 import com.sun.star.drawing.XShape; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.uno.UnoRuntime; 46 import com.sun.star.uno.XInterface; 47 import com.sun.star.util.XCloseable; 48 import com.sun.star.view.XControlAccess; 49 50 51 /** 52 * Test for object which is represented by default controller 53 * of the <code>com.sun.star.form.component.ImageButton</code> 54 * component. <p> 55 * 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::lang::XComponent</code></li> 59 * <li> <code>com::sun::star::awt::XWindow</code></li> 60 * <li> <code>com::sun::star::form::XApproveActionBroadcaster</code></li> 61 * <li> <code>com::sun::star::awt::XControl</code></li> 62 * <li> <code>com::sun::star::awt::XLayoutConstrains</code></li> 63 * <li> <code>com::sun::star::awt::XView</code></li> 64 * </ul> <p> 65 * This object test <b> is NOT </b> designed to be run in several 66 * threads concurently. 67 * 68 * @see com.sun.star.lang.XComponent 69 * @see com.sun.star.awt.XWindow 70 * @see com.sun.star.form.XApproveActionBroadcaster 71 * @see com.sun.star.awt.XControl 72 * @see com.sun.star.awt.XLayoutConstrains 73 * @see com.sun.star.awt.XView 74 * @see ifc.lang._XComponent 75 * @see ifc.awt._XWindow 76 * @see ifc.form._XApproveActionBroadcaster 77 * @see ifc.awt._XControl 78 * @see ifc.awt._XLayoutConstrains 79 * @see ifc.awt._XView 80 */ 81 public class OImageButtonControl extends TestCase { 82 XTextDocument xTextDoc; 83 84 /** 85 * Creates a new text document. 86 */ initialize(TestParameters Param, PrintWriter log)87 protected void initialize(TestParameters Param, PrintWriter log) { 88 SOfficeFactory SOF = SOfficeFactory.getFactory(((XMultiServiceFactory) Param.getMSF())); 89 90 try { 91 log.println("creating a textdocument"); 92 xTextDoc = SOF.createTextDoc(null); 93 } catch (com.sun.star.uno.Exception e) { 94 // Some exception occured.FAILED 95 e.printStackTrace(log); 96 throw new StatusException("Couldn't create document", e); 97 } 98 } 99 100 /** 101 * Disposes the text document created before 102 */ cleanup(TestParameters tParam, PrintWriter log)103 protected void cleanup(TestParameters tParam, PrintWriter log) { 104 log.println(" disposing xTextDoc "); 105 106 try { 107 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 108 XCloseable.class, xTextDoc); 109 closer.close(true); 110 } catch (com.sun.star.util.CloseVetoException e) { 111 log.println("couldn't close document"); 112 } catch (com.sun.star.lang.DisposedException e) { 113 log.println("couldn't close document"); 114 } 115 } 116 117 /** 118 * Creates two components and inserts them to the form of 119 * text document. One component 120 * (<code>com.sun.star.form.component.ImageButton</code>) is created 121 * for testing, another to be passed as relation. Using a controller 122 * of the text document the controller of the first component is 123 * obtained and returned in environment as a test object. <p> 124 * 125 * Object relations created : 126 * <ul> 127 * <li> <code>'GRAPHICS'</code> for 128 * {@link ifc.awt._XView} : a graphics component 129 * created using screen device of the window peer of 130 * the controller tested. </li> 131 * <li> <code>'CONTEXT'</code> for 132 * {@link ifc.awt._XControl} : the text document 133 * where the component is inserted. </li> 134 * <li> <code>'WINPEER'</code> for 135 * {@link ifc.awt._XControl} : Window peer of the 136 * controller tested. </li> 137 * <li> <code>'TOOLKIT'</code> for 138 * {@link ifc.awt._XControl} : toolkit of the component.</li> 139 * <li> <code>'MODEL'</code> for 140 * {@link ifc.awt._XControl} : the model of the controller.</li> 141 * <li> <code>'XWindow.AnotherWindow'</code> for 142 * {@link ifc.awt._XWindow} : the controller of another 143 * component. </li> 144 * </ul> 145 */ createTestEnvironment(TestParameters Param, PrintWriter log)146 protected TestEnvironment createTestEnvironment(TestParameters Param, 147 PrintWriter log) { 148 XInterface oObj = null; 149 Object anotherCtrl = null; 150 XWindowPeer the_win = null; 151 XToolkit the_kit = null; 152 XDevice aDevice = null; 153 XGraphics aGraphic = null; 154 155 //Insert a ControlShape and get the ControlModel 156 XControlShape aShape = FormTools.createControlShape(xTextDoc, 3000, 157 4500, 15000, 10000, 158 "ImageButton"); 159 160 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 161 162 XControlModel the_Model = aShape.getControl(); 163 164 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000, 165 4500, 5000, 10000, 166 "TextField"); 167 168 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2); 169 170 XControlModel the_Model2 = aShape2.getControl(); 171 172 //Try to query XControlAccess 173 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 174 XControlAccess.class, 175 xTextDoc.getCurrentController()); 176 177 //now get the OImageButtonControl 178 try { 179 oObj = the_access.getControl(the_Model); 180 anotherCtrl = the_access.getControl(the_Model2); 181 the_win = the_access.getControl(the_Model).getPeer(); 182 the_kit = the_win.getToolkit(); 183 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 184 aGraphic = aDevice.createGraphics(); 185 } catch (com.sun.star.container.NoSuchElementException e) { 186 log.println("Couldn't get OImageButtonControl"); 187 e.printStackTrace(log); 188 throw new StatusException("Couldn't get OImageButtonControl", e); 189 } 190 191 log.println( 192 "creating a new environment for OImageButtonControl object"); 193 194 TestEnvironment tEnv = new TestEnvironment(oObj); 195 196 197 //Adding ObjRelation for XView 198 tEnv.addObjRelation("GRAPHICS", aGraphic); 199 200 201 //Adding ObjRelation for XControl 202 tEnv.addObjRelation("CONTEXT", xTextDoc); 203 tEnv.addObjRelation("WINPEER", the_win); 204 tEnv.addObjRelation("TOOLKIT", the_kit); 205 tEnv.addObjRelation("MODEL", the_Model); 206 207 // Adding relation for XWindow 208 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class, 209 anotherCtrl); 210 211 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel); 212 213 return tEnv; 214 } // finish method getTestEnvironment 215 } // finish class OImageButtonControl 216