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: _XScrollBar.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 ************************************************************************/
32 import com
.sun
.star
.accessibility
.XAccessible
;
33 import com
.sun
.star
.accessibility
.XAccessibleComponent
;
34 import com
.sun
.star
.awt
.Point
;
35 import com
.sun
.star
.awt
.ScrollBarOrientation
;
36 import com
.sun
.star
.awt
.XScrollBar
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
41 import java
.awt
.Robot
;
42 import java
.awt
.event
.InputEvent
;
44 import lib
.MultiMethodTest
;
47 public class _XScrollBar
extends MultiMethodTest
{
48 public XScrollBar oObj
;
49 public boolean adjusted
= false;
50 com
.sun
.star
.awt
.XAdjustmentListener listener
= new AdjustmentListener();
52 public void _addAdjustmentListener() {
53 util
.FormTools
.switchDesignOf((XMultiServiceFactory
) tParam
.getMSF(),
54 (XTextDocument
) tEnv
.getObjRelation("Document"));
56 oObj
.addAdjustmentListener(listener
);
59 boolean res
= adjusted
;
60 oObj
.removeAdjustmentListener(listener
);
64 tRes
.tested("addAdjustmentListener()", res
);
67 public void _removeAdjustmentListener() {
68 //this method is checked in addAjustmentListener
69 //so that method is requiered here and if it works
70 //this method is given OK too
71 requiredMethod("addAdjustmentListener()");
72 tRes
.tested("removeAdjustmentListener()", true);
75 public void _setBlockIncrement() {
76 oObj
.setBlockIncrement(15);
77 oObj
.setBlockIncrement(5);
78 int bi
= oObj
.getBlockIncrement();
79 tRes
.tested("setBlockIncrement()",bi
==5);
82 public void _getBlockIncrement() {
83 //this method is checked in the corresponding set method
84 //so that method is requiered here and if it works
85 //this method is given OK too
86 requiredMethod("setBlockIncrement()");
87 tRes
.tested("getBlockIncrement()", true);
90 public void _setLineIncrement() {
91 oObj
.setLineIncrement(12);
92 oObj
.setLineIncrement(2);
93 int li
= oObj
.getLineIncrement();
94 tRes
.tested("setLineIncrement()",li
==2);
97 public void _getLineIncrement() {
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("setLineIncrement()");
102 tRes
.tested("getLineIncrement()", true);
105 public void _setMaximum() {
106 oObj
.setMaximum(490);
107 oObj
.setMaximum(480);
108 int max
= oObj
.getMaximum();
109 tRes
.tested("setMaximum()",max
==480);
112 public void _getMaximum() {
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("setMaximum()");
117 tRes
.tested("getMaximum()", true);
120 public void _setOrientation() {
121 oObj
.setOrientation(ScrollBarOrientation
.HORIZONTAL
);
122 oObj
.setOrientation(ScrollBarOrientation
.VERTICAL
);
123 int ori
= oObj
.getOrientation();
124 tRes
.tested("setOrientation()",ori
==ScrollBarOrientation
.VERTICAL
);
127 public void _getOrientation() {
128 //this method is checked in the corresponding set method
129 //so that method is requiered here and if it works
130 //this method is given OK too
131 requiredMethod("setOrientation()");
132 tRes
.tested("getOrientation()", true);
135 public void _setValue() {
136 oObj
.setMaximum(600);
139 int val
= oObj
.getValue();
140 tRes
.tested("setValue()",val
==520);
143 public void _getValue() {
144 //this method is checked in the corresponding set method
145 //so that method is requiered here and if it works
146 //this method is given OK too
147 requiredMethod("setValue()");
148 tRes
.tested("getValue()", true);
151 public void _setVisibleSize() {
152 oObj
.setVisibleSize(700);
153 oObj
.setVisibleSize(500);
154 int vs
= oObj
.getVisibleSize();
155 tRes
.tested("setVisibleSize()",vs
==500);
158 public void _getVisibleSize() {
159 //this method is checked in the corresponding set method
160 //so that method is requiered here and if it works
161 //this method is given OK too
162 requiredMethod("setVisibleSize()");
163 tRes
.tested("getVisibleSize()", true);
166 public void _setValues() {
167 oObj
.setValues(80, 200, 300);
168 oObj
.setValues(70, 210, 500);
169 int val
= oObj
.getValue();
170 int vs
= oObj
.getVisibleSize();
171 int max
= oObj
.getMaximum();
172 tRes
.tested("setValues()",((val
==70) && (vs
==210) && (max
==500)));
175 private void adjustScrollBar() {
178 XScrollBar sc
= (XScrollBar
) UnoRuntime
.queryInterface(
179 XScrollBar
.class, tEnv
.getTestObject());
185 XAccessible acc
= (XAccessible
) UnoRuntime
.queryInterface(
186 XAccessible
.class, tEnv
.getTestObject());
188 XAccessibleComponent aCom
= (XAccessibleComponent
) UnoRuntime
.queryInterface(
189 XAccessibleComponent
.class,
190 acc
.getAccessibleContext());
192 Point location
= aCom
.getLocationOnScreen();
193 //Point location = (Point) tEnv.getObjRelation("Location");
194 //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
195 //Point location = aCom.getLocationOnScreen();
197 Robot rob
= new Robot();
198 rob
.mouseMove(location
.X
+ 50, location
.Y
+ 75);
199 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
200 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
201 } catch (java
.awt
.AWTException e
) {
202 System
.out
.println("couldn't adjust scrollbar");
209 * Sleeps for 0.5 sec. to allow Office to react
211 private void shortWait() {
214 } catch (InterruptedException e
) {
215 log
.println("While waiting :" + e
);
219 public class AdjustmentListener
220 implements com
.sun
.star
.awt
.XAdjustmentListener
{
221 public void adjustmentValueChanged(com
.sun
.star
.awt
.AdjustmentEvent adjustmentEvent
) {
222 System
.out
.println("Adjustment Value changed");
223 System
.out
.println("AdjustmentEvent: " + adjustmentEvent
.Value
);
227 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {
228 System
.out
.println("Listener disposed");