Update ooo320-m1
[ooovba.git] / qadevOOo / runner / util / UITools.java
blob74badc6499c8ecff1ac8525e4118df714ca93e63
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UITools.java,v $
10 * $Revision: 1.11 $
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 ************************************************************************/
31 package util;
33 import com.sun.star.awt.Point;
34 import com.sun.star.awt.XTopWindow;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.frame.XModel;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.accessibility.XAccessible;
42 import com.sun.star.accessibility.XAccessibleAction;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessibleComponent;
45 import com.sun.star.awt.XExtendedToolkit;
46 import com.sun.star.accessibility.XAccessibleContext;
47 import com.sun.star.accessibility.XAccessibleEditableText;
48 import com.sun.star.accessibility.XAccessibleSelection;
49 import com.sun.star.accessibility.XAccessibleText;
50 import com.sun.star.accessibility.XAccessibleValue;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import java.awt.Robot;
53 import java.awt.event.InputEvent;
54 import java.io.PrintWriter;
55 import java.util.Vector;
56 import util.AccessibilityTools;
59 /**
60 * This class supports some functions to handle easily accessible objects
62 public class UITools {
64 private static final AccessibilityTools mAT = new AccessibilityTools();
65 private final XAccessible mXRoot;
66 private final XMultiServiceFactory mMSF;
68 public UITools(XMultiServiceFactory msf, XModel xModel)
70 mMSF = msf;
71 mXRoot = makeRoot(mMSF, xModel);
74 public UITools(XMultiServiceFactory msf, XTextDocument xTextDoc)
76 mMSF = msf;
77 XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
78 mXRoot = makeRoot(mMSF, xModel);
81 public UITools(XMultiServiceFactory msf, XWindow xWindow)
83 mMSF = msf;
84 mXRoot = makeRoot(xWindow);
87 private static XAccessible makeRoot(XMultiServiceFactory msf, XModel aModel)
89 XWindow xWindow = mAT.getCurrentWindow(msf, aModel);
90 return mAT.getAccessibleObject(xWindow);
94 private static String getString(XInterface xInt)
96 XAccessibleText oText = (XAccessibleText)
97 UnoRuntime.queryInterface(XAccessibleText.class, xInt);
98 return oText.getText();
101 private static void setString(XInterface xInt, String cText)
103 XAccessibleEditableText oText = (XAccessibleEditableText)
104 UnoRuntime.queryInterface(XAccessibleEditableText.class, xInt);
106 oText.setText(cText);
109 private static Object getValue(XInterface xInt)
111 XAccessibleValue oValue = (XAccessibleValue)
112 UnoRuntime.queryInterface(XAccessibleValue.class, xInt);
113 return oValue.getCurrentValue();
116 private static XAccessible makeRoot(XWindow xWindow)
118 return mAT.getAccessibleObject(xWindow);
122 * get the root element of the accessible tree
123 * @return the root element
125 public XAccessible getRoot()
127 return mXRoot;
131 * Helper mathod: set a text into AccessibleEdit field
132 * @param textfiledName is the name of the text field
133 * @param stringToSet is the string to set
134 * @throws java.lang.Exception if something fail
136 public void setTextEditFiledText(String textfiledName, String stringToSet)
137 throws java.lang.Exception
139 XInterface oTextField = mAT.getAccessibleObjectForRole(mXRoot,
140 AccessibleRole.TEXT, textfiledName);
141 setString(oTextField, stringToSet);
145 * returns the button by the given name
146 * @param buttonName is name name of the button to get
147 * @return a XAccessibleContext of the button
148 * @throws java.lang.Exception if something fail
150 public XAccessibleContext getButton(String buttonName) throws java.lang.Exception
152 return mAT.getAccessibleObjectForRole
153 (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName);
157 * Helper method: gets button via accessibility and 'click' it</code>
158 * @param buttonName is name name of the button to click
159 * @throws java.lang.Exception if something fail
162 public void clickButton(String buttonName) throws java.lang.Exception
165 XAccessibleContext oButton =mAT.getAccessibleObjectForRole
166 (mXRoot, AccessibleRole.PUSH_BUTTON, buttonName);
167 if (oButton == null){
168 throw new Exception("Could not get button '" + buttonName + "'");
170 XAccessibleAction oAction = (XAccessibleAction)
171 UnoRuntime.queryInterface(XAccessibleAction.class, oButton);
173 // "click" the button
174 try{
175 oAction.doAccessibleAction(0);
176 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
177 throw new Exception("Could not do accessible action with '" +
178 buttonName + "'" + e.toString());
185 * Helper method: gets button via accessibility and 'click' it
186 * @param buttonName The name of the button in the accessibility tree
187 * @param toBePressed desired state of the toggle button
189 * @return true if the state of the button could be changed in the desired manner
191 private boolean clickToggleButton(String buttonName, boolean toBePressed)
193 XAccessibleContext oButton =mAT.getAccessibleObjectForRole
194 (mXRoot, AccessibleRole.TOGGLE_BUTTON, buttonName);
196 if (oButton != null){
197 boolean isChecked = oButton.getAccessibleStateSet().contains(com.sun.star.accessibility.AccessibleStateType.CHECKED);
198 if((isChecked && !toBePressed) || (!isChecked && toBePressed)){
199 XAccessibleAction oAction = (XAccessibleAction)
200 UnoRuntime.queryInterface(XAccessibleAction.class, oButton);
201 try{
202 // "click" the button
203 oAction.doAccessibleAction(0);
204 return true;
205 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
206 System.out.println("Could not do accessible action with '"
207 + buttonName + "'" + e.toString());
208 return false;
210 }else
211 //no need to press togglebar, do nothing
212 return true;
213 } else{
214 System.out.println("Could not get button '" + buttonName + "'");
215 return false;
220 * Deactivates toggle button via Accessibility
221 * @param buttonName The name of the button in the Accessibility tree
223 * @return true if the button could be set to deactivated
225 public boolean deactivateToggleButton(String buttonName){
226 return clickToggleButton(buttonName, false);
230 * Activates toggle button via Accessibility
231 * @param buttonName The name of the button in the Accessibility tree
233 * @return true if the button could be set to activated
235 public boolean activateToggleButton(String buttonName){
236 return clickToggleButton(buttonName, true);
240 * returns the value of named radio button
241 * @param buttonName the name of the button to get the value of
242 * @throws java.lang.Exception if something fail
243 * @return Integer
245 public Integer getRadioButtonValue(String buttonName)
246 throws java.lang.Exception
248 try {
249 XInterface xRB =mAT.getAccessibleObjectForRole(mXRoot,
250 AccessibleRole.RADIO_BUTTON, buttonName);
252 return (Integer) getValue(xRB);
253 } catch (Exception e) {
254 throw new Exception("Could not get value from RadioButton '"
255 + buttonName + "' : " + e.toString());
260 * returns the named graphic
261 * @param GraphicName the name of the graphic
262 * @return XInterface
263 * @throws java.lang.Exception if something fail
265 public XInterface getGraphic(String GraphicName) throws java.lang.Exception
267 return mAT.getAccessibleObjectForRole(mXRoot, AccessibleRole.GRAPHIC,
268 GraphicName);
273 * set a named radio button the a given value
274 * @param buttonName the name of the button to set
275 * @param iValue the value to set
276 * @throws java.lang.Exception if something fail
278 public void setRadioButtonValue(String buttonName, int iValue)
279 throws java.lang.Exception
281 try {
282 XInterface xRB =mAT.getAccessibleObjectForRole(mXRoot, AccessibleRole.RADIO_BUTTON, buttonName);
283 if(xRB == null)
284 System.out.println("AccessibleObjectForRole couldn't be found for " + buttonName);
285 XAccessibleValue oValue = (XAccessibleValue)
286 UnoRuntime.queryInterface(XAccessibleValue.class, xRB);
287 if(oValue == null)
288 System.out.println("XAccessibleValue couldn't be queried for " + buttonName);
289 oValue.setCurrentValue(new Integer(iValue));
290 } catch (Exception e) {
291 e.printStackTrace();
293 throw new Exception("Could not set value to RadioButton '"
294 + buttonName + "' : " + e.toString());
300 * select an item in nanmed listbox
301 * @param ListBoxName the name of the listbox
302 * @param nChildIndex the index of the item to set
303 * @throws java.lang.Exception if something fail
305 public void selectListboxItem(String ListBoxName, int nChildIndex)
306 throws java.lang.Exception
308 try {
309 XAccessibleContext xListBox = null;
311 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
312 AccessibleRole.COMBO_BOX, ListBoxName);
313 if (xListBox == null){
314 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
315 AccessibleRole.PANEL, ListBoxName);
317 XAccessible xListBoxAccess = (XAccessible)
318 UnoRuntime.queryInterface(XAccessible.class, xListBox);
320 // if a List is not pulled to be open all entries are not visiblle, therefore the
321 // boolean argument
322 XAccessibleContext xList =mAT.getAccessibleObjectForRole(
323 xListBoxAccess, AccessibleRole.LIST, true);
324 XAccessibleSelection xListSelect = (XAccessibleSelection)
325 UnoRuntime.queryInterface(XAccessibleSelection.class, xList);
327 xListSelect.selectAccessibleChild(nChildIndex);
329 } catch (Exception e) {
330 throw new Exception("Could not select item '" +nChildIndex+
331 "' in listbox '" + ListBoxName + "' : " + e.toString());
336 * This method returns all entries as XInterface of a list box
337 * @param ListBoxName the name of the listbox
338 * @return Object[] containing XInterface
339 * @throws java.lang.Exception if something fail
342 public Object[] getListBoxObjects(String ListBoxName)
343 throws java.lang.Exception
345 Vector Items = new Vector();
346 try {
347 XAccessibleContext xListBox = null;
348 XAccessibleContext xList = null;
350 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
351 AccessibleRole.COMBO_BOX, ListBoxName);
352 if (xListBox == null){
353 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
354 AccessibleRole.PANEL, ListBoxName);
357 if (xListBox == null){
358 // get the list of TreeListBox
359 xList =mAT.getAccessibleObjectForRole(mXRoot,
360 AccessibleRole.TREE, ListBoxName);
362 // all other list boxes have a children of kind of LIST
363 } else {
365 XAccessible xListBoxAccess = (XAccessible)
366 UnoRuntime.queryInterface(XAccessible.class, xListBox);
367 // if a List is not pulled to be open all entries are not visiblle, therefore the
368 // boolean argument
369 xList =mAT.getAccessibleObjectForRole(
370 xListBoxAccess, AccessibleRole.LIST, true);
373 for (int i=0;i<xList.getAccessibleChildCount();i++) {
374 try {
375 XAccessible xChild = xList.getAccessibleChild(i);
376 XAccessibleContext xChildCont =
377 xChild.getAccessibleContext();
378 XInterface xChildInterface = (XInterface)
379 UnoRuntime.queryInterface(XInterface.class, xChildCont);
380 Items.add(xChildInterface);
382 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
383 throw new Exception("Could not get child form list of '"
384 + ListBoxName + "' : " + e.toString());
388 } catch (Exception e) {
389 throw new Exception("Could not get list of items from '"
390 + ListBoxName + "' : " + e.toString());
392 Object[]ret = new XInterface[Items.size()];
393 for (int i=0;i<Items.size();i++){
394 ret[i] = Items.get(i);
396 return ret;
400 * Helper method: returns the entry manes of a List-Box
401 * @param ListBoxName the name of the listbox
402 * @return the listbox entry names
403 * @throws java.lang.Exception if something fail
406 public String[] getListBoxItems(String ListBoxName)
407 throws java.lang.Exception
409 Vector Items = new Vector();
410 try {
411 XAccessibleContext xListBox = null;
412 XAccessibleContext xList = null;
414 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
415 AccessibleRole.COMBO_BOX, ListBoxName);
416 if (xListBox == null){
417 xListBox =mAT.getAccessibleObjectForRole(mXRoot,
418 AccessibleRole.PANEL, ListBoxName);
421 if (xListBox == null){
422 // get the list of TreeListBox
423 xList =mAT.getAccessibleObjectForRole(mXRoot,
424 AccessibleRole.TREE, ListBoxName);
426 // all other list boxes have a children of kind of LIST
427 } else {
429 XAccessible xListBoxAccess = (XAccessible)
430 UnoRuntime.queryInterface(XAccessible.class, xListBox);
431 // if a List is not pulled to be open all entries are not visiblle, therefore the
432 // boolean argument
433 xList =mAT.getAccessibleObjectForRole(
434 xListBoxAccess, AccessibleRole.LIST, true);
437 for (int i=0;i<xList.getAccessibleChildCount();i++) {
438 try {
439 XAccessible xChild = xList.getAccessibleChild(i);
440 XAccessibleContext xChildCont =
441 xChild.getAccessibleContext();
442 XInterface xChildInterface = (XInterface)
443 UnoRuntime.queryInterface(XInterface.class, xChildCont);
444 Items.add(getString(xChildInterface));
446 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
447 throw new Exception("Could not get child form list of '"
448 + ListBoxName + "' : " + e.toString());
452 } catch (Exception e) {
453 throw new Exception("Could not get list of items from '"
454 + ListBoxName + "' : " + e.toString());
456 String[]ret = new String[Items.size()];
457 return (String[])Items.toArray(ret);
460 * set to a named nureric filed a given value
461 * @param NumericFieldName the name of the nureic field
462 * @param cValue the value to set
463 * @throws java.lang.Exception if something fail
465 public void setNumericFieldValue(String NumericFieldName, String cValue)
466 throws java.lang.Exception
468 try{
469 XInterface xNumericField =mAT.getAccessibleObjectForRole(
470 mXRoot, AccessibleRole.TEXT, NumericFieldName);
471 //util.dbg.printInterfaces(xNumericField);
472 XAccessibleEditableText oValue = (XAccessibleEditableText)
473 UnoRuntime.queryInterface(
474 XAccessibleEditableText.class, xNumericField);
476 setString(xNumericField, cValue);
477 } catch (Exception e) {
478 throw new Exception("Could not set value '" + cValue +
479 "' into NumericField '" + NumericFieldName + "' : " + e.toString());
484 * returns the value of a numeric field
485 * @param NumericFieldName the name of the numreic field
486 * @throws java.lang.Exception if something fail
487 * @return the value of the named numeric filed
489 public String getNumericFieldValue(String NumericFieldName)
490 throws java.lang.Exception
492 try{
493 XInterface xNumericField =mAT.getAccessibleObjectForRole(
494 mXRoot, AccessibleRole.TEXT, NumericFieldName);
495 return (String) getString(xNumericField);
497 } catch (Exception e) {
498 throw new Exception("Could get value from NumericField '"
499 + NumericFieldName + "' : " + e.toString());
503 private String removeCharactersFromCurrencyString(String stringVal)
504 throws java.lang.Exception
506 try{
507 int beginIndex = 0;
508 int endIndex = 0;
509 boolean startFound = false;
510 // find the first numeric character in stringVal
511 for(int i = 0; i < stringVal.length(); i++){
512 int numVal = Character.getNumericValue(stringVal.charAt(i));
513 // if ascii is a numeric value
514 if (numVal != -1){
515 beginIndex = i;
516 break;
519 // find the last numeric character in stringVal
520 for(int i = stringVal.length()-1; i > 0; i--){
521 int numVal = Character.getNumericValue(stringVal.charAt(i));
522 if (numVal != -1){
523 endIndex = i+1;
524 break;
527 String currencyVal = stringVal.substring(beginIndex, endIndex);
529 currencyVal = currencyVal.substring(0, currencyVal.length()-3) +
530 "#" + currencyVal.substring(currencyVal.length()-2);
532 currencyVal = utils.replaceAll13(currencyVal, ",", "");
533 currencyVal = utils.replaceAll13(currencyVal, "\\.", "");
534 currencyVal = utils.replaceAll13(currencyVal, "#", ".");
536 return currencyVal;
537 } catch (Exception e) {
538 throw new Exception("Could get remove characters from currency string '"
539 + stringVal + "' : " + e.toString());
545 * returns the numeric value of a numeric filed. This is needed ie. for
546 * fileds include the moneytary unit.
547 * @param NumericFieldName the name of the numeric filed
548 * @return the value of the numeric filed
549 * @throws java.lang.Exception if something fail
551 public Double getNumericFieldNumericValue(String NumericFieldName)
552 throws java.lang.Exception
554 try{
555 Double retValue = null;
556 String sValue = getNumericFieldValue(NumericFieldName);
557 String sAmount = removeCharactersFromCurrencyString(sValue);
558 retValue = retValue.valueOf(sAmount);
560 return retValue;
562 } catch (Exception e) {
563 throw new Exception("Could get numeric value from NumericField '"
564 + NumericFieldName + "' : " + e.toString());
570 * returns the content of a TextBox
571 * @param TextFieldName the name of the textbox
572 * @return the value of the text box
573 * @throws java.lang.Exception if something fail
575 public String getTextBoxText(String TextFieldName)
576 throws java.lang.Exception
578 String TextFieldText = null;
579 try{
580 XAccessibleContext xTextField =mAT.getAccessibleObjectForRole(mXRoot,
581 AccessibleRole.SCROLL_PANE, TextFieldName);
582 XAccessible xTextFieldAccess = (XAccessible)
583 UnoRuntime.queryInterface(XAccessible.class, xTextField);
584 XAccessibleContext xFrame =mAT.getAccessibleObjectForRole(
585 xTextFieldAccess, AccessibleRole.TEXT_FRAME);
586 for (int i=0;i<xFrame.getAccessibleChildCount();i++) {
587 try {
588 XAccessible xChild = xFrame.getAccessibleChild(i);
589 XAccessibleContext xChildCont =
590 xChild.getAccessibleContext();
591 XInterface xChildInterface = (XInterface)
592 UnoRuntime.queryInterface(XInterface.class, xChildCont);
593 TextFieldText += (getString(xChildInterface));
595 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
596 throw new Exception("Could not get child fom TextFrame of '"
597 + TextFieldName + "' : " + e.toString());
600 return TextFieldText;
601 } catch (Exception e) {
602 throw new Exception("Could not get content fom Textbox '"
603 + TextFieldName + "' : " + e.toString());
608 * set a value to a named check box
609 * @param CheckBoxName the name of the check box
610 * @param Value the value to set
611 *<ul>
612 * <li>0: not checked </li>
613 * <li>1: checked </li>
614 * <li>2: don't know </li>
615 *</ul>
616 * @throws java.lang.Exception if something fail
618 public void setCheckBoxValue(String CheckBoxName, Integer Value)
619 throws java.lang.Exception
621 try {
622 XInterface xCheckBox =mAT.getAccessibleObjectForRole(mXRoot,
623 AccessibleRole.CHECK_BOX, CheckBoxName);
624 XAccessibleValue xCheckBoxValue = (XAccessibleValue)
625 UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox);
626 xCheckBoxValue.setCurrentValue(Value);
628 } catch (Exception e) {
629 throw new Exception("Could not set value to CheckBox '"
630 + CheckBoxName + "' : " + e.toString());
635 * returns the value of the named check box
636 * @param CheckBoxName the name of the check box
637 * @return the value of the check box
638 * @throws java.lang.Exception if something fail
640 public Integer getCheckBoxValue(String CheckBoxName)
641 throws java.lang.Exception
643 try {
644 XInterface xCheckBox =mAT.getAccessibleObjectForRole(mXRoot,
645 AccessibleRole.CHECK_BOX, CheckBoxName);
646 XAccessibleValue xCheckBoxValue = (XAccessibleValue)
647 UnoRuntime.queryInterface(XAccessibleValue.class, xCheckBox);
649 return (Integer) xCheckBoxValue.getCurrentValue();
650 } catch (Exception e) {
651 throw new Exception("Could not set value to CheckBox '"
652 + CheckBoxName + "' : " + e.toString());
657 * returns the message of a Basic-MessageBox
658 * @return the message of a Basic-MessageBox
659 * @throws java.lang.Exception if something fail
661 public String getMsgBoxText()
662 throws java.lang.Exception
664 String cMessage = null;
665 try{
666 XAccessibleContext xMessage =mAT.getAccessibleObjectForRole(mXRoot,
667 AccessibleRole.LABEL);
669 XInterface xMessageInterface = (XInterface)
670 UnoRuntime.queryInterface(XInterface.class, xMessage);
671 cMessage += (getString(xMessageInterface));
674 return cMessage;
675 } catch (Exception e) {
676 throw new Exception("Could not get message from Basic-MessageBox: " + e.toString());
682 * fetch the active window which is on the top of the X-desktop
683 * @return the active window
684 * @throws java.lang.Exception if something fail
686 public XWindow getActiveTopWindow() throws java.lang.Exception
688 XInterface xToolKit = null;
689 try {
690 xToolKit = (XInterface) mMSF.createInstance("com.sun.star.awt.Toolkit") ;
691 } catch (com.sun.star.uno.Exception e) {
692 throw new Exception("Could not toolkit: " + e.toString());
694 XExtendedToolkit tk = (XExtendedToolkit)
695 UnoRuntime.queryInterface(XExtendedToolkit.class, xToolKit);
696 Object atw = tk.getActiveTopWindow();
697 return (XWindow) UnoRuntime.queryInterface(XWindow.class, atw);
701 * fetch the window which is equal to the given <CODE>WindowName</CODE>
702 * @return the named window
703 * @throws java.lang.Exception if something fail
705 public XWindow getTopWindow(String WindowName, boolean debug) throws java.lang.Exception
707 XInterface xToolKit = null;
708 try {
709 xToolKit = (XInterface) mMSF.createInstance("com.sun.star.awt.Toolkit") ;
710 } catch (com.sun.star.uno.Exception e) {
711 throw new Exception("Could not toolkit: " + e.toString());
713 XExtendedToolkit tk = (XExtendedToolkit)
714 UnoRuntime.queryInterface(XExtendedToolkit.class, xToolKit);
716 int count = tk.getTopWindowCount();
718 XTopWindow retWindow = null;
720 if (debug) System.out.println("getTopWindow ->");
722 for (int i=0; i < count ; i++){
723 XTopWindow xTopWindow = tk.getTopWindow(i);
724 XAccessible xAcc = mAT.getAccessibleObject(xTopWindow);
725 String accName = xAcc.getAccessibleContext().getAccessibleName();
727 if (debug){
728 System.out.println("AccessibleName: " + accName);
731 if (WindowName.equals(accName)){
732 if (debug) System.out.println("-> found window with name '" + WindowName + "'");
733 retWindow = xTopWindow;
738 if (debug) {
739 if (retWindow == null) System.out.println("could not found window with name '" + WindowName + "'");
740 System.out.println("<- getTopWindow ");
742 return (XWindow) UnoRuntime.queryInterface(XWindow.class, retWindow);
745 public void clickMiddleOfAccessibleObject(short role, String name){
747 XAccessibleContext xAcc =mAT.getAccessibleObjectForRole(mXRoot, role, name);
748 XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface(
749 XAccessibleComponent.class, xAcc);
751 System.out.println(xAcc.getAccessibleRole() + "," +
752 xAcc.getAccessibleName() + "(" +
753 xAcc.getAccessibleDescription() + "):" +
754 utils.getImplName(xAcc));
756 if (aComp != null) {
757 Point location = aComp.getLocationOnScreen();
758 String bounds = "(" + aComp.getBounds().X + "," +
759 aComp.getBounds().Y + ")" + " (" +
760 aComp.getBounds().Width + "," +
761 aComp.getBounds().Height + ")";
762 System.out.println("The boundary Rectangle is " + bounds);
763 try {
764 Robot rob = new Robot();
765 int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2);
766 int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2);
767 System.out.println("try to click mouse button on x/y " + x + "/" + y);
768 rob.mouseMove(x, y);
769 rob.mousePress(InputEvent.BUTTON1_MASK);
770 rob.mouseRelease(InputEvent.BUTTON1_MASK);
771 } catch (java.awt.AWTException e) {
772 System.out.println("couldn't press mouse button");
778 public void doubleClickMiddleOfAccessibleObject(short role, String name) {
779 XAccessibleContext xAcc =mAT.getAccessibleObjectForRole(mXRoot, role, name);
780 XAccessibleComponent aComp = (XAccessibleComponent) UnoRuntime.queryInterface(
781 XAccessibleComponent.class, xAcc);
783 System.out.println(xAcc.getAccessibleRole() + "," +
784 xAcc.getAccessibleName() + "(" +
785 xAcc.getAccessibleDescription() + "):" +
786 utils.getImplName(xAcc));
788 if (aComp != null) {
789 Point location = aComp.getLocationOnScreen();
790 String bounds = "(" + aComp.getBounds().X + "," +
791 aComp.getBounds().Y + ")" + " (" +
792 aComp.getBounds().Width + "," +
793 aComp.getBounds().Height + ")";
794 System.out.println("The boundary Rectangle is " + bounds);
795 try {
796 Robot rob = new Robot();
797 int x = aComp.getLocationOnScreen().X + (aComp.getBounds().Width / 2);
798 int y = aComp.getLocationOnScreen().Y + (aComp.getBounds().Height / 2);
799 System.out.println("try to double click mouse button on x/y " + x + "/" + y);
800 rob.mouseMove(x, y);
801 rob.mousePress(InputEvent.BUTTON1_MASK);
802 rob.mouseRelease(InputEvent.BUTTON1_MASK);
803 utils.shortWait(100);
804 rob.mousePress(InputEvent.BUTTON1_MASK);
805 rob.mouseRelease(InputEvent.BUTTON1_MASK);
806 } catch (java.awt.AWTException e) {
807 System.out.println("couldn't press mouse button");
814 * <B>DEPRECATED</B>
815 * Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
816 * this function does not work anymore.
817 * @deprecated Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
818 * this function does not work anymore.
819 * @param log logWriter
821 public void printAccessibleTree(PrintWriter log)
823 mAT.printAccessibleTree(log, mXRoot);
828 * Prints the accessible tree to the <CODE>logWriter</CODE> only if <CODE>debugIsActive</CODE>
829 * is set to <CODE>true</CODE>
830 * @param log logWriter
831 * @param debugIsActive prints only if this parameter is set to TRUE
833 public void printAccessibleTree(PrintWriter log, boolean debugIsActive) {
834 mAT.printAccessibleTree(log, mXRoot, debugIsActive);