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