diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs')
3 files changed, 416 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/CreatingDialogs.odt b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/CreatingDialogs.odt Binary files differnew file mode 100644 index 000000000..dd55f9076 --- /dev/null +++ b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/CreatingDialogs.odt diff --git a/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/Makefile b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/Makefile new file mode 100644 index 000000000..3af249f9d --- /dev/null +++ b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/Makefile @@ -0,0 +1,138 @@ +#************************************************************************* +# +# 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. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# 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. +# +#************************************************************************** + +# Builds the CreatingDialogs example of the Developers Guide. + +PRJ=../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +EXAMPLE_NAME=BaDCreatingDialogsExample +OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME) + +COMPONENT_NAME=SampleDialog +COMPONENT_PACKAGE = $(OUT_BIN)/$(COMPONENT_NAME).$(UNOOXT_EXT) +COMPONENT_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMPONENT_NAME).$(UNOOXT_EXT)") +COMPONENT_JAR_NAME = $(COMPONENT_NAME).uno.jar +COMPONENT_JAR = $(OUT_CLASS)/$(COMPONENT_JAR_NAME) +COMPONENT_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMPONENT_NAME).uno.Manifest +COMPONENT_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMPONENT_NAME)/META-INF/manifest.xml +REGISTERFLAG = $(OUT_MISC)/devguide_basicanddialogs_creatingdialogs_register_component.flag + +# often the java files are structured in a hierarchy similar to the package, +# for the example we know the package +PACKAGE = com.sun.star.comp.sdk.examples + +JAVAFILES = \ + SampleDialog.java + +CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES)) + +$(COMPONENT_NAME)_CLASSFILES = SampleDialog.class \ + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(OUT_COMP_CLASS)) + + +# Targets +.PHONY: ALL +ALL: $(EXAMPLE_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_CLASS)/%.Manifest : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo RegistrationClassName: $(PACKAGE).$(basename $(basename $(@F)))> $@ + +$(OUT_COMP_CLASS)/%.class : %.java + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $< + +# rule for component jar file +$(COMPONENT_JAR) : $(COMPONENT_MANIFESTFILE) $(CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAR) cvfm $@ $< -C $(OUT_COMP_CLASS) . + +# rule for component package manifest +$(OUT_COMP_CLASS)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +# rule for component package file +$(COMPONENT_PACKAGE) : $(COMPONENT_JAR) $(COMPONENT_UNOPKG_MANIFEST) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + cd $(subst /,$(PS),$(OUT_CLASS)) && $(SDK_ZIP) ../bin/$(@F) $(<F) + cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(REGISTERFLAG) : $(COMPONENT_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(DEPLOYTOOL) $(COMPONENT_PACKAGE_URL) + @echo flagged > $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +$(EXAMPLE_NAME) : $(REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The SampleDialog Java component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo Please load the "$(QM)CreatingDialogs.odt$(QM)" document to use the component or use it + @echo by yourself in your office installation, see the example description. + @echo - + @echo $(MAKE) CreatingDialogs.odt.load + @echo -------------------------------------------------------------------------------- + +CreatingDialogs.odt.load : $(REGISTERFLAG) + "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMPONENT_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG))) diff --git a/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java new file mode 100644 index 000000000..d5a976c59 --- /dev/null +++ b/odk/examples/DevelopersGuide/BasicAndDialogs/CreatingDialogs/SampleDialog.java @@ -0,0 +1,278 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * 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. + * + *************************************************************************/ + +package com.sun.star.comp.sdk.examples; + +import com.sun.star.awt.ActionEvent; +import com.sun.star.awt.XActionListener; +import com.sun.star.awt.XButton; +import com.sun.star.lang.XComponent; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XControlContainer; +import com.sun.star.awt.XDialog; +import com.sun.star.awt.XFixedText; +import com.sun.star.awt.XToolkit; +import com.sun.star.awt.XWindow; +import com.sun.star.beans.XPropertySet; +import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.container.XNameContainer; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XTypeProvider; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.task.XJobExecutor; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + + +/** example of a Java component which creates a dialog at runtime + + This component can be tested by the following StarOffice Basic code: + Sub Main + Dim oJobExecutor + oJobExecutor = CreateUnoService( "com.sun.star.examples.SampleDialog" ) + oJobExecutor.trigger( "execute" ) + End Sub +*/ + +public class SampleDialog extends WeakBase implements XServiceInfo, XJobExecutor { + + static final String __serviceName = "com.sun.star.examples.SampleDialog"; + + private static final String _buttonName = "Button1"; + private static final String _cancelButtonName = "CancelButton"; + private static final String _labelName = "Label1"; + private static final String _labelPrefix = "Number of button clicks: "; + + private XComponentContext _xComponentContext; + + public SampleDialog( XComponentContext xComponentContext ) { + _xComponentContext = xComponentContext; + } + + // static component operations + public static XSingleServiceFactory __getServiceFactory( String implName, + XMultiServiceFactory multiFactory, + XRegistryKey regKey ) { + XSingleServiceFactory xSingleServiceFactory = null; + if ( implName.equals( SampleDialog.class.getName() ) ) { + xSingleServiceFactory = FactoryHelper.getServiceFactory( + SampleDialog.class, SampleDialog.__serviceName, multiFactory, regKey ); + } + return xSingleServiceFactory; + } + + public static boolean __writeRegistryServiceInfo( XRegistryKey regKey ) { + return FactoryHelper.writeRegistryServiceInfo( + SampleDialog.class.getName(), SampleDialog.__serviceName, regKey ); + } + + // XServiceInfo + public String getImplementationName( ) { + return getClass().getName(); + } + + // XServiceInfo + public boolean supportsService( /*IN*/String serviceName ) { + if ( serviceName.equals( __serviceName)) + return true; + return false; + } + + // XServiceInfo + public String[] getSupportedServiceNames( ) { + String[] retValue= new String[0]; + retValue[0] = __serviceName; + return retValue; + } + + // XJobExecutor + public void trigger(String sEvent) { + if ( sEvent.equals( "execute" ) ) { + try { + createDialog(); + } + catch ( Exception e ) { + throw new com.sun.star.lang.WrappedTargetRuntimeException( e, e.getMessage(), this, e ); + } + } + } + + /** method for creating a dialog at runtime + */ + private void createDialog() throws com.sun.star.uno.Exception { + + // get the service manager from the component context + XMultiComponentFactory xMultiComponentFactory = _xComponentContext.getServiceManager(); + + // create the dialog model and set the properties + Object dialogModel = xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.UnoControlDialogModel", _xComponentContext ); + XPropertySet xPSetDialog = ( XPropertySet )UnoRuntime.queryInterface( + XPropertySet.class, dialogModel ); + xPSetDialog.setPropertyValue( "PositionX", Integer.valueOf( 100 ) ); + xPSetDialog.setPropertyValue( "PositionY", Integer.valueOf( 100 ) ); + xPSetDialog.setPropertyValue( "Width", Integer.valueOf( 150 ) ); + xPSetDialog.setPropertyValue( "Height", Integer.valueOf( 100 ) ); + xPSetDialog.setPropertyValue( "Title", "Runtime Dialog Demo" ); + + // get the service manager from the dialog model + XMultiServiceFactory xMultiServiceFactory = ( XMultiServiceFactory )UnoRuntime.queryInterface( + XMultiServiceFactory.class, dialogModel ); + + // create the button model and set the properties + Object buttonModel = xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlButtonModel" ); + XPropertySet xPSetButton = ( XPropertySet )UnoRuntime.queryInterface( + XPropertySet.class, buttonModel ); + xPSetButton.setPropertyValue( "PositionX", Integer.valueOf( 20 ) ); + xPSetButton.setPropertyValue( "PositionY", Integer.valueOf( 70 ) ); + xPSetButton.setPropertyValue( "Width", Integer.valueOf( 50 ) ); + xPSetButton.setPropertyValue( "Height", Integer.valueOf( 14 ) ); + xPSetButton.setPropertyValue( "Name", _buttonName ); + xPSetButton.setPropertyValue( "TabIndex", Short.valueOf( (short)0 ) ); + xPSetButton.setPropertyValue( "Label", "Click Me" ); + + // create the label model and set the properties + Object labelModel = xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlFixedTextModel" ); + XPropertySet xPSetLabel = ( XPropertySet )UnoRuntime.queryInterface( + XPropertySet.class, labelModel ); + xPSetLabel.setPropertyValue( "PositionX", Integer.valueOf( 40 ) ); + xPSetLabel.setPropertyValue( "PositionY", Integer.valueOf( 30 ) ); + xPSetLabel.setPropertyValue( "Width", Integer.valueOf( 100 ) ); + xPSetLabel.setPropertyValue( "Height", Integer.valueOf( 14 ) ); + xPSetLabel.setPropertyValue( "Name", _labelName ); + xPSetLabel.setPropertyValue( "TabIndex", Short.valueOf( (short)1 ) ); + xPSetLabel.setPropertyValue( "Label", _labelPrefix ); + + // create a Cancel button model and set the properties + Object cancelButtonModel = xMultiServiceFactory.createInstance( + "com.sun.star.awt.UnoControlButtonModel" ); + XPropertySet xPSetCancelButton = ( XPropertySet )UnoRuntime.queryInterface( + XPropertySet.class, cancelButtonModel ); + xPSetCancelButton.setPropertyValue( "PositionX", Integer.valueOf( 80 ) ); + xPSetCancelButton.setPropertyValue( "PositionY", Integer.valueOf( 70 ) ); + xPSetCancelButton.setPropertyValue( "Width", Integer.valueOf( 50 ) ); + xPSetCancelButton.setPropertyValue( "Height", Integer.valueOf( 14 ) ); + xPSetCancelButton.setPropertyValue( "Name", _cancelButtonName ); + xPSetCancelButton.setPropertyValue( "TabIndex", Short.valueOf( (short)2 ) ); + xPSetCancelButton.setPropertyValue( "PushButtonType", Short.valueOf( (short)2 ) ); + xPSetCancelButton.setPropertyValue( "Label", "Cancel" ); + + // insert the control models into the dialog model + XNameContainer xNameCont = ( XNameContainer )UnoRuntime.queryInterface( + XNameContainer.class, dialogModel ); + xNameCont.insertByName( _buttonName, buttonModel ); + xNameCont.insertByName( _labelName, labelModel ); + xNameCont.insertByName( _cancelButtonName, cancelButtonModel ); + + // create the dialog control and set the model + Object dialog = xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.UnoControlDialog", _xComponentContext ); + XControl xControl = ( XControl )UnoRuntime.queryInterface( + XControl.class, dialog ); + XControlModel xControlModel = ( XControlModel )UnoRuntime.queryInterface( + XControlModel.class, dialogModel ); + xControl.setModel( xControlModel ); + + // add an action listener to the button control + XControlContainer xControlCont = ( XControlContainer )UnoRuntime.queryInterface( + XControlContainer.class, dialog ); + Object objectButton = xControlCont.getControl( "Button1" ); + XButton xButton = ( XButton )UnoRuntime.queryInterface( + XButton.class, objectButton ); + xButton.addActionListener( new ActionListenerImpl( xControlCont ) ); + + // create a peer + Object toolkit = xMultiComponentFactory.createInstanceWithContext( + "com.sun.star.awt.ExtToolkit", _xComponentContext ); + XToolkit xToolkit = ( XToolkit )UnoRuntime.queryInterface( + XToolkit.class, toolkit ); + XWindow xWindow = ( XWindow )UnoRuntime.queryInterface( + XWindow.class, xControl ); + xWindow.setVisible( false ); + xControl.createPeer( xToolkit, null ); + + // execute the dialog + XDialog xDialog = ( XDialog )UnoRuntime.queryInterface( + XDialog.class, dialog ); + xDialog.execute(); + + // dispose the dialog + XComponent xComponent = ( XComponent )UnoRuntime.queryInterface( + XComponent.class, dialog ); + xComponent.dispose(); + } + + /** action listener + */ + public class ActionListenerImpl implements com.sun.star.awt.XActionListener { + + private int _nCounts = 0; + + private XControlContainer _xControlCont; + + public ActionListenerImpl( XControlContainer xControlCont ) { + _xControlCont = xControlCont; + } + + // XEventListener + public void disposing( EventObject eventObject ) { + _xControlCont = null; + } + + // XActionListener + public void actionPerformed( ActionEvent actionEvent ) { + + // increase click counter + _nCounts++; + + // set label text + Object label = _xControlCont.getControl( "Label1" ); + XFixedText xLabel = ( XFixedText )UnoRuntime.queryInterface( + XFixedText.class, label ); + xLabel.setText( _labelPrefix + _nCounts ); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |