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._toolkit; 24 25 import com.sun.star.accessibility.AccessibleRole; 26 import com.sun.star.accessibility.XAccessible; 27 import com.sun.star.accessibility.XAccessibleAction; 28 import com.sun.star.accessibility.XAccessibleText; 29 import com.sun.star.awt.PosSize; 30 import com.sun.star.awt.XControl; 31 import com.sun.star.awt.XControlContainer; 32 import com.sun.star.awt.XControlModel; 33 import com.sun.star.awt.XFixedText; 34 import com.sun.star.awt.XWindow; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.text.XTextDocument; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 40 import java.io.PrintWriter; 41 42 import lib.StatusException; 43 import lib.TestCase; 44 import lib.TestEnvironment; 45 import lib.TestParameters; 46 47 import util.AccessibilityTools; 48 import util.utils; 49 50 51 /** 52 * Test for object which is represented by accesible component 53 * of the fixed text label in 'Hyperlink' Dialog. <p> 54 * 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 58 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 59 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 60 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 61 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 62 * </ul> <p> 63 * 64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent 65 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 66 * @see com.sun.star.accessibility.XAccessibleComponent 67 * @see com.sun.star.accessibility.XAccessibleContext 68 * @see com.sun.star.accessibility.XAccessibleText 69 * @see ifc.accessibility._XAccessibleExtendedComponent 70 * @see ifc.accessibility._XAccessibleEventBroadcaster 71 * @see ifc.accessibility._XAccessibleComponent 72 * @see ifc.accessibility._XAccessibleContext 73 * @see ifc.accessibility._XAccessibleText 74 */ 75 public class AccessibleFixedText extends TestCase { 76 private static XTextDocument xTextDoc = null; 77 private static XAccessibleAction action = null; 78 private static XWindow xWinDlg = null; 79 80 /** 81 * Creates a new dialog adds fixed text control to it and 82 * displays it. Then the text's accessible component is 83 * obtained. 84 */ createTestEnvironment(TestParameters Param, PrintWriter log)85 protected TestEnvironment createTestEnvironment(TestParameters Param, 86 PrintWriter log) { 87 XInterface oObj = null; 88 XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF(); 89 XControlModel dlgModel = null; 90 91 XControl txtControl = null; 92 XControlModel txtModel = null; 93 94 try { 95 dlgModel = (XControlModel) UnoRuntime.queryInterface( 96 XControlModel.class, 97 xMSF.createInstance( 98 "com.sun.star.awt.UnoControlDialogModel")); 99 100 XControl dlgControl = (XControl) UnoRuntime.queryInterface( 101 XControl.class, 102 xMSF.createInstance( 103 "com.sun.star.awt.UnoControlDialog")); 104 105 dlgControl.setModel(dlgModel); 106 107 txtModel = (XControlModel) UnoRuntime.queryInterface( 108 XControlModel.class, 109 xMSF.createInstance( 110 "com.sun.star.awt.UnoControlFixedTextModel")); 111 112 txtControl = (XControl) UnoRuntime.queryInterface(XControl.class, 113 xMSF.createInstance( 114 "com.sun.star.awt.UnoControlFixedText")); 115 116 txtControl.setModel(txtModel); 117 118 XFixedText xFT = (XFixedText) UnoRuntime.queryInterface( 119 XFixedText.class, txtControl); 120 xFT.setText("FxedText"); 121 122 XControlContainer ctrlCont = (XControlContainer) UnoRuntime.queryInterface( 123 XControlContainer.class, 124 dlgControl); 125 126 ctrlCont.addControl("Text", txtControl); 127 128 xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class, 129 dlgControl); 130 131 xWinDlg.setVisible(true); 132 133 xWinDlg.setPosSize(0, 0, 200, 100, PosSize.SIZE); 134 } catch (com.sun.star.uno.Exception e) { 135 log.println("Error creating dialog :"); 136 e.printStackTrace(log); 137 } 138 139 try { 140 oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 141 "com.sun.star.awt.Toolkit"); 142 } catch (com.sun.star.uno.Exception e) { 143 log.println("Couldn't get toolkit"); 144 e.printStackTrace(log); 145 throw new StatusException("Couldn't get toolkit", e); 146 } 147 148 shortWait(); 149 150 AccessibilityTools at = new AccessibilityTools(); 151 152 XAccessible xRoot = at.getAccessibleObject(xWinDlg); 153 154 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 155 156 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL); 157 158 log.println("ImplementationName " + utils.getImplName(oObj)); 159 160 TestEnvironment tEnv = new TestEnvironment(oObj); 161 162 final XWindow xWin = (XWindow) UnoRuntime.queryInterface(XWindow.class, 163 txtControl); 164 165 tEnv.addObjRelation("EventProducer", 166 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 167 public void fireEvent() { 168 xWin.setEnable(false); 169 xWin.setEnable(true); 170 } 171 }); 172 173 XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 174 XAccessibleText.class, oObj); 175 176 tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 177 178 tEnv.addObjRelation("EditOnly", 179 "This method isn't supported in this component"); 180 181 tEnv.addObjRelation("LimitedBounds", "yes"); 182 183 return tEnv; 184 } 185 186 /** 187 * Closes dialog using action of button 'Close' 188 */ cleanup(TestParameters Param, PrintWriter log)189 protected void cleanup(TestParameters Param, PrintWriter log) { 190 log.println(" Closing dialog ... "); 191 xWinDlg.dispose(); 192 } 193 194 /** 195 * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 196 * reset</code> call. 197 */ shortWait()198 private void shortWait() { 199 try { 200 Thread.sleep(500); 201 } catch (InterruptedException e) { 202 log.println("While waiting :" + e); 203 } 204 } 205 }