1*34dd1e25SAndrew Rist /************************************************************** 2*34dd1e25SAndrew Rist * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10*34dd1e25SAndrew Rist * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*34dd1e25SAndrew Rist * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19*34dd1e25SAndrew Rist * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir import com.sun.star.awt.ActionEvent; 25cdf0e10cSrcweir import com.sun.star.awt.AdjustmentEvent; 26cdf0e10cSrcweir import com.sun.star.awt.AdjustmentType; 27cdf0e10cSrcweir import com.sun.star.awt.FocusChangeReason; 28cdf0e10cSrcweir import com.sun.star.awt.FocusEvent; 29cdf0e10cSrcweir import com.sun.star.awt.ItemEvent; 30cdf0e10cSrcweir import com.sun.star.awt.KeyEvent; 31cdf0e10cSrcweir import com.sun.star.awt.MouseEvent; 32cdf0e10cSrcweir import com.sun.star.awt.PosSize; 33cdf0e10cSrcweir import com.sun.star.awt.PushButtonType; 34cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 35cdf0e10cSrcweir import com.sun.star.awt.SpinEvent; 36cdf0e10cSrcweir import com.sun.star.awt.TextEvent; 37cdf0e10cSrcweir import com.sun.star.awt.XActionListener; 38cdf0e10cSrcweir import com.sun.star.awt.XAdjustmentListener; 39cdf0e10cSrcweir import com.sun.star.awt.XButton; 40cdf0e10cSrcweir import com.sun.star.awt.XCheckBox; 41cdf0e10cSrcweir import com.sun.star.awt.XComboBox; 42cdf0e10cSrcweir import com.sun.star.awt.XControl; 43cdf0e10cSrcweir import com.sun.star.awt.XControlContainer; 44cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 45cdf0e10cSrcweir import com.sun.star.awt.XDialog; 46cdf0e10cSrcweir import com.sun.star.awt.XFixedText; 47cdf0e10cSrcweir import com.sun.star.awt.XFocusListener; 48cdf0e10cSrcweir import com.sun.star.awt.XItemEventBroadcaster; 49cdf0e10cSrcweir import com.sun.star.awt.XItemListener; 50cdf0e10cSrcweir import com.sun.star.awt.XKeyListener; 51cdf0e10cSrcweir import com.sun.star.awt.XListBox; 52cdf0e10cSrcweir //import com.sun.star.awt.XMessageBoxFactory; 53cdf0e10cSrcweir import com.sun.star.awt.XMouseListener; 54cdf0e10cSrcweir import com.sun.star.awt.XPointer; 55cdf0e10cSrcweir import com.sun.star.awt.XReschedule; 56cdf0e10cSrcweir import com.sun.star.awt.XScrollBar; 57cdf0e10cSrcweir import com.sun.star.awt.XSpinField; 58cdf0e10cSrcweir import com.sun.star.awt.XSpinListener; 59cdf0e10cSrcweir import com.sun.star.awt.XTextComponent; 60cdf0e10cSrcweir import com.sun.star.awt.XTextListener; 61cdf0e10cSrcweir import com.sun.star.awt.XToolkit; 62cdf0e10cSrcweir import com.sun.star.awt.XTopWindow; 63cdf0e10cSrcweir import com.sun.star.awt.XWindow; 64cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer; 65cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 66cdf0e10cSrcweir import com.sun.star.beans.XMultiPropertySet; 67cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 68cdf0e10cSrcweir import com.sun.star.container.XIndexContainer; 69cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 70cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 71cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 72cdf0e10cSrcweir import com.sun.star.frame.XFrame; 73cdf0e10cSrcweir import com.sun.star.frame.XModel; 74cdf0e10cSrcweir import com.sun.star.lang.EventObject; 75cdf0e10cSrcweir import com.sun.star.lang.XComponent; 76cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 77cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 78cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 79cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 80cdf0e10cSrcweir import com.sun.star.ucb.XFileIdentifierConverter; 81cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 82cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 83cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 84cdf0e10cSrcweir import com.sun.star.util.XMacroExpander; 85cdf0e10cSrcweir import com.sun.star.util.XNumberFormats; 86cdf0e10cSrcweir import com.sun.star.util.XNumberFormatsSupplier; 87cdf0e10cSrcweir 88cdf0e10cSrcweir 89cdf0e10cSrcweir // Anregung von DV: 90cdf0e10cSrcweir // Position und Weite als Parameter uebergeben 91cdf0e10cSrcweir 92cdf0e10cSrcweir public class UnoDialogSample implements XTextListener, XSpinListener, XActionListener, XFocusListener, XMouseListener, XItemListener, XAdjustmentListener, XKeyListener { 93cdf0e10cSrcweir protected XComponentContext m_xContext = null; 94cdf0e10cSrcweir protected com.sun.star.lang.XMultiComponentFactory m_xMCF; 95cdf0e10cSrcweir protected XMultiServiceFactory m_xMSFDialogModel; 96cdf0e10cSrcweir protected XModel m_xModel; 97cdf0e10cSrcweir protected XNameContainer m_xDlgModelNameContainer; 98cdf0e10cSrcweir protected XControlContainer m_xDlgContainer; 99cdf0e10cSrcweir // protected XNameAccess m_xDlgModelNameAccess; 100cdf0e10cSrcweir protected XControl m_xDialogControl; 101cdf0e10cSrcweir protected XDialog xDialog; 102cdf0e10cSrcweir protected XReschedule mxReschedule; 103cdf0e10cSrcweir protected XWindowPeer m_xWindowPeer = null; 104cdf0e10cSrcweir protected XTopWindow m_xTopWindow = null; 105cdf0e10cSrcweir protected XFrame m_xFrame = null; 106cdf0e10cSrcweir protected XComponent m_xComponent = null; 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** 110cdf0e10cSrcweir * Creates a new instance of UnoDialogSample 111cdf0e10cSrcweir */ UnoDialogSample(XComponentContext _xContext, XMultiComponentFactory _xMCF)112cdf0e10cSrcweir public UnoDialogSample(XComponentContext _xContext, XMultiComponentFactory _xMCF) { 113cdf0e10cSrcweir m_xContext = _xContext; 114cdf0e10cSrcweir m_xMCF = _xMCF; 115cdf0e10cSrcweir createDialog(m_xMCF); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir main(String args[])119cdf0e10cSrcweir public static void main(String args[]) { 120cdf0e10cSrcweir UnoDialogSample oUnoDialogSample = null; 121cdf0e10cSrcweir 122cdf0e10cSrcweir try { 123cdf0e10cSrcweir XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 124cdf0e10cSrcweir if(xContext != null ) 125cdf0e10cSrcweir System.out.println("Connected to a running office ..."); 126cdf0e10cSrcweir XMultiComponentFactory xMCF = xContext.getServiceManager(); 127cdf0e10cSrcweir oUnoDialogSample = new UnoDialogSample(xContext, xMCF); 128cdf0e10cSrcweir oUnoDialogSample.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"}, 129cdf0e10cSrcweir new Object[] { new Integer(380), Boolean.TRUE, "MyTestDialog", new Integer(102),new Integer(41), new Integer(0), new Short((short) 0), "OpenOffice", new Integer(380)}); 130cdf0e10cSrcweir Object oFTHeaderModel = oUnoDialogSample.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); 131cdf0e10cSrcweir XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); 132cdf0e10cSrcweir xFTHeaderModelMPSet.setPropertyValues( 133cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, 134cdf0e10cSrcweir new Object[] { new Integer(8), "This code-sample demonstrates how to create various controls in a dialog", "HeaderLabel", new Integer(106), new Integer(6), new Integer(300)}); 135cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 136cdf0e10cSrcweir oUnoDialogSample.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel); 137cdf0e10cSrcweir oUnoDialogSample.insertFixedText(oUnoDialogSample, 106, 18, 100, 0, "My ~Label"); 138cdf0e10cSrcweir oUnoDialogSample.insertCurrencyField(oUnoDialogSample, 106, 30, 60); 139cdf0e10cSrcweir oUnoDialogSample.insertProgressBar(106, 44, 100, 100); 140cdf0e10cSrcweir oUnoDialogSample.insertHorizontalFixedLine(106, 58, 100, "My FixedLine"); 141cdf0e10cSrcweir oUnoDialogSample.insertEditField(oUnoDialogSample, oUnoDialogSample, 106, 72, 60); 142cdf0e10cSrcweir oUnoDialogSample.insertTimeField(106, 96, 50, 0, 170000, 1000); 143cdf0e10cSrcweir oUnoDialogSample.insertDateField(oUnoDialogSample, 166, 96, 50); 144cdf0e10cSrcweir oUnoDialogSample.insertGroupBox(102, 124, 70, 100); 145cdf0e10cSrcweir oUnoDialogSample.insertPatternField(106, 136, 50); 146cdf0e10cSrcweir oUnoDialogSample.insertNumericField(106, 152, 50, 0.0, 1000.0, 500.0, 100.0, (short) 1); 147cdf0e10cSrcweir oUnoDialogSample.insertCheckBox(oUnoDialogSample, 106, 168, 150); 148cdf0e10cSrcweir oUnoDialogSample.insertRadioButtonGroup((short) 50, 130, 200, 150); 149cdf0e10cSrcweir oUnoDialogSample.insertListBox(106, 230, 50, 0, new String[]{"First Item", "Second Item"}); 150cdf0e10cSrcweir oUnoDialogSample.insertComboBox(106, 250, 50); 151cdf0e10cSrcweir oUnoDialogSample.insertFormattedField(oUnoDialogSample, 106, 270, 100); 152cdf0e10cSrcweir oUnoDialogSample.insertVerticalScrollBar(oUnoDialogSample, 230, 230, 52); 153cdf0e10cSrcweir oUnoDialogSample.insertFileControl(oUnoDialogSample, 106, 290, 200 ); 154cdf0e10cSrcweir oUnoDialogSample.insertButton(oUnoDialogSample, 106, 320, 50, "~Close dialog", (short) PushButtonType.OK_value); 155cdf0e10cSrcweir oUnoDialogSample.createWindowPeer(); 156cdf0e10cSrcweir oUnoDialogSample.addRoadmap(oUnoDialogSample.getRoadmapItemStateChangeListener()); 157cdf0e10cSrcweir oUnoDialogSample.insertRoadmapItem(0, true, "Introduction", 1); 158cdf0e10cSrcweir oUnoDialogSample.insertRoadmapItem(1, true, "Documents", 2); 159cdf0e10cSrcweir oUnoDialogSample.xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample.m_xDialogControl); 160cdf0e10cSrcweir oUnoDialogSample.executeDialog(); 161cdf0e10cSrcweir }catch( Exception e ) { 162cdf0e10cSrcweir System.err.println( e + e.getMessage()); 163cdf0e10cSrcweir e.printStackTrace(); 164cdf0e10cSrcweir } finally{ 165cdf0e10cSrcweir //make sure always to dispose the component and free the memory! 166cdf0e10cSrcweir if (oUnoDialogSample != null){ 167cdf0e10cSrcweir if (oUnoDialogSample.m_xComponent != null){ 168cdf0e10cSrcweir oUnoDialogSample.m_xComponent.dispose(); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir System.exit( 0 ); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir 177cdf0e10cSrcweir /** 178cdf0e10cSrcweir * @param _sKeyName 179cdf0e10cSrcweir * @return 180cdf0e10cSrcweir */ getRegistryKeyContent(String _sKeyName)181cdf0e10cSrcweir public XNameAccess getRegistryKeyContent(String _sKeyName){ 182cdf0e10cSrcweir try { 183cdf0e10cSrcweir Object oConfigProvider; 184cdf0e10cSrcweir PropertyValue[] aNodePath = new PropertyValue[1]; 185cdf0e10cSrcweir oConfigProvider = m_xMCF.createInstanceWithContext("com.sun.star.configuration.ConfigurationProvider", this.m_xContext); 186cdf0e10cSrcweir aNodePath[0] = new PropertyValue(); 187cdf0e10cSrcweir aNodePath[0].Name = "nodepath"; 188cdf0e10cSrcweir aNodePath[0].Value = _sKeyName; 189cdf0e10cSrcweir XMultiServiceFactory xMSFConfig = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); 190cdf0e10cSrcweir Object oNode = xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath); 191cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oNode); 192cdf0e10cSrcweir return xNameAccess; 193cdf0e10cSrcweir } catch (Exception exception) { 194cdf0e10cSrcweir exception.printStackTrace(System.out); 195cdf0e10cSrcweir return null; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir 200cdf0e10cSrcweir /** 201cdf0e10cSrcweir * @param _sRegistryPath the path a registryNode 202cdf0e10cSrcweir * @param _sImageName the name of the image 203cdf0e10cSrcweir */ getImageUrl(String _sRegistryPath, String _sImageName)204cdf0e10cSrcweir public String getImageUrl(String _sRegistryPath, String _sImageName) { 205cdf0e10cSrcweir String sImageUrl = ""; 206cdf0e10cSrcweir try { 207cdf0e10cSrcweir // retrive the configuration node of the extension 208cdf0e10cSrcweir XNameAccess xNameAccess = getRegistryKeyContent(_sRegistryPath); 209cdf0e10cSrcweir if (xNameAccess != null){ 210cdf0e10cSrcweir if (xNameAccess.hasByName(_sImageName)){ 211cdf0e10cSrcweir // get the Image Url and process the Url by the macroexpander... 212cdf0e10cSrcweir sImageUrl = (String) xNameAccess.getByName(_sImageName); 213cdf0e10cSrcweir Object oMacroExpander = this.m_xContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander"); 214cdf0e10cSrcweir XMacroExpander xMacroExpander = (XMacroExpander) UnoRuntime.queryInterface(XMacroExpander.class, oMacroExpander); 215cdf0e10cSrcweir sImageUrl = xMacroExpander.expandMacros(sImageUrl); 216cdf0e10cSrcweir sImageUrl = sImageUrl.substring(new String("vnd.sun.star.expand:").length(), sImageUrl.length()); 217cdf0e10cSrcweir sImageUrl = sImageUrl.trim(); 218cdf0e10cSrcweir sImageUrl += "/" + _sImageName; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir } 221cdf0e10cSrcweir } catch (Exception ex) { 222cdf0e10cSrcweir /* perform individual exception handling here. 223cdf0e10cSrcweir * Possible exception types are: 224cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 225cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 226cdf0e10cSrcweir */ 227cdf0e10cSrcweir ex.printStackTrace(System.out); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir return sImageUrl; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir createDialog(XMultiComponentFactory _xMCF)232cdf0e10cSrcweir protected void createDialog(XMultiComponentFactory _xMCF) { 233cdf0e10cSrcweir try { 234cdf0e10cSrcweir Object oDialogModel = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", m_xContext); 235cdf0e10cSrcweir 236cdf0e10cSrcweir // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls... 237cdf0e10cSrcweir m_xMSFDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel); 238cdf0e10cSrcweir 239cdf0e10cSrcweir // The named container is used to insert the created controls into... 240cdf0e10cSrcweir m_xDlgModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel); 241cdf0e10cSrcweir 242cdf0e10cSrcweir // create the dialog... 243cdf0e10cSrcweir Object oUnoDialog = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", m_xContext); 244cdf0e10cSrcweir m_xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog); 245cdf0e10cSrcweir 246cdf0e10cSrcweir // The scope of the control container is public... 247cdf0e10cSrcweir m_xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog); 248cdf0e10cSrcweir 249cdf0e10cSrcweir m_xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer); 250cdf0e10cSrcweir 251cdf0e10cSrcweir // link the dialog and its model... 252cdf0e10cSrcweir XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel); 253cdf0e10cSrcweir m_xDialogControl.setModel(xControlModel); 254cdf0e10cSrcweir } catch (com.sun.star.uno.Exception exception) { 255cdf0e10cSrcweir exception.printStackTrace(System.out); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir 260cdf0e10cSrcweir executeDialogWithembeddedExampleSnippets()261cdf0e10cSrcweir public short executeDialogWithembeddedExampleSnippets() throws com.sun.star.script.BasicErrorException { 262cdf0e10cSrcweir if (m_xWindowPeer == null){ 263cdf0e10cSrcweir createWindowPeer(); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir addRoadmap(getRoadmapItemStateChangeListener()); 266cdf0e10cSrcweir insertRoadmapItem(0, true, "Introduction", 1); 267cdf0e10cSrcweir insertRoadmapItem(1, true, "Documents", 2); 268cdf0e10cSrcweir xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); 269cdf0e10cSrcweir return xDialog.execute(); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir executeDialog()273cdf0e10cSrcweir public short executeDialog() throws com.sun.star.script.BasicErrorException { 274cdf0e10cSrcweir if (m_xWindowPeer == null) { 275cdf0e10cSrcweir createWindowPeer(); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); 278cdf0e10cSrcweir m_xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, m_xDialogControl); 279cdf0e10cSrcweir return xDialog.execute(); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir 282cdf0e10cSrcweir 283cdf0e10cSrcweir 284cdf0e10cSrcweir getRoadmapItemStateChangeListener()285cdf0e10cSrcweir public XItemListener getRoadmapItemStateChangeListener(){ 286cdf0e10cSrcweir return new RoadmapItemStateChangeListener(m_xMSFDialogModel); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir initialize(String[] PropertyNames, Object[] PropertyValues)290cdf0e10cSrcweir public void initialize(String[] PropertyNames, Object[] PropertyValues) throws com.sun.star.script.BasicErrorException{ 291cdf0e10cSrcweir try{ 292cdf0e10cSrcweir XMultiPropertySet xMultiPropertySet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, m_xDlgModelNameContainer); 293cdf0e10cSrcweir xMultiPropertySet.setPropertyValues(PropertyNames, PropertyValues); 294cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 295cdf0e10cSrcweir ex.printStackTrace(System.out); 296cdf0e10cSrcweir }} 297cdf0e10cSrcweir 298cdf0e10cSrcweir 299cdf0e10cSrcweir 300cdf0e10cSrcweir /** 301cdf0e10cSrcweir * create a peer for this 302cdf0e10cSrcweir * dialog, using the given 303cdf0e10cSrcweir * peer as a parent. 304cdf0e10cSrcweir * @param parentPeer 305cdf0e10cSrcweir * @return 306cdf0e10cSrcweir * @throws java.lang.Exception 307cdf0e10cSrcweir */ createWindowPeer(XWindowPeer _xWindowParentPeer)308cdf0e10cSrcweir public XWindowPeer createWindowPeer(XWindowPeer _xWindowParentPeer) throws com.sun.star.script.BasicErrorException{ 309cdf0e10cSrcweir try{ 310cdf0e10cSrcweir if (_xWindowParentPeer == null){ 311cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer); 312cdf0e10cSrcweir xWindow.setVisible(false); 313cdf0e10cSrcweir Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); 314cdf0e10cSrcweir XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, tk); 315cdf0e10cSrcweir mxReschedule = (XReschedule) UnoRuntime.queryInterface(XReschedule.class, xToolkit); 316cdf0e10cSrcweir m_xDialogControl.createPeer(xToolkit, _xWindowParentPeer); 317cdf0e10cSrcweir m_xWindowPeer = m_xDialogControl.getPeer(); 318cdf0e10cSrcweir return m_xWindowPeer; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir } catch (com.sun.star.uno.Exception exception) { 321cdf0e10cSrcweir exception.printStackTrace(System.out); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir return null; 324cdf0e10cSrcweir } 325cdf0e10cSrcweir 326cdf0e10cSrcweir calculateDialogPosition(XWindow _xWindow)327cdf0e10cSrcweir public void calculateDialogPosition(XWindow _xWindow) { 328cdf0e10cSrcweir Rectangle aFramePosSize = m_xModel.getCurrentController().getFrame().getComponentWindow().getPosSize(); 329cdf0e10cSrcweir Rectangle CurPosSize = _xWindow.getPosSize(); 330cdf0e10cSrcweir int WindowHeight = aFramePosSize.Height; 331cdf0e10cSrcweir int WindowWidth = aFramePosSize.Width; 332cdf0e10cSrcweir int DialogWidth = CurPosSize.Width; 333cdf0e10cSrcweir int DialogHeight = CurPosSize.Height; 334cdf0e10cSrcweir int iXPos = ((WindowWidth / 2) - (DialogWidth / 2)); 335cdf0e10cSrcweir int iYPos = ((WindowHeight / 2) - (DialogHeight / 2)); 336cdf0e10cSrcweir _xWindow.setPosSize(iXPos, iYPos, DialogWidth, DialogHeight, PosSize.POS); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir 340cdf0e10cSrcweir 341cdf0e10cSrcweir /** 342cdf0e10cSrcweir * Creates a peer for this 343cdf0e10cSrcweir * dialog, using the active OO frame 344cdf0e10cSrcweir * as the parent window. 345cdf0e10cSrcweir * @return 346cdf0e10cSrcweir * @throws java.lang.Exception 347cdf0e10cSrcweir */ createWindowPeer()348cdf0e10cSrcweir public XWindowPeer createWindowPeer() throws com.sun.star.script.BasicErrorException{ 349cdf0e10cSrcweir return createWindowPeer(null); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir endExecute()352cdf0e10cSrcweir public void endExecute() { 353cdf0e10cSrcweir xDialog.endExecute(); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir insertControlModel(String ServiceName, String sName, String[] sProperties, Object[] sValues)357cdf0e10cSrcweir public Object insertControlModel(String ServiceName, String sName, String[] sProperties, Object[] sValues) throws com.sun.star.script.BasicErrorException{ 358cdf0e10cSrcweir try { 359cdf0e10cSrcweir Object oControlModel = m_xMSFDialogModel.createInstance(ServiceName); 360cdf0e10cSrcweir XMultiPropertySet xControlMultiPropertySet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oControlModel); 361cdf0e10cSrcweir xControlMultiPropertySet.setPropertyValues(sProperties, sValues); 362cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oControlModel); 363cdf0e10cSrcweir return oControlModel; 364cdf0e10cSrcweir } catch (com.sun.star.uno.Exception exception) { 365cdf0e10cSrcweir exception.printStackTrace(System.out); 366cdf0e10cSrcweir return null; 367cdf0e10cSrcweir } 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir insertFixedText(XMouseListener _xMouseListener, int _nPosX, int _nPosY, int _nWidth, int _nStep, String _sLabel)371cdf0e10cSrcweir public XFixedText insertFixedText(XMouseListener _xMouseListener, int _nPosX, int _nPosY, int _nWidth, int _nStep, String _sLabel){ 372cdf0e10cSrcweir XFixedText xFixedText = null; 373cdf0e10cSrcweir try{ 374cdf0e10cSrcweir // create a unique name by means of an own implementation... 375cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "Label"); 376cdf0e10cSrcweir 377cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 378cdf0e10cSrcweir Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); 379cdf0e10cSrcweir XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); 380cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 381cdf0e10cSrcweir 382cdf0e10cSrcweir xFTModelMPSet.setPropertyValues( 383cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Step", "Width"}, 384cdf0e10cSrcweir new Object[] { new Integer(8), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nStep), new Integer(_nWidth)}); 385cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 386cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oFTModel); 387cdf0e10cSrcweir 388cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 389cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 390cdf0e10cSrcweir XPropertySet xFTPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFTModel); 391cdf0e10cSrcweir xFTPSet.setPropertyValue("Label", _sLabel); 392cdf0e10cSrcweir 393cdf0e10cSrcweir // reference the control by the Name 394cdf0e10cSrcweir XControl xFTControl = m_xDlgContainer.getControl(sName); 395cdf0e10cSrcweir xFixedText = (XFixedText) UnoRuntime.queryInterface(XFixedText.class, xFTControl); 396cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xFTControl); 397cdf0e10cSrcweir xWindow.addMouseListener(_xMouseListener); 398cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 399cdf0e10cSrcweir /* perform individual exception handling here. 400cdf0e10cSrcweir * Possible exception types are: 401cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 402cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 403cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 404cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 405cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 406cdf0e10cSrcweir * com.sun.star.uno.Exception 407cdf0e10cSrcweir */ 408cdf0e10cSrcweir ex.printStackTrace(System.out); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir return xFixedText; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir insertCurrencyField(XTextListener _xTextListener, int _nPositionX, int _nPositionY, int _nWidth)414cdf0e10cSrcweir public XTextComponent insertCurrencyField(XTextListener _xTextListener, int _nPositionX, int _nPositionY, int _nWidth){ 415cdf0e10cSrcweir XTextComponent xTextComponent = null; 416cdf0e10cSrcweir try{ 417cdf0e10cSrcweir // create a unique name by means of an own implementation... 418cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "CurrencyField"); 419cdf0e10cSrcweir 420cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 421cdf0e10cSrcweir Object oCFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCurrencyFieldModel"); 422cdf0e10cSrcweir XMultiPropertySet xCFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel); 423cdf0e10cSrcweir 424cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 425cdf0e10cSrcweir xCFModelMPSet.setPropertyValues( 426cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Width"}, 427cdf0e10cSrcweir new Object[] { new Integer(12), sName, new Integer(_nPositionX), new Integer(_nPositionY), new Integer(_nWidth)}); 428cdf0e10cSrcweir 429cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 430cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oCFModel); 431cdf0e10cSrcweir XPropertySet xCFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oCFModel); 432cdf0e10cSrcweir 433cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 434cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 435cdf0e10cSrcweir xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Boolean.TRUE); 436cdf0e10cSrcweir xCFModelPSet.setPropertyValue("CurrencySymbol", "$"); 437cdf0e10cSrcweir xCFModelPSet.setPropertyValue("Value", new Double(2.93)); 438cdf0e10cSrcweir 439cdf0e10cSrcweir // add a textlistener that is notified on each change of the controlvalue... 440cdf0e10cSrcweir Object oCFControl = m_xDlgContainer.getControl(sName); 441cdf0e10cSrcweir xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, oCFControl); 442cdf0e10cSrcweir xTextComponent.addTextListener(_xTextListener); 443cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 444cdf0e10cSrcweir /* perform individual exception handling here. 445cdf0e10cSrcweir * Possible exception types are: 446cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 447cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 448cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 449cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 450cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 451cdf0e10cSrcweir * com.sun.star.uno.Exception 452cdf0e10cSrcweir */ 453cdf0e10cSrcweir ex.printStackTrace(System.out); 454cdf0e10cSrcweir } 455cdf0e10cSrcweir return xTextComponent; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir 459cdf0e10cSrcweir insertProgressBar(int _nPosX, int _nPosY, int _nWidth, int _nProgressMax)460cdf0e10cSrcweir public XPropertySet insertProgressBar(int _nPosX, int _nPosY, int _nWidth, int _nProgressMax){ 461cdf0e10cSrcweir XPropertySet xPBModelPSet = null; 462cdf0e10cSrcweir try{ 463cdf0e10cSrcweir // create a unique name by means of an own implementation... 464cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "ProgressBar"); 465cdf0e10cSrcweir 466cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 467cdf0e10cSrcweir Object oPBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlProgressBarModel"); 468cdf0e10cSrcweir 469cdf0e10cSrcweir XMultiPropertySet xPBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oPBModel); 470cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 471cdf0e10cSrcweir xPBModelMPSet.setPropertyValues( 472cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Width"}, 473cdf0e10cSrcweir new Object[] { new Integer(8), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 474cdf0e10cSrcweir 475cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 476cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oPBModel); 477cdf0e10cSrcweir xPBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oPBModel); 478cdf0e10cSrcweir 479cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 480cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 481cdf0e10cSrcweir xPBModelPSet.setPropertyValue("ProgressValueMin", new Integer(0)); 482cdf0e10cSrcweir xPBModelPSet.setPropertyValue("ProgressValueMax", new Integer(_nProgressMax)); 483cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 484cdf0e10cSrcweir /* perform individual exception handling here. 485cdf0e10cSrcweir * Possible exception types are: 486cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 487cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 488cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 489cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 490cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 491cdf0e10cSrcweir * com.sun.star.uno.Exception 492cdf0e10cSrcweir */ 493cdf0e10cSrcweir ex.printStackTrace(System.out); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir return xPBModelPSet; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir 499cdf0e10cSrcweir insertHorizontalFixedLine(int _nPosX, int _nPosY, int _nWidth, String _sLabel)500cdf0e10cSrcweir public void insertHorizontalFixedLine(int _nPosX, int _nPosY, int _nWidth, String _sLabel){ 501cdf0e10cSrcweir try{ 502cdf0e10cSrcweir // create a unique name by means of an own implementation... 503cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "FixedLine"); 504cdf0e10cSrcweir 505cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 506cdf0e10cSrcweir Object oFLModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedLineModel"); 507cdf0e10cSrcweir XMultiPropertySet xFLModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFLModel); 508cdf0e10cSrcweir 509cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 510cdf0e10cSrcweir xFLModelMPSet.setPropertyValues( 511cdf0e10cSrcweir new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"}, 512cdf0e10cSrcweir new Object[] { new Integer(8), sName, new Integer(0), new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 513cdf0e10cSrcweir 514cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 515cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oFLModel); 516cdf0e10cSrcweir 517cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 518cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 519cdf0e10cSrcweir XPropertySet xFLPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFLModel); 520cdf0e10cSrcweir xFLPSet.setPropertyValue("Label", _sLabel); 521cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 522cdf0e10cSrcweir /* perform individual exception handling here. 523cdf0e10cSrcweir * Possible exception types are: 524cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 525cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 526cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 527cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 528cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 529cdf0e10cSrcweir * com.sun.star.uno.Exception 530cdf0e10cSrcweir */ 531cdf0e10cSrcweir ex.printStackTrace(System.out); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir 536cdf0e10cSrcweir insertGroupBox(int _nPosX, int _nPosY, int _nHeight, int _nWidth)537cdf0e10cSrcweir public void insertGroupBox(int _nPosX, int _nPosY, int _nHeight, int _nWidth){ 538cdf0e10cSrcweir try{ 539cdf0e10cSrcweir // create a unique name by means of an own implementation... 540cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "FrameControl"); 541cdf0e10cSrcweir 542cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 543cdf0e10cSrcweir Object oGBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlGroupBoxModel"); 544cdf0e10cSrcweir XMultiPropertySet xGBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oGBModel); 545cdf0e10cSrcweir 546cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 547cdf0e10cSrcweir xGBModelMPSet.setPropertyValues( 548cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Width"}, 549cdf0e10cSrcweir new Object[] { new Integer(_nHeight), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 550cdf0e10cSrcweir 551cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 552cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oGBModel); 553cdf0e10cSrcweir 554cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 555cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 556cdf0e10cSrcweir XPropertySet xGBPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oGBModel); 557cdf0e10cSrcweir xGBPSet.setPropertyValue("Label", "~My GroupBox"); 558cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 559cdf0e10cSrcweir /* perform individual exception handling here. 560cdf0e10cSrcweir * Possible exception types are: 561cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 562cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 563cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 564cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 565cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 566cdf0e10cSrcweir * com.sun.star.uno.Exception 567cdf0e10cSrcweir */ 568cdf0e10cSrcweir ex.printStackTrace(System.out); 569cdf0e10cSrcweir } 570cdf0e10cSrcweir } 571cdf0e10cSrcweir 572cdf0e10cSrcweir 573cdf0e10cSrcweir insertEditField(XTextListener _xTextListener, XFocusListener _xFocusListener, int _nPosX, int _nPosY, int _nWidth)574cdf0e10cSrcweir public XTextComponent insertEditField(XTextListener _xTextListener, XFocusListener _xFocusListener, int _nPosX, int _nPosY, int _nWidth){ 575cdf0e10cSrcweir XTextComponent xTextComponent = null; 576cdf0e10cSrcweir try{ 577cdf0e10cSrcweir // create a unique name by means of an own implementation... 578cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "TextField"); 579cdf0e10cSrcweir 580cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 581cdf0e10cSrcweir Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel"); 582cdf0e10cSrcweir XMultiPropertySet xTFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); 583cdf0e10cSrcweir 584cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 585cdf0e10cSrcweir xTFModelMPSet.setPropertyValues( 586cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"}, 587cdf0e10cSrcweir new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), "MyText", new Integer(_nWidth)}); 588cdf0e10cSrcweir 589cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 590cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oTFModel); 591cdf0e10cSrcweir XPropertySet xTFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTFModel); 592cdf0e10cSrcweir 593cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 594cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 595cdf0e10cSrcweir xTFModelPSet.setPropertyValue("EchoChar", new Short((short) '*')); 596cdf0e10cSrcweir XControl xTFControl = m_xDlgContainer.getControl(sName); 597cdf0e10cSrcweir 598cdf0e10cSrcweir // add a textlistener that is notified on each change of the controlvalue... 599cdf0e10cSrcweir xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xTFControl); 600cdf0e10cSrcweir XWindow xTFWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xTFControl); 601cdf0e10cSrcweir xTFWindow.addFocusListener(_xFocusListener); 602cdf0e10cSrcweir xTextComponent.addTextListener(_xTextListener); 603cdf0e10cSrcweir xTFWindow.addKeyListener(this); 604cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 605cdf0e10cSrcweir /* perform individual exception handling here. 606cdf0e10cSrcweir * Possible exception types are: 607cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 608cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 609cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 610cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 611cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 612cdf0e10cSrcweir * com.sun.star.uno.Exception 613cdf0e10cSrcweir */ 614cdf0e10cSrcweir ex.printStackTrace(System.out); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir return xTextComponent; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir insertTimeField(int _nPosX, int _nPosY, int _nWidth, int _nTime, int _nTimeMin, int _nTimeMax)619cdf0e10cSrcweir public XPropertySet insertTimeField(int _nPosX, int _nPosY, int _nWidth, int _nTime, int _nTimeMin, int _nTimeMax){ 620cdf0e10cSrcweir XPropertySet xTFModelPSet = null; 621cdf0e10cSrcweir try{ 622cdf0e10cSrcweir // create a unique name by means of an own implementation... 623cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "TimeField"); 624cdf0e10cSrcweir 625cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 626cdf0e10cSrcweir Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlTimeFieldModel"); 627cdf0e10cSrcweir XMultiPropertySet xTFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); 628cdf0e10cSrcweir 629cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 630cdf0e10cSrcweir xTFModelMPSet.setPropertyValues( 631cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "Width"}, 632cdf0e10cSrcweir new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, new Integer(_nWidth)}); 633cdf0e10cSrcweir 634cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 635cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oTFModel); 636cdf0e10cSrcweir xTFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTFModel); 637cdf0e10cSrcweir 638cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 639cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 640cdf0e10cSrcweir xTFModelPSet.setPropertyValue("TimeFormat", new Short((short) 5)); 641cdf0e10cSrcweir xTFModelPSet.setPropertyValue("TimeMin", new Integer(_nTimeMin)); 642cdf0e10cSrcweir xTFModelPSet.setPropertyValue("TimeMax", new Integer(_nTimeMax)); 643cdf0e10cSrcweir xTFModelPSet.setPropertyValue("Time", new Integer(_nTime)); 644cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 645cdf0e10cSrcweir /* perform individual exception handling here. 646cdf0e10cSrcweir * Possible exception types are: 647cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 648cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 649cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 650cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 651cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 652cdf0e10cSrcweir * com.sun.star.uno.Exception 653cdf0e10cSrcweir */ 654cdf0e10cSrcweir ex.printStackTrace(System.out); 655cdf0e10cSrcweir } 656cdf0e10cSrcweir return xTFModelPSet; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir 660cdf0e10cSrcweir insertDateField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth)661cdf0e10cSrcweir public XPropertySet insertDateField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth){ 662cdf0e10cSrcweir XPropertySet xDFModelPSet = null; 663cdf0e10cSrcweir try{ 664cdf0e10cSrcweir // create a unique name by means of an own implementation... 665cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "DateField"); 666cdf0e10cSrcweir 667cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 668cdf0e10cSrcweir Object oDFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlDateFieldModel"); 669cdf0e10cSrcweir XMultiPropertySet xDFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oDFModel); 670cdf0e10cSrcweir 671cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 672cdf0e10cSrcweir xDFModelMPSet.setPropertyValues( 673cdf0e10cSrcweir new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Width"}, 674cdf0e10cSrcweir new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 675cdf0e10cSrcweir 676cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 677cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oDFModel); 678cdf0e10cSrcweir xDFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oDFModel); 679cdf0e10cSrcweir 680cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 681cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 682cdf0e10cSrcweir xDFModelPSet.setPropertyValue("DateFormat", new Short((short) 7)); 683cdf0e10cSrcweir xDFModelPSet.setPropertyValue("DateMin", new Integer(20070401)); 684cdf0e10cSrcweir xDFModelPSet.setPropertyValue("DateMax", new Integer(20070501)); 685cdf0e10cSrcweir xDFModelPSet.setPropertyValue("Date", new Integer(20000415)); 686cdf0e10cSrcweir Object oDFControl = m_xDlgContainer.getControl(sName); 687cdf0e10cSrcweir 688cdf0e10cSrcweir // add a SpinListener that is notified on each change of the controlvalue... 689cdf0e10cSrcweir XSpinField xSpinField = (XSpinField) UnoRuntime.queryInterface(XSpinField.class, oDFControl); 690cdf0e10cSrcweir xSpinField.addSpinListener(_xSpinListener); 691cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 692cdf0e10cSrcweir /* perform individual exception handling here. 693cdf0e10cSrcweir * Possible exception types are: 694cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 695cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 696cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 697cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 698cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 699cdf0e10cSrcweir * com.sun.star.uno.Exception 700cdf0e10cSrcweir */ 701cdf0e10cSrcweir ex.printStackTrace(System.out); 702cdf0e10cSrcweir } 703cdf0e10cSrcweir return xDFModelPSet; 704cdf0e10cSrcweir } 705cdf0e10cSrcweir 706cdf0e10cSrcweir insertPatternField(int _nPosX, int _nPosY, int _nWidth)707cdf0e10cSrcweir public XPropertySet insertPatternField(int _nPosX, int _nPosY, int _nWidth){ 708cdf0e10cSrcweir XPropertySet xPFModelPSet = null; 709cdf0e10cSrcweir try{ 710cdf0e10cSrcweir // create a unique name by means of an own implementation... 711cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "PatternField"); 712cdf0e10cSrcweir 713cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 714cdf0e10cSrcweir Object oPFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlPatternFieldModel"); 715cdf0e10cSrcweir XMultiPropertySet xPFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oPFModel); 716cdf0e10cSrcweir 717cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 718cdf0e10cSrcweir xPFModelMPSet.setPropertyValues( 719cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Width"}, 720cdf0e10cSrcweir new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 721cdf0e10cSrcweir 722cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 723cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oPFModel); 724cdf0e10cSrcweir xPFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oPFModel); 725cdf0e10cSrcweir 726cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 727cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 728cdf0e10cSrcweir xPFModelPSet.setPropertyValue("LiteralMask", "__.05.2007"); 729cdf0e10cSrcweir // Allow only numbers for the first two digits... 730cdf0e10cSrcweir xPFModelPSet.setPropertyValue("EditMask", "NNLLLLLLLL"); 731cdf0e10cSrcweir // verify the user input immediately... 732cdf0e10cSrcweir xPFModelPSet.setPropertyValue("StrictFormat", Boolean.TRUE); 733cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 734cdf0e10cSrcweir /* perform individual exception handling here. 735cdf0e10cSrcweir * Possible exception types are: 736cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 737cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 738cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 739cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 740cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 741cdf0e10cSrcweir * com.sun.star.uno.Exception 742cdf0e10cSrcweir */ 743cdf0e10cSrcweir ex.printStackTrace(System.out); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir return xPFModelPSet; 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir insertNumericField( int _nPosX, int _nPosY, int _nWidth, double _fValueMin, double _fValueMax, double _fValue, double _fValueStep, short _nDecimalAccuracy)749cdf0e10cSrcweir public XPropertySet insertNumericField( int _nPosX, int _nPosY, int _nWidth, 750cdf0e10cSrcweir double _fValueMin, double _fValueMax, double _fValue, 751cdf0e10cSrcweir double _fValueStep, short _nDecimalAccuracy){ 752cdf0e10cSrcweir XPropertySet xNFModelPSet = null; 753cdf0e10cSrcweir try{ 754cdf0e10cSrcweir // create a unique name by means of an own implementation... 755cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "NumericField"); 756cdf0e10cSrcweir 757cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 758cdf0e10cSrcweir Object oNFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel"); 759cdf0e10cSrcweir XMultiPropertySet xNFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oNFModel); 760cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 761cdf0e10cSrcweir xNFModelMPSet.setPropertyValues( 762cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "StrictFormat", "Width"}, 763cdf0e10cSrcweir new Object[] { new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, Boolean.TRUE, new Integer(_nWidth)}); 764cdf0e10cSrcweir 765cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 766cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oNFModel); 767cdf0e10cSrcweir xNFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oNFModel); 768cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 769cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 770cdf0e10cSrcweir xNFModelPSet.setPropertyValue("ValueMin", new Double(_fValueMin)); 771cdf0e10cSrcweir xNFModelPSet.setPropertyValue("ValueMax", new Double(_fValueMax)); 772cdf0e10cSrcweir xNFModelPSet.setPropertyValue("Value", new Double(_fValue)); 773cdf0e10cSrcweir xNFModelPSet.setPropertyValue("ValueStep", new Double(_fValueStep)); 774cdf0e10cSrcweir xNFModelPSet.setPropertyValue("ShowThousandsSeparator", Boolean.TRUE); 775cdf0e10cSrcweir xNFModelPSet.setPropertyValue("DecimalAccuracy", new Short(_nDecimalAccuracy)); 776cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 777cdf0e10cSrcweir /* perform individual exception handling here. 778cdf0e10cSrcweir * Possible exception types are: 779cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 780cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 781cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 782cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 783cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 784cdf0e10cSrcweir * com.sun.star.uno.Exception 785cdf0e10cSrcweir */ 786cdf0e10cSrcweir ex.printStackTrace(System.out); 787cdf0e10cSrcweir } 788cdf0e10cSrcweir return xNFModelPSet; 789cdf0e10cSrcweir } 790cdf0e10cSrcweir 791cdf0e10cSrcweir 792cdf0e10cSrcweir insertVerticalScrollBar(XAdjustmentListener _xAdjustmentListener, int _nPosX, int _nPosY, int _nHeight)793cdf0e10cSrcweir public XPropertySet insertVerticalScrollBar(XAdjustmentListener _xAdjustmentListener, int _nPosX, int _nPosY, int _nHeight){ 794cdf0e10cSrcweir XPropertySet xSBModelPSet = null; 795cdf0e10cSrcweir try{ 796cdf0e10cSrcweir // create a unique name by means of an own implementation... 797cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "ScrollBar"); 798cdf0e10cSrcweir 799cdf0e10cSrcweir Integer NOrientation = new Integer(com.sun.star.awt.ScrollBarOrientation.VERTICAL); 800cdf0e10cSrcweir 801cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 802cdf0e10cSrcweir Object oSBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel"); 803cdf0e10cSrcweir XMultiPropertySet xSBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oSBModel); 804cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 805cdf0e10cSrcweir xSBModelMPSet.setPropertyValues( 806cdf0e10cSrcweir new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"}, 807cdf0e10cSrcweir new Object[] { new Integer(_nHeight), sName, NOrientation, new Integer(_nPosX), new Integer(_nPosY), new Integer(8)}); 808cdf0e10cSrcweir 809cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 810cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oSBModel); 811cdf0e10cSrcweir 812cdf0e10cSrcweir xSBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oSBModel); 813cdf0e10cSrcweir // The following properties may also be set with XMultiPropertySet but we 814cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 815cdf0e10cSrcweir xSBModelPSet.setPropertyValue("ScrollValueMin", new Integer(0)); 816cdf0e10cSrcweir xSBModelPSet.setPropertyValue("ScrollValueMax", new Integer(100)); 817cdf0e10cSrcweir xSBModelPSet.setPropertyValue("ScrollValue", new Integer(5)); 818cdf0e10cSrcweir xSBModelPSet.setPropertyValue("LineIncrement", new Integer(2)); 819cdf0e10cSrcweir xSBModelPSet.setPropertyValue("BlockIncrement", new Integer(10)); 820cdf0e10cSrcweir 821cdf0e10cSrcweir // Add an Adjustment that will listen to changes of the scrollbar... 822cdf0e10cSrcweir XControl xSBControl = m_xDlgContainer.getControl(sName); 823cdf0e10cSrcweir XScrollBar xScrollBar = (XScrollBar) UnoRuntime.queryInterface(XScrollBar.class, xSBControl); 824cdf0e10cSrcweir xScrollBar.addAdjustmentListener(_xAdjustmentListener); 825cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 826cdf0e10cSrcweir /* perform individual exception handling here. 827cdf0e10cSrcweir * Possible exception types are: 828cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 829cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 830cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 831cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 832cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 833cdf0e10cSrcweir * com.sun.star.uno.Exception 834cdf0e10cSrcweir */ 835cdf0e10cSrcweir ex.printStackTrace(System.out); 836cdf0e10cSrcweir } 837cdf0e10cSrcweir return xSBModelPSet; 838cdf0e10cSrcweir } 839cdf0e10cSrcweir 840cdf0e10cSrcweir 841cdf0e10cSrcweir /** makes a String unique by appending a numerical suffix 842cdf0e10cSrcweir * @param _xElementContainer the com.sun.star.container.XNameAccess container 843cdf0e10cSrcweir * that the new Element is going to be inserted to 844cdf0e10cSrcweir * @param _sElementName the StemName of the Element 845cdf0e10cSrcweir */ createUniqueName(XNameAccess _xElementContainer, String _sElementName)846cdf0e10cSrcweir public static String createUniqueName(XNameAccess _xElementContainer, String _sElementName) { 847cdf0e10cSrcweir boolean bElementexists = true; 848cdf0e10cSrcweir int i = 1; 849cdf0e10cSrcweir String sIncSuffix = ""; 850cdf0e10cSrcweir String BaseName = _sElementName; 851cdf0e10cSrcweir while (bElementexists) { 852cdf0e10cSrcweir bElementexists = _xElementContainer.hasByName(_sElementName); 853cdf0e10cSrcweir if (bElementexists) { 854cdf0e10cSrcweir i += 1; 855cdf0e10cSrcweir _sElementName = BaseName + Integer.toString(i); 856cdf0e10cSrcweir } 857cdf0e10cSrcweir } 858cdf0e10cSrcweir return _sElementName; 859cdf0e10cSrcweir } 860cdf0e10cSrcweir 861cdf0e10cSrcweir insertCheckBox(XItemListener _xItemListener, int _nPosX, int _nPosY, int _nWidth)862cdf0e10cSrcweir public XCheckBox insertCheckBox(XItemListener _xItemListener, int _nPosX, int _nPosY, int _nWidth){ 863cdf0e10cSrcweir XCheckBox xCheckBox = null; 864cdf0e10cSrcweir try{ 865cdf0e10cSrcweir // create a unique name by means of an own implementation... 866cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "CheckBox"); 867cdf0e10cSrcweir 868cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 869cdf0e10cSrcweir Object oCBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel"); 870cdf0e10cSrcweir 871cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 872cdf0e10cSrcweir XMultiPropertySet xCBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCBModel); 873cdf0e10cSrcweir xCBMPSet.setPropertyValues( 874cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width" } , 875cdf0e10cSrcweir new Object[] {new Integer(8), "~Include page number", sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); 876cdf0e10cSrcweir 877cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 878cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 879cdf0e10cSrcweir XPropertySet xCBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCBMPSet); 880cdf0e10cSrcweir xCBModelPSet.setPropertyValue("TriState", Boolean.TRUE); 881cdf0e10cSrcweir xCBModelPSet.setPropertyValue("State", new Short((short) 1)); 882cdf0e10cSrcweir 883cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 884cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oCBModel); 885cdf0e10cSrcweir XControl xCBControl = m_xDlgContainer.getControl(sName); 886cdf0e10cSrcweir xCheckBox = (XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, xCBControl); 887cdf0e10cSrcweir // An ActionListener will be notified on the activation of the button... 888cdf0e10cSrcweir xCheckBox.addItemListener(_xItemListener); 889cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 890cdf0e10cSrcweir /* perform individual exception handling here. 891cdf0e10cSrcweir * Possible exception types are: 892cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 893cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 894cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 895cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 896cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 897cdf0e10cSrcweir * com.sun.star.uno.Exception 898cdf0e10cSrcweir */ 899cdf0e10cSrcweir ex.printStackTrace(System.out); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir return xCheckBox; 902cdf0e10cSrcweir } 903cdf0e10cSrcweir 904cdf0e10cSrcweir 905cdf0e10cSrcweir 906cdf0e10cSrcweir insertRadioButtonGroup(short _nTabIndex, int _nPosX, int _nPosY, int _nWidth)907cdf0e10cSrcweir public void insertRadioButtonGroup(short _nTabIndex, int _nPosX, int _nPosY, int _nWidth){ 908cdf0e10cSrcweir try{ 909cdf0e10cSrcweir // create a unique name by means of an own implementation... 910cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton"); 911cdf0e10cSrcweir 912cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 913cdf0e10cSrcweir Object oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); 914cdf0e10cSrcweir XMultiPropertySet xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); 915cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 916cdf0e10cSrcweir xRBMPSet.setPropertyValues( 917cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "State", "TabIndex", "Width" } , 918cdf0e10cSrcweir new Object[] {new Integer(8), "~First Option", sName, new Integer(_nPosX), new Integer(_nPosY), new Short((short) 1), new Short(_nTabIndex++),new Integer(_nWidth)}); 919cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 920cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oRBModel); 921cdf0e10cSrcweir 922cdf0e10cSrcweir // create a unique name by means of an own implementation... 923cdf0e10cSrcweir sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton"); 924cdf0e10cSrcweir 925cdf0e10cSrcweir oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); 926cdf0e10cSrcweir xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); 927cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 928cdf0e10cSrcweir xRBMPSet.setPropertyValues( 929cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width" } , 930cdf0e10cSrcweir new Object[] {new Integer(8), "~Second Option", sName, new Integer(130), new Integer(214), new Short(_nTabIndex), new Integer(150)}); 931cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 932cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oRBModel); 933cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 934cdf0e10cSrcweir /* perform individual exception handling here. 935cdf0e10cSrcweir * Possible exception types are: 936cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 937cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 938cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 939cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 940cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 941cdf0e10cSrcweir * com.sun.star.uno.Exception 942cdf0e10cSrcweir */ 943cdf0e10cSrcweir ex.printStackTrace(System.out); 944cdf0e10cSrcweir } 945cdf0e10cSrcweir } 946cdf0e10cSrcweir 947cdf0e10cSrcweir insertListBox(int _nPosX, int _nPosY, int _nWidth, int _nStep, String[] _sStringItemList)948cdf0e10cSrcweir public XListBox insertListBox(int _nPosX, int _nPosY, int _nWidth, int _nStep, String[] _sStringItemList){ 949cdf0e10cSrcweir XListBox xListBox = null; 950cdf0e10cSrcweir try{ 951cdf0e10cSrcweir // create a unique name by means of an own implementation... 952cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "ListBox"); 953cdf0e10cSrcweir 954cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 955cdf0e10cSrcweir Object oListBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel"); 956cdf0e10cSrcweir XMultiPropertySet xLBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel); 957cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 958cdf0e10cSrcweir xLBModelMPSet.setPropertyValues( 959cdf0e10cSrcweir new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Step", "StringItemList", "Width" } , 960cdf0e10cSrcweir new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nStep), _sStringItemList, new Integer(_nWidth)}); 961cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 962cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 963cdf0e10cSrcweir XPropertySet xLBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xLBModelMPSet); 964cdf0e10cSrcweir xLBModelPSet.setPropertyValue("MultiSelection", Boolean.TRUE); 965cdf0e10cSrcweir short[] nSelItems = new short[] {(short) 1, (short) 3}; 966cdf0e10cSrcweir xLBModelPSet.setPropertyValue("SelectedItems", nSelItems); 967cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 968cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, xLBModelMPSet); 969cdf0e10cSrcweir XControl xControl = m_xDlgContainer.getControl(sName); 970cdf0e10cSrcweir // retrieve a ListBox that is more convenient to work with than the Model of the ListBox... 971cdf0e10cSrcweir xListBox = (XListBox) UnoRuntime.queryInterface(XListBox.class, xControl); 972cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 973cdf0e10cSrcweir /* perform individual exception handling here. 974cdf0e10cSrcweir * Possible exception types are: 975cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 976cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 977cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 978cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 979cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 980cdf0e10cSrcweir * com.sun.star.uno.Exception 981cdf0e10cSrcweir */ 982cdf0e10cSrcweir ex.printStackTrace(System.out); 983cdf0e10cSrcweir } 984cdf0e10cSrcweir return xListBox; 985cdf0e10cSrcweir } 986cdf0e10cSrcweir 987cdf0e10cSrcweir insertComboBox(int _nPosX, int _nPosY, int _nWidth)988cdf0e10cSrcweir public XComboBox insertComboBox(int _nPosX, int _nPosY, int _nWidth){ 989cdf0e10cSrcweir XComboBox xComboBox = null; 990cdf0e10cSrcweir try{ 991cdf0e10cSrcweir // create a unique name by means of an own implementation... 992cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "ComboBox"); 993cdf0e10cSrcweir 994cdf0e10cSrcweir String[] sStringItemList = new String[]{"First Entry", "Second Entry", "Third Entry", "Fourth Entry"}; 995cdf0e10cSrcweir 996cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 997cdf0e10cSrcweir Object oComboBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlComboBoxModel"); 998cdf0e10cSrcweir XMultiPropertySet xCbBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oComboBoxModel); 999cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 1000cdf0e10cSrcweir xCbBModelMPSet.setPropertyValues( 1001cdf0e10cSrcweir new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "StringItemList", "Width" } , 1002cdf0e10cSrcweir new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), sStringItemList, new Integer(_nWidth)}); 1003cdf0e10cSrcweir 1004cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 1005cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 1006cdf0e10cSrcweir XPropertySet xCbBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCbBModelMPSet); 1007cdf0e10cSrcweir xCbBModelPSet.setPropertyValue("MaxTextLen", new Short((short) 10)); 1008cdf0e10cSrcweir xCbBModelPSet.setPropertyValue("ReadOnly", Boolean.FALSE); 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 1011cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, xCbBModelMPSet); 1012cdf0e10cSrcweir XControl xControl = m_xDlgContainer.getControl(sName); 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir // retrieve a ListBox that is more convenient to work with than the Model of the ListBox... 1015cdf0e10cSrcweir xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, xControl); 1016cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1017cdf0e10cSrcweir /* perform individual exception handling here. 1018cdf0e10cSrcweir * Possible exception types are: 1019cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 1020cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1021cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 1022cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 1023cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1024cdf0e10cSrcweir * com.sun.star.uno.Exception 1025cdf0e10cSrcweir */ 1026cdf0e10cSrcweir ex.printStackTrace(System.out); 1027cdf0e10cSrcweir } 1028cdf0e10cSrcweir return xComboBox; 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir insertFormattedField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth)1033cdf0e10cSrcweir public XPropertySet insertFormattedField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth){ 1034cdf0e10cSrcweir XPropertySet xFFModelPSet = null; 1035cdf0e10cSrcweir try{ 1036cdf0e10cSrcweir // create a unique name by means of an own implementation... 1037cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "FormattedField"); 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 1040cdf0e10cSrcweir Object oFFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFormattedFieldModel"); 1041cdf0e10cSrcweir XMultiPropertySet xFFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFFModel); 1042cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 1043cdf0e10cSrcweir xFFModelMPSet.setPropertyValues( 1044cdf0e10cSrcweir new String[] {"EffectiveValue", "Height", "Name", "PositionX", "PositionY", "StrictFormat", "Spin", "Width"}, 1045cdf0e10cSrcweir new Object[] { new Double(12348), new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, Boolean.TRUE, new Integer(_nWidth)}); 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir xFFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFFModel); 1048cdf0e10cSrcweir // to define a numberformat you always need a locale... 1049cdf0e10cSrcweir com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale(); 1050cdf0e10cSrcweir aLocale.Country = "US"; 1051cdf0e10cSrcweir aLocale.Language = "en"; 1052cdf0e10cSrcweir // this Format is only compliant to the english locale! 1053cdf0e10cSrcweir String sFormatString = "NNNNMMMM DD, YYYY"; 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir // a NumberFormatsSupplier has to be created first "in the open countryside"... 1056cdf0e10cSrcweir Object oNumberFormatsSupplier = m_xMCF.createInstanceWithContext("com.sun.star.util.NumberFormatsSupplier", m_xContext); 1057cdf0e10cSrcweir XNumberFormatsSupplier xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, oNumberFormatsSupplier); 1058cdf0e10cSrcweir XNumberFormats xNumberFormats = xNumberFormatsSupplier.getNumberFormats(); 1059cdf0e10cSrcweir // is the numberformat already defined? 1060cdf0e10cSrcweir int nFormatKey = xNumberFormats.queryKey(sFormatString, aLocale, true); 1061cdf0e10cSrcweir if (nFormatKey == -1){ 1062cdf0e10cSrcweir // if not then add it to the NumberFormatsSupplier 1063cdf0e10cSrcweir nFormatKey = xNumberFormats.addNew(sFormatString, aLocale); 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir // The following property may also be set with XMultiPropertySet but we 1067cdf0e10cSrcweir // use the XPropertySet interface merely for reasons of demonstration 1068cdf0e10cSrcweir xFFModelPSet.setPropertyValue("FormatsSupplier", xNumberFormatsSupplier); 1069cdf0e10cSrcweir xFFModelPSet.setPropertyValue("FormatKey", new Integer(nFormatKey)); 1070cdf0e10cSrcweir 1071cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 1072cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oFFModel); 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir // finally we add a Spin-Listener to the control 1075cdf0e10cSrcweir XControl xFFControl = m_xDlgContainer.getControl(sName); 1076cdf0e10cSrcweir // add a SpinListener that is notified on each change of the controlvalue... 1077cdf0e10cSrcweir XSpinField xSpinField = (XSpinField) UnoRuntime.queryInterface(XSpinField.class, xFFControl); 1078cdf0e10cSrcweir xSpinField.addSpinListener(_xSpinListener); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1081cdf0e10cSrcweir /* perform individual exception handling here. 1082cdf0e10cSrcweir * Possible exception types are: 1083cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 1084cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1085cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 1086cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 1087cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1088cdf0e10cSrcweir * com.sun.star.uno.Exception 1089cdf0e10cSrcweir */ 1090cdf0e10cSrcweir ex.printStackTrace(System.out); 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir return xFFModelPSet; 1093cdf0e10cSrcweir } 1094cdf0e10cSrcweir convertUnits()1095cdf0e10cSrcweir public void convertUnits(){ 1096cdf0e10cSrcweir // iXPixelFactor = (int) (100000/xDevice.getInfo().PixelPerMeterX); 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir insertFileControl(XTextListener _xTextListener, int _nPosX, int _nPosY, int _nWidth)1100cdf0e10cSrcweir public XTextComponent insertFileControl(XTextListener _xTextListener, int _nPosX, int _nPosY, int _nWidth){ 1101cdf0e10cSrcweir XTextComponent xTextComponent = null; 1102cdf0e10cSrcweir try{ 1103cdf0e10cSrcweir // create a unique name by means of an own implementation... 1104cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "FileControl"); 1105cdf0e10cSrcweir 1106cdf0e10cSrcweir // retrieve the configured Work path... 1107cdf0e10cSrcweir Object oPathSettings = m_xMCF.createInstanceWithContext("com.sun.star.util.PathSettings",m_xContext); 1108cdf0e10cSrcweir XPropertySet xPropertySet = (XPropertySet) com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); 1109cdf0e10cSrcweir String sWorkUrl = (String) xPropertySet.getPropertyValue("Work"); 1110cdf0e10cSrcweir 1111cdf0e10cSrcweir // convert the Url to a system path that is "human readable"... 1112cdf0e10cSrcweir Object oFCProvider = m_xMCF.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", m_xContext); 1113cdf0e10cSrcweir XFileIdentifierConverter xFileIdentifierConverter = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider); 1114cdf0e10cSrcweir String sSystemWorkPath = xFileIdentifierConverter.getSystemPathFromFileURL(sWorkUrl); 1115cdf0e10cSrcweir 1116cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 1117cdf0e10cSrcweir Object oFCModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFileControlModel"); 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 1120cdf0e10cSrcweir XMultiPropertySet xFCModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFCModel); 1121cdf0e10cSrcweir xFCModelMPSet.setPropertyValues( 1122cdf0e10cSrcweir new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"}, 1123cdf0e10cSrcweir new Object[] { new Integer(14), sName, new Integer(_nPosX), new Integer(_nPosY), sSystemWorkPath, new Integer(_nWidth)}); 1124cdf0e10cSrcweir 1125cdf0e10cSrcweir // The controlmodel is not really available until inserted to the Dialog container 1126cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oFCModel); 1127cdf0e10cSrcweir XPropertySet xFCModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFCModel); 1128cdf0e10cSrcweir 1129cdf0e10cSrcweir // add a textlistener that is notified on each change of the controlvalue... 1130cdf0e10cSrcweir XControl xFCControl = m_xDlgContainer.getControl(sName); 1131cdf0e10cSrcweir xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xFCControl); 1132cdf0e10cSrcweir XWindow xFCWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xFCControl); 1133cdf0e10cSrcweir xTextComponent.addTextListener(_xTextListener); 1134cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1135cdf0e10cSrcweir /* perform individual exception handling here. 1136cdf0e10cSrcweir * Possible exception types are: 1137cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 1138cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1139cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 1140cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 1141cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1142cdf0e10cSrcweir * com.sun.star.uno.Exception 1143cdf0e10cSrcweir */ 1144cdf0e10cSrcweir ex.printStackTrace(System.out); 1145cdf0e10cSrcweir } 1146cdf0e10cSrcweir return xTextComponent; 1147cdf0e10cSrcweir } 1148cdf0e10cSrcweir 1149cdf0e10cSrcweir insertButton(XActionListener _xActionListener, int _nPosX, int _nPosY, int _nWidth, String _sLabel, short _nPushButtonType)1150cdf0e10cSrcweir public XButton insertButton(XActionListener _xActionListener, int _nPosX, int _nPosY, int _nWidth, String _sLabel, short _nPushButtonType){ 1151cdf0e10cSrcweir XButton xButton = null; 1152cdf0e10cSrcweir try{ 1153cdf0e10cSrcweir // create a unique name by means of an own implementation... 1154cdf0e10cSrcweir String sName = createUniqueName(m_xDlgModelNameContainer, "CommandButton"); 1155cdf0e10cSrcweir 1156cdf0e10cSrcweir // create a controlmodel at the multiservicefactory of the dialog model... 1157cdf0e10cSrcweir Object oButtonModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel"); 1158cdf0e10cSrcweir XMultiPropertySet xButtonMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oButtonModel); 1159cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 1160cdf0e10cSrcweir xButtonMPSet.setPropertyValues( 1161cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "PushButtonType", "Width" } , 1162cdf0e10cSrcweir new Object[] {new Integer(14), _sLabel, sName, new Integer(_nPosX), new Integer(_nPosY), new Short(_nPushButtonType), new Integer(_nWidth)}); 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 1165cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oButtonModel); 1166cdf0e10cSrcweir XControl xButtonControl = m_xDlgContainer.getControl(sName); 1167cdf0e10cSrcweir xButton = (XButton) UnoRuntime.queryInterface(XButton.class, xButtonControl); 1168cdf0e10cSrcweir // An ActionListener will be notified on the activation of the button... 1169cdf0e10cSrcweir xButton.addActionListener(_xActionListener); 1170cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1171cdf0e10cSrcweir /* perform individual exception handling here. 1172cdf0e10cSrcweir * Possible exception types are: 1173cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException, 1174cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1175cdf0e10cSrcweir * com.sun.star.container.ElementExistException, 1176cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException, 1177cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1178cdf0e10cSrcweir * com.sun.star.uno.Exception 1179cdf0e10cSrcweir */ 1180cdf0e10cSrcweir ex.printStackTrace(System.out); 1181cdf0e10cSrcweir } 1182cdf0e10cSrcweir return xButton; 1183cdf0e10cSrcweir } 1184cdf0e10cSrcweir 1185cdf0e10cSrcweir /** gets the WindowPeer of a frame 1186cdf0e10cSrcweir * @param _XTextDocument the instance of a textdocument 1187cdf0e10cSrcweir * @return the windowpeer of the frame 1188cdf0e10cSrcweir */ getWindowPeer(XTextDocument _xTextDocument)1189cdf0e10cSrcweir public XWindowPeer getWindowPeer(XTextDocument _xTextDocument){ 1190cdf0e10cSrcweir XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, _xTextDocument); 1191cdf0e10cSrcweir XFrame xFrame = xModel.getCurrentController().getFrame(); 1192cdf0e10cSrcweir XWindow xWindow = xFrame.getContainerWindow(); 1193cdf0e10cSrcweir XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWindow); 1194cdf0e10cSrcweir return xWindowPeer; 1195cdf0e10cSrcweir } 1196cdf0e10cSrcweir getCurrentFrame()1197cdf0e10cSrcweir public XFrame getCurrentFrame(){ 1198cdf0e10cSrcweir XFrame xRetFrame = null; 1199cdf0e10cSrcweir try { 1200cdf0e10cSrcweir Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext); 1201cdf0e10cSrcweir XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop); 1202cdf0e10cSrcweir xRetFrame = xDesktop.getCurrentFrame(); 1203cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1204cdf0e10cSrcweir ex.printStackTrace(); 1205cdf0e10cSrcweir } 1206cdf0e10cSrcweir return xRetFrame; 1207cdf0e10cSrcweir } 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir textChanged(TextEvent textEvent)1210cdf0e10cSrcweir public void textChanged(TextEvent textEvent) { 1211cdf0e10cSrcweir try { 1212cdf0e10cSrcweir // get the control that has fired the event, 1213cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, textEvent.Source); 1214cdf0e10cSrcweir XControlModel xControlModel = xControl.getModel(); 1215cdf0e10cSrcweir XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); 1216cdf0e10cSrcweir String sName = (String) xPSet.getPropertyValue("Name"); 1217cdf0e10cSrcweir // just in case the listener has been added to several controls, 1218cdf0e10cSrcweir // we make sure we refer to the right one 1219cdf0e10cSrcweir if (sName.equals("TextField1")){ 1220cdf0e10cSrcweir String sText = (String) xPSet.getPropertyValue("Text"); 1221cdf0e10cSrcweir System.out.println(sText); 1222cdf0e10cSrcweir // insert your code here to validate the text of the control... 1223cdf0e10cSrcweir } 1224cdf0e10cSrcweir }catch (com.sun.star.uno.Exception ex){ 1225cdf0e10cSrcweir /* perform individual exception handling here. 1226cdf0e10cSrcweir * Possible exception types are: 1227cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1228cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1229cdf0e10cSrcweir * com.sun.star.uno.Exception 1230cdf0e10cSrcweir */ 1231cdf0e10cSrcweir ex.printStackTrace(System.out); 1232cdf0e10cSrcweir } 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir 1236cdf0e10cSrcweir up(SpinEvent spinEvent)1237cdf0e10cSrcweir public void up(SpinEvent spinEvent) { 1238cdf0e10cSrcweir try { 1239cdf0e10cSrcweir // get the control that has fired the event, 1240cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, spinEvent.Source); 1241cdf0e10cSrcweir XControlModel xControlModel = xControl.getModel(); 1242cdf0e10cSrcweir XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); 1243cdf0e10cSrcweir String sName = (String) xPSet.getPropertyValue("Name"); 1244cdf0e10cSrcweir // just in case the listener has been added to several controls, 1245cdf0e10cSrcweir // we make sure we refer to the right one 1246cdf0e10cSrcweir if (sName.equals("FormattedField1")){ 1247cdf0e10cSrcweir double fvalue = AnyConverter.toDouble(xPSet.getPropertyValue("EffectiveValue")); 1248cdf0e10cSrcweir System.out.println("Controlvalue: " + fvalue); 1249cdf0e10cSrcweir // insert your code here to validate the value of the control... 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir }catch (com.sun.star.uno.Exception ex){ 1252cdf0e10cSrcweir /* perform individual exception handling here. 1253cdf0e10cSrcweir * Possible exception types are: 1254cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1255cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1256cdf0e10cSrcweir * com.sun.star.uno.Exception 1257cdf0e10cSrcweir */ 1258cdf0e10cSrcweir ex.printStackTrace(System.out); 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir } 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir down(SpinEvent spinEvent)1263cdf0e10cSrcweir public void down(SpinEvent spinEvent) { 1264cdf0e10cSrcweir } 1265cdf0e10cSrcweir last(SpinEvent spinEvent)1266cdf0e10cSrcweir public void last(SpinEvent spinEvent) { 1267cdf0e10cSrcweir } 1268cdf0e10cSrcweir first(SpinEvent spinEvent)1269cdf0e10cSrcweir public void first(SpinEvent spinEvent) { 1270cdf0e10cSrcweir } 1271cdf0e10cSrcweir disposing(EventObject rEventObject)1272cdf0e10cSrcweir public void disposing(EventObject rEventObject) { 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir 1275cdf0e10cSrcweir actionPerformed(ActionEvent rEvent)1276cdf0e10cSrcweir public void actionPerformed(ActionEvent rEvent) { 1277cdf0e10cSrcweir try{ 1278cdf0e10cSrcweir // get the control that has fired the event, 1279cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, rEvent.Source); 1280cdf0e10cSrcweir XControlModel xControlModel = xControl.getModel(); 1281cdf0e10cSrcweir XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); 1282cdf0e10cSrcweir String sName = (String) xPSet.getPropertyValue("Name"); 1283cdf0e10cSrcweir // just in case the listener has been added to several controls, 1284cdf0e10cSrcweir // we make sure we refer to the right one 1285cdf0e10cSrcweir if (sName.equals("CommandButton1")) { 1286cdf0e10cSrcweir //... 1287cdf0e10cSrcweir } 1288cdf0e10cSrcweir }catch (com.sun.star.uno.Exception ex){ 1289cdf0e10cSrcweir /* perform individual exception handling here. 1290cdf0e10cSrcweir * Possible exception types are: 1291cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1292cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1293cdf0e10cSrcweir * com.sun.star.uno.Exception 1294cdf0e10cSrcweir */ 1295cdf0e10cSrcweir ex.printStackTrace(System.out); 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir focusLost(FocusEvent _focusEvent)1300cdf0e10cSrcweir public void focusLost(FocusEvent _focusEvent) { 1301cdf0e10cSrcweir short nFocusFlags = _focusEvent.FocusFlags; 1302cdf0e10cSrcweir int nFocusChangeReason = nFocusFlags & FocusChangeReason.TAB; 1303cdf0e10cSrcweir if (nFocusChangeReason == FocusChangeReason.TAB) { 1304cdf0e10cSrcweir // get the window of the Window that has gained the Focus... 1305cdf0e10cSrcweir // Note that the xWindow is just a representation of the controlwindow 1306cdf0e10cSrcweir // but not of the control itself 1307cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, _focusEvent.NextFocus); 1308cdf0e10cSrcweir } 1309cdf0e10cSrcweir } 1310cdf0e10cSrcweir 1311cdf0e10cSrcweir focusGained(FocusEvent focusEvent)1312cdf0e10cSrcweir public void focusGained(FocusEvent focusEvent) { 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir mouseReleased(MouseEvent mouseEvent)1315cdf0e10cSrcweir public void mouseReleased(MouseEvent mouseEvent) { 1316cdf0e10cSrcweir } 1317cdf0e10cSrcweir mousePressed(MouseEvent mouseEvent)1318cdf0e10cSrcweir public void mousePressed(MouseEvent mouseEvent) { 1319cdf0e10cSrcweir } 1320cdf0e10cSrcweir mouseExited(MouseEvent mouseEvent)1321cdf0e10cSrcweir public void mouseExited(MouseEvent mouseEvent) { 1322cdf0e10cSrcweir } 1323cdf0e10cSrcweir mouseEntered(MouseEvent _mouseEvent)1324cdf0e10cSrcweir public void mouseEntered(MouseEvent _mouseEvent) { 1325cdf0e10cSrcweir try { 1326cdf0e10cSrcweir // retrieve the control that the event has been invoked at... 1327cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, _mouseEvent.Source); 1328cdf0e10cSrcweir Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); 1329cdf0e10cSrcweir XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, tk); 1330cdf0e10cSrcweir // create the peer of the control by passing the windowpeer of the parent 1331cdf0e10cSrcweir // in this case the windowpeer of the control 1332cdf0e10cSrcweir xControl.createPeer(xToolkit, m_xWindowPeer); 1333cdf0e10cSrcweir // create a pointer object "in the open countryside" and set the type accordingly... 1334cdf0e10cSrcweir Object oPointer = this.m_xMCF.createInstanceWithContext("com.sun.star.awt.Pointer", this.m_xContext); 1335cdf0e10cSrcweir XPointer xPointer = (XPointer) UnoRuntime.queryInterface(XPointer.class, oPointer); 1336cdf0e10cSrcweir xPointer.setType(com.sun.star.awt.SystemPointer.REFHAND); 1337cdf0e10cSrcweir // finally set the created pointer at the windowpeer of the control 1338cdf0e10cSrcweir xControl.getPeer().setPointer(xPointer); 1339cdf0e10cSrcweir } catch (com.sun.star.uno.Exception ex) { 1340cdf0e10cSrcweir throw new java.lang.RuntimeException("cannot happen..."); 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir 1345cdf0e10cSrcweir itemStateChanged(ItemEvent itemEvent)1346cdf0e10cSrcweir public void itemStateChanged(ItemEvent itemEvent) { 1347cdf0e10cSrcweir try{ 1348cdf0e10cSrcweir // retrieve the control that the event has been invoked at... 1349cdf0e10cSrcweir XCheckBox xCheckBox = (XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, itemEvent.Source); 1350cdf0e10cSrcweir // retrieve the control that we want to disable or enable 1351cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, m_xDlgContainer.getControl("CommandButton1")); 1352cdf0e10cSrcweir XPropertySet xModelPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel()); 1353cdf0e10cSrcweir short nState = xCheckBox.getState(); 1354cdf0e10cSrcweir boolean bdoEnable = true; 1355cdf0e10cSrcweir switch (nState){ 1356cdf0e10cSrcweir case 1: // checked 1357cdf0e10cSrcweir bdoEnable = true; 1358cdf0e10cSrcweir break; 1359cdf0e10cSrcweir case 0: // not checked 1360cdf0e10cSrcweir case 2: // don't know 1361cdf0e10cSrcweir bdoEnable = false; 1362cdf0e10cSrcweir break; 1363cdf0e10cSrcweir } 1364cdf0e10cSrcweir // Alternatively we could have done it also this way: 1365cdf0e10cSrcweir // bdoEnable = (nState == 1); 1366cdf0e10cSrcweir xModelPropertySet.setPropertyValue("Enabled", new Boolean(bdoEnable)); 1367cdf0e10cSrcweir }catch (com.sun.star.uno.Exception ex){ 1368cdf0e10cSrcweir /* perform individual exception handling here. 1369cdf0e10cSrcweir * Possible exception types are: 1370cdf0e10cSrcweir * com.sun.star.lang.IllegalArgumentException 1371cdf0e10cSrcweir * com.sun.star.lang.WrappedTargetException, 1372cdf0e10cSrcweir * com.sun.star.beans.UnknownPropertyException, 1373cdf0e10cSrcweir * com.sun.star.beans.PropertyVetoException 1374cdf0e10cSrcweir * com.sun.star.uno.Exception 1375cdf0e10cSrcweir */ 1376cdf0e10cSrcweir ex.printStackTrace(System.out); 1377cdf0e10cSrcweir } 1378cdf0e10cSrcweir } 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir adjustmentValueChanged(AdjustmentEvent _adjustmentEvent)1381cdf0e10cSrcweir public void adjustmentValueChanged(AdjustmentEvent _adjustmentEvent) { 1382cdf0e10cSrcweir switch (_adjustmentEvent.Type.getValue()){ 1383cdf0e10cSrcweir case AdjustmentType.ADJUST_ABS_value: 1384cdf0e10cSrcweir System.out.println( "The event has been triggered by dragging the thumb..." ); 1385cdf0e10cSrcweir break; 1386cdf0e10cSrcweir case AdjustmentType.ADJUST_LINE_value: 1387cdf0e10cSrcweir System.out.println( "The event has been triggered by a single line move.." ); 1388cdf0e10cSrcweir break; 1389cdf0e10cSrcweir case AdjustmentType.ADJUST_PAGE_value: 1390cdf0e10cSrcweir System.out.println( "The event has been triggered by a block move..." ); 1391cdf0e10cSrcweir break; 1392cdf0e10cSrcweir } 1393cdf0e10cSrcweir System.out.println( "The value of the scrollbar is: " + _adjustmentEvent.Value); 1394cdf0e10cSrcweir } 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir // Globally available object variables of the roadmapmodel 1399cdf0e10cSrcweir XPropertySet m_xRMPSet; 1400cdf0e10cSrcweir XSingleServiceFactory m_xSSFRoadmap; 1401cdf0e10cSrcweir XIndexContainer m_xRMIndexCont; 1402cdf0e10cSrcweir addRoadmap(XItemListener _xItemListener)1403cdf0e10cSrcweir public void addRoadmap(XItemListener _xItemListener) { 1404cdf0e10cSrcweir XPropertySet xDialogModelPropertySet = null; 1405cdf0e10cSrcweir try { 1406cdf0e10cSrcweir // create a unique name by means of an own implementation... 1407cdf0e10cSrcweir String sRoadmapName = createUniqueName(m_xDlgModelNameContainer, "Roadmap"); 1408cdf0e10cSrcweir 1409cdf0e10cSrcweir xDialogModelPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel); 1410cdf0e10cSrcweir // Similar to the office assistants the roadmap is adjusted to the height of the dialog 1411cdf0e10cSrcweir // where a certain space is left at the bottom for the buttons... 1412cdf0e10cSrcweir int nDialogHeight = ((Integer) xDialogModelPropertySet.getPropertyValue("Height")).intValue(); 1413cdf0e10cSrcweir 1414cdf0e10cSrcweir // instantiate the roadmapmodel... 1415cdf0e10cSrcweir Object oRoadmapModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRoadmapModel"); 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir // define the properties of the roadmapmodel 1418cdf0e10cSrcweir XMultiPropertySet xRMMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRoadmapModel); 1419cdf0e10cSrcweir xRMMPSet.setPropertyValues( new String[] {"Complete", "Height", "Name", "PositionX", "PositionY", "Text", "Width" }, 1420cdf0e10cSrcweir new Object[] {Boolean.FALSE, new Integer(nDialogHeight - 26), sRoadmapName, new Integer(0), new Integer(0), "Steps", new Integer(85)}); 1421cdf0e10cSrcweir m_xRMPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmapModel); 1422cdf0e10cSrcweir 1423cdf0e10cSrcweir // add the roadmapmodel to the dialog container.. 1424cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sRoadmapName, oRoadmapModel); 1425cdf0e10cSrcweir 1426cdf0e10cSrcweir // the roadmapmodel is a SingleServiceFactory to instantiate the roadmapitems... 1427cdf0e10cSrcweir m_xSSFRoadmap = (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmapModel); 1428cdf0e10cSrcweir m_xRMIndexCont = (XIndexContainer) UnoRuntime.queryInterface(XIndexContainer.class, oRoadmapModel); 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir // add the itemlistener to the control... 1431cdf0e10cSrcweir XControl xRMControl = this.m_xDlgContainer.getControl(sRoadmapName); 1432cdf0e10cSrcweir XItemEventBroadcaster xRMBroadcaster = (XItemEventBroadcaster) UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRMControl); 1433cdf0e10cSrcweir xRMBroadcaster.addItemListener( getRoadmapItemStateChangeListener() ); 1434cdf0e10cSrcweir } catch (java.lang.Exception jexception) { 1435cdf0e10cSrcweir jexception.printStackTrace(System.out); 1436cdf0e10cSrcweir } 1437cdf0e10cSrcweir } 1438cdf0e10cSrcweir 1439cdf0e10cSrcweir /** 1440cdf0e10cSrcweir *To fully understand the example one has to be aware that the passed ???Index??? parameter 1441cdf0e10cSrcweir * refers to the position of the roadmap item in the roadmapmodel container 1442cdf0e10cSrcweir * whereas the variable ???_ID??? directyl references to a certain step of dialog. 1443cdf0e10cSrcweir */ insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _ID)1444cdf0e10cSrcweir public void insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _ID) { 1445cdf0e10cSrcweir try { 1446cdf0e10cSrcweir // a roadmap is a SingleServiceFactory that can only create roadmapitems that are the only possible 1447cdf0e10cSrcweir // element types of the container 1448cdf0e10cSrcweir Object oRoadmapItem = m_xSSFRoadmap.createInstance(); 1449cdf0e10cSrcweir XPropertySet xRMItemPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmapItem); 1450cdf0e10cSrcweir xRMItemPSet.setPropertyValue("Label", _sLabel); 1451cdf0e10cSrcweir // sometimes steps are supposed to be set disabled depending on the program logic... 1452cdf0e10cSrcweir xRMItemPSet.setPropertyValue("Enabled", new Boolean(_bEnabled)); 1453cdf0e10cSrcweir // in this context the "ID" is meant to refer to a step of the dialog 1454cdf0e10cSrcweir xRMItemPSet.setPropertyValue("ID", new Integer(_ID)); 1455cdf0e10cSrcweir m_xRMIndexCont.insertByIndex(Index, oRoadmapItem); 1456cdf0e10cSrcweir } catch (com.sun.star.uno.Exception exception) { 1457cdf0e10cSrcweir exception.printStackTrace(System.out); 1458cdf0e10cSrcweir } 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir keyReleased(KeyEvent keyEvent)1462cdf0e10cSrcweir public void keyReleased(KeyEvent keyEvent) { 1463cdf0e10cSrcweir int i = keyEvent.KeyChar; 1464cdf0e10cSrcweir int n = keyEvent.KeyCode; 1465cdf0e10cSrcweir int m = keyEvent.KeyFunc; 1466cdf0e10cSrcweir } 1467cdf0e10cSrcweir keyPressed(KeyEvent keyEvent)1468cdf0e10cSrcweir public void keyPressed(KeyEvent keyEvent) { 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir } 1472