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