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