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