Adapt example to use retrofitted UNO service ctors

Change-Id: I85bf8e3fe76ff107cc3e611cc1103ca1f27fc00f
This commit is contained in:
Stephan Bergmann
2013-07-11 16:07:33 +02:00
parent 386af68921
commit b62d8e6b08

View File

@@ -32,15 +32,16 @@
* *
*************************************************************************/ *************************************************************************/
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.Desktop;
import com.sun.star.frame.XDesktop2;
import com.sun.star.datatransfer.DataFlavor; import com.sun.star.datatransfer.DataFlavor;
import com.sun.star.datatransfer.UnsupportedFlavorException; import com.sun.star.datatransfer.UnsupportedFlavorException;
import com.sun.star.datatransfer.XTransferable; import com.sun.star.datatransfer.XTransferable;
import com.sun.star.datatransfer.clipboard.XClipboard; import com.sun.star.datatransfer.clipboard.XClipboard;
import com.sun.star.datatransfer.clipboard.XClipboardNotifier; import com.sun.star.datatransfer.clipboard.SystemClipboard;
import com.sun.star.datatransfer.clipboard.XSystemClipboard;
import com.sun.star.text.XTextDocument; import com.sun.star.text.XTextDocument;
import com.sun.star.uno.AnyConverter; import com.sun.star.uno.AnyConverter;
@@ -59,18 +60,11 @@ public class Clipboard
XComponentContext xOfficeContext = XComponentContext xOfficeContext =
com.sun.star.comp.helper.Bootstrap.bootstrap(); com.sun.star.comp.helper.Bootstrap.bootstrap();
System.out.println("Connected to a running office ..."); System.out.println("Connected to a running office ...");
// get the service manager from the office context
XMultiComponentFactory xServiceManager =
xOfficeContext.getServiceManager();
// create a new test document // create a new test document
Object oDesktop = xServiceManager.createInstanceWithContext( XDesktop2 xDesktop = Desktop.create(xOfficeContext);
"com.sun.star.frame.Desktop", xOfficeContext);
XComponentLoader xCompLoader =UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
com.sun.star.lang.XComponent xComponent = com.sun.star.lang.XComponent xComponent =
xCompLoader.loadComponentFromURL("private:factory/swriter", xDesktop.loadComponentFromURL("private:factory/swriter",
"_blank", 0, new com.sun.star.beans.PropertyValue[0]); "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
{ {
XTextDocument xDoc =UnoRuntime.queryInterface(XTextDocument.class, xComponent); XTextDocument xDoc =UnoRuntime.queryInterface(XTextDocument.class, xComponent);
@@ -93,21 +87,15 @@ public class Clipboard
} }
// test document will be closed later // test document will be closed later
Object oClipboard = xServiceManager.createInstanceWithContext( XSystemClipboard xClipboard = SystemClipboard.create(xOfficeContext);
"com.sun.star.datatransfer.clipboard.SystemClipboard",
xOfficeContext);
XClipboard xClipboard = UnoRuntime.queryInterface(XClipboard.class, oClipboard);
//--------------------------------------------------- //---------------------------------------------------
// registering as clipboard listener // registering as clipboard listener
//--------------------------------------------------- //---------------------------------------------------
XClipboardNotifier xClipNotifier = UnoRuntime.queryInterface(XClipboardNotifier.class, oClipboard);
ClipboardListener aClipListener= new ClipboardListener(); ClipboardListener aClipListener= new ClipboardListener();
xClipNotifier.addClipboardListener(aClipListener); xClipboard.addClipboardListener(aClipListener);
// Read ClipBoard // Read ClipBoard
readClipBoard(xClipboard); readClipBoard(xClipboard);
@@ -145,7 +133,7 @@ public class Clipboard
//--------------------------------------------------- //---------------------------------------------------
// unregistering as clipboard listener // unregistering as clipboard listener
//--------------------------------------------------- //---------------------------------------------------
xClipNotifier.removeClipboardListener(aClipListener); xClipboard.removeClipboardListener(aClipListener);
// close test document // close test document
com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,