1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski package mod._toolkit; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import com.sun.star.accessibility.AccessibleRole; 26*b1cdbd2cSJim Jagielski import com.sun.star.accessibility.XAccessible; 27*b1cdbd2cSJim Jagielski import com.sun.star.accessibility.XAccessibleAction; 28*b1cdbd2cSJim Jagielski import com.sun.star.accessibility.XAccessibleText; 29*b1cdbd2cSJim Jagielski import com.sun.star.awt.PosSize; 30*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControl; 31*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlContainer; 32*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlModel; 33*b1cdbd2cSJim Jagielski import com.sun.star.awt.XFixedText; 34*b1cdbd2cSJim Jagielski import com.sun.star.awt.XWindow; 35*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 36*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextDocument; 37*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 38*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface; 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski import java.io.PrintWriter; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski import lib.StatusException; 43*b1cdbd2cSJim Jagielski import lib.TestCase; 44*b1cdbd2cSJim Jagielski import lib.TestEnvironment; 45*b1cdbd2cSJim Jagielski import lib.TestParameters; 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim Jagielski import util.AccessibilityTools; 48*b1cdbd2cSJim Jagielski import util.utils; 49*b1cdbd2cSJim Jagielski 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski /** 52*b1cdbd2cSJim Jagielski * Test for object which is represented by accesible component 53*b1cdbd2cSJim Jagielski * of the fixed text label in 'Hyperlink' Dialog. <p> 54*b1cdbd2cSJim Jagielski * 55*b1cdbd2cSJim Jagielski * Object implements the following interfaces : 56*b1cdbd2cSJim Jagielski * <ul> 57*b1cdbd2cSJim Jagielski * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li> 58*b1cdbd2cSJim Jagielski * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li> 59*b1cdbd2cSJim Jagielski * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li> 60*b1cdbd2cSJim Jagielski * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li> 61*b1cdbd2cSJim Jagielski * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li> 62*b1cdbd2cSJim Jagielski * </ul> <p> 63*b1cdbd2cSJim Jagielski * 64*b1cdbd2cSJim Jagielski * @see com.sun.star.accessibility.XAccessibleExtendedComponent 65*b1cdbd2cSJim Jagielski * @see com.sun.star.accessibility.XAccessibleEventBroadcaster 66*b1cdbd2cSJim Jagielski * @see com.sun.star.accessibility.XAccessibleComponent 67*b1cdbd2cSJim Jagielski * @see com.sun.star.accessibility.XAccessibleContext 68*b1cdbd2cSJim Jagielski * @see com.sun.star.accessibility.XAccessibleText 69*b1cdbd2cSJim Jagielski * @see ifc.accessibility._XAccessibleExtendedComponent 70*b1cdbd2cSJim Jagielski * @see ifc.accessibility._XAccessibleEventBroadcaster 71*b1cdbd2cSJim Jagielski * @see ifc.accessibility._XAccessibleComponent 72*b1cdbd2cSJim Jagielski * @see ifc.accessibility._XAccessibleContext 73*b1cdbd2cSJim Jagielski * @see ifc.accessibility._XAccessibleText 74*b1cdbd2cSJim Jagielski */ 75*b1cdbd2cSJim Jagielski public class AccessibleFixedText extends TestCase { 76*b1cdbd2cSJim Jagielski private static XTextDocument xTextDoc = null; 77*b1cdbd2cSJim Jagielski private static XAccessibleAction action = null; 78*b1cdbd2cSJim Jagielski private static XWindow xWinDlg = null; 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim Jagielski /** 81*b1cdbd2cSJim Jagielski * Creates a new dialog adds fixed text control to it and 82*b1cdbd2cSJim Jagielski * displays it. Then the text's accessible component is 83*b1cdbd2cSJim Jagielski * obtained. 84*b1cdbd2cSJim Jagielski */ createTestEnvironment(TestParameters Param, PrintWriter log)85*b1cdbd2cSJim Jagielski protected TestEnvironment createTestEnvironment(TestParameters Param, 86*b1cdbd2cSJim Jagielski PrintWriter log) { 87*b1cdbd2cSJim Jagielski XInterface oObj = null; 88*b1cdbd2cSJim Jagielski XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF(); 89*b1cdbd2cSJim Jagielski XControlModel dlgModel = null; 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski XControl txtControl = null; 92*b1cdbd2cSJim Jagielski XControlModel txtModel = null; 93*b1cdbd2cSJim Jagielski 94*b1cdbd2cSJim Jagielski try { 95*b1cdbd2cSJim Jagielski dlgModel = (XControlModel) UnoRuntime.queryInterface( 96*b1cdbd2cSJim Jagielski XControlModel.class, 97*b1cdbd2cSJim Jagielski xMSF.createInstance( 98*b1cdbd2cSJim Jagielski "com.sun.star.awt.UnoControlDialogModel")); 99*b1cdbd2cSJim Jagielski 100*b1cdbd2cSJim Jagielski XControl dlgControl = (XControl) UnoRuntime.queryInterface( 101*b1cdbd2cSJim Jagielski XControl.class, 102*b1cdbd2cSJim Jagielski xMSF.createInstance( 103*b1cdbd2cSJim Jagielski "com.sun.star.awt.UnoControlDialog")); 104*b1cdbd2cSJim Jagielski 105*b1cdbd2cSJim Jagielski dlgControl.setModel(dlgModel); 106*b1cdbd2cSJim Jagielski 107*b1cdbd2cSJim Jagielski txtModel = (XControlModel) UnoRuntime.queryInterface( 108*b1cdbd2cSJim Jagielski XControlModel.class, 109*b1cdbd2cSJim Jagielski xMSF.createInstance( 110*b1cdbd2cSJim Jagielski "com.sun.star.awt.UnoControlFixedTextModel")); 111*b1cdbd2cSJim Jagielski 112*b1cdbd2cSJim Jagielski txtControl = (XControl) UnoRuntime.queryInterface(XControl.class, 113*b1cdbd2cSJim Jagielski xMSF.createInstance( 114*b1cdbd2cSJim Jagielski "com.sun.star.awt.UnoControlFixedText")); 115*b1cdbd2cSJim Jagielski 116*b1cdbd2cSJim Jagielski txtControl.setModel(txtModel); 117*b1cdbd2cSJim Jagielski 118*b1cdbd2cSJim Jagielski XFixedText xFT = (XFixedText) UnoRuntime.queryInterface( 119*b1cdbd2cSJim Jagielski XFixedText.class, txtControl); 120*b1cdbd2cSJim Jagielski xFT.setText("FxedText"); 121*b1cdbd2cSJim Jagielski 122*b1cdbd2cSJim Jagielski XControlContainer ctrlCont = (XControlContainer) UnoRuntime.queryInterface( 123*b1cdbd2cSJim Jagielski XControlContainer.class, 124*b1cdbd2cSJim Jagielski dlgControl); 125*b1cdbd2cSJim Jagielski 126*b1cdbd2cSJim Jagielski ctrlCont.addControl("Text", txtControl); 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class, 129*b1cdbd2cSJim Jagielski dlgControl); 130*b1cdbd2cSJim Jagielski 131*b1cdbd2cSJim Jagielski xWinDlg.setVisible(true); 132*b1cdbd2cSJim Jagielski 133*b1cdbd2cSJim Jagielski xWinDlg.setPosSize(0, 0, 200, 100, PosSize.SIZE); 134*b1cdbd2cSJim Jagielski } catch (com.sun.star.uno.Exception e) { 135*b1cdbd2cSJim Jagielski log.println("Error creating dialog :"); 136*b1cdbd2cSJim Jagielski e.printStackTrace(log); 137*b1cdbd2cSJim Jagielski } 138*b1cdbd2cSJim Jagielski 139*b1cdbd2cSJim Jagielski try { 140*b1cdbd2cSJim Jagielski oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 141*b1cdbd2cSJim Jagielski "com.sun.star.awt.Toolkit"); 142*b1cdbd2cSJim Jagielski } catch (com.sun.star.uno.Exception e) { 143*b1cdbd2cSJim Jagielski log.println("Couldn't get toolkit"); 144*b1cdbd2cSJim Jagielski e.printStackTrace(log); 145*b1cdbd2cSJim Jagielski throw new StatusException("Couldn't get toolkit", e); 146*b1cdbd2cSJim Jagielski } 147*b1cdbd2cSJim Jagielski 148*b1cdbd2cSJim Jagielski shortWait(); 149*b1cdbd2cSJim Jagielski 150*b1cdbd2cSJim Jagielski AccessibilityTools at = new AccessibilityTools(); 151*b1cdbd2cSJim Jagielski 152*b1cdbd2cSJim Jagielski XAccessible xRoot = at.getAccessibleObject(xWinDlg); 153*b1cdbd2cSJim Jagielski 154*b1cdbd2cSJim Jagielski at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE)); 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.LABEL); 157*b1cdbd2cSJim Jagielski 158*b1cdbd2cSJim Jagielski log.println("ImplementationName " + utils.getImplName(oObj)); 159*b1cdbd2cSJim Jagielski 160*b1cdbd2cSJim Jagielski TestEnvironment tEnv = new TestEnvironment(oObj); 161*b1cdbd2cSJim Jagielski 162*b1cdbd2cSJim Jagielski final XWindow xWin = (XWindow) UnoRuntime.queryInterface(XWindow.class, 163*b1cdbd2cSJim Jagielski txtControl); 164*b1cdbd2cSJim Jagielski 165*b1cdbd2cSJim Jagielski tEnv.addObjRelation("EventProducer", 166*b1cdbd2cSJim Jagielski new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() { 167*b1cdbd2cSJim Jagielski public void fireEvent() { 168*b1cdbd2cSJim Jagielski xWin.setEnable(false); 169*b1cdbd2cSJim Jagielski xWin.setEnable(true); 170*b1cdbd2cSJim Jagielski } 171*b1cdbd2cSJim Jagielski }); 172*b1cdbd2cSJim Jagielski 173*b1cdbd2cSJim Jagielski XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface( 174*b1cdbd2cSJim Jagielski XAccessibleText.class, oObj); 175*b1cdbd2cSJim Jagielski 176*b1cdbd2cSJim Jagielski tEnv.addObjRelation("XAccessibleText.Text", text.getText()); 177*b1cdbd2cSJim Jagielski 178*b1cdbd2cSJim Jagielski tEnv.addObjRelation("EditOnly", 179*b1cdbd2cSJim Jagielski "This method isn't supported in this component"); 180*b1cdbd2cSJim Jagielski 181*b1cdbd2cSJim Jagielski tEnv.addObjRelation("LimitedBounds", "yes"); 182*b1cdbd2cSJim Jagielski 183*b1cdbd2cSJim Jagielski return tEnv; 184*b1cdbd2cSJim Jagielski } 185*b1cdbd2cSJim Jagielski 186*b1cdbd2cSJim Jagielski /** 187*b1cdbd2cSJim Jagielski * Closes dialog using action of button 'Close' 188*b1cdbd2cSJim Jagielski */ cleanup(TestParameters Param, PrintWriter log)189*b1cdbd2cSJim Jagielski protected void cleanup(TestParameters Param, PrintWriter log) { 190*b1cdbd2cSJim Jagielski log.println(" Closing dialog ... "); 191*b1cdbd2cSJim Jagielski xWinDlg.dispose(); 192*b1cdbd2cSJim Jagielski } 193*b1cdbd2cSJim Jagielski 194*b1cdbd2cSJim Jagielski /** 195*b1cdbd2cSJim Jagielski * Sleeps for 0.5 sec. to allow StarOffice to react on <code> 196*b1cdbd2cSJim Jagielski * reset</code> call. 197*b1cdbd2cSJim Jagielski */ shortWait()198*b1cdbd2cSJim Jagielski private void shortWait() { 199*b1cdbd2cSJim Jagielski try { 200*b1cdbd2cSJim Jagielski Thread.sleep(500); 201*b1cdbd2cSJim Jagielski } catch (InterruptedException e) { 202*b1cdbd2cSJim Jagielski log.println("While waiting :" + e); 203*b1cdbd2cSJim Jagielski } 204*b1cdbd2cSJim Jagielski } 205*b1cdbd2cSJim Jagielski }