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: UnoControlNumericField.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 java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
38 import util
.FormTools
;
39 import util
.SOfficeFactory
;
40 import util
.WriterTools
;
43 import com
.sun
.star
.awt
.XControl
;
44 import com
.sun
.star
.awt
.XControlModel
;
45 import com
.sun
.star
.awt
.XDevice
;
46 import com
.sun
.star
.awt
.XGraphics
;
47 import com
.sun
.star
.awt
.XTextComponent
;
48 import com
.sun
.star
.awt
.XToolkit
;
49 import com
.sun
.star
.awt
.XWindow
;
50 import com
.sun
.star
.awt
.XWindowPeer
;
51 import com
.sun
.star
.drawing
.XControlShape
;
52 import com
.sun
.star
.drawing
.XShape
;
53 import com
.sun
.star
.lang
.XMultiServiceFactory
;
54 import com
.sun
.star
.text
.XTextDocument
;
55 import com
.sun
.star
.uno
.UnoRuntime
;
56 import com
.sun
.star
.uno
.XInterface
;
57 import com
.sun
.star
.util
.XCloseable
;
58 import com
.sun
.star
.view
.XControlAccess
;
61 public class UnoControlNumericField
extends TestCase
{
62 private static XTextDocument xTextDoc
;
64 protected void initialize(TestParameters Param
, PrintWriter log
) {
65 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) Param
.getMSF());
68 log
.println("creating a textdocument");
69 xTextDoc
= SOF
.createTextDoc(null);
70 } catch (com
.sun
.star
.uno
.Exception e
) {
71 // Some exception occures.FAILED
72 e
.printStackTrace(log
);
73 throw new StatusException("Couldn't create document", e
);
77 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
78 log
.println(" disposing xTextDoc ");
81 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
82 XCloseable
.class, xTextDoc
);
84 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
85 log
.println("couldn't close document");
86 } catch (com
.sun
.star
.lang
.DisposedException e
) {
87 log
.println("couldn't close document");
91 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
93 XInterface oObj
= null;
94 XWindowPeer the_win
= null;
95 XToolkit the_kit
= null;
96 XDevice aDevice
= null;
97 XGraphics aGraphic
= null;
98 XControl aControl
= null;
100 //Insert a ControlShape and get the ControlModel
101 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
105 "UnoControlNumericField");
107 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
109 XControlModel the_Model
= aShape
.getControl();
111 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
115 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
117 XControlModel the_Model2
= aShape2
.getControl();
119 //Try to query XControlAccess
120 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
121 XControlAccess
.class,
122 xTextDoc
.getCurrentController());
124 //get the NumericFieldControl for the needed Object relations
126 oObj
= the_access
.getControl(the_Model
);
127 aControl
= the_access
.getControl(the_Model2
);
128 the_win
= the_access
.getControl(the_Model
).getPeer();
129 the_kit
= the_win
.getToolkit();
130 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
131 aGraphic
= aDevice
.createGraphics();
132 } catch (Exception e
) {
133 log
.println("Couldn't get NumericFieldControl");
134 e
.printStackTrace(log
);
135 throw new StatusException("Couldn't get NumericFieldControl", e
);
139 "creating a new environment for UnoControlNumericField object");
141 TestEnvironment tEnv
= new TestEnvironment(oObj
);
144 //Adding ObjRelation for XView
145 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
148 //Adding ObjRelation for XControl
149 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
150 tEnv
.addObjRelation("WINPEER", the_win
);
151 tEnv
.addObjRelation("TOOLKIT", the_kit
);
152 tEnv
.addObjRelation("MODEL", the_Model
);
154 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
157 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
158 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
160 // Adding relation for XTextListener
161 ifc
.awt
._XTextListener
.TestTextListener listener
=
162 new ifc
.awt
._XTextListener
.TestTextListener();
163 XTextComponent textComp
= (XTextComponent
) UnoRuntime
.queryInterface(
164 XTextComponent
.class, oObj
);
165 textComp
.addTextListener(listener
);
166 tEnv
.addObjRelation("TestTextListener", listener
);
168 tEnv
.addObjRelation("XTextComponent.onlyNumbers", "");
170 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
173 } // finish method getTestEnvironment
174 } // finish class UnoControlNumericField