2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
21 import java
.io
.PrintWriter
;
23 import lib
.MultiMethodTest
;
25 import com
.sun
.star
.awt
.XMenuBar
;
26 import com
.sun
.star
.awt
.XTopWindow
;
27 import com
.sun
.star
.awt
.XTopWindowListener
;
28 import com
.sun
.star
.lang
.EventObject
;
29 import com
.sun
.star
.text
.XTextDocument
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
33 * Testing <code>com.sun.star.awt.XTopWindow</code>
36 * <li><code> addTopWindowListener()</code></li>
37 * <li><code> removeTopWindowListener()</code></li>
38 * <li><code> toFront()</code></li>
39 * <li><code> toBack()</code></li>
40 * <li><code> setMenuBar()</code></li>
42 * Test is <b> NOT </b> multithread compliant. <p>
43 * @see com.sun.star.awt.XTopWindow
45 public class _XTopWindow
extends MultiMethodTest
{
47 public XTopWindow oObj
= null;
50 * Listener implementation which sets flags on different
53 protected class TestListener
implements XTopWindowListener
{
54 private final PrintWriter log
;
55 public boolean activated
= false ;
56 public boolean deactivated
= false ;
58 public TestListener(PrintWriter log
) {
62 public void initListener() {
67 public void windowOpened(EventObject e
) {
68 log
.println("windowOpened() called") ;
70 public void windowClosing(EventObject e
) {
71 log
.println("windowClosing() called") ;
73 public void windowClosed(EventObject e
) {
74 log
.println("windowClosed() called") ;
76 public void windowMinimized(EventObject e
) {
77 log
.println("windowMinimized() called") ;
79 public void windowNormalized(EventObject e
) {
80 log
.println("windowNormalized() called") ;
82 public void windowActivated(EventObject e
) {
84 log
.println("windowActivated() called") ;
86 public void windowDeactivated(EventObject e
) {
88 log
.println("windowDeactivated() called") ;
90 public void disposing(EventObject e
) {}
93 protected TestListener listener
= null ;
95 XTextDocument aTextDoc
= null;
99 protected void before() {
100 aTextDoc
= util
.WriterTools
.createTextDoc(tParam
.getMSF());
104 * Adds a listener . <p>
106 * Has <b>OK</b> status always (listener calls are checked in
109 public void _addTopWindowListener() {
110 listener
= new TestListener(log
) ;
112 oObj
.addTopWindowListener(listener
) ;
114 tRes
.tested("addTopWindowListener()", true);
118 * Removes a listener added before. <p>
119 * Has <b>OK</b> status always. <p>
120 * The following method tests are to be completed successfully before :
122 * <li> <code> toBack </code> : to have a definite method execution
126 public void _removeTopWindowListener() {
127 executeMethod("toBack()");
129 oObj
.removeTopWindowListener(listener
);
131 tRes
.tested("removeTopWindowListener()", true);
135 * Moves the window to front and check the listener calls. <p>
136 * Has <b>OK</b> status if listener <code>activated</code> method
139 public void _toFront() {
140 requiredMethod("addTopWindowListener()");
141 listener
.initListener();
143 util
.utils
.pause(1000);
145 tRes
.tested("toFront()", listener
.activated
&& !listener
.deactivated
);
149 * This method doesn't do anything the Office implementation. <p>
150 * So it has always <b>OK</b> status
152 public void _toBack() {
154 tRes
.tested("toBack()", true);
158 * Creates a simple menu bar and adds to the window. <p>
159 * Has <b>OK</b> status if no runtime exceptions occurred.
161 public void _setMenuBar() {
162 XMenuBar menu
= null ;
163 boolean result
= true ;
166 menu
= UnoRuntime
.queryInterface(XMenuBar
.class,
168 createInstance("com.sun.star.awt.MenuBar")) ;
169 } catch (com
.sun
.star
.uno
.Exception e
) {
170 log
.println("Can't instanciate MenuBar service") ;
174 menu
.insertItem((short)1, "MenuItem",
175 com
.sun
.star
.awt
.MenuItemStyle
.CHECKABLE
, (short)1) ;
177 oObj
.setMenuBar(menu
) ;
179 tRes
.tested("setMenuBar()", result
) ;
183 * Disposes the document created in <code>before</code> method.
186 protected void after() {