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: UnoControlDateField.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
.awt
.XControlModel
;
33 import com
.sun
.star
.awt
.XDevice
;
34 import com
.sun
.star
.awt
.XGraphics
;
35 import com
.sun
.star
.awt
.XTextComponent
;
36 import com
.sun
.star
.awt
.XToolkit
;
37 import com
.sun
.star
.awt
.XWindow
;
38 import com
.sun
.star
.awt
.XWindowPeer
;
39 import com
.sun
.star
.drawing
.XControlShape
;
40 import com
.sun
.star
.drawing
.XShape
;
41 import com
.sun
.star
.frame
.XController
;
42 import com
.sun
.star
.frame
.XFrame
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.view
.XControlAccess
;
49 import java
.io
.PrintWriter
;
51 import lib
.StatusException
;
53 import lib
.TestEnvironment
;
54 import lib
.TestParameters
;
56 import util
.FormTools
;
57 import util
.SOfficeFactory
;
58 import util
.WriterTools
;
62 public class UnoControlDateField
extends TestCase
{
63 private static XTextDocument xTextDoc
;
64 private static XTextDocument xTD2
;
66 protected void initialize(TestParameters Param
, PrintWriter log
) {
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
68 (XMultiServiceFactory
) Param
.getMSF());
71 log
.println("creating a textdocument");
72 xTextDoc
= SOF
.createTextDoc(null);
73 xTD2
= WriterTools
.createTextDoc(
74 (XMultiServiceFactory
) Param
.getMSF());
75 } catch (com
.sun
.star
.uno
.Exception e
) {
76 // Some exception occures.FAILED
77 e
.printStackTrace(log
);
78 throw new StatusException("Couldn't create document", e
);
82 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
83 log
.println(" disposing xTextDoc ");
85 util
.DesktopTools
.closeDoc(xTextDoc
);
86 util
.DesktopTools
.closeDoc(xTD2
);
89 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
91 XInterface oObj
= null;
92 XWindowPeer the_win
= null;
93 XToolkit the_kit
= null;
94 XDevice aDevice
= null;
95 XGraphics aGraphic
= null;
96 XWindow anotherWindow
= null;
98 //Insert a ControlShape and get the ControlModel
99 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
103 "UnoControlDateField");
105 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
107 XControlModel the_Model
= aShape
.getControl();
109 //Try to query XControlAccess
110 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
111 XControlAccess
.class,
112 xTextDoc
.getCurrentController());
114 //get the DateFieldControl for the needed Object relations
116 oObj
= the_access
.getControl(the_Model
);
117 the_win
= the_access
.getControl(the_Model
).getPeer();
118 the_kit
= the_win
.getToolkit();
119 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
120 aGraphic
= aDevice
.createGraphics();
121 } catch (Exception e
) {
122 log
.println("Couldn't get DateFieldControl");
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't get DateFieldControl", e
);
128 "creating a new environment for UnoControlDateField object");
130 TestEnvironment tEnv
= new TestEnvironment(oObj
);
133 //Adding ObjRelation for XView
134 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
137 //Adding ObjRelation for XControl
138 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
139 tEnv
.addObjRelation("WINPEER", the_win
);
140 tEnv
.addObjRelation("TOOLKIT", the_kit
);
141 tEnv
.addObjRelation("MODEL", the_Model
);
143 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
146 XController aController
= xTD2
.getCurrentController();
147 XFrame aFrame
= aController
.getFrame();
148 anotherWindow
= aFrame
.getComponentWindow();
149 } catch (Exception e
) {
150 e
.printStackTrace(log
);
151 throw new StatusException("Couldn't create XWindow", e
);
155 // Object Relation for XWindow
156 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
157 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
159 // Adding relation for XTextListener
160 ifc
.awt
._XTextListener
.TestTextListener listener
=
161 new ifc
.awt
._XTextListener
.TestTextListener();
162 XTextComponent textComp
= (XTextComponent
) UnoRuntime
.queryInterface(
163 XTextComponent
.class, oObj
);
164 textComp
.addTextListener(listener
);
165 tEnv
.addObjRelation("TestTextListener", listener
);
168 } // finish method getTestEnvironment
169 } // finish class UnoControlDateField