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: UnoSpinButtonControl.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
.WriterTools
;
59 public class UnoSpinButtonControl
extends TestCase
{
60 private static XTextDocument xTextDoc
;
62 protected void initialize(TestParameters Param
, PrintWriter log
) {
63 log
.println("creating a textdocument");
64 xTextDoc
= WriterTools
.createTextDoc(
65 (XMultiServiceFactory
) Param
.getMSF());
68 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
69 log
.println(" disposing xTextDoc ");
71 util
.DesktopTools
.closeDoc(xTextDoc
);
74 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
76 XInterface oObj
= null;
77 XWindowPeer the_win
= null;
78 XToolkit the_kit
= null;
79 XDevice aDevice
= null;
80 XGraphics aGraphic
= null;
81 XControl aControl
= null;
83 //Insert a ControlShape and get the ControlModel
84 XControlShape aShape
= FormTools
.createUnoControlShape(xTextDoc
, 3000,
88 "UnoControlSpinButton");
90 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape
);
92 XControlModel the_Model
= aShape
.getControl();
94 XControlShape aShape2
= FormTools
.createControlShape(xTextDoc
, 3000,
98 WriterTools
.getDrawPage(xTextDoc
).add((XShape
) aShape2
);
100 XControlModel the_Model2
= aShape2
.getControl();
102 //Try to query XControlAccess
103 XControlAccess the_access
= (XControlAccess
) UnoRuntime
.queryInterface(
104 XControlAccess
.class,
105 xTextDoc
.getCurrentController());
107 //get the SpinButtonControl for the needed Object relations
109 oObj
= the_access
.getControl(the_Model
);
110 aControl
= the_access
.getControl(the_Model2
);
111 the_win
= the_access
.getControl(the_Model
).getPeer();
112 the_kit
= the_win
.getToolkit();
113 aDevice
= the_kit
.createScreenCompatibleDevice(200, 200);
114 aGraphic
= aDevice
.createGraphics();
115 } catch (Exception e
) {
116 log
.println("Couldn't get SpinButtonControl");
117 e
.printStackTrace(log
);
118 throw new StatusException("Couldn't get SpinButtonControl", e
);
122 "creating a new environment for UnoControlSpinButton object");
124 TestEnvironment tEnv
= new TestEnvironment(oObj
);
127 //adding Object-Relation for XScrollBar
128 tEnv
.addObjRelation("Document", xTextDoc
);
131 //Adding ObjRelation for XView
132 tEnv
.addObjRelation("GRAPHICS", aGraphic
);
135 //Adding ObjRelation for XControl
136 tEnv
.addObjRelation("CONTEXT", xTextDoc
);
137 tEnv
.addObjRelation("WINPEER", the_win
);
138 tEnv
.addObjRelation("TOOLKIT", the_kit
);
139 tEnv
.addObjRelation("MODEL", the_Model
);
141 XWindow forObjRel
= (XWindow
) UnoRuntime
.queryInterface(XWindow
.class,
144 tEnv
.addObjRelation("XWindow.AnotherWindow", forObjRel
);
146 tEnv
.addObjRelation("Document", xTextDoc
);
148 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
151 } // finish method getTestEnvironment