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 ifc.awt; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole; 31*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 32*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 33*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 34*cdf0e10cSrcweir import com.sun.star.awt.KeyEvent; 35*cdf0e10cSrcweir import com.sun.star.awt.MouseEvent; 36*cdf0e10cSrcweir import com.sun.star.awt.Point; 37*cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 38*cdf0e10cSrcweir import com.sun.star.awt.XKeyHandler; 39*cdf0e10cSrcweir import com.sun.star.awt.XMouseClickHandler; 40*cdf0e10cSrcweir import com.sun.star.awt.XUserInputInterception; 41*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 42*cdf0e10cSrcweir import com.sun.star.frame.XModel; 43*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 44*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 45*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 46*cdf0e10cSrcweir import java.awt.Robot; 47*cdf0e10cSrcweir import java.awt.event.InputEvent; 48*cdf0e10cSrcweir import lib.MultiMethodTest; 49*cdf0e10cSrcweir import util.AccessibilityTools; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /** 52*cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XUserInputInterception</code> 53*cdf0e10cSrcweir * interface methods: 54*cdf0e10cSrcweir * <ul> 55*cdf0e10cSrcweir * <li><code> addKeyHandler() </code></li> 56*cdf0e10cSrcweir * <li><code> removeKeyHandler() </code></li> 57*cdf0e10cSrcweir * <li><code> addMouseClickHandler() </code></li> 58*cdf0e10cSrcweir * <li><code> removeMouseClickHandler() </code></li> 59*cdf0e10cSrcweir * </ul><p> 60*cdf0e10cSrcweir * This test needs the following object relations : 61*cdf0e10cSrcweir * <ul> 62*cdf0e10cSrcweir * <li> <code>'XUserInputInterception.XModel'</code> (of type <code>XModel</code>): 63*cdf0e10cSrcweir * used as model where a mouse click or a key press could be done </li> 64*cdf0e10cSrcweir * </ul> <p> 65*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 66*cdf0e10cSrcweir * @see com.sun.star.awt.XUserInputInterception 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public class _XUserInputInterception extends MultiMethodTest { 69*cdf0e10cSrcweir public XUserInputInterception oObj = null; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir private XModel m_XModel = null; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir /** the listener 1 for the mouse click test */ 74*cdf0e10cSrcweir private MyMouseClickHandler1 m_MouseListener1 = null; 75*cdf0e10cSrcweir /** the listener 2 for the mouse click test */ 76*cdf0e10cSrcweir private MyMouseClickHandler2 m_MouseListener2 = null; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir /** the listener 1 for the key event test */ 79*cdf0e10cSrcweir private MyKeyHandler1 m_KeyListener1 = null; 80*cdf0e10cSrcweir /** the listener 2 for the key event test */ 81*cdf0e10cSrcweir private MyKeyHandler2 m_KeyListener2 = null; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** indicates if the mousePressed event was called*/ 84*cdf0e10cSrcweir private boolean m_mousePressed1 = false; 85*cdf0e10cSrcweir /** indicates if the mouseReleased event was called*/ 86*cdf0e10cSrcweir private boolean m_mouseReleased1 = false; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir /** indicates if the mousePressed event was called*/ 89*cdf0e10cSrcweir private boolean m_mousePressed2 = false; 90*cdf0e10cSrcweir /** indicates if the mouseReleased event was called*/ 91*cdf0e10cSrcweir private boolean m_mouseReleased2 = false; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir /** indicates if the mousePressed event was called*/ 94*cdf0e10cSrcweir private boolean m_keyPressed1 = false; 95*cdf0e10cSrcweir /** indicates if the mouseReleased event was called*/ 96*cdf0e10cSrcweir private boolean m_keyReleased1 = false; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** indicates if the mousePressed event was called*/ 99*cdf0e10cSrcweir private boolean m_keyPressed2 = false; 100*cdf0e10cSrcweir /** indicates if the mouseReleased event was called*/ 101*cdf0e10cSrcweir private boolean m_keyReleased2 = false; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /** get the object rlation XUserInputInterception.XModel from the 104*cdf0e10cSrcweir * test environment 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir protected void before() { 107*cdf0e10cSrcweir log.print("try to get object relation 'XUserInputInterception.XModel': "); 108*cdf0e10cSrcweir m_XModel = (XModel)tEnv.getObjRelation("XUserInputInterception.XModel"); 109*cdf0e10cSrcweir if (m_XModel == null) log.println("failed => null"); 110*cdf0e10cSrcweir else log.println("OK"); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir /** 115*cdf0e10cSrcweir * This test adds two different key listener to the object. <p> 116*cdf0e10cSrcweir * 117*cdf0e10cSrcweir * Has <b> OK </b> if no exception is thrown. 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir public void _addKeyHandler() { 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir log.println("creating key listener 1"); 122*cdf0e10cSrcweir m_KeyListener1 = new MyKeyHandler1(); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir log.println("creating key listener 2"); 125*cdf0e10cSrcweir m_KeyListener2 = new MyKeyHandler2(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir log.println("adding key listener 1"); 129*cdf0e10cSrcweir oObj.addKeyHandler(m_KeyListener1); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir log.println("adding key listener 2"); 133*cdf0e10cSrcweir oObj.addKeyHandler(m_KeyListener2); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir tRes.tested("addKeyHandler()", true); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir /** 139*cdf0e10cSrcweir * The test requires <CODE>addKeyHandler()</CODE> which adds two key listener. 140*cdf0e10cSrcweir * Then one of them will be removed. In a second thread a key event is released 141*cdf0e10cSrcweir * by the <CODE>robot</CODE> class.<p> 142*cdf0e10cSrcweir * Has <b> OK </b> status if only one of the listener are triggered. <p> 143*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 144*cdf0e10cSrcweir * <ul> 145*cdf0e10cSrcweir * <li> <code> addKeyHandler() </code> : adds two key listener </li> 146*cdf0e10cSrcweir * </ul> 147*cdf0e10cSrcweir */ 148*cdf0e10cSrcweir public void _removeKeyHandler() { 149*cdf0e10cSrcweir requiredMethod("addKeyHandler()"); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir log.println("remove key listener 2"); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir oObj.removeKeyHandler(m_KeyListener2); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir log.println("starting thread to check the key listener..."); 156*cdf0e10cSrcweir EventTrigger et = new EventTrigger(m_XModel, EventTriggerType.KEY_TEXT_INTO_DOC); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir et.run(); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT) * 2); 161*cdf0e10cSrcweir log.println("key listener thread should be finished."); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir boolean bOK = m_keyPressed1 & m_keyReleased1 & 165*cdf0e10cSrcweir ! m_keyPressed2 & ! m_keyReleased2; 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if (! bOK){ 168*cdf0e10cSrcweir log.println("The key listener has not the expectd status:"); 169*cdf0e10cSrcweir log.println("listener\texpected\tgot"); 170*cdf0e10cSrcweir log.println("keyPressed1\ttrue\t"+m_keyPressed1); 171*cdf0e10cSrcweir log.println("keyReleased1\ttrue\t"+m_keyReleased1); 172*cdf0e10cSrcweir log.println("keyPressed2\tfalse\t"+m_keyPressed2); 173*cdf0e10cSrcweir log.println("keyReleased2\tfalse\t"+m_keyReleased2); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir log.println("remove Key listener 1"); 177*cdf0e10cSrcweir oObj.removeKeyHandler(m_KeyListener1); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir tRes.tested("removeKeyHandler()", bOK); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /** 183*cdf0e10cSrcweir * This test adds two different mouse klick listener to the object. <p> 184*cdf0e10cSrcweir * 185*cdf0e10cSrcweir * Has <b> OK </b> if no exception is thrown. 186*cdf0e10cSrcweir */ 187*cdf0e10cSrcweir public void _addMouseClickHandler() { 188*cdf0e10cSrcweir log.println("creating mouse listener 1"); 189*cdf0e10cSrcweir m_MouseListener1 = new MyMouseClickHandler1(); 190*cdf0e10cSrcweir log.println("creating mouse listener 2"); 191*cdf0e10cSrcweir m_MouseListener2 = new MyMouseClickHandler2(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir log.println("adding mouse listener 1"); 194*cdf0e10cSrcweir oObj.addMouseClickHandler(m_MouseListener1); 195*cdf0e10cSrcweir log.println("adding mouse listener 2"); 196*cdf0e10cSrcweir oObj.addMouseClickHandler(m_MouseListener2); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir tRes.tested("addMouseClickHandler()", true); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir /** 202*cdf0e10cSrcweir * The test requires <CODE>addMouseClickHandler()</CODE> which adds two key listener. 203*cdf0e10cSrcweir * Then one of them will be removed. In a second thread a mouse klick event is released 204*cdf0e10cSrcweir * by the <CODE>robot</CODE> class.<p> 205*cdf0e10cSrcweir * Has <b> OK </b> status if only one of the listener are triggered. <p> 206*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 207*cdf0e10cSrcweir * <ul> 208*cdf0e10cSrcweir * <li> <code> addMouseKlickHandler() </code> : adds two key listener </li> 209*cdf0e10cSrcweir * </ul> 210*cdf0e10cSrcweir */ 211*cdf0e10cSrcweir public void _removeMouseClickHandler() { 212*cdf0e10cSrcweir requiredMethod("addMouseClickHandler"); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir log.println("remove mouse listener 2"); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir oObj.removeMouseClickHandler(m_MouseListener2); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir log.println("starting thread to check the mouse listener..."); 219*cdf0e10cSrcweir EventTrigger et = new EventTrigger(m_XModel, EventTriggerType.MOUSE_KLICK_INTO_DOC); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir et.run(); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT) * 2); 224*cdf0e10cSrcweir log.println("mouse listener thread should be finished."); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir boolean bOK = m_mousePressed1 & m_mouseReleased1 & 227*cdf0e10cSrcweir ! m_mousePressed2 & ! m_mouseReleased2; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir if (! bOK){ 230*cdf0e10cSrcweir log.println("The mouse listener has not the expectd status:"); 231*cdf0e10cSrcweir log.println("listener\t\texpected\tgot"); 232*cdf0e10cSrcweir log.println("mousePressed1\ttrue\t\t"+m_mousePressed1); 233*cdf0e10cSrcweir log.println("mouseReleased1\ttrue\t\t"+m_mouseReleased1); 234*cdf0e10cSrcweir log.println("mousePressed2\tfalse\t\t"+m_mousePressed2); 235*cdf0e10cSrcweir log.println("mouseReleased2\tfalse\t\t"+m_mouseReleased2); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir log.println("remove mouse listener 1"); 239*cdf0e10cSrcweir oObj.removeMouseClickHandler(m_MouseListener1); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir tRes.tested("removeMouseClickHandler()", bOK); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir /** 246*cdf0e10cSrcweir * Forces environment recreation. 247*cdf0e10cSrcweir */ 248*cdf0e10cSrcweir protected void after() { 249*cdf0e10cSrcweir disposeEnvironment(); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir /** 253*cdf0e10cSrcweir * Listener which added and its method must be called 254*cdf0e10cSrcweir * on <code>keyPressed</code> and <code>keyReleased</code> call. 255*cdf0e10cSrcweir */ 256*cdf0e10cSrcweir public class MyKeyHandler1 implements XKeyHandler { 257*cdf0e10cSrcweir /** 258*cdf0e10cSrcweir * This event sets the member <code>m_keyPressed</coed> to 259*cdf0e10cSrcweir * <code>true</code> 260*cdf0e10cSrcweir * @param oEvent The key event informs about the pressed key. 261*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 262*cdf0e10cSrcweir */ 263*cdf0e10cSrcweir public boolean keyPressed( KeyEvent oEvent ){ 264*cdf0e10cSrcweir log.println("XKeyHandler 1: keyPressed-Event"); 265*cdf0e10cSrcweir m_keyPressed1 = true; 266*cdf0e10cSrcweir return true; 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir /** 269*cdf0e10cSrcweir * This event sets the member <code>m_keyReleased</coed> to 270*cdf0e10cSrcweir * <code>true</code> 271*cdf0e10cSrcweir * @param oEvent The key event informs about the pressed key. 272*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 273*cdf0e10cSrcweir */ 274*cdf0e10cSrcweir public boolean keyReleased( KeyEvent oEvent ){ 275*cdf0e10cSrcweir log.println("XKeyHandler 1: keyReleased-Event"); 276*cdf0e10cSrcweir m_keyReleased1 = true; 277*cdf0e10cSrcweir return true; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir /** 280*cdf0e10cSrcweir * This event does nothing usefull 281*cdf0e10cSrcweir * @param oEvent refers to the object that fired the event. 282*cdf0e10cSrcweir */ 283*cdf0e10cSrcweir public void disposing( EventObject oEvent ){ 284*cdf0e10cSrcweir log.println("XKeyHandler 1: disposing-Event"); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir /** 288*cdf0e10cSrcweir * Listener which added and its method must be called 289*cdf0e10cSrcweir * on <code>keyPressed</code> and <code>keyReleased</code> call. 290*cdf0e10cSrcweir */ 291*cdf0e10cSrcweir public class MyKeyHandler2 implements XKeyHandler { 292*cdf0e10cSrcweir /** 293*cdf0e10cSrcweir * This event sets the member <code>m_keyPressed</coed> to 294*cdf0e10cSrcweir * <code>true</code> 295*cdf0e10cSrcweir * @param oEvent The key event informs about the pressed key. 296*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 297*cdf0e10cSrcweir */ 298*cdf0e10cSrcweir public boolean keyPressed( KeyEvent oEvent ){ 299*cdf0e10cSrcweir log.println("XKeyHandler 2: keyPressed-Event: " + 300*cdf0e10cSrcweir "This should not be happen because listener is removed!"); 301*cdf0e10cSrcweir m_keyPressed2 = true; 302*cdf0e10cSrcweir return true; 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir /** 305*cdf0e10cSrcweir * This event sets the member <code>m_keyReleased</coed> to 306*cdf0e10cSrcweir * <code>true</code> 307*cdf0e10cSrcweir * @param oEvent The key event informs about the pressed key. 308*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 309*cdf0e10cSrcweir */ 310*cdf0e10cSrcweir public boolean keyReleased( KeyEvent oEvent ){ 311*cdf0e10cSrcweir log.println("XKeyHandler 2: keyReleased-Event: " + 312*cdf0e10cSrcweir "This should not be happen because listener is removed!"); 313*cdf0e10cSrcweir m_keyReleased2 = true; 314*cdf0e10cSrcweir return true; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir /** 317*cdf0e10cSrcweir * This event does nothing usefull 318*cdf0e10cSrcweir * @param oEvent refers to the object that fired the event. 319*cdf0e10cSrcweir */ 320*cdf0e10cSrcweir public void disposing( EventObject oEvent ){ 321*cdf0e10cSrcweir log.println("XKeyHandler 2: disposing-Event: " + 322*cdf0e10cSrcweir "This should not be happen because listener is removed!"); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir /** 327*cdf0e10cSrcweir * Listener which added and its method must be called 328*cdf0e10cSrcweir * on <code>mousePressed</code> and <code>mouseReleased</code> call. 329*cdf0e10cSrcweir */ 330*cdf0e10cSrcweir public class MyMouseClickHandler1 implements XMouseClickHandler { 331*cdf0e10cSrcweir /** 332*cdf0e10cSrcweir * This event sets the member <code>m_mousePressed</coed> to 333*cdf0e10cSrcweir * <code>true</code> 334*cdf0e10cSrcweir * @param oEvent The mouse event informs about the kind of mouse event. 335*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 336*cdf0e10cSrcweir */ 337*cdf0e10cSrcweir public boolean mousePressed( MouseEvent oEvent ){ 338*cdf0e10cSrcweir log.println("XMouseClickHandler 1: mousePressed-Event"); 339*cdf0e10cSrcweir m_mousePressed1 = true; 340*cdf0e10cSrcweir return true; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir /** 343*cdf0e10cSrcweir * This event sets the member <code>m_mouseReleased</coed> to 344*cdf0e10cSrcweir * <code>true</code> 345*cdf0e10cSrcweir * @param oEvent The mouse event informs about the kind of mouse event. 346*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 347*cdf0e10cSrcweir */ 348*cdf0e10cSrcweir public boolean mouseReleased( MouseEvent oEvent ){ 349*cdf0e10cSrcweir log.println("XMouseClickHandler 1: mouseReleased-Event"); 350*cdf0e10cSrcweir m_mouseReleased1 = true; 351*cdf0e10cSrcweir return true; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir /** 354*cdf0e10cSrcweir * This event does nothing usefull 355*cdf0e10cSrcweir * @param oEvent refers to the object that fired the event. 356*cdf0e10cSrcweir */ 357*cdf0e10cSrcweir public void disposing( EventObject oEvent ){ 358*cdf0e10cSrcweir log.println("XMouseClickHandler 1: disposing-Event"); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir }; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir /** 363*cdf0e10cSrcweir * Listener which added and removed. Its method must NOT be called 364*cdf0e10cSrcweir * on <code>mousePressed</code> and <code>mouseReleased</code> call. 365*cdf0e10cSrcweir */ 366*cdf0e10cSrcweir public class MyMouseClickHandler2 implements XMouseClickHandler { 367*cdf0e10cSrcweir /** 368*cdf0e10cSrcweir * This event sets the member <code>m_mousePressed</coed> to 369*cdf0e10cSrcweir * <code>true</code> 370*cdf0e10cSrcweir * @param oEvent The mouse event informs about the kind of mouse event. 371*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 372*cdf0e10cSrcweir */ 373*cdf0e10cSrcweir public boolean mousePressed( MouseEvent oEvent ){ 374*cdf0e10cSrcweir log.println("XMouseClickHandler 2: mousePressed-Event: " + 375*cdf0e10cSrcweir "This should not be happen because listener is removed!"); 376*cdf0e10cSrcweir m_mousePressed2 = true; 377*cdf0e10cSrcweir return true; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir /** 380*cdf0e10cSrcweir * This event sets the member <code>m_mouseReleased</coed> to 381*cdf0e10cSrcweir * <code>true</code> 382*cdf0e10cSrcweir * @param oEvent The mouse event informs about the kind of mouse event. 383*cdf0e10cSrcweir * @return returns <CODE>TRUE</CODE> in erery case 384*cdf0e10cSrcweir */ 385*cdf0e10cSrcweir public boolean mouseReleased( MouseEvent oEvent ){ 386*cdf0e10cSrcweir log.println("XMouseClickHandler 2: mouseReleased-Event: " + 387*cdf0e10cSrcweir "This should not be happen because listener is removed!"); 388*cdf0e10cSrcweir m_mouseReleased2 = true; 389*cdf0e10cSrcweir return true; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir /** 392*cdf0e10cSrcweir * This event does nothing usefull 393*cdf0e10cSrcweir * @param oEvent refers to the object that fired the event. 394*cdf0e10cSrcweir */ 395*cdf0e10cSrcweir public void disposing( EventObject oEvent ){ 396*cdf0e10cSrcweir log.println("XMouseClickHandler 2: disposing-Event: " + 397*cdf0e10cSrcweir " This should not be happen because listener is removed!"); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir }; 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir /** 402*cdf0e10cSrcweir * To check the events this class is a thread which click a mouse button and 403*cdf0e10cSrcweir * press a key with the <CODE>Robot</CODE> class 404*cdf0e10cSrcweir * @see java.awt.Robot 405*cdf0e10cSrcweir */ 406*cdf0e10cSrcweir private class EventTrigger extends Thread{ 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir /** 409*cdf0e10cSrcweir * represents a <CODE>AccessibilityTools</CODE> 410*cdf0e10cSrcweir */ 411*cdf0e10cSrcweir private final AccessibilityTools at = new AccessibilityTools(); 412*cdf0e10cSrcweir /** 413*cdf0e10cSrcweir * represents an <CODE>EventType</CODE> 414*cdf0e10cSrcweir * @see EventTest.EventTriggerType 415*cdf0e10cSrcweir */ 416*cdf0e10cSrcweir private int eventType = 0; 417*cdf0e10cSrcweir /** 418*cdf0e10cSrcweir * represents a <CODE>XModel</CODE> of a document 419*cdf0e10cSrcweir */ 420*cdf0e10cSrcweir private XModel xModel = null; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir /** 423*cdf0e10cSrcweir * Creates an instacne of this class. The parameter <CODE>eType</CODE> represents 424*cdf0e10cSrcweir * the kind of event wich will be triggert at <CODE>run()</CODE> 425*cdf0e10cSrcweir * @param model the model of a document 426*cdf0e10cSrcweir * @param eType the kind of event which should be trigger 427*cdf0e10cSrcweir */ 428*cdf0e10cSrcweir public EventTrigger(XModel model, int eType) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir this.xModel = model; 431*cdf0e10cSrcweir this.eventType = eType; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir /** 435*cdf0e10cSrcweir * Triggers the event wich is represented by <CODE>eventType</CODE> 436*cdf0e10cSrcweir * The scenarios are: 437*cdf0e10cSrcweir * <ul> 438*cdf0e10cSrcweir * <li>EventTest.EventTriggerType.MOUSE_KLICK_INTO_DOC 439*cdf0e10cSrcweir * which calls 440*cdf0e10cSrcweir * <li><CODE>clickIntoDoc</CODE></LI> 441*cdf0e10cSrcweir * </LI> 442*cdf0e10cSrcweir * <li>EventTest.EventTriggerType.KEY_TEXT_INTO_DOC 443*cdf0e10cSrcweir * which calls 444*cdf0e10cSrcweir * <li><CODE>clickIntodoc</CODE></LI> 445*cdf0e10cSrcweir * <li><CODE>keyIntoDoc</CODE></LI> 446*cdf0e10cSrcweir * </LI> 447*cdf0e10cSrcweir * </UL> 448*cdf0e10cSrcweir */ 449*cdf0e10cSrcweir public void run(){ 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir switch (this.eventType){ 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir case EventTriggerType.MOUSE_KLICK_INTO_DOC: 454*cdf0e10cSrcweir clickIntoDoc(); 455*cdf0e10cSrcweir break; 456*cdf0e10cSrcweir case EventTriggerType.KEY_TEXT_INTO_DOC: 457*cdf0e10cSrcweir clickIntoDoc(); 458*cdf0e10cSrcweir keyIntoDoc(); 459*cdf0e10cSrcweir break; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir /** 464*cdf0e10cSrcweir * This method cklicks into the middel of a document. It uses Accessibility 465*cdf0e10cSrcweir * to get the document and query for its position and its range to calculate 466*cdf0e10cSrcweir * the middle. This values was used for <CODE>Robot</CODE> Class. This 467*cdf0e10cSrcweir * Robot class is able to move the mouse and to cklick a mouse button 468*cdf0e10cSrcweir * @see java.awt.Robot 469*cdf0e10cSrcweir */ 470*cdf0e10cSrcweir private void clickIntoDoc(){ 471*cdf0e10cSrcweir try{ 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir util.DesktopTools.bringWindowToFront(xModel); 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir XWindow xWindow = at.getCurrentWindow( 476*cdf0e10cSrcweir (XMultiServiceFactory) tParam.getMSF(), 477*cdf0e10cSrcweir xModel); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir XAccessible xRoot = at.getAccessibleObject(xWindow); 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir XAccessibleContext xPanel = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL); 484*cdf0e10cSrcweir XAccessibleComponent xPanelCont = (XAccessibleComponent) UnoRuntime.queryInterface(XAccessibleComponent.class, xPanel); 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir // the position of the panel 487*cdf0e10cSrcweir Point point = xPanelCont.getLocationOnScreen(); 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir // the range of the panel 490*cdf0e10cSrcweir Rectangle rect = xPanelCont.getBounds(); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir try { 493*cdf0e10cSrcweir Robot rob = new Robot(); 494*cdf0e10cSrcweir int x = point.X + (rect.Width / 2); 495*cdf0e10cSrcweir int y = point.Y + (rect.Height / 2); 496*cdf0e10cSrcweir log.println("try to klick into the middle of the document"); 497*cdf0e10cSrcweir rob.mouseMove(x, y); 498*cdf0e10cSrcweir rob.mousePress(InputEvent.BUTTON1_MASK); 499*cdf0e10cSrcweir rob.mouseRelease(InputEvent.BUTTON1_MASK); 500*cdf0e10cSrcweir } catch (java.awt.AWTException e) { 501*cdf0e10cSrcweir log.println("couldn't press mouse button"); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir } catch (java.lang.Exception e){ 504*cdf0e10cSrcweir log.println("could not click into the scroll bar: " + e.toString()); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir /** 509*cdf0e10cSrcweir * This method press the "A" key. Therefore it uses the <CODE>Robot</CODE> 510*cdf0e10cSrcweir * class. 511*cdf0e10cSrcweir * @see java.awt.Robot 512*cdf0e10cSrcweir */ 513*cdf0e10cSrcweir private void keyIntoDoc(){ 514*cdf0e10cSrcweir try { 515*cdf0e10cSrcweir Robot rob = new Robot(); 516*cdf0e10cSrcweir log.println("try to press 'A'"); 517*cdf0e10cSrcweir rob.keyPress(java.awt.event.KeyEvent.VK_A); 518*cdf0e10cSrcweir rob.keyRelease(java.awt.event.KeyEvent.VK_A); 519*cdf0e10cSrcweir } catch (java.awt.AWTException e) { 520*cdf0e10cSrcweir log.println("couldn't press key"); 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir /** This interface represents all possible actions which could be used 527*cdf0e10cSrcweir * in the <CODE>EventTrigger</CODE> class. 528*cdf0e10cSrcweir * @see EventTest.EventTrigger 529*cdf0e10cSrcweir */ 530*cdf0e10cSrcweir private interface EventTriggerType{ 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir /** klick the mouse into the scroll bar*/ 533*cdf0e10cSrcweir final public static int MOUSE_KLICK_INTO_DOC = 1; 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir /** write some text into a spread sheet*/ 536*cdf0e10cSrcweir final public static int KEY_TEXT_INTO_DOC = 2; 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540