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