2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.awt
.Robot
;
22 import java
.awt
.event
.InputEvent
;
23 import java
.io
.PrintWriter
;
24 import java
.util
.ArrayList
;
26 import com
.sun
.star
.accessibility
.AccessibleRole
;
27 import com
.sun
.star
.accessibility
.XAccessible
;
28 import com
.sun
.star
.accessibility
.XAccessibleAction
;
29 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
30 import com
.sun
.star
.accessibility
.XAccessibleContext
;
31 import com
.sun
.star
.accessibility
.XAccessibleEditableText
;
32 import com
.sun
.star
.accessibility
.XAccessibleSelection
;
33 import com
.sun
.star
.accessibility
.XAccessibleText
;
34 import com
.sun
.star
.accessibility
.XAccessibleValue
;
35 import com
.sun
.star
.awt
.XExtendedToolkit
;
36 import com
.sun
.star
.awt
.XTopWindow
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.frame
.XModel
;
39 import com
.sun
.star
.lang
.XMultiServiceFactory
;
40 import com
.sun
.star
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
46 * This class supports some functions to handle easily accessible objects
48 public class UITools
{
50 private static final AccessibilityTools mAT
= new AccessibilityTools();
51 private final XAccessible mXRoot
;
52 private final XMultiServiceFactory mMSF
;
54 public UITools(XMultiServiceFactory msf
, XModel xModel
)
57 mXRoot
= makeRoot(mMSF
, xModel
);
60 public UITools(XMultiServiceFactory msf
, XTextDocument xTextDoc
)
63 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
64 mXRoot
= makeRoot(mMSF
, xModel
);
67 public UITools(XMultiServiceFactory msf
, XWindow xWindow
)
70 mXRoot
= makeRoot(xWindow
);
73 private static XAccessible
makeRoot(XMultiServiceFactory msf
, XModel aModel
)
75 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(msf
, aModel
);
76 return AccessibilityTools
.getAccessibleObject(xWindow
);
80 private static String
getString(XInterface xInt
)
82 XAccessibleText oText
= UnoRuntime
.queryInterface(XAccessibleText
.class, xInt
);
83 return oText
.getText();
86 private static void setString(XInterface xInt
, String cText
)
88 XAccessibleEditableText oText
= UnoRuntime
.queryInterface(XAccessibleEditableText
.class, xInt
);
93 private static Object
getValue(XInterface xInt
)
95 XAccessibleValue oValue
= UnoRuntime
.queryInterface(XAccessibleValue
.class, xInt
);
96 return oValue
.getCurrentValue();
99 private static XAccessible
makeRoot(XWindow xWindow
)
101 return AccessibilityTools
.getAccessibleObject(xWindow
);
105 * get the root element of the accessible tree
106 * @return the root element
108 public XAccessible
getRoot()
114 * Helper mathod: set a text into AccessibleEdit field
115 * @param textfiledName is the name of the text field
116 * @param stringToSet is the string to set
117 * @throws java.lang.Exception if something fail
119 public void setTextEditFiledText(String textfiledName
, String stringToSet
)
120 throws java
.lang
.Exception
122 XInterface oTextField
= AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
123 AccessibleRole
.TEXT
, textfiledName
);
124 setString(oTextField
, stringToSet
);
128 * returns the button by the given name
129 * @param buttonName is name name of the button to get
130 * @return a XAccessibleContext of the button
131 * @throws java.lang.Exception if something fail
133 public XAccessibleContext
getButton(String buttonName
) throws java
.lang
.Exception
135 return AccessibilityTools
.getAccessibleObjectForRole
136 (mXRoot
, AccessibleRole
.PUSH_BUTTON
, buttonName
);
140 * Helper method: gets button via accessibility and 'click' it</code>
141 * @param buttonName is name name of the button to click
142 * @throws java.lang.Exception if something fail
145 public void clickButton(String buttonName
) throws java
.lang
.Exception
148 XAccessibleContext oButton
=AccessibilityTools
.getAccessibleObjectForRole
149 (mXRoot
, AccessibleRole
.PUSH_BUTTON
, buttonName
);
150 if (oButton
== null){
151 throw new Exception("Could not get button '" + buttonName
+ "'");
153 XAccessibleAction oAction
= UnoRuntime
.queryInterface(XAccessibleAction
.class, oButton
);
155 // "click" the button
157 oAction
.doAccessibleAction(0);
158 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
159 throw new Exception("Could not do accessible action with '" +
160 buttonName
+ "'" + e
.toString());
167 * Helper method: gets button via accessibility and 'click' it
168 * @param buttonName The name of the button in the accessibility tree
169 * @param toBePressed desired state of the toggle button
171 * @return true if the state of the button could be changed in the desired manner
173 private boolean clickToggleButton(String buttonName
, boolean toBePressed
)
175 XAccessibleContext oButton
=AccessibilityTools
.getAccessibleObjectForRole
176 (mXRoot
, AccessibleRole
.TOGGLE_BUTTON
, buttonName
);
178 if (oButton
!= null){
179 boolean isChecked
= oButton
.getAccessibleStateSet().contains(com
.sun
.star
.accessibility
.AccessibleStateType
.CHECKED
);
180 if((isChecked
&& !toBePressed
) || (!isChecked
&& toBePressed
)){
181 XAccessibleAction oAction
= UnoRuntime
.queryInterface(XAccessibleAction
.class, oButton
);
183 // "click" the button
184 oAction
.doAccessibleAction(0);
186 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
187 System
.out
.println("Could not do accessible action with '"
188 + buttonName
+ "'" + e
.toString());
192 //no need to press togglebar, do nothing
195 System
.out
.println("Could not get button '" + buttonName
+ "'");
201 * Deactivates toggle button via Accessibility
202 * @param buttonName The name of the button in the Accessibility tree
204 * @return true if the button could be set to deactivated
206 public boolean deactivateToggleButton(String buttonName
){
207 return clickToggleButton(buttonName
, false);
211 * Activates toggle button via Accessibility
212 * @param buttonName The name of the button in the Accessibility tree
214 * @return true if the button could be set to activated
216 public boolean activateToggleButton(String buttonName
){
217 return clickToggleButton(buttonName
, true);
221 * returns the value of named radio button
222 * @param buttonName the name of the button to get the value of
223 * @throws java.lang.Exception if something fail
226 public Integer
getRadioButtonValue(String buttonName
)
227 throws java
.lang
.Exception
230 XInterface xRB
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
231 AccessibleRole
.RADIO_BUTTON
, buttonName
);
233 return (Integer
) getValue(xRB
);
234 } catch (Exception e
) {
235 throw new Exception("Could not get value from RadioButton '"
236 + buttonName
+ "' : " + e
.toString());
241 * returns the named graphic
242 * @param GraphicName the name of the graphic
244 * @throws java.lang.Exception if something fail
246 public XInterface
getGraphic(String GraphicName
) throws java
.lang
.Exception
248 return AccessibilityTools
.getAccessibleObjectForRole(mXRoot
, AccessibleRole
.GRAPHIC
,
254 * set a named radio button the a given value
255 * @param buttonName the name of the button to set
256 * @param iValue the value to set
257 * @throws java.lang.Exception if something fail
259 public void setRadioButtonValue(String buttonName
, int iValue
)
260 throws java
.lang
.Exception
263 XInterface xRB
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
, AccessibleRole
.RADIO_BUTTON
, buttonName
);
265 System
.out
.println("AccessibleObjectForRole couldn't be found for " + buttonName
);
266 XAccessibleValue oValue
= UnoRuntime
.queryInterface(XAccessibleValue
.class, xRB
);
268 System
.out
.println("XAccessibleValue couldn't be queried for " + buttonName
);
269 oValue
.setCurrentValue(new Integer(iValue
));
270 } catch (Exception e
) {
273 throw new Exception("Could not set value to RadioButton '"
274 + buttonName
+ "' : " + e
.toString());
280 * select an item in nanmed listbox
281 * @param ListBoxName the name of the listbox
282 * @param nChildIndex the index of the item to set
283 * @throws java.lang.Exception if something fail
285 public void selectListboxItem(String ListBoxName
, int nChildIndex
)
286 throws java
.lang
.Exception
289 XAccessibleContext xListBox
= null;
291 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
292 AccessibleRole
.COMBO_BOX
, ListBoxName
);
293 if (xListBox
== null){
294 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
295 AccessibleRole
.PANEL
, ListBoxName
);
297 XAccessible xListBoxAccess
= UnoRuntime
.queryInterface(XAccessible
.class, xListBox
);
299 // if a List is not pulled to be open all entries are not visiblle, therefore the
301 XAccessibleContext xList
=AccessibilityTools
.getAccessibleObjectForRole(
302 xListBoxAccess
, AccessibleRole
.LIST
, true);
303 XAccessibleSelection xListSelect
= UnoRuntime
.queryInterface(XAccessibleSelection
.class, xList
);
305 xListSelect
.selectAccessibleChild(nChildIndex
);
307 } catch (Exception e
) {
308 throw new Exception("Could not select item '" +nChildIndex
+
309 "' in listbox '" + ListBoxName
+ "' : " + e
.toString());
314 * This method returns all entries as XInterface of a list box
315 * @param ListBoxName the name of the listbox
316 * @return Object[] containing XInterface
317 * @throws java.lang.Exception if something fail
320 public Object
[] getListBoxObjects(String ListBoxName
)
321 throws java
.lang
.Exception
323 ArrayList
<XInterface
> Items
= new ArrayList
<XInterface
>();
325 XAccessibleContext xListBox
= null;
326 XAccessibleContext xList
= null;
328 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
329 AccessibleRole
.COMBO_BOX
, ListBoxName
);
330 if (xListBox
== null){
331 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
332 AccessibleRole
.PANEL
, ListBoxName
);
335 if (xListBox
== null){
336 // get the list of TreeListBox
337 xList
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
338 AccessibleRole
.TREE
, ListBoxName
);
340 // all other list boxes have a children of kind of LIST
343 XAccessible xListBoxAccess
= UnoRuntime
.queryInterface(XAccessible
.class, xListBox
);
344 // if a List is not pulled to be open all entries are not visiblle, therefore the
346 xList
=AccessibilityTools
.getAccessibleObjectForRole(
347 xListBoxAccess
, AccessibleRole
.LIST
, true);
350 for (int i
=0;i
<xList
.getAccessibleChildCount();i
++) {
352 XAccessible xChild
= xList
.getAccessibleChild(i
);
353 XAccessibleContext xChildCont
=
354 xChild
.getAccessibleContext();
355 XInterface xChildInterface
= UnoRuntime
.queryInterface(XInterface
.class, xChildCont
);
356 Items
.add(xChildInterface
);
358 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
359 throw new Exception("Could not get child form list of '"
360 + ListBoxName
+ "' : " + e
.toString());
364 } catch (Exception e
) {
365 throw new Exception("Could not get list of items from '"
366 + ListBoxName
+ "' : " + e
.toString());
368 Object
[]ret
= new XInterface
[Items
.size()];
369 for (int i
=0;i
<Items
.size();i
++){
370 ret
[i
] = Items
.get(i
);
376 * Helper method: returns the entry manes of a List-Box
377 * @param ListBoxName the name of the listbox
378 * @return the listbox entry names
379 * @throws java.lang.Exception if something fail
382 public String
[] getListBoxItems(String ListBoxName
)
383 throws java
.lang
.Exception
385 ArrayList
<String
> Items
= new ArrayList
<String
>();
387 XAccessibleContext xListBox
= null;
388 XAccessibleContext xList
= null;
390 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
391 AccessibleRole
.COMBO_BOX
, ListBoxName
);
392 if (xListBox
== null){
393 xListBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
394 AccessibleRole
.PANEL
, ListBoxName
);
397 if (xListBox
== null){
398 // get the list of TreeListBox
399 xList
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
400 AccessibleRole
.TREE
, ListBoxName
);
402 // all other list boxes have a children of kind of LIST
405 XAccessible xListBoxAccess
= UnoRuntime
.queryInterface(XAccessible
.class, xListBox
);
406 // if a List is not pulled to be open all entries are not visiblle, therefore the
408 xList
=AccessibilityTools
.getAccessibleObjectForRole(
409 xListBoxAccess
, AccessibleRole
.LIST
, true);
412 for (int i
=0;i
<xList
.getAccessibleChildCount();i
++) {
414 XAccessible xChild
= xList
.getAccessibleChild(i
);
415 XAccessibleContext xChildCont
=
416 xChild
.getAccessibleContext();
417 XInterface xChildInterface
= UnoRuntime
.queryInterface(XInterface
.class, xChildCont
);
418 Items
.add(getString(xChildInterface
));
420 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
421 throw new Exception("Could not get child form list of '"
422 + ListBoxName
+ "' : " + e
.toString());
426 } catch (Exception e
) {
427 throw new Exception("Could not get list of items from '"
428 + ListBoxName
+ "' : " + e
.toString());
430 String
[]ret
= new String
[Items
.size()];
431 return Items
.toArray(ret
);
434 * set to a named nureric filed a given value
435 * @param NumericFieldName the name of the nureic field
436 * @param cValue the value to set
437 * @throws java.lang.Exception if something fail
439 public void setNumericFieldValue(String NumericFieldName
, String cValue
)
440 throws java
.lang
.Exception
443 XInterface xNumericField
=AccessibilityTools
.getAccessibleObjectForRole(
444 mXRoot
, AccessibleRole
.TEXT
, NumericFieldName
);
445 UnoRuntime
.queryInterface(
446 XAccessibleEditableText
.class, xNumericField
);
448 setString(xNumericField
, cValue
);
449 } catch (Exception e
) {
450 throw new Exception("Could not set value '" + cValue
+
451 "' into NumericField '" + NumericFieldName
+ "' : " + e
.toString());
456 * returns the value of a numeric field
457 * @param NumericFieldName the name of the numreic field
458 * @throws java.lang.Exception if something fail
459 * @return the value of the named numeric filed
461 public String
getNumericFieldValue(String NumericFieldName
)
462 throws java
.lang
.Exception
465 XInterface xNumericField
=AccessibilityTools
.getAccessibleObjectForRole(
466 mXRoot
, AccessibleRole
.TEXT
, NumericFieldName
);
467 return getString(xNumericField
);
469 } catch (Exception e
) {
470 throw new Exception("Could get value from NumericField '"
471 + NumericFieldName
+ "' : " + e
.toString());
475 private String
removeCharactersFromCurrencyString(String stringVal
)
476 throws java
.lang
.Exception
481 // find the first numeric character in stringVal
482 for(int i
= 0; i
< stringVal
.length(); i
++){
483 int numVal
= Character
.getNumericValue(stringVal
.charAt(i
));
484 // if ascii is a numeric value
490 // find the last numeric character in stringVal
491 for(int i
= stringVal
.length()-1; i
> 0; i
--){
492 int numVal
= Character
.getNumericValue(stringVal
.charAt(i
));
498 String currencyVal
= stringVal
.substring(beginIndex
, endIndex
);
500 currencyVal
= currencyVal
.substring(0, currencyVal
.length()-3) +
501 "#" + currencyVal
.substring(currencyVal
.length()-2);
503 currencyVal
= utils
.replaceAll13(currencyVal
, ",", "");
504 currencyVal
= utils
.replaceAll13(currencyVal
, "\\.", "");
505 currencyVal
= utils
.replaceAll13(currencyVal
, "#", ".");
508 } catch (Exception e
) {
509 throw new Exception("Could get remove characters from currency string '"
510 + stringVal
+ "' : " + e
.toString());
516 * returns the numeric value of a numeric filed. This is needed ie. for
517 * fileds include the moneytary unit.
518 * @param NumericFieldName the name of the numeric filed
519 * @return the value of the numeric filed
520 * @throws java.lang.Exception if something fail
522 public Double
getNumericFieldNumericValue(String NumericFieldName
)
523 throws java
.lang
.Exception
526 Double retValue
= null;
527 String sValue
= getNumericFieldValue(NumericFieldName
);
528 String sAmount
= removeCharactersFromCurrencyString(sValue
);
529 retValue
= Double
.valueOf(sAmount
);
533 } catch (Exception e
) {
534 throw new Exception("Could get numeric value from NumericField '"
535 + NumericFieldName
+ "' : " + e
.toString());
541 * returns the content of a TextBox
542 * @param TextFieldName the name of the textbox
543 * @return the value of the text box
544 * @throws java.lang.Exception if something fail
546 public String
getTextBoxText(String TextFieldName
)
547 throws java
.lang
.Exception
549 String TextFieldText
= null;
551 XAccessibleContext xTextField
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
552 AccessibleRole
.SCROLL_PANE
, TextFieldName
);
553 XAccessible xTextFieldAccess
= UnoRuntime
.queryInterface(XAccessible
.class, xTextField
);
554 XAccessibleContext xFrame
=AccessibilityTools
.getAccessibleObjectForRole(
555 xTextFieldAccess
, AccessibleRole
.TEXT_FRAME
);
556 for (int i
=0;i
<xFrame
.getAccessibleChildCount();i
++) {
558 XAccessible xChild
= xFrame
.getAccessibleChild(i
);
559 XAccessibleContext xChildCont
=
560 xChild
.getAccessibleContext();
561 XInterface xChildInterface
= UnoRuntime
.queryInterface(XInterface
.class, xChildCont
);
562 TextFieldText
+= (getString(xChildInterface
));
564 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
565 throw new Exception("Could not get child fom TextFrame of '"
566 + TextFieldName
+ "' : " + e
.toString());
569 return TextFieldText
;
570 } catch (Exception e
) {
571 throw new Exception("Could not get content fom Textbox '"
572 + TextFieldName
+ "' : " + e
.toString());
577 * set a value to a named check box
578 * @param CheckBoxName the name of the check box
579 * @param Value the value to set
581 * <li>0: not checked </li>
582 * <li>1: checked </li>
583 * <li>2: don't know </li>
585 * @throws java.lang.Exception if something fail
587 public void setCheckBoxValue(String CheckBoxName
, Integer Value
)
588 throws java
.lang
.Exception
591 XInterface xCheckBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
592 AccessibleRole
.CHECK_BOX
, CheckBoxName
);
593 XAccessibleValue xCheckBoxValue
= UnoRuntime
.queryInterface(XAccessibleValue
.class, xCheckBox
);
594 xCheckBoxValue
.setCurrentValue(Value
);
596 } catch (Exception e
) {
597 throw new Exception("Could not set value to CheckBox '"
598 + CheckBoxName
+ "' : " + e
.toString());
603 * returns the value of the named check box
604 * @param CheckBoxName the name of the check box
605 * @return the value of the check box
606 * @throws java.lang.Exception if something fail
608 public Integer
getCheckBoxValue(String CheckBoxName
)
609 throws java
.lang
.Exception
612 XInterface xCheckBox
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
613 AccessibleRole
.CHECK_BOX
, CheckBoxName
);
614 XAccessibleValue xCheckBoxValue
= UnoRuntime
.queryInterface(XAccessibleValue
.class, xCheckBox
);
616 return (Integer
) xCheckBoxValue
.getCurrentValue();
617 } catch (Exception e
) {
618 throw new Exception("Could not set value to CheckBox '"
619 + CheckBoxName
+ "' : " + e
.toString());
624 * returns the message of a Basic-MessageBox
625 * @return the message of a Basic-MessageBox
626 * @throws java.lang.Exception if something fail
628 public String
getMsgBoxText()
629 throws java
.lang
.Exception
631 String cMessage
= null;
633 XAccessibleContext xMessage
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
,
634 AccessibleRole
.LABEL
);
636 XInterface xMessageInterface
= UnoRuntime
.queryInterface(XInterface
.class, xMessage
);
637 cMessage
+= (getString(xMessageInterface
));
641 } catch (Exception e
) {
642 throw new Exception("Could not get message from Basic-MessageBox: " + e
.toString());
647 * fetch the window which is equal to the given <CODE>WindowName</CODE>
648 * @return the named window
649 * @throws java.lang.Exception if something fail
651 public XWindow
getTopWindow(String WindowName
, boolean debug
) throws java
.lang
.Exception
653 XInterface xToolKit
= null;
655 xToolKit
= (XInterface
) mMSF
.createInstance("com.sun.star.awt.Toolkit") ;
656 } catch (com
.sun
.star
.uno
.Exception e
) {
657 throw new Exception("Could not toolkit: " + e
.toString());
659 XExtendedToolkit tk
= UnoRuntime
.queryInterface(XExtendedToolkit
.class, xToolKit
);
661 int count
= tk
.getTopWindowCount();
663 XTopWindow retWindow
= null;
665 if (debug
) System
.out
.println("getTopWindow ->");
667 for (int i
=0; i
< count
; i
++){
668 XTopWindow xTopWindow
= tk
.getTopWindow(i
);
669 XAccessible xAcc
= AccessibilityTools
.getAccessibleObject(xTopWindow
);
670 String accName
= xAcc
.getAccessibleContext().getAccessibleName();
673 System
.out
.println("AccessibleName: " + accName
);
676 if (WindowName
.equals(accName
)){
677 if (debug
) System
.out
.println("-> found window with name '" + WindowName
+ "'");
678 retWindow
= xTopWindow
;
684 if (retWindow
== null) System
.out
.println("could not found window with name '" + WindowName
+ "'");
685 System
.out
.println("<- getTopWindow ");
687 return UnoRuntime
.queryInterface(XWindow
.class, retWindow
);
690 public void clickMiddleOfAccessibleObject(short role
, String name
){
692 XAccessibleContext xAcc
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
, role
, name
);
693 XAccessibleComponent aComp
= UnoRuntime
.queryInterface(
694 XAccessibleComponent
.class, xAcc
);
696 System
.out
.println(xAcc
.getAccessibleRole() + "," +
697 xAcc
.getAccessibleName() + "(" +
698 xAcc
.getAccessibleDescription() + "):" +
699 utils
.getImplName(xAcc
));
702 aComp
.getLocationOnScreen();
703 String bounds
= "(" + aComp
.getBounds().X
+ "," +
704 aComp
.getBounds().Y
+ ")" + " (" +
705 aComp
.getBounds().Width
+ "," +
706 aComp
.getBounds().Height
+ ")";
707 System
.out
.println("The boundary Rectangle is " + bounds
);
709 Robot rob
= new Robot();
710 int x
= aComp
.getLocationOnScreen().X
+ (aComp
.getBounds().Width
/ 2);
711 int y
= aComp
.getLocationOnScreen().Y
+ (aComp
.getBounds().Height
/ 2);
712 System
.out
.println("try to click mouse button on x/y " + x
+ "/" + y
);
714 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
715 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
716 } catch (java
.awt
.AWTException e
) {
717 System
.out
.println("couldn't press mouse button");
723 public void doubleClickMiddleOfAccessibleObject(short role
, String name
) {
724 XAccessibleContext xAcc
=AccessibilityTools
.getAccessibleObjectForRole(mXRoot
, role
, name
);
725 XAccessibleComponent aComp
= UnoRuntime
.queryInterface(
726 XAccessibleComponent
.class, xAcc
);
728 System
.out
.println(xAcc
.getAccessibleRole() + "," +
729 xAcc
.getAccessibleName() + "(" +
730 xAcc
.getAccessibleDescription() + "):" +
731 utils
.getImplName(xAcc
));
734 aComp
.getLocationOnScreen();
735 String bounds
= "(" + aComp
.getBounds().X
+ "," +
736 aComp
.getBounds().Y
+ ")" + " (" +
737 aComp
.getBounds().Width
+ "," +
738 aComp
.getBounds().Height
+ ")";
739 System
.out
.println("The boundary Rectangle is " + bounds
);
741 Robot rob
= new Robot();
742 int x
= aComp
.getLocationOnScreen().X
+ (aComp
.getBounds().Width
/ 2);
743 int y
= aComp
.getLocationOnScreen().Y
+ (aComp
.getBounds().Height
/ 2);
744 System
.out
.println("try to double click mouse button on x/y " + x
+ "/" + y
);
746 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
747 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
748 utils
.shortWait(100);
749 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
750 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
751 } catch (java
.awt
.AWTException e
) {
752 System
.out
.println("couldn't press mouse button");
760 * Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
761 * this function does not work anymore.
762 * @deprecated Since <CODE>AccessibilityTools</CODE> handle parameter <CODE>debugIsActive</CODE>
763 * this function does not work anymore.
764 * @param log logWriter
766 public void printAccessibleTree(PrintWriter log
)
768 AccessibilityTools
.printAccessibleTree(log
, mXRoot
);
773 * Prints the accessible tree to the <CODE>logWriter</CODE> only if <CODE>debugIsActive</CODE>
774 * is set to <CODE>true</CODE>
775 * @param log logWriter
776 * @param debugIsActive prints only if this parameter is set to TRUE
778 public void printAccessibleTree(PrintWriter log
, boolean debugIsActive
) {
779 AccessibilityTools
.printAccessibleTree(log
, mXRoot
, debugIsActive
);