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.XAccessible; 31*cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleComponent; 32*cdf0e10cSrcweir import com.sun.star.awt.Point; 33*cdf0e10cSrcweir import com.sun.star.awt.ScrollBarOrientation; 34*cdf0e10cSrcweir import com.sun.star.awt.XSpinValue; 35*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 36*cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 37*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 38*cdf0e10cSrcweir import java.awt.Robot; 39*cdf0e10cSrcweir import java.awt.event.InputEvent; 40*cdf0e10cSrcweir import lib.MultiMethodTest; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir public class _XSpinValue extends MultiMethodTest { 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir public XSpinValue oObj; 45*cdf0e10cSrcweir public boolean adjusted = false; 46*cdf0e10cSrcweir com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener(); 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir public void _addAdjustmentListener() { 49*cdf0e10cSrcweir util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(), 50*cdf0e10cSrcweir (XTextDocument) tEnv.getObjRelation("Document")); 51*cdf0e10cSrcweir shortWait(); 52*cdf0e10cSrcweir oObj.addAdjustmentListener(listener); 53*cdf0e10cSrcweir adjustScrollBar(); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir boolean res = adjusted; 56*cdf0e10cSrcweir oObj.removeAdjustmentListener(listener); 57*cdf0e10cSrcweir adjusted = false; 58*cdf0e10cSrcweir adjustScrollBar(); 59*cdf0e10cSrcweir res &= !adjusted; 60*cdf0e10cSrcweir tRes.tested("addAdjustmentListener()", res); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir public void _removeAdjustmentListener() { 64*cdf0e10cSrcweir //this method is checked in addAjustmentListener 65*cdf0e10cSrcweir //so that method is requiered here and if it works 66*cdf0e10cSrcweir //this method is given OK too 67*cdf0e10cSrcweir requiredMethod("addAdjustmentListener()"); 68*cdf0e10cSrcweir tRes.tested("removeAdjustmentListener()", true); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir public void _setSpinIncrement() { 72*cdf0e10cSrcweir oObj.setSpinIncrement(15); 73*cdf0e10cSrcweir oObj.setSpinIncrement(5); 74*cdf0e10cSrcweir int bi = oObj.getSpinIncrement(); 75*cdf0e10cSrcweir tRes.tested("setSpinIncrement()",bi==5); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir public void _getSpinIncrement() { 79*cdf0e10cSrcweir //this method is checked in the corresponding set method 80*cdf0e10cSrcweir //so that method is requiered here and if it works 81*cdf0e10cSrcweir //this method is given OK too 82*cdf0e10cSrcweir requiredMethod("setSpinIncrement()"); 83*cdf0e10cSrcweir tRes.tested("getSpinIncrement()", true); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public void _setMaximum() { 88*cdf0e10cSrcweir oObj.setMaximum(490); 89*cdf0e10cSrcweir oObj.setMaximum(480); 90*cdf0e10cSrcweir int max = oObj.getMaximum(); 91*cdf0e10cSrcweir tRes.tested("setMaximum()",max==480); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir public void _getMaximum() { 95*cdf0e10cSrcweir //this method is checked in the corresponding set method 96*cdf0e10cSrcweir //so that method is requiered here and if it works 97*cdf0e10cSrcweir //this method is given OK too 98*cdf0e10cSrcweir requiredMethod("setMaximum()"); 99*cdf0e10cSrcweir tRes.tested("getMaximum()", true); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir public void _setMinimum() { 103*cdf0e10cSrcweir oObj.setMinimum(90); 104*cdf0e10cSrcweir oObj.setMinimum(80); 105*cdf0e10cSrcweir int max = oObj.getMinimum(); 106*cdf0e10cSrcweir tRes.tested("setMinimum()",max==80); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir public void _getMinimum() { 110*cdf0e10cSrcweir //this method is checked in the corresponding set method 111*cdf0e10cSrcweir //so that method is requiered here and if it works 112*cdf0e10cSrcweir //this method is given OK too 113*cdf0e10cSrcweir requiredMethod("setMinimum()"); 114*cdf0e10cSrcweir tRes.tested("getMinimum()", true); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir public void _setOrientation() { 118*cdf0e10cSrcweir boolean res = true; 119*cdf0e10cSrcweir try { 120*cdf0e10cSrcweir oObj.setOrientation(ScrollBarOrientation.HORIZONTAL); 121*cdf0e10cSrcweir oObj.setOrientation(ScrollBarOrientation.VERTICAL); 122*cdf0e10cSrcweir } catch (com.sun.star.lang.NoSupportException e) { 123*cdf0e10cSrcweir log.println("Couldn't set Orientation"); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir int ori = oObj.getOrientation(); 126*cdf0e10cSrcweir res &= (ori==ScrollBarOrientation.VERTICAL); 127*cdf0e10cSrcweir tRes.tested("setOrientation()",res ); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir public void _getOrientation() { 131*cdf0e10cSrcweir //this method is checked in the corresponding set method 132*cdf0e10cSrcweir //so that method is requiered here and if it works 133*cdf0e10cSrcweir //this method is given OK too 134*cdf0e10cSrcweir requiredMethod("setOrientation()"); 135*cdf0e10cSrcweir tRes.tested("getOrientation()", true); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir public void _setValue() { 139*cdf0e10cSrcweir oObj.setMaximum(600); 140*cdf0e10cSrcweir oObj.setValue(480); 141*cdf0e10cSrcweir oObj.setValue(520); 142*cdf0e10cSrcweir int val = oObj.getValue(); 143*cdf0e10cSrcweir tRes.tested("setValue()",val==520); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir public void _getValue() { 147*cdf0e10cSrcweir //this method is checked in the corresponding set method 148*cdf0e10cSrcweir //so that method is requiered here and if it works 149*cdf0e10cSrcweir //this method is given OK too 150*cdf0e10cSrcweir requiredMethod("setValue()"); 151*cdf0e10cSrcweir tRes.tested("getValue()", true); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir public void _setValues() { 155*cdf0e10cSrcweir oObj.setValues(80, 200, 180); 156*cdf0e10cSrcweir oObj.setValues(70, 210, 200); 157*cdf0e10cSrcweir int val = oObj.getValue(); 158*cdf0e10cSrcweir int min = oObj.getMinimum(); 159*cdf0e10cSrcweir int max = oObj.getMaximum(); 160*cdf0e10cSrcweir tRes.tested("setValues()",((min==70) && (max==210) && (val==200))); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir private void adjustScrollBar() { 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir XSpinValue sv = (XSpinValue) UnoRuntime.queryInterface( 167*cdf0e10cSrcweir XSpinValue.class, tEnv.getTestObject()); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sv.setValue(500); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir shortWait(); 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir XAccessible acc = (XAccessible) UnoRuntime.queryInterface( 174*cdf0e10cSrcweir XAccessible.class, tEnv.getTestObject()); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface( 177*cdf0e10cSrcweir XAccessibleComponent.class, 178*cdf0e10cSrcweir acc.getAccessibleContext()); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir Point location = aCom.getLocationOnScreen(); 181*cdf0e10cSrcweir //Point location = (Point) tEnv.getObjRelation("Location"); 182*cdf0e10cSrcweir //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location"); 183*cdf0e10cSrcweir //Point location = aCom.getLocationOnScreen(); 184*cdf0e10cSrcweir try { 185*cdf0e10cSrcweir Robot rob = new Robot(); 186*cdf0e10cSrcweir rob.mouseMove(location.X + 20, location.Y + 10); 187*cdf0e10cSrcweir rob.mousePress(InputEvent.BUTTON1_MASK); 188*cdf0e10cSrcweir rob.mouseRelease(InputEvent.BUTTON1_MASK); 189*cdf0e10cSrcweir } catch (java.awt.AWTException e) { 190*cdf0e10cSrcweir System.out.println("couldn't adjust scrollbar"); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir shortWait(); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir /** 197*cdf0e10cSrcweir * Sleeps for 0.5 sec. to allow Office to react 198*cdf0e10cSrcweir */ 199*cdf0e10cSrcweir private void shortWait() { 200*cdf0e10cSrcweir try { 201*cdf0e10cSrcweir Thread.sleep(500); 202*cdf0e10cSrcweir } catch (InterruptedException e) { 203*cdf0e10cSrcweir log.println("While waiting :" + e); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir public class AdjustmentListener 208*cdf0e10cSrcweir implements com.sun.star.awt.XAdjustmentListener { 209*cdf0e10cSrcweir public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) { 210*cdf0e10cSrcweir System.out.println("Adjustment Value changed"); 211*cdf0e10cSrcweir System.out.println("AdjustmentEvent: " + adjustmentEvent.Value); 212*cdf0e10cSrcweir adjusted = true; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir public void disposing(com.sun.star.lang.EventObject eventObject) { 216*cdf0e10cSrcweir System.out.println("Listener disposed"); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir } 221