Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / UnoControlPatternField.java
blob21711c1492d3fdd0f345a7d65198bc09a2be0eb3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UnoControlPatternField.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
30 package mod._toolkit;
32 import com.sun.star.awt.XControl;
33 import com.sun.star.awt.XControlModel;
34 import com.sun.star.awt.XDevice;
35 import com.sun.star.awt.XGraphics;
36 import com.sun.star.awt.XTextComponent;
37 import com.sun.star.awt.XToolkit;
38 import com.sun.star.awt.XWindow;
39 import com.sun.star.awt.XWindowPeer;
40 import com.sun.star.drawing.XControlShape;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import com.sun.star.view.XControlAccess;
48 import java.io.PrintWriter;
50 import lib.StatusException;
51 import lib.TestCase;
52 import lib.TestEnvironment;
53 import lib.TestParameters;
55 import util.FormTools;
56 import util.SOfficeFactory;
57 import util.WriterTools;
58 import util.utils;
61 public class UnoControlPatternField extends TestCase {
62 private static XTextDocument xTextDoc;
64 protected void initialize(TestParameters Param, PrintWriter log) {
65 SOfficeFactory SOF = SOfficeFactory.getFactory(
66 (XMultiServiceFactory) Param.getMSF());
68 try {
69 log.println("creating a textdocument");
70 xTextDoc = SOF.createTextDoc(null);
71 } catch (com.sun.star.uno.Exception e) {
72 // Some exception occures.FAILED
73 e.printStackTrace(log);
74 throw new StatusException("Couldn't create document", e);
78 protected void cleanup(TestParameters tParam, PrintWriter log) {
79 log.println(" disposing xTextDoc ");
81 util.DesktopTools.closeDoc(xTextDoc);
84 protected TestEnvironment createTestEnvironment(TestParameters Param,
85 PrintWriter log) {
86 XInterface oObj = null;
87 XWindowPeer the_win = null;
88 XToolkit the_kit = null;
89 XDevice aDevice = null;
90 XGraphics aGraphic = null;
91 XControl aControl = null;
93 //Insert a ControlShape and get the ControlModel
94 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
95 4500, 15000,
96 10000,
97 "PatternField",
98 "UnoControlPatternField");
100 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
102 XControlModel the_Model = aShape.getControl();
104 XControlShape aShape2 = FormTools.createControlShape(xTextDoc, 3000,
105 4500, 5000, 10000,
106 "TextField");
108 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
110 XControlModel the_Model2 = aShape2.getControl();
112 //Try to query XControlAccess
113 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
114 XControlAccess.class,
115 xTextDoc.getCurrentController());
117 //get the PatternFieldControl for the needed Object relations
118 try {
119 oObj = the_access.getControl(the_Model);
120 aControl = the_access.getControl(the_Model2);
121 the_win = the_access.getControl(the_Model).getPeer();
122 the_kit = the_win.getToolkit();
123 aDevice = the_kit.createScreenCompatibleDevice(200, 200);
124 aGraphic = aDevice.createGraphics();
125 } catch (Exception e) {
126 log.println("Couldn't get PatternFieldControl");
127 e.printStackTrace(log);
128 throw new StatusException("Couldn't get PatternFieldControl", e);
131 log.println(
132 "creating a new environment for UnoControlPatternField object");
134 TestEnvironment tEnv = new TestEnvironment(oObj);
137 //Adding ObjRelation for XView
138 tEnv.addObjRelation("GRAPHICS", aGraphic);
141 //Adding ObjRelation for XControl
142 tEnv.addObjRelation("CONTEXT", xTextDoc);
143 tEnv.addObjRelation("WINPEER", the_win);
144 tEnv.addObjRelation("TOOLKIT", the_kit);
145 tEnv.addObjRelation("MODEL", the_Model);
147 XWindow forObjRel = (XWindow) UnoRuntime.queryInterface(XWindow.class,
148 aControl);
150 tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
151 tEnv.addObjRelation("XWindow.ControlShape", aShape);
153 // Adding relation for XTextListener
154 ifc.awt._XTextListener.TestTextListener listener =
155 new ifc.awt._XTextListener.TestTextListener();
156 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface(
157 XTextComponent.class, oObj);
158 textComp.addTextListener(listener);
159 tEnv.addObjRelation("TestTextListener", listener);
161 log.println("ImplementationName: " + utils.getImplName(oObj));
163 return tEnv;
164 } // finish method getTestEnvironment
165 } // finish class UnoControlPatternField