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