bump product version to 7.2.5.1
[LibreOffice.git] / toolkit / test / accessibility / SimpleOffice.java
blobecb16a6e38778bc629e77adf90ad27a075738495
1 /*
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 .
19 import com.sun.star.frame.XDesktop;
20 import com.sun.star.lang.XMultiServiceFactory;
21 import com.sun.star.uno.UnoRuntime;
22 import com.sun.star.uno.XInterface;
23 import com.sun.star.accessibility.XAccessible;
24 import com.sun.star.awt.XExtendedToolkit;
27 /** This class tries to simplify some tasks like loading a document or
28 getting various objects.
30 public class SimpleOffice
32 private XDesktop mxDesktop = null;
33 private OfficeConnection aConnection;
34 private int mnPortNumber;
36 public SimpleOffice (int nPortNumber)
38 mnPortNumber = nPortNumber;
39 connect ();
40 getDesktop ();
43 public void connect ()
45 aConnection = new OfficeConnection (mnPortNumber);
46 mxDesktop = null;
47 getDesktop ();
60 public XDesktop getDesktop ()
62 if (mxDesktop != null)
63 return mxDesktop;
64 try
66 // Get the factory of the connected office.
67 XMultiServiceFactory xMSF = aConnection.getServiceManager ();
68 if (xMSF == null)
70 MessageArea.println ("can't connect to office");
71 return null;
73 else
74 MessageArea.println ("Connected successfully.");
76 // Create a new desktop.
77 mxDesktop = UnoRuntime.queryInterface(
78 XDesktop.class,
79 xMSF.createInstance ("com.sun.star.frame.Desktop")
82 catch (Exception e)
84 MessageArea.println ("caught exception while creating desktop: "
85 + e);
88 return mxDesktop;
92 /** Return a reference to the extended toolkit which is a broadcaster of
93 top window, key, and focus events.
95 public XExtendedToolkit getExtendedToolkit ()
97 XExtendedToolkit xToolkit = null;
98 try
100 // Get the factory of the connected office.
101 XMultiServiceFactory xMSF = aConnection.getServiceManager ();
102 if (xMSF != null)
104 xToolkit = UnoRuntime.queryInterface(
105 XExtendedToolkit.class,
106 xMSF.createInstance ("stardiv.Toolkit.VCLXToolkit")
110 catch (Exception e)
112 MessageArea.println ("caught exception while creating extended toolkit: " + e);
115 return xToolkit;
120 public XAccessible getAccessibleObject (XInterface xObject)
122 XAccessible xAccessible = null;
125 xAccessible = UnoRuntime.queryInterface(
126 XAccessible.class, xObject);
128 catch (Exception e)
130 MessageArea.println (
131 "caught exception while getting accessible object" + e);
132 e.printStackTrace();
134 return xAccessible;