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: _XPrintJobBroadcaster.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 ************************************************************************/
32 import com
.sun
.star
.beans
.PropertyValue
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.view
.PrintJobEvent
;
35 import com
.sun
.star
.view
.XPrintJobBroadcaster
;
36 import com
.sun
.star
.view
.XPrintJobListener
;
37 import com
.sun
.star
.view
.XPrintable
;
39 import lib
.MultiMethodTest
;
41 import lib
.StatusException
;
44 * Test the XPrintJobBroadcaster interface
46 public class _XPrintJobBroadcaster
extends MultiMethodTest
{
47 public XPrintJobBroadcaster oObj
= null;
48 MyPrintJobListener listenerImpl
= null;
51 * Get an object implementation of the _XPrintJobListener interface from the
54 public void before() {
55 listenerImpl
= (MyPrintJobListener
)tEnv
.getObjRelation("XPrintJobBroadcaster.XPrintJobListener");
56 if (listenerImpl
== null) {
57 throw new StatusException(Status
.failed(" No test possible. The XPrintJobListener interface has to be implemented."));
62 * add the listener, see if it's called.
64 public void _addPrintJobListener() {
65 oObj
.addPrintJobListener(listenerImpl
);
66 listenerImpl
.fireEvent();
67 util
.utils
.shortWait(1000);
68 tRes
.tested("addPrintJobListener()", listenerImpl
.actionTriggered());
72 * remove the listener, see if it's still caleed.
74 public void _removePrintJobListener() {
75 requiredMethod("addPrintJobListener");
76 oObj
.removePrintJobListener(listenerImpl
);
78 util
.utils
.shortWait(5000);
81 listenerImpl
.fireEvent();
82 tRes
.tested("removePrintJobListener()", !listenerImpl
.actionTriggered());
86 * Implementation for testing the XPrintJobBroadcaster interface:
89 public static class MyPrintJobListener
implements XPrintJobListener
{
90 boolean eventCalled
= false;
91 // object to trigger the event
92 XPrintable xPrintable
= null;
93 PropertyValue
[]printProps
= null;
94 String printFileName
= null;
98 * @param An object that can be cast to an XPrintable.
100 public MyPrintJobListener(Object printable
, String printFileName
) {
101 this.printFileName
= printFileName
;
102 xPrintable
= (XPrintable
)UnoRuntime
.queryInterface(XPrintable
.class, printable
);
103 printProps
= new PropertyValue
[2];
104 printProps
[0] = new PropertyValue();
105 printProps
[0].Name
= "FileName";
106 printProps
[0].Value
= printFileName
;
107 printProps
[0].State
= com
.sun
.star
.beans
.PropertyState
.DEFAULT_VALUE
;
108 printProps
[1] = new PropertyValue();
109 printProps
[1].Name
= "Wait";
110 printProps
[1].Value
= new Boolean(true);
114 * Has the action been triggered?
115 * @return True if "printJobEvent" has been called.
117 public boolean actionTriggered() {
122 * Fire the event that calls the printJobEvent
124 public void fireEvent() {
126 xPrintable
.print(printProps
);
128 catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
132 public void reset() {
133 File f
= new File(printFileName
);
140 * The print job event: has to be called when the action is triggered.
142 public void printJobEvent(PrintJobEvent printJobEvent
) {
147 * Disposing event: ignore.
149 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
) {