1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package ifc.awt;
24 
25 import com.sun.star.accessibility.XAccessible;
26 import com.sun.star.accessibility.XAccessibleComponent;
27 import com.sun.star.awt.Point;
28 import com.sun.star.awt.ScrollBarOrientation;
29 import com.sun.star.awt.XScrollBar;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 
34 import java.awt.Robot;
35 import java.awt.event.InputEvent;
36 
37 import lib.MultiMethodTest;
38 
39 
40 public class _XScrollBar extends MultiMethodTest {
41     public XScrollBar oObj;
42     public boolean adjusted = false;
43     com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
44 
_addAdjustmentListener()45     public void _addAdjustmentListener() {
46         util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
47                                  (XTextDocument) tEnv.getObjRelation("Document"));
48         shortWait();
49         oObj.addAdjustmentListener(listener);
50         adjustScrollBar();
51 
52         boolean res = adjusted;
53         oObj.removeAdjustmentListener(listener);
54         adjusted = false;
55         adjustScrollBar();
56         res &= !adjusted;
57         tRes.tested("addAdjustmentListener()", res);
58     }
59 
_removeAdjustmentListener()60     public void _removeAdjustmentListener() {
61         //this method is checked in addAjustmentListener
62         //so that method is requiered here and if it works
63         //this method is given OK too
64         requiredMethod("addAdjustmentListener()");
65         tRes.tested("removeAdjustmentListener()", true);
66     }
67 
_setBlockIncrement()68     public void _setBlockIncrement() {
69         oObj.setBlockIncrement(15);
70         oObj.setBlockIncrement(5);
71         int bi = oObj.getBlockIncrement();
72         tRes.tested("setBlockIncrement()",bi==5);
73     }
74 
_getBlockIncrement()75     public void _getBlockIncrement() {
76         //this method is checked in the corresponding set method
77         //so that method is requiered here and if it works
78         //this method is given OK too
79         requiredMethod("setBlockIncrement()");
80         tRes.tested("getBlockIncrement()", true);
81     }
82 
_setLineIncrement()83     public void _setLineIncrement() {
84         oObj.setLineIncrement(12);
85         oObj.setLineIncrement(2);
86         int li = oObj.getLineIncrement();
87         tRes.tested("setLineIncrement()",li==2);
88     }
89 
_getLineIncrement()90     public void _getLineIncrement() {
91         //this method is checked in the corresponding set method
92         //so that method is requiered here and if it works
93         //this method is given OK too
94         requiredMethod("setLineIncrement()");
95         tRes.tested("getLineIncrement()", true);
96     }
97 
_setMaximum()98     public void _setMaximum() {
99         oObj.setMaximum(490);
100         oObj.setMaximum(480);
101         int max = oObj.getMaximum();
102         tRes.tested("setMaximum()",max==480);
103     }
104 
_getMaximum()105     public void _getMaximum() {
106         //this method is checked in the corresponding set method
107         //so that method is requiered here and if it works
108         //this method is given OK too
109         requiredMethod("setMaximum()");
110         tRes.tested("getMaximum()", true);
111     }
112 
_setOrientation()113     public void _setOrientation() {
114         oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
115         oObj.setOrientation(ScrollBarOrientation.VERTICAL);
116         int ori = oObj.getOrientation();
117         tRes.tested("setOrientation()",ori==ScrollBarOrientation.VERTICAL);
118     }
119 
_getOrientation()120     public void _getOrientation() {
121         //this method is checked in the corresponding set method
122         //so that method is requiered here and if it works
123         //this method is given OK too
124         requiredMethod("setOrientation()");
125         tRes.tested("getOrientation()", true);
126     }
127 
_setValue()128     public void _setValue() {
129         oObj.setMaximum(600);
130         oObj.setValue(480);
131         oObj.setValue(520);
132         int val = oObj.getValue();
133         tRes.tested("setValue()",val==520);
134     }
135 
_getValue()136     public void _getValue() {
137         //this method is checked in the corresponding set method
138         //so that method is requiered here and if it works
139         //this method is given OK too
140         requiredMethod("setValue()");
141         tRes.tested("getValue()", true);
142     }
143 
_setVisibleSize()144     public void _setVisibleSize() {
145         oObj.setVisibleSize(700);
146         oObj.setVisibleSize(500);
147         int vs = oObj.getVisibleSize();
148         tRes.tested("setVisibleSize()",vs==500);
149     }
150 
_getVisibleSize()151     public void _getVisibleSize() {
152         //this method is checked in the corresponding set method
153         //so that method is requiered here and if it works
154         //this method is given OK too
155         requiredMethod("setVisibleSize()");
156         tRes.tested("getVisibleSize()", true);
157     }
158 
_setValues()159     public void _setValues() {
160         oObj.setValues(80, 200, 300);
161         oObj.setValues(70, 210, 500);
162         int val = oObj.getValue();
163         int vs = oObj.getVisibleSize();
164         int max = oObj.getMaximum();
165         tRes.tested("setValues()",((val==70) && (vs==210) && (max==500)));
166     }
167 
adjustScrollBar()168     private void adjustScrollBar() {
169 
170 
171         XScrollBar sc = (XScrollBar) UnoRuntime.queryInterface(
172                                 XScrollBar.class, tEnv.getTestObject());
173 
174         sc.setValue(500);
175 
176         shortWait();
177 
178         XAccessible acc = (XAccessible) UnoRuntime.queryInterface(
179                                   XAccessible.class, tEnv.getTestObject());
180 
181         XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface(
182                                             XAccessibleComponent.class,
183                                             acc.getAccessibleContext());
184 
185         Point location = aCom.getLocationOnScreen();
186         //Point location = (Point) tEnv.getObjRelation("Location");
187         //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
188         //Point location = aCom.getLocationOnScreen();
189         try {
190             Robot rob = new Robot();
191             rob.mouseMove(location.X + 50, location.Y + 75);
192             rob.mousePress(InputEvent.BUTTON1_MASK);
193             rob.mouseRelease(InputEvent.BUTTON1_MASK);
194         } catch (java.awt.AWTException e) {
195             System.out.println("couldn't adjust scrollbar");
196         }
197 
198         shortWait();
199     }
200 
201     /**
202      * Sleeps for 0.5 sec. to allow Office to react
203      */
shortWait()204     private void shortWait() {
205         try {
206             Thread.sleep(500);
207         } catch (InterruptedException e) {
208             log.println("While waiting :" + e);
209         }
210     }
211 
212     public class AdjustmentListener
213         implements com.sun.star.awt.XAdjustmentListener {
adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent)214         public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
215             System.out.println("Adjustment Value changed");
216             System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
217             adjusted = true;
218         }
219 
disposing(com.sun.star.lang.EventObject eventObject)220         public void disposing(com.sun.star.lang.EventObject eventObject) {
221             System.out.println("Listener disposed");
222         }
223     }
224 }
225