1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSpinValue.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import com
.sun
.star
.accessibility
.XAccessible
;
34 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
35 import com
.sun
.star
.awt
.Point
;
36 import com
.sun
.star
.awt
.ScrollBarOrientation
;
37 import com
.sun
.star
.awt
.XSpinValue
;
38 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.text
.XTextDocument
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import java
.awt
.Robot
;
42 import java
.awt
.event
.InputEvent
;
43 import lib
.MultiMethodTest
;
45 public class _XSpinValue
extends MultiMethodTest
{
47 public XSpinValue oObj
;
48 public boolean adjusted
= false;
49 com
.sun
.star
.awt
.XAdjustmentListener listener
= new AdjustmentListener();
51 public void _addAdjustmentListener() {
52 util
.FormTools
.switchDesignOf((XMultiServiceFactory
) tParam
.getMSF(),
53 (XTextDocument
) tEnv
.getObjRelation("Document"));
55 oObj
.addAdjustmentListener(listener
);
58 boolean res
= adjusted
;
59 oObj
.removeAdjustmentListener(listener
);
63 tRes
.tested("addAdjustmentListener()", res
);
66 public void _removeAdjustmentListener() {
67 //this method is checked in addAjustmentListener
68 //so that method is requiered here and if it works
69 //this method is given OK too
70 requiredMethod("addAdjustmentListener()");
71 tRes
.tested("removeAdjustmentListener()", true);
74 public void _setSpinIncrement() {
75 oObj
.setSpinIncrement(15);
76 oObj
.setSpinIncrement(5);
77 int bi
= oObj
.getSpinIncrement();
78 tRes
.tested("setSpinIncrement()",bi
==5);
81 public void _getSpinIncrement() {
82 //this method is checked in the corresponding set method
83 //so that method is requiered here and if it works
84 //this method is given OK too
85 requiredMethod("setSpinIncrement()");
86 tRes
.tested("getSpinIncrement()", true);
90 public void _setMaximum() {
93 int max
= oObj
.getMaximum();
94 tRes
.tested("setMaximum()",max
==480);
97 public void _getMaximum() {
98 //this method is checked in the corresponding set method
99 //so that method is requiered here and if it works
100 //this method is given OK too
101 requiredMethod("setMaximum()");
102 tRes
.tested("getMaximum()", true);
105 public void _setMinimum() {
108 int max
= oObj
.getMinimum();
109 tRes
.tested("setMinimum()",max
==80);
112 public void _getMinimum() {
113 //this method is checked in the corresponding set method
114 //so that method is requiered here and if it works
115 //this method is given OK too
116 requiredMethod("setMinimum()");
117 tRes
.tested("getMinimum()", true);
120 public void _setOrientation() {
123 oObj
.setOrientation(ScrollBarOrientation
.HORIZONTAL
);
124 oObj
.setOrientation(ScrollBarOrientation
.VERTICAL
);
125 } catch (com
.sun
.star
.lang
.NoSupportException e
) {
126 log
.println("Couldn't set Orientation");
128 int ori
= oObj
.getOrientation();
129 res
&= (ori
==ScrollBarOrientation
.VERTICAL
);
130 tRes
.tested("setOrientation()",res
);
133 public void _getOrientation() {
134 //this method is checked in the corresponding set method
135 //so that method is requiered here and if it works
136 //this method is given OK too
137 requiredMethod("setOrientation()");
138 tRes
.tested("getOrientation()", true);
141 public void _setValue() {
142 oObj
.setMaximum(600);
145 int val
= oObj
.getValue();
146 tRes
.tested("setValue()",val
==520);
149 public void _getValue() {
150 //this method is checked in the corresponding set method
151 //so that method is requiered here and if it works
152 //this method is given OK too
153 requiredMethod("setValue()");
154 tRes
.tested("getValue()", true);
157 public void _setValues() {
158 oObj
.setValues(80, 200, 180);
159 oObj
.setValues(70, 210, 200);
160 int val
= oObj
.getValue();
161 int min
= oObj
.getMinimum();
162 int max
= oObj
.getMaximum();
163 tRes
.tested("setValues()",((min
==70) && (max
==210) && (val
==200)));
166 private void adjustScrollBar() {
169 XSpinValue sv
= (XSpinValue
) UnoRuntime
.queryInterface(
170 XSpinValue
.class, tEnv
.getTestObject());
176 XAccessible acc
= (XAccessible
) UnoRuntime
.queryInterface(
177 XAccessible
.class, tEnv
.getTestObject());
179 XAccessibleComponent aCom
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
180 XAccessibleComponent
.class,
181 acc
.getAccessibleContext());
183 Point location
= aCom
.getLocationOnScreen();
184 //Point location = (Point) tEnv.getObjRelation("Location");
185 //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
186 //Point location = aCom.getLocationOnScreen();
188 Robot rob
= new Robot();
189 rob
.mouseMove(location
.X
+ 20, location
.Y
+ 10);
190 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
191 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
192 } catch (java
.awt
.AWTException e
) {
193 System
.out
.println("couldn't adjust scrollbar");
200 * Sleeps for 0.5 sec. to allow Office to react
202 private void shortWait() {
205 } catch (InterruptedException e
) {
206 log
.println("While waiting :" + e
);
210 public class AdjustmentListener
211 implements com
.sun
.star
.awt
.XAdjustmentListener
{
212 public void adjustmentValueChanged(com
.sun
.star
.awt
.AdjustmentEvent adjustmentEvent
) {
213 System
.out
.println("Adjustment Value changed");
214 System
.out
.println("AdjustmentEvent: " + adjustmentEvent
.Value
);
218 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {
219 System
.out
.println("Listener disposed");