//---------------------------------------------------
// registering as clipboard listener
//---------------------------------------------------
XClipboardNotifier xClipNotifier = (XClipboardNotifier)
UnoRuntime.queryInterface(XClipboardNotifier.class, oClipboard);
ClipboardListener aClipListener= new ClipboardListener();
xClipNotifier.addClipboardListener(aClipListener);
// Read ClipBoard
readClipBoard(xClipboard);
//---------------------------------------------------
// becoming a clipboard owner
//---------------------------------------------------
System.out.println("Becoming a clipboard owner...");
System.out.println("");
ClipboardOwner aClipOwner = new ClipboardOwner();
xClipboard.setContents(new TextTransferable("Hello World!"), aClipOwner);
int iFirst = 0;
while (aClipOwner.isClipboardOwner())
{
if (iFirst != 2) {
if (iFirst == 1) {
System.out.println("Change clipboard ownership by putting something into the clipboard!\n");
System.out.print("Still clipboard owner...");
} else {
System.out.println("Still clipboard owner...");
}
++iFirst;
} else {
System.out.print(".");
}
Thread.sleep(1000);
}
// Read ClipBoard again
readClipBoard(xClipboard);
//---------------------------------------------------
// unregistering as clipboard listener
//---------------------------------------------------
xClipNotifier.removeClipboardListener(aClipListener);
// close test document
com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
xComponent );