1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.awt;
29 
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.accessibility.XAccessibleComponent;
32 import com.sun.star.awt.Point;
33 import com.sun.star.awt.ScrollBarOrientation;
34 import com.sun.star.awt.XSpinValue;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import java.awt.Robot;
39 import java.awt.event.InputEvent;
40 import lib.MultiMethodTest;
41 
42 public class _XSpinValue extends MultiMethodTest {
43 
44     public XSpinValue oObj;
45     public boolean adjusted = false;
46     com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
47 
48     public void _addAdjustmentListener() {
49         util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
50                                  (XTextDocument) tEnv.getObjRelation("Document"));
51         shortWait();
52         oObj.addAdjustmentListener(listener);
53         adjustScrollBar();
54 
55         boolean res = adjusted;
56         oObj.removeAdjustmentListener(listener);
57         adjusted = false;
58         adjustScrollBar();
59         res &= !adjusted;
60         tRes.tested("addAdjustmentListener()", res);
61     }
62 
63     public void _removeAdjustmentListener() {
64         //this method is checked in addAjustmentListener
65         //so that method is requiered here and if it works
66         //this method is given OK too
67         requiredMethod("addAdjustmentListener()");
68         tRes.tested("removeAdjustmentListener()", true);
69     }
70 
71     public void _setSpinIncrement() {
72         oObj.setSpinIncrement(15);
73         oObj.setSpinIncrement(5);
74         int bi = oObj.getSpinIncrement();
75         tRes.tested("setSpinIncrement()",bi==5);
76     }
77 
78     public void _getSpinIncrement() {
79         //this method is checked in the corresponding set method
80         //so that method is requiered here and if it works
81         //this method is given OK too
82         requiredMethod("setSpinIncrement()");
83         tRes.tested("getSpinIncrement()", true);
84     }
85 
86 
87     public void _setMaximum() {
88         oObj.setMaximum(490);
89         oObj.setMaximum(480);
90         int max = oObj.getMaximum();
91         tRes.tested("setMaximum()",max==480);
92     }
93 
94     public void _getMaximum() {
95         //this method is checked in the corresponding set method
96         //so that method is requiered here and if it works
97         //this method is given OK too
98         requiredMethod("setMaximum()");
99         tRes.tested("getMaximum()", true);
100     }
101 
102     public void _setMinimum() {
103         oObj.setMinimum(90);
104         oObj.setMinimum(80);
105         int max = oObj.getMinimum();
106         tRes.tested("setMinimum()",max==80);
107     }
108 
109     public void _getMinimum() {
110         //this method is checked in the corresponding set method
111         //so that method is requiered here and if it works
112         //this method is given OK too
113         requiredMethod("setMinimum()");
114         tRes.tested("getMinimum()", true);
115     }
116 
117     public void _setOrientation() {
118         boolean res = true;
119         try {
120             oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
121             oObj.setOrientation(ScrollBarOrientation.VERTICAL);
122         } catch (com.sun.star.lang.NoSupportException e) {
123             log.println("Couldn't set Orientation");
124         }
125         int ori = oObj.getOrientation();
126         res &= (ori==ScrollBarOrientation.VERTICAL);
127         tRes.tested("setOrientation()",res );
128     }
129 
130     public void _getOrientation() {
131         //this method is checked in the corresponding set method
132         //so that method is requiered here and if it works
133         //this method is given OK too
134         requiredMethod("setOrientation()");
135         tRes.tested("getOrientation()", true);
136     }
137 
138     public void _setValue() {
139         oObj.setMaximum(600);
140         oObj.setValue(480);
141         oObj.setValue(520);
142         int val = oObj.getValue();
143         tRes.tested("setValue()",val==520);
144     }
145 
146     public void _getValue() {
147         //this method is checked in the corresponding set method
148         //so that method is requiered here and if it works
149         //this method is given OK too
150         requiredMethod("setValue()");
151         tRes.tested("getValue()", true);
152     }
153 
154     public void _setValues() {
155         oObj.setValues(80, 200, 180);
156         oObj.setValues(70, 210, 200);
157         int val = oObj.getValue();
158         int min = oObj.getMinimum();
159         int max = oObj.getMaximum();
160         tRes.tested("setValues()",((min==70) && (max==210) && (val==200)));
161     }
162 
163     private void adjustScrollBar() {
164 
165 
166         XSpinValue sv = (XSpinValue) UnoRuntime.queryInterface(
167                                 XSpinValue.class, tEnv.getTestObject());
168 
169         sv.setValue(500);
170 
171         shortWait();
172 
173         XAccessible acc = (XAccessible) UnoRuntime.queryInterface(
174                                   XAccessible.class, tEnv.getTestObject());
175 
176         XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface(
177                                             XAccessibleComponent.class,
178                                             acc.getAccessibleContext());
179 
180         Point location = aCom.getLocationOnScreen();
181         //Point location = (Point) tEnv.getObjRelation("Location");
182         //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
183         //Point location = aCom.getLocationOnScreen();
184         try {
185             Robot rob = new Robot();
186             rob.mouseMove(location.X + 20, location.Y + 10);
187             rob.mousePress(InputEvent.BUTTON1_MASK);
188             rob.mouseRelease(InputEvent.BUTTON1_MASK);
189         } catch (java.awt.AWTException e) {
190             System.out.println("couldn't adjust scrollbar");
191         }
192 
193         shortWait();
194     }
195 
196     /**
197      * Sleeps for 0.5 sec. to allow Office to react
198      */
199     private void shortWait() {
200         try {
201             Thread.sleep(500);
202         } catch (InterruptedException e) {
203             log.println("While waiting :" + e);
204         }
205     }
206 
207     public class AdjustmentListener
208         implements com.sun.star.awt.XAdjustmentListener {
209         public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
210             System.out.println("Adjustment Value changed");
211             System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
212             adjusted = true;
213         }
214 
215         public void disposing(com.sun.star.lang.EventObject eventObject) {
216             System.out.println("Listener disposed");
217         }
218     }
219 
220 }
221