1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package util; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.awt.Point; 31*cdf0e10cSrcweir import com.sun.star.awt.XTopWindow; 32*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 33*cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 34*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir import com.sun.star.frame.XModel; 37*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 38*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 39*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleAction; 40*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 41*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 42*cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit; 43*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 44*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleEditableText; 45*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleSelection; 46*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText; 47*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleValue; 48*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 49*cdf0e10cSrcweir import java.awt.Robot; 50*cdf0e10cSrcweir import java.awt.event.InputEvent; 51*cdf0e10cSrcweir import java.io.PrintWriter; 52*cdf0e10cSrcweir import java.util.Vector; 53*cdf0e10cSrcweir import util.AccessibilityTools; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** 57*cdf0e10cSrcweir * This class supports some functions to handle easily accessible objects 58*cdf0e10cSrcweir */ 59*cdf0e10cSrcweir public class UITools { 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir private static final AccessibilityTools mAT = new AccessibilityTools(); 62*cdf0e10cSrcweir private final XAccessible mXRoot; 63*cdf0e10cSrcweir private final XMultiServiceFactory mMSF; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir public UITools(XMultiServiceFactory msf, XModel xModel) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir mMSF = msf; 68*cdf0e10cSrcweir mXRoot = makeRoot(mMSF, xModel); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir public UITools(XMultiServiceFactory msf, XTextDocument xTextDoc) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir mMSF = msf; 74*cdf0e10cSrcweir XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc); 75*cdf0e10cSrcweir mXRoot = makeRoot(mMSF, xModel); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir public UITools(XMultiServiceFactory msf, XWindow xWindow) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir mMSF = msf; 81*cdf0e10cSrcweir mXRoot = makeRoot(xWindow); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir private static XAccessible makeRoot(XMultiServiceFactory msf, XModel aModel) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir XWindow xWindow = mAT.getCurrentWindow(msf, aModel); 87*cdf0e10cSrcweir return mAT.getAccessibleObject(xWindow); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir private static String getString(XInterface xInt) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir XAccessibleText oText = (XAccessibleText) 94*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleText.class, xInt); 95*cdf0e10cSrcweir return oText.getText(); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir private static void setString(XInterface xInt, String cText) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir XAccessibleEditableText oText = (XAccessibleEditableText) 101*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleEditableText.class, xInt); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir oText.setText(cText); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir private static Object getValue(XInterface xInt) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir XAccessibleValue oValue = (XAccessibleValue) 109*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleValue.class, xInt); 110*cdf0e10cSrcweir return oValue.getCurrentValue(); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir private static XAccessible makeRoot(XWindow xWindow) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir return mAT.getAccessibleObject(xWindow); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir /** 119*cdf0e10cSrcweir * get the root element of the accessible tree 120*cdf0e10cSrcweir * @return the root element 121*cdf0e10cSrcweir */ 122*cdf0e10cSrcweir public XAccessible getRoot() 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir return mXRoot; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir /** 128*cdf0e10cSrcweir * Helper mathod: set a text into AccessibleEdit field 129*cdf0e10cSrcweir * @param textfiledName is the name of the text field 130*cdf0e10cSrcweir * @param stringToSet is the string to set 131*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 132*cdf0e10cSrcweir */ 133*cdf0e10cSrcweir public void setTextEditFiledText(String textfiledName, String stringToSet) 134*cdf0e10cSrcweir throws java.lang.Exception 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir XInterface oTextField = mAT.getAccessibleObjectForRole(mXRoot, 137*cdf0e10cSrcweir AccessibleRole.TEXT, textfiledName); 138*cdf0e10cSrcweir setString(oTextField, stringToSet); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir /** 142*cdf0e10cSrcweir * returns the button by the given name 143*cdf0e10cSrcweir * @param buttonName is name name of the button to get 144*cdf0e10cSrcweir * @return a XAccessibleContext of the button 145*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir public XAccessibleContext getButton(String buttonName) throws java.lang.Exception 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return mAT.getAccessibleObjectForRole 150*cdf0e10cSrcweir (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir /** 154*cdf0e10cSrcweir * Helper method: gets button via accessibility and 'click' it</code> 155*cdf0e10cSrcweir * @param buttonName is name name of the button to click 156*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 157*cdf0e10cSrcweir */ 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir public void clickButton(String buttonName) throws java.lang.Exception 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir XAccessibleContext oButton =mAT.getAccessibleObjectForRole 163*cdf0e10cSrcweir (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName); 164*cdf0e10cSrcweir if (oButton == null){ 165*cdf0e10cSrcweir throw new Exception("Could not get button '" + buttonName + "'"); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir XAccessibleAction oAction = (XAccessibleAction) 168*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleAction.class, oButton); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // "click" the button 171*cdf0e10cSrcweir try{ 172*cdf0e10cSrcweir oAction.doAccessibleAction(0); 173*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 174*cdf0e10cSrcweir throw new Exception("Could not do accessible action with '" + 175*cdf0e10cSrcweir buttonName + "'" + e.toString()); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir /** 182*cdf0e10cSrcweir * Helper method: gets button via accessibility and 'click' it 183*cdf0e10cSrcweir * @param buttonName The name of the button in the accessibility tree 184*cdf0e10cSrcweir * @param toBePressed desired state of the toggle button 185*cdf0e10cSrcweir * 186*cdf0e10cSrcweir * @return true if the state of the button could be changed in the desired manner 187*cdf0e10cSrcweir */ 188*cdf0e10cSrcweir private boolean clickToggleButton(String buttonName, boolean toBePressed) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir XAccessibleContext oButton =mAT.getAccessibleObjectForRole 191*cdf0e10cSrcweir (mXRoot, AccessibleRole.TOGGLE_BUTTON, buttonName); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if (oButton != null){ 194*cdf0e10cSrcweir boolean isChecked = oButton.getAccessibleStateSet().contains(com.sun.star.accessibility.AccessibleStateType.CHECKED); 195*cdf0e10cSrcweir if((isChecked && !toBePressed) || (!isChecked && toBePressed)){ 196*cdf0e10cSrcweir XAccessibleAction oAction = (XAccessibleAction) 197*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleAction.class, oButton); 198*cdf0e10cSrcweir try{ 199*cdf0e10cSrcweir // "click" the button 200*cdf0e10cSrcweir oAction.doAccessibleAction(0); 201*cdf0e10cSrcweir return true; 202*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 203*cdf0e10cSrcweir System.out.println("Could not do accessible action with '" 204*cdf0e10cSrcweir + buttonName + "'" + e.toString()); 205*cdf0e10cSrcweir return false; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir }else 208*cdf0e10cSrcweir //no need to press togglebar, do nothing 209*cdf0e10cSrcweir return true; 210*cdf0e10cSrcweir } else{ 211*cdf0e10cSrcweir System.out.println("Could not get button '" + buttonName + "'"); 212*cdf0e10cSrcweir return false; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir /** 217*cdf0e10cSrcweir * Deactivates toggle button via Accessibility 218*cdf0e10cSrcweir * @param buttonName The name of the button in the Accessibility tree 219*cdf0e10cSrcweir * 220*cdf0e10cSrcweir * @return true if the button could be set to deactivated 221*cdf0e10cSrcweir */ 222*cdf0e10cSrcweir public boolean deactivateToggleButton(String buttonName){ 223*cdf0e10cSrcweir return clickToggleButton(buttonName, false); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir /** 227*cdf0e10cSrcweir * Activates toggle button via Accessibility 228*cdf0e10cSrcweir * @param buttonName The name of the button in the Accessibility tree 229*cdf0e10cSrcweir * 230*cdf0e10cSrcweir * @return true if the button could be set to activated 231*cdf0e10cSrcweir */ 232*cdf0e10cSrcweir public boolean activateToggleButton(String buttonName){ 233*cdf0e10cSrcweir return clickToggleButton(buttonName, true); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir /** 237*cdf0e10cSrcweir * returns the value of named radio button 238*cdf0e10cSrcweir * @param buttonName the name of the button to get the value of 239*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 240*cdf0e10cSrcweir * @return Integer 241*cdf0e10cSrcweir */ 242*cdf0e10cSrcweir public Integer getRadioButtonValue(String buttonName) 243*cdf0e10cSrcweir throws java.lang.Exception 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir try { 246*cdf0e10cSrcweir XInterface xRB =mAT.getAccessibleObjectForRole(mXRoot, 247*cdf0e10cSrcweir AccessibleRole.RADIO_BUTTON, buttonName); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir return (Integer) getValue(xRB); 250*cdf0e10cSrcweir } catch (Exception e) { 251*cdf0e10cSrcweir throw new Exception("Could not get value from RadioButton '" 252*cdf0e10cSrcweir + buttonName + "' : " + e.toString()); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir /** 257*cdf0e10cSrcweir * returns the named graphic 258*cdf0e10cSrcweir * @param GraphicName the name of the graphic 259*cdf0e10cSrcweir * @return XInterface 260*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 261*cdf0e10cSrcweir */ 262*cdf0e10cSrcweir public XInterface getGraphic(String GraphicName) throws java.lang.Exception 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir return mAT.getAccessibleObjectForRole(mXRoot, AccessibleRole.GRAPHIC, 265*cdf0e10cSrcweir GraphicName); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir /** 270*cdf0e10cSrcweir * set a named radio button the a given value 271*cdf0e10cSrcweir * @param buttonName the name of the button to set 272*cdf0e10cSrcweir * @param iValue the value to set 273*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 274*cdf0e10cSrcweir */ 275*cdf0e10cSrcweir public void setRadioButtonValue(String buttonName, int iValue) 276*cdf0e10cSrcweir throws java.lang.Exception 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir try { 279*cdf0e10cSrcweir XInterface xRB =mAT.getAccessibleObjectForRole(mXRoot, AccessibleRole.RADIO_BUTTON, buttonName); 280*cdf0e10cSrcweir if(xRB == null) 281*cdf0e10cSrcweir System.out.println("AccessibleObjectForRole couldn't be found for " + buttonName); 282*cdf0e10cSrcweir XAccessibleValue oValue = (XAccessibleValue) 283*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleValue.class, xRB); 284*cdf0e10cSrcweir if(oValue == null) 285*cdf0e10cSrcweir System.out.println("XAccessibleValue couldn't be queried for " + buttonName); 286*cdf0e10cSrcweir oValue.setCurrentValue(new Integer(iValue)); 287*cdf0e10cSrcweir } catch (Exception e) { 288*cdf0e10cSrcweir e.printStackTrace(); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir throw new Exception("Could not set value to RadioButton '" 291*cdf0e10cSrcweir + buttonName + "' : " + e.toString()); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir /** 297*cdf0e10cSrcweir * select an item in nanmed listbox 298*cdf0e10cSrcweir * @param ListBoxName the name of the listbox 299*cdf0e10cSrcweir * @param nChildIndex the index of the item to set 300*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 301*cdf0e10cSrcweir */ 302*cdf0e10cSrcweir public void selectListboxItem(String ListBoxName, int nChildIndex) 303*cdf0e10cSrcweir throws java.lang.Exception 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir try { 306*cdf0e10cSrcweir XAccessibleContext xListBox = null; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 309*cdf0e10cSrcweir AccessibleRole.COMBO_BOX, ListBoxName); 310*cdf0e10cSrcweir if (xListBox == null){ 311*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 312*cdf0e10cSrcweir AccessibleRole.PANEL, ListBoxName); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir XAccessible xListBoxAccess = (XAccessible) 315*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessible.class, xListBox); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir // if a List is not pulled to be open all entries are not visiblle, therefore the 318*cdf0e10cSrcweir // boolean argument 319*cdf0e10cSrcweir XAccessibleContext xList =mAT.getAccessibleObjectForRole( 320*cdf0e10cSrcweir xListBoxAccess, AccessibleRole.LIST, true); 321*cdf0e10cSrcweir XAccessibleSelection xListSelect = (XAccessibleSelection) 322*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleSelection.class, xList); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir xListSelect.selectAccessibleChild(nChildIndex); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir } catch (Exception e) { 327*cdf0e10cSrcweir throw new Exception("Could not select item '" +nChildIndex+ 328*cdf0e10cSrcweir "' in listbox '" + ListBoxName + "' : " + e.toString()); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir /** 333*cdf0e10cSrcweir * This method returns all entries as XInterface of a list box 334*cdf0e10cSrcweir * @param ListBoxName the name of the listbox 335*cdf0e10cSrcweir * @return Object[] containing XInterface 336*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 337*cdf0e10cSrcweir */ 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir public Object[] getListBoxObjects(String ListBoxName) 340*cdf0e10cSrcweir throws java.lang.Exception 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir Vector Items = new Vector(); 343*cdf0e10cSrcweir try { 344*cdf0e10cSrcweir XAccessibleContext xListBox = null; 345*cdf0e10cSrcweir XAccessibleContext xList = null; 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 348*cdf0e10cSrcweir AccessibleRole.COMBO_BOX, ListBoxName); 349*cdf0e10cSrcweir if (xListBox == null){ 350*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 351*cdf0e10cSrcweir AccessibleRole.PANEL, ListBoxName); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir if (xListBox == null){ 355*cdf0e10cSrcweir // get the list of TreeListBox 356*cdf0e10cSrcweir xList =mAT.getAccessibleObjectForRole(mXRoot, 357*cdf0e10cSrcweir AccessibleRole.TREE, ListBoxName); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir // all other list boxes have a children of kind of LIST 360*cdf0e10cSrcweir } else { 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir XAccessible xListBoxAccess = (XAccessible) 363*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessible.class, xListBox); 364*cdf0e10cSrcweir // if a List is not pulled to be open all entries are not visiblle, therefore the 365*cdf0e10cSrcweir // boolean argument 366*cdf0e10cSrcweir xList =mAT.getAccessibleObjectForRole( 367*cdf0e10cSrcweir xListBoxAccess, AccessibleRole.LIST, true); 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir for (int i=0;i<xList.getAccessibleChildCount();i++) { 371*cdf0e10cSrcweir try { 372*cdf0e10cSrcweir XAccessible xChild = xList.getAccessibleChild(i); 373*cdf0e10cSrcweir XAccessibleContext xChildCont = 374*cdf0e10cSrcweir xChild.getAccessibleContext(); 375*cdf0e10cSrcweir XInterface xChildInterface = (XInterface) 376*cdf0e10cSrcweir UnoRuntime.queryInterface(XInterface.class, xChildCont); 377*cdf0e10cSrcweir Items.add(xChildInterface); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 380*cdf0e10cSrcweir throw new Exception("Could not get child form list of '" 381*cdf0e10cSrcweir + ListBoxName + "' : " + e.toString()); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir } catch (Exception e) { 386*cdf0e10cSrcweir throw new Exception("Could not get list of items from '" 387*cdf0e10cSrcweir + ListBoxName + "' : " + e.toString()); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir Object[]ret = new XInterface[Items.size()]; 390*cdf0e10cSrcweir for (int i=0;i<Items.size();i++){ 391*cdf0e10cSrcweir ret[i] = Items.get(i); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir return ret; 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir /** 397*cdf0e10cSrcweir * Helper method: returns the entry manes of a List-Box 398*cdf0e10cSrcweir * @param ListBoxName the name of the listbox 399*cdf0e10cSrcweir * @return the listbox entry names 400*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 401*cdf0e10cSrcweir */ 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir public String[] getListBoxItems(String ListBoxName) 404*cdf0e10cSrcweir throws java.lang.Exception 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir Vector Items = new Vector(); 407*cdf0e10cSrcweir try { 408*cdf0e10cSrcweir XAccessibleContext xListBox = null; 409*cdf0e10cSrcweir XAccessibleContext xList = null; 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 412*cdf0e10cSrcweir AccessibleRole.COMBO_BOX, ListBoxName); 413*cdf0e10cSrcweir if (xListBox == null){ 414*cdf0e10cSrcweir xListBox =mAT.getAccessibleObjectForRole(mXRoot, 415*cdf0e10cSrcweir AccessibleRole.PANEL, ListBoxName); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir if (xListBox == null){ 419*cdf0e10cSrcweir // get the list of TreeListBox 420*cdf0e10cSrcweir xList =mAT.getAccessibleObjectForRole(mXRoot, 421*cdf0e10cSrcweir AccessibleRole.TREE, ListBoxName); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir // all other list boxes have a children of kind of LIST 424*cdf0e10cSrcweir } else { 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir XAccessible xListBoxAccess = (XAccessible) 427*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessible.class, xListBox); 428*cdf0e10cSrcweir // if a List is not pulled to be open all entries are not visiblle, therefore the 429*cdf0e10cSrcweir // boolean argument 430*cdf0e10cSrcweir xList =mAT.getAccessibleObjectForRole( 431*cdf0e10cSrcweir xListBoxAccess, AccessibleRole.LIST, true); 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir for (int i=0;i<xList.getAccessibleChildCount();i++) { 435*cdf0e10cSrcweir try { 436*cdf0e10cSrcweir XAccessible xChild = xList.getAccessibleChild(i); 437*cdf0e10cSrcweir XAccessibleContext xChildCont = 438*cdf0e10cSrcweir xChild.getAccessibleContext(); 439*cdf0e10cSrcweir XInterface xChildInterface = (XInterface) 440*cdf0e10cSrcweir UnoRuntime.queryInterface(XInterface.class, xChildCont); 441*cdf0e10cSrcweir Items.add(getString(xChildInterface)); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 444*cdf0e10cSrcweir throw new Exception("Could not get child form list of '" 445*cdf0e10cSrcweir + ListBoxName + "' : " + e.toString()); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir } catch (Exception e) { 450*cdf0e10cSrcweir throw new Exception("Could not get list of items from '" 451*cdf0e10cSrcweir + ListBoxName + "' : " + e.toString()); 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir String[]ret = new String[Items.size()]; 454*cdf0e10cSrcweir return (String[])Items.toArray(ret); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir /** 457*cdf0e10cSrcweir * set to a named nureric filed a given value 458*cdf0e10cSrcweir * @param NumericFieldName the name of the nureic field 459*cdf0e10cSrcweir * @param cValue the value to set 460*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 461*cdf0e10cSrcweir */ 462*cdf0e10cSrcweir public void setNumericFieldValue(String NumericFieldName, String cValue) 463*cdf0e10cSrcweir throws java.lang.Exception 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir try{ 466*cdf0e10cSrcweir XInterface xNumericField =mAT.getAccessibleObjectForRole( 467*cdf0e10cSrcweir mXRoot, AccessibleRole.TEXT, NumericFieldName); 468*cdf0e10cSrcweir //util.dbg.printInterfaces(xNumericField); 469*cdf0e10cSrcweir XAccessibleEditableText oValue = (XAccessibleEditableText) 470*cdf0e10cSrcweir UnoRuntime.queryInterface( 471*cdf0e10cSrcweir XAccessibleEditableText.class, xNumericField); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir setString(xNumericField, cValue); 474*cdf0e10cSrcweir } catch (Exception e) { 475*cdf0e10cSrcweir throw new Exception("Could not set value '" + cValue + 476*cdf0e10cSrcweir "' into NumericField '" + NumericFieldName + "' : " + e.toString()); 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir /** 481*cdf0e10cSrcweir * returns the value of a numeric field 482*cdf0e10cSrcweir * @param NumericFieldName the name of the numreic field 483*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 484*cdf0e10cSrcweir * @return the value of the named numeric filed 485*cdf0e10cSrcweir */ 486*cdf0e10cSrcweir public String getNumericFieldValue(String NumericFieldName) 487*cdf0e10cSrcweir throws java.lang.Exception 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir try{ 490*cdf0e10cSrcweir XInterface xNumericField =mAT.getAccessibleObjectForRole( 491*cdf0e10cSrcweir mXRoot, AccessibleRole.TEXT, NumericFieldName); 492*cdf0e10cSrcweir return (String) getString(xNumericField); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir } catch (Exception e) { 495*cdf0e10cSrcweir throw new Exception("Could get value from NumericField '" 496*cdf0e10cSrcweir + NumericFieldName + "' : " + e.toString()); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir private String removeCharactersFromCurrencyString(String stringVal) 501*cdf0e10cSrcweir throws java.lang.Exception 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir try{ 504*cdf0e10cSrcweir int beginIndex = 0; 505*cdf0e10cSrcweir int endIndex = 0; 506*cdf0e10cSrcweir boolean startFound = false; 507*cdf0e10cSrcweir // find the first numeric character in stringVal 508*cdf0e10cSrcweir for(int i = 0; i < stringVal.length(); i++){ 509*cdf0e10cSrcweir int numVal = Character.getNumericValue(stringVal.charAt(i)); 510*cdf0e10cSrcweir // if ascii is a numeric value 511*cdf0e10cSrcweir if (numVal != -1){ 512*cdf0e10cSrcweir beginIndex = i; 513*cdf0e10cSrcweir break; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir // find the last numeric character in stringVal 517*cdf0e10cSrcweir for(int i = stringVal.length()-1; i > 0; i--){ 518*cdf0e10cSrcweir int numVal = Character.getNumericValue(stringVal.charAt(i)); 519*cdf0e10cSrcweir if (numVal != -1){ 520*cdf0e10cSrcweir endIndex = i+1; 521*cdf0e10cSrcweir break; 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir String currencyVal = stringVal.substring(beginIndex, endIndex); 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir currencyVal = currencyVal.substring(0, currencyVal.length()-3) + 527*cdf0e10cSrcweir "#" + currencyVal.substring(currencyVal.length()-2); 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir currencyVal = utils.replaceAll13(currencyVal, ",", ""); 530*cdf0e10cSrcweir currencyVal = utils.replaceAll13(currencyVal, "\\.", ""); 531*cdf0e10cSrcweir currencyVal = utils.replaceAll13(currencyVal, "#", "."); 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir return currencyVal; 534*cdf0e10cSrcweir } catch (Exception e) { 535*cdf0e10cSrcweir throw new Exception("Could get remove characters from currency string '" 536*cdf0e10cSrcweir + stringVal + "' : " + e.toString()); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir /** 542*cdf0e10cSrcweir * returns the numeric value of a numeric filed. This is needed ie. for 543*cdf0e10cSrcweir * fileds include the moneytary unit. 544*cdf0e10cSrcweir * @param NumericFieldName the name of the numeric filed 545*cdf0e10cSrcweir * @return the value of the numeric filed 546*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 547*cdf0e10cSrcweir */ 548*cdf0e10cSrcweir public Double getNumericFieldNumericValue(String NumericFieldName) 549*cdf0e10cSrcweir throws java.lang.Exception 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir try{ 552*cdf0e10cSrcweir Double retValue = null; 553*cdf0e10cSrcweir String sValue = getNumericFieldValue(NumericFieldName); 554*cdf0e10cSrcweir String sAmount = removeCharactersFromCurrencyString(sValue); 555*cdf0e10cSrcweir retValue = retValue.valueOf(sAmount); 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir return retValue; 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir } catch (Exception e) { 560*cdf0e10cSrcweir throw new Exception("Could get numeric value from NumericField '" 561*cdf0e10cSrcweir + NumericFieldName + "' : " + e.toString()); 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir /** 567*cdf0e10cSrcweir * returns the content of a TextBox 568*cdf0e10cSrcweir * @param TextFieldName the name of the textbox 569*cdf0e10cSrcweir * @return the value of the text box 570*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 571*cdf0e10cSrcweir */ 572*cdf0e10cSrcweir public String getTextBoxText(String TextFieldName) 573*cdf0e10cSrcweir throws java.lang.Exception 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir String TextFieldText = null; 576*cdf0e10cSrcweir try{ 577*cdf0e10cSrcweir XAccessibleContext xTextField =mAT.getAccessibleObjectForRole(mXRoot, 578*cdf0e10cSrcweir AccessibleRole.SCROLL_PANE, TextFieldName); 579*cdf0e10cSrcweir XAccessible xTextFieldAccess = (XAccessible) 580*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessible.class, xTextField); 581*cdf0e10cSrcweir XAccessibleContext xFrame =mAT.getAccessibleObjectForRole( 582*cdf0e10cSrcweir xTextFieldAccess, AccessibleRole.TEXT_FRAME); 583*cdf0e10cSrcweir for (int i=0;i<xFrame.getAccessibleChildCount();i++) { 584*cdf0e10cSrcweir try { 585*cdf0e10cSrcweir XAccessible xChild = xFrame.getAccessibleChild(i); 586*cdf0e10cSrcweir XAccessibleContext xChildCont = 587*cdf0e10cSrcweir xChild.getAccessibleContext(); 588*cdf0e10cSrcweir XInterface xChildInterface = (XInterface) 589*cdf0e10cSrcweir UnoRuntime.queryInterface(XInterface.class, xChildCont); 590*cdf0e10cSrcweir TextFieldText += (getString(xChildInterface)); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 593*cdf0e10cSrcweir throw new Exception("Could not get child fom TextFrame of '" 594*cdf0e10cSrcweir + TextFieldName + "' : " + e.toString()); 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir return TextFieldText; 598*cdf0e10cSrcweir } catch (Exception e) { 599*cdf0e10cSrcweir throw new Exception("Could not get content fom Textbox '" 600*cdf0e10cSrcweir + TextFieldName + "' : " + e.toString()); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir /** 605*cdf0e10cSrcweir * set a value to a named check box 606*cdf0e10cSrcweir * @param CheckBoxName the name of the check box 607*cdf0e10cSrcweir * @param Value the value to set 608*cdf0e10cSrcweir *<ul> 609*cdf0e10cSrcweir * <li>0: not checked </li> 610*cdf0e10cSrcweir * <li>1: checked </li> 611*cdf0e10cSrcweir * <li>2: don't know </li> 612*cdf0e10cSrcweir *</ul> 613*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 614*cdf0e10cSrcweir */ 615*cdf0e10cSrcweir public void setCheckBoxValue(String CheckBoxName, Integer Value) 616*cdf0e10cSrcweir throws java.lang.Exception 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir try { 619*cdf0e10cSrcweir XInterface xCheckBox =mAT.getAccessibleObjectForRole(mXRoot, 620*cdf0e10cSrcweir AccessibleRole.CHECK_BOX, CheckBoxName); 621*cdf0e10cSrcweir XAccessibleValue xCheckBoxValue = (XAccessibleValue) 622*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox); 623*cdf0e10cSrcweir xCheckBoxValue.setCurrentValue(Value); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir } catch (Exception e) { 626*cdf0e10cSrcweir throw new Exception("Could not set value to CheckBox '" 627*cdf0e10cSrcweir + CheckBoxName + "' : " + e.toString()); 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir /** 632*cdf0e10cSrcweir * returns the value of the named check box 633*cdf0e10cSrcweir * @param CheckBoxName the name of the check box 634*cdf0e10cSrcweir * @return the value of the check box 635*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 636*cdf0e10cSrcweir */ 637*cdf0e10cSrcweir public Integer getCheckBoxValue(String CheckBoxName) 638*cdf0e10cSrcweir throws java.lang.Exception 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir try { 641*cdf0e10cSrcweir XInterface xCheckBox =mAT.getAccessibleObjectForRole(mXRoot, 642*cdf0e10cSrcweir AccessibleRole.CHECK_BOX, CheckBoxName); 643*cdf0e10cSrcweir XAccessibleValue xCheckBoxValue = (XAccessibleValue) 644*cdf0e10cSrcweir UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox); 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir return (Integer) xCheckBoxValue.getCurrentValue(); 647*cdf0e10cSrcweir } catch (Exception e) { 648*cdf0e10cSrcweir throw new Exception("Could not set value to CheckBox '" 649*cdf0e10cSrcweir + CheckBoxName + "' : " + e.toString()); 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir /** 654*cdf0e10cSrcweir * returns the message of a Basic-MessageBox 655*cdf0e10cSrcweir * @return the message of a Basic-MessageBox 656*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 657*cdf0e10cSrcweir */ 658*cdf0e10cSrcweir public String getMsgBoxText() 659*cdf0e10cSrcweir throws java.lang.Exception 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir String cMessage = null; 662*cdf0e10cSrcweir try{ 663*cdf0e10cSrcweir XAccessibleContext xMessage =mAT.getAccessibleObjectForRole(mXRoot, 664*cdf0e10cSrcweir AccessibleRole.LABEL); 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir XInterface xMessageInterface = (XInterface) 667*cdf0e10cSrcweir UnoRuntime.queryInterface(XInterface.class, xMessage); 668*cdf0e10cSrcweir cMessage += (getString(xMessageInterface)); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir return cMessage; 672*cdf0e10cSrcweir } catch (Exception e) { 673*cdf0e10cSrcweir throw new Exception("Could not get message from Basic-MessageBox: " + e.toString()); 674*cdf0e10cSrcweir } 675*cdf0e10cSrcweir } 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir /** 678*cdf0e10cSrcweir * fetch the window which is equal to the given <CODE>WindowName</CODE> 679*cdf0e10cSrcweir * @return the named window 680*cdf0e10cSrcweir * @throws java.lang.Exception if something fail 681*cdf0e10cSrcweir */ 682*cdf0e10cSrcweir public XWindow getTopWindow(String WindowName, boolean debug) throws java.lang.Exception 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir XInterface xToolKit = null; 685*cdf0e10cSrcweir try { 686*cdf0e10cSrcweir xToolKit = (XInterface) mMSF.createInstance("com.sun.star.awt.Toolkit") ; 687*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 688*cdf0e10cSrcweir throw new Exception("Could not toolkit: " + e.toString()); 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir XExtendedToolkit tk = (XExtendedToolkit) 691*cdf0e10cSrcweir UnoRuntime.queryInterface(XExtendedToolkit.class, xToolKit); 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir int count = tk.getTopWindowCount(); 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir XTopWindow retWindow = null; 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir if (debug) System.out.println("getTopWindow ->"); 698*cdf0e10cSrcweir 699*cdf0e10cSrcweir for (int i=0; i < count ; i++){ 700*cdf0e10cSrcweir XTopWindow xTopWindow = tk.getTopWindow(i); 701*cdf0e10cSrcweir XAccessible xAcc = mAT.getAccessibleObject(xTopWindow); 702*cdf0e10cSrcweir String accName = xAcc.getAccessibleContext().getAccessibleName(); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir if (debug){ 705*cdf0e10cSrcweir System.out.println("AccessibleName: " + accName); 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir if (WindowName.equals(accName)){ 709*cdf0e10cSrcweir if (debug) System.out.println("-> found window with name '" + WindowName + "'"); 710*cdf0e10cSrcweir retWindow = xTopWindow; 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir if (debug) { 716*cdf0e10cSrcweir if (retWindow == null) System.out.println("could not found window with name '" + WindowName + "'"); 717*cdf0e10cSrcweir System.out.println("<- getTopWindow "); 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir return (XWindow) UnoRuntime.queryInterface(XWindow.class, retWindow); 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir public void clickMiddleOfAccessibleObject(short role, String name){ 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir XAccessibleContext xAcc =mAT.getAccessibleObjectForRole(mXRoot, role, name); 725*cdf0e10cSrcweir XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface( 726*cdf0e10cSrcweir XAccessibleComponent.class, xAcc); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir System.out.println(xAcc.getAccessibleRole() + "," + 729*cdf0e10cSrcweir xAcc.getAccessibleName() + "(" + 730*cdf0e10cSrcweir xAcc.getAccessibleDescription() + "):" + 731*cdf0e10cSrcweir utils.getImplName(xAcc)); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir if (aComp != null) { 734*cdf0e10cSrcweir Point location = aComp.getLocationOnScreen(); 735*cdf0e10cSrcweir String bounds = "(" + aComp.getBounds().X + "," + 736*cdf0e10cSrcweir aComp.getBounds().Y + ")" + " (" + 737*cdf0e10cSrcweir aComp.getBounds().Width + "," + 738*cdf0e10cSrcweir aComp.getBounds().Height + ")"; 739*cdf0e10cSrcweir System.out.println("The boundary Rectangle is " + bounds); 740*cdf0e10cSrcweir try { 741*cdf0e10cSrcweir Robot rob = new Robot(); 742*cdf0e10cSrcweir int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2); 743*cdf0e10cSrcweir int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2); 744*cdf0e10cSrcweir System.out.println("try to click mouse button on x/y " + x + "/" + y); 745*cdf0e10cSrcweir rob.mouseMove(x, y); 746*cdf0e10cSrcweir rob.mousePress(InputEvent.BUTTON1_MASK); 747*cdf0e10cSrcweir rob.mouseRelease(InputEvent.BUTTON1_MASK); 748*cdf0e10cSrcweir } catch (java.awt.AWTException e) { 749*cdf0e10cSrcweir System.out.println("couldn't press mouse button"); 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir public void doubleClickMiddleOfAccessibleObject(short role, String name) { 756*cdf0e10cSrcweir XAccessibleContext xAcc =mAT.getAccessibleObjectForRole(mXRoot, role, name); 757*cdf0e10cSrcweir XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface( 758*cdf0e10cSrcweir XAccessibleComponent.class, xAcc); 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir System.out.println(xAcc.getAccessibleRole() + "," + 761*cdf0e10cSrcweir xAcc.getAccessibleName() + "(" + 762*cdf0e10cSrcweir xAcc.getAccessibleDescription() + "):" + 763*cdf0e10cSrcweir utils.getImplName(xAcc)); 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir if (aComp != null) { 766*cdf0e10cSrcweir Point location = aComp.getLocationOnScreen(); 767*cdf0e10cSrcweir String bounds = "(" + aComp.getBounds().X + "," + 768*cdf0e10cSrcweir aComp.getBounds().Y + ")" + " (" + 769*cdf0e10cSrcweir aComp.getBounds().Width + "," + 770*cdf0e10cSrcweir aComp.getBounds().Height + ")"; 771*cdf0e10cSrcweir System.out.println("The boundary Rectangle is " + bounds); 772*cdf0e10cSrcweir try { 773*cdf0e10cSrcweir Robot rob = new Robot(); 774*cdf0e10cSrcweir int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2); 775*cdf0e10cSrcweir int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2); 776*cdf0e10cSrcweir System.out.println("try to double click mouse button on x/y " + x + "/" + y); 777*cdf0e10cSrcweir rob.mouseMove(x, y); 778*cdf0e10cSrcweir rob.mousePress(InputEvent.BUTTON1_MASK); 779*cdf0e10cSrcweir rob.mouseRelease(InputEvent.BUTTON1_MASK); 780*cdf0e10cSrcweir utils.shortWait(100); 781*cdf0e10cSrcweir rob.mousePress(InputEvent.BUTTON1_MASK); 782*cdf0e10cSrcweir rob.mouseRelease(InputEvent.BUTTON1_MASK); 783*cdf0e10cSrcweir } catch (java.awt.AWTException e) { 784*cdf0e10cSrcweir System.out.println("couldn't press mouse button"); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir } 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir /** 791*cdf0e10cSrcweir * <B>DEPRECATED</B> 792*cdf0e10cSrcweir * Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE> 793*cdf0e10cSrcweir * this function does not work anymore. 794*cdf0e10cSrcweir * @deprecated Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE> 795*cdf0e10cSrcweir * this function does not work anymore. 796*cdf0e10cSrcweir * @param log logWriter 797*cdf0e10cSrcweir */ 798*cdf0e10cSrcweir public void printAccessibleTree(PrintWriter log) 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir mAT.printAccessibleTree(log, mXRoot); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir /** 805*cdf0e10cSrcweir * Prints the accessible tree to the <CODE>logWriter</CODE> only if <CODE>debugIsActive</CODE> 806*cdf0e10cSrcweir * is set to <CODE>true</CODE> 807*cdf0e10cSrcweir * @param log logWriter 808*cdf0e10cSrcweir * @param debugIsActive prints only if this parameter is set to TRUE 809*cdf0e10cSrcweir */ 810*cdf0e10cSrcweir public void printAccessibleTree(PrintWriter log, boolean debugIsActive) { 811*cdf0e10cSrcweir mAT.printAccessibleTree(log, mXRoot, debugIsActive); 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir } 815