diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java')
-rw-r--r-- | odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java index 1b10f7d50dcb..a5d81e306492 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java +++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java @@ -2,7 +2,7 @@ * * The Contents of this file are made available subject to the terms of * the BSD license. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * All rights reserved. * @@ -29,7 +29,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * *************************************************************************/ import com.sun.star.beans.XPropertySet; @@ -51,7 +51,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { try { OfficeConnect aConnect = OfficeConnect.createConnection(); - com.sun.star.frame.XDesktop xDesktop = + com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)aConnect.createRemoteInstance( com.sun.star.frame.XDesktop.class,"com.sun.star.frame.Desktop"); @@ -71,16 +71,16 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class, xComponent); - String infoMsg = new String("All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!"); + String infoMsg = new String("All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!"); xDoc.getText().setString(infoMsg); // ensure that the document content is optimal visible - com.sun.star.frame.XModel xModel = + com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel)UnoRuntime.queryInterface( com.sun.star.frame.XModel.class, xDoc); // get the frame for later usage xFrame = xModel.getCurrentController().getFrame(); - + com.sun.star.view.XViewSettingsSupplier xViewSettings = (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface( com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController()); @@ -88,26 +88,26 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { "ZoomType", new Short((short)0)); } // test document will be closed later - + // reuse the frame com.sun.star.frame.XController xController = xFrame.getController(); if ( xController != null ) { - com.sun.star.ui.XContextMenuInterception xContextMenuInterception = - (com.sun.star.ui.XContextMenuInterception)UnoRuntime.queryInterface( + com.sun.star.ui.XContextMenuInterception xContextMenuInterception = + (com.sun.star.ui.XContextMenuInterception)UnoRuntime.queryInterface( com.sun.star.ui.XContextMenuInterception.class, xController ); if( xContextMenuInterception != null ) { ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(); - com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor = - (com.sun.star.ui.XContextMenuInterceptor)UnoRuntime.queryInterface( + com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor = + (com.sun.star.ui.XContextMenuInterceptor)UnoRuntime.queryInterface( com.sun.star.ui.XContextMenuInterceptor.class, aContextMenuInterceptor ); xContextMenuInterception.registerContextMenuInterceptor( xContextMenuInterceptor ); - + System.out.println( "\n ... all context menus of the created document frame contains now a 'Help' entry with the\n submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' to remove the context menu interceptor and finish the example!"); java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); reader.read(); - + xContextMenuInterception.releaseContextMenuInterceptor( xContextMenuInterceptor ); System.out.println( " ... context menu interceptor removed!" ); @@ -138,7 +138,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { } System.out.println(" ... exit!\n"); - System.exit( 0 ); + System.exit( 0 ); } /** @@ -147,7 +147,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { *@param args Description of Parameter *@since */ - public ContextMenuInterceptorAction notifyContextMenuExecute( + public ContextMenuInterceptorAction notifyContextMenuExecute( com.sun.star.ui.ContextMenuExecuteEvent aEvent ) throws RuntimeException { try { @@ -155,30 +155,30 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // Retrieve context menu container and query for service factory to // create sub menus, menu entries and separators com.sun.star.container.XIndexContainer xContextMenu = aEvent.ActionTriggerContainer; - com.sun.star.lang.XMultiServiceFactory xMenuElementFactory = + com.sun.star.lang.XMultiServiceFactory xMenuElementFactory = (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, xContextMenu ); if ( xMenuElementFactory != null ) { // create root menu entry and sub menu com.sun.star.beans.XPropertySet xRootMenuEntry = (XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, + com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); // create a line separator for our new help sub menu - com.sun.star.beans.XPropertySet xSeparator = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, + com.sun.star.beans.XPropertySet xSeparator = + (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTriggerSeparator" )); - + Short aSeparatorType = new Short( ActionTriggerSeparatorType.LINE ); xSeparator.setPropertyValue( "SeparatorType", (Object)aSeparatorType ); - + // query sub menu for index container to get access com.sun.star.container.XIndexContainer xSubMenuContainer = - (com.sun.star.container.XIndexContainer)UnoRuntime.queryInterface( + (com.sun.star.container.XIndexContainer)UnoRuntime.queryInterface( com.sun.star.container.XIndexContainer.class, - xMenuElementFactory.createInstance( + xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTriggerContainer" )); // intialize root menu entry @@ -188,21 +188,21 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { xRootMenuEntry.setPropertyValue( "SubContainer", (Object)xSubMenuContainer ); // create menu entries for the new sub menu - + // intialize help/content menu entry - XPropertySet xMenuEntry = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xMenuEntry = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); xMenuEntry.setPropertyValue( "Text", new String( "Content" )); xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5401" )); xMenuEntry.setPropertyValue( "HelpURL", new String( "5401" )); - + // insert menu entry to sub menu xSubMenuContainer.insertByIndex( 0, (Object)xMenuEntry ); // intialize help/help agent - xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); @@ -212,11 +212,11 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // insert menu entry to sub menu xSubMenuContainer.insertByIndex( 1, (Object)xMenuEntry ); - + // intialize help/tips - xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, - xMenuElementFactory.createInstance( + xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); xMenuEntry.setPropertyValue( "Text", new String( "Tips" )); xMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5404" )); @@ -230,7 +230,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // add new sub menu into the given context menu xContextMenu.insertByIndex( 0, (Object)xRootMenuEntry ); - + // The controller should execute the modified context menu and stop notifying other // interceptors. return com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED; @@ -238,7 +238,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { } catch ( com.sun.star.beans.UnknownPropertyException ex ) { // do something useful - // we used a unknown property + // we used a unknown property } catch ( com.sun.star.lang.IndexOutOfBoundsException ex ) { // do something useful @@ -250,7 +250,7 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { catch ( java.lang.Exception ex ) { // catch java exceptions and something useful } - + return com.sun.star.ui.ContextMenuInterceptorAction.IGNORED; } } |