1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.awt;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import java.io.PrintWriter;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import lib.MultiMethodTest;
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir import com.sun.star.awt.XMenuBar;
35*cdf0e10cSrcweir import com.sun.star.awt.XTopWindow;
36*cdf0e10cSrcweir import com.sun.star.awt.XTopWindowListener;
37*cdf0e10cSrcweir import com.sun.star.lang.EventObject;
38*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
39*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
40*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /**
43*cdf0e10cSrcweir * Testing <code>com.sun.star.awt.XTopWindow</code>
44*cdf0e10cSrcweir * interface methods :
45*cdf0e10cSrcweir * <ul>
46*cdf0e10cSrcweir *  <li><code> addTopWindowListener()</code></li>
47*cdf0e10cSrcweir *  <li><code> removeTopWindowListener()</code></li>
48*cdf0e10cSrcweir *  <li><code> toFront()</code></li>
49*cdf0e10cSrcweir *  <li><code> toBack()</code></li>
50*cdf0e10cSrcweir *  <li><code> setMenuBar()</code></li>
51*cdf0e10cSrcweir * </ul> <p>
52*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
53*cdf0e10cSrcweir * @see com.sun.star.awt.XTopWindow
54*cdf0e10cSrcweir */
55*cdf0e10cSrcweir public class _XTopWindow extends MultiMethodTest {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     public XTopWindow oObj = null;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     /**
60*cdf0e10cSrcweir     * Listener implementation which sets flags on different
61*cdf0e10cSrcweir     * method calls.
62*cdf0e10cSrcweir     */
63*cdf0e10cSrcweir     protected class TestListener implements XTopWindowListener {
64*cdf0e10cSrcweir         private PrintWriter log = null ;
65*cdf0e10cSrcweir         public boolean activated = false ;
66*cdf0e10cSrcweir         public boolean deactivated = false ;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir         public TestListener(PrintWriter log) {
69*cdf0e10cSrcweir             this.log = log ;
70*cdf0e10cSrcweir         }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir         public void initListener() {
73*cdf0e10cSrcweir             activated = false;
74*cdf0e10cSrcweir             deactivated = false;
75*cdf0e10cSrcweir         }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         public void windowOpened(EventObject e) {
78*cdf0e10cSrcweir             log.println("windowOpened() called") ;
79*cdf0e10cSrcweir         }
80*cdf0e10cSrcweir         public void windowClosing(EventObject e) {
81*cdf0e10cSrcweir             log.println("windowClosing() called") ;
82*cdf0e10cSrcweir         }
83*cdf0e10cSrcweir         public void windowClosed(EventObject e) {
84*cdf0e10cSrcweir             log.println("windowClosed() called") ;
85*cdf0e10cSrcweir         }
86*cdf0e10cSrcweir         public void windowMinimized(EventObject e) {
87*cdf0e10cSrcweir             log.println("windowMinimized() called") ;
88*cdf0e10cSrcweir         }
89*cdf0e10cSrcweir         public void windowNormalized(EventObject e) {
90*cdf0e10cSrcweir             log.println("windowNormalized() called") ;
91*cdf0e10cSrcweir         }
92*cdf0e10cSrcweir         public void windowActivated(EventObject e) {
93*cdf0e10cSrcweir             activated = true;
94*cdf0e10cSrcweir             log.println("windowActivated() called") ;
95*cdf0e10cSrcweir         }
96*cdf0e10cSrcweir         public void windowDeactivated(EventObject e) {
97*cdf0e10cSrcweir             deactivated = true;
98*cdf0e10cSrcweir             log.println("windowDeactivated() called") ;
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir         public void disposing(EventObject e) {}
101*cdf0e10cSrcweir     }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     protected TestListener listener = null ;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     XTextDocument aTextDoc = null;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     protected void before() {
109*cdf0e10cSrcweir         aTextDoc = util.WriterTools.createTextDoc((XMultiServiceFactory)tParam.getMSF());
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     /**
113*cdf0e10cSrcweir      * Adds a listener . <p>
114*cdf0e10cSrcweir      *
115*cdf0e10cSrcweir      * Has <b>OK</b> status always (listener calls are checked in
116*cdf0e10cSrcweir      * other methods. <p>
117*cdf0e10cSrcweir      */
118*cdf0e10cSrcweir     public void _addTopWindowListener() {
119*cdf0e10cSrcweir         listener = new TestListener(log) ;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir         oObj.addTopWindowListener(listener) ;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         tRes.tested("addTopWindowListener()", true);
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     /**
127*cdf0e10cSrcweir      * Removes a listener added before. <p>
128*cdf0e10cSrcweir      * Has <b>OK</b> status always. <p>
129*cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
130*cdf0e10cSrcweir      * <ul>
131*cdf0e10cSrcweir      *  <li> <code> toBack </code> : to have a definite method execution
132*cdf0e10cSrcweir      *    order.</li>
133*cdf0e10cSrcweir      * </ul>
134*cdf0e10cSrcweir      */
135*cdf0e10cSrcweir     public void _removeTopWindowListener() {
136*cdf0e10cSrcweir         executeMethod("toBack()");
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir         oObj.removeTopWindowListener(listener);
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         tRes.tested("removeTopWindowListener()", true);
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     /**
144*cdf0e10cSrcweir      * Moves the window to front and check the listener calls. <p>
145*cdf0e10cSrcweir      * Has <b>OK</b> status if listener <code>activated</code> method
146*cdf0e10cSrcweir      * was called.
147*cdf0e10cSrcweir      */
148*cdf0e10cSrcweir     public void _toFront() {
149*cdf0e10cSrcweir         requiredMethod("addTopWindowListener()");
150*cdf0e10cSrcweir         listener.initListener();
151*cdf0e10cSrcweir         oObj.toFront();
152*cdf0e10cSrcweir         shortWait();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         tRes.tested("toFront()", listener.activated && !listener.deactivated);
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     /**
158*cdf0e10cSrcweir      * This method doesn't do anything the Office implementation. <p>
159*cdf0e10cSrcweir      * So it has always <b>OK</b> status
160*cdf0e10cSrcweir      */
161*cdf0e10cSrcweir     public void _toBack() {
162*cdf0e10cSrcweir         oObj.toBack();
163*cdf0e10cSrcweir         tRes.tested("toBack()", true);
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     /**
167*cdf0e10cSrcweir     * Creates a simple menu bar and adds to the window. <p>
168*cdf0e10cSrcweir     * Has <b>OK</b> status if no runtime exceptions occured.
169*cdf0e10cSrcweir     */
170*cdf0e10cSrcweir     public void _setMenuBar() {
171*cdf0e10cSrcweir         XMenuBar menu = null ;
172*cdf0e10cSrcweir         boolean result = true ;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         try {
175*cdf0e10cSrcweir             menu = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class,
176*cdf0e10cSrcweir                 ((XMultiServiceFactory)tParam.getMSF()).
177*cdf0e10cSrcweir                 createInstance("com.sun.star.awt.MenuBar")) ;
178*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
179*cdf0e10cSrcweir             log.println("Can't instanciate MenuBar service") ;
180*cdf0e10cSrcweir             result = false ;
181*cdf0e10cSrcweir         }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         menu.insertItem((short)1, "MenuItem",
184*cdf0e10cSrcweir             com.sun.star.awt.MenuItemStyle.CHECKABLE, (short)1) ;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         oObj.setMenuBar(menu) ;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         tRes.tested("setMenuBar()", result) ;
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     /**
192*cdf0e10cSrcweir      * Disposes the document created in <code>before</code> method.
193*cdf0e10cSrcweir      */
194*cdf0e10cSrcweir     protected void after() {
195*cdf0e10cSrcweir         aTextDoc.dispose();
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     private void shortWait() {
199*cdf0e10cSrcweir         try {
200*cdf0e10cSrcweir             Thread.sleep(1000) ;
201*cdf0e10cSrcweir         } catch (InterruptedException e) {
202*cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207