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