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: UnoControlRadioButton.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
.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
.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
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
45 import com
.sun
.star
.view
.XControlAccess
;
47 import java
.io
.PrintWriter
;
49 import lib
.StatusException
;
51 import lib
.TestEnvironment
;
52 import lib
.TestParameters
;
54 import util
.FormTools
;
55 import util
.SOfficeFactory
;
56 import util
.WriterTools
;
60 public class UnoControlRadioButton
extends TestCase
{
61 private static XTextDocument xTextDoc
;
63 protected void initialize(TestParameters Param
, PrintWriter log
) {
64 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
65 (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 ");
80 util
.DesktopTools
.closeDoc(xTextDoc
);
83 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
85 XInterface oObj
= null;
86 XWindowPeer the_win
= null;
87 XToolkit the_kit
= null;
88 XDevice aDevice
= null;
89 XGraphics aGraphic
= null;
90 XControl aControl
= null;
92 //Insert a ControlShape and get the ControlModel
93 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
97 "UnoControlRadioButton");
99 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
101 XControlModel the_Model
= aShape
.getControl();
103 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
107 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
109 XControlModel the_Model2
= aShape2
.getControl();
111 //Try to query XControlAccess
112 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
113 XControlAccess
.class,
114 xTextDoc
.getCurrentController());
116 //get the RadioButtonControl for the needed Object relations
118 oObj
= the_access
.getControl(the_Model
);
119 aControl
= the_access
.getControl(the_Model2
);
120 the_win
= the_access
.getControl(the_Model
).getPeer();
121 the_kit
= the_win
.getToolkit();
122 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
123 aGraphic
= aDevice
.createGraphics();
124 } catch (Exception e
) {
125 log
.println("Couldn't get RadioButtonControl");
126 e
.printStackTrace(log
);
127 throw new StatusException("Couldn't get RadioButtonControl", e
);
131 "creating a new environment for UnoControlRadioButton object");
133 TestEnvironment tEnv
= new TestEnvironment(oObj
);
136 //Adding ObjRelation for XView
137 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
140 //Adding ObjRelation for XControl
141 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
142 tEnv
.addObjRelation("WINPEER", the_win
);
143 tEnv
.addObjRelation("TOOLKIT", the_kit
);
144 tEnv
.addObjRelation("MODEL", the_Model
);
146 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
149 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
151 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
154 } // finish method getTestEnvironment
155 } // finish class UnoControlRadioButton