1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTopWindow.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.MultiMethodTest
;
37 import com
.sun
.star
.awt
.XMenuBar
;
38 import com
.sun
.star
.awt
.XTopWindow
;
39 import com
.sun
.star
.awt
.XTopWindowListener
;
40 import com
.sun
.star
.lang
.EventObject
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
46 * Testing <code>com.sun.star.awt.XTopWindow</code>
49 * <li><code> addTopWindowListener()</code></li>
50 * <li><code> removeTopWindowListener()</code></li>
51 * <li><code> toFront()</code></li>
52 * <li><code> toBack()</code></li>
53 * <li><code> setMenuBar()</code></li>
55 * Test is <b> NOT </b> multithread compilant. <p>
56 * @see com.sun.star.awt.XTopWindow
58 public class _XTopWindow
extends MultiMethodTest
{
60 public XTopWindow oObj
= null;
63 * Listener implementation which sets flags on different
66 protected class TestListener
implements XTopWindowListener
{
67 private PrintWriter log
= null ;
68 public boolean activated
= false ;
69 public boolean deactivated
= false ;
71 public TestListener(PrintWriter log
) {
75 public void initListener() {
80 public void windowOpened(EventObject e
) {
81 log
.println("windowOpened() called") ;
83 public void windowClosing(EventObject e
) {
84 log
.println("windowClosing() called") ;
86 public void windowClosed(EventObject e
) {
87 log
.println("windowClosed() called") ;
89 public void windowMinimized(EventObject e
) {
90 log
.println("windowMinimized() called") ;
92 public void windowNormalized(EventObject e
) {
93 log
.println("windowNormalized() called") ;
95 public void windowActivated(EventObject e
) {
97 log
.println("windowActivated() called") ;
99 public void windowDeactivated(EventObject e
) {
101 log
.println("windowDeactivated() called") ;
103 public void disposing(EventObject e
) {}
106 protected TestListener listener
= null ;
108 XTextDocument aTextDoc
= null;
111 protected void before() {
112 aTextDoc
= util
.WriterTools
.createTextDoc((XMultiServiceFactory
)tParam
.getMSF());
116 * Adds a listener . <p>
118 * Has <b>OK</b> status always (listener calls are checked in
121 public void _addTopWindowListener() {
122 listener
= new TestListener(log
) ;
124 oObj
.addTopWindowListener(listener
) ;
126 tRes
.tested("addTopWindowListener()", true);
130 * Removes a listener added before. <p>
131 * Has <b>OK</b> status always. <p>
132 * The following method tests are to be completed successfully before :
134 * <li> <code> toBack </code> : to have a definite method execution
138 public void _removeTopWindowListener() {
139 executeMethod("toBack()");
141 oObj
.removeTopWindowListener(listener
);
143 tRes
.tested("removeTopWindowListener()", true);
147 * Moves the window to front and check the listener calls. <p>
148 * Has <b>OK</b> status if listener <code>activated</code> method
151 public void _toFront() {
152 requiredMethod("addTopWindowListener()");
153 listener
.initListener();
157 tRes
.tested("toFront()", listener
.activated
&& !listener
.deactivated
);
161 * This method doesn't do anything the Office implementation. <p>
162 * So it has always <b>OK</b> status
164 public void _toBack() {
166 tRes
.tested("toBack()", true);
170 * Creates a simple menu bar and adds to the window. <p>
171 * Has <b>OK</b> status if no runtime exceptions occured.
173 public void _setMenuBar() {
174 XMenuBar menu
= null ;
175 boolean result
= true ;
178 menu
= (XMenuBar
) UnoRuntime
.queryInterface(XMenuBar
.class,
179 ((XMultiServiceFactory
)tParam
.getMSF()).
180 createInstance("com.sun.star.awt.MenuBar")) ;
181 } catch (com
.sun
.star
.uno
.Exception e
) {
182 log
.println("Can't instanciate MenuBar service") ;
186 menu
.insertItem((short)1, "MenuItem",
187 com
.sun
.star
.awt
.MenuItemStyle
.CHECKABLE
, (short)1) ;
189 oObj
.setMenuBar(menu
) ;
191 tRes
.tested("setMenuBar()", result
) ;
195 * Disposes the document created in <code>before</code> method.
197 protected void after() {
201 private void shortWait() {
204 } catch (InterruptedException e
) {
205 System
.out
.println("While waiting :" + e
) ;