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 .
20 import java
.io
.PrintWriter
;
22 import lib
.StatusException
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.FormTools
;
27 import util
.SOfficeFactory
;
28 import util
.WriterTools
;
31 import com
.sun
.star
.awt
.XControl
;
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
.text
.XTextDocument
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
43 import com
.sun
.star
.util
.XCloseable
;
44 import com
.sun
.star
.view
.XControlAccess
;
47 public class UnoControlNumericField
extends TestCase
{
48 private static XTextDocument xTextDoc
;
51 protected void initialize(TestParameters Param
, PrintWriter log
) {
52 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
55 log
.println("creating a textdocument");
56 xTextDoc
= SOF
.createTextDoc(null);
57 } catch (com
.sun
.star
.uno
.Exception e
) {
58 // Some exception occurs.FAILED
59 e
.printStackTrace(log
);
60 throw new StatusException("Couldn't create document", e
);
65 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
66 log
.println(" disposing xTextDoc ");
69 XCloseable closer
= UnoRuntime
.queryInterface(
70 XCloseable
.class, xTextDoc
);
72 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
73 log
.println("couldn't close document");
74 } catch (com
.sun
.star
.lang
.DisposedException e
) {
75 log
.println("couldn't close document");
80 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
82 XInterface oObj
= null;
83 XWindowPeer the_win
= null;
84 XToolkit the_kit
= null;
85 XDevice aDevice
= null;
86 XGraphics aGraphic
= null;
87 XControl aControl
= null;
89 //Insert a ControlShape and get the ControlModel
90 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
94 "UnoControlNumericField");
96 WriterTools
.getDrawPage(xTextDoc
).add(aShape
);
98 XControlModel the_Model
= aShape
.getControl();
100 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
104 WriterTools
.getDrawPage(xTextDoc
).add(aShape2
);
106 XControlModel the_Model2
= aShape2
.getControl();
108 //Try to query XControlAccess
109 XControlAccess the_access
= UnoRuntime
.queryInterface(
110 XControlAccess
.class,
111 xTextDoc
.getCurrentController());
113 //get the NumericFieldControl for the needed Object relations
115 oObj
= the_access
.getControl(the_Model
);
116 aControl
= the_access
.getControl(the_Model2
);
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 NumericFieldControl");
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't get NumericFieldControl", e
);
128 "creating a new environment for UnoControlNumericField 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 XWindow forObjRel
= UnoRuntime
.queryInterface(XWindow
.class,
146 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
147 tEnv
.addObjRelation("XWindow.ControlShape", aShape
);
149 // Adding relation for XTextListener
150 ifc
.awt
._XTextListener
.TestTextListener listener
=
151 new ifc
.awt
._XTextListener
.TestTextListener();
152 XTextComponent textComp
= UnoRuntime
.queryInterface(
153 XTextComponent
.class, oObj
);
154 textComp
.addTextListener(listener
);
155 tEnv
.addObjRelation("TestTextListener", listener
);
157 tEnv
.addObjRelation("XTextComponent.onlyNumbers", "");
159 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
162 } // finish method getTestEnvironment
163 } // finish class UnoControlNumericField