bump product version to 5.0.4.1
[LibreOffice.git] / odk / examples / DevelopersGuide / GUI / UnoDialogSample.java
blobd2730e0f3e54752342223f379105d91be2e08547
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * the BSD license.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * All rights reserved.
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.
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.
33 *************************************************************************/
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.PushButtonType;
44 import com.sun.star.awt.SpinEvent;
45 import com.sun.star.awt.TextEvent;
46 import com.sun.star.awt.XActionListener;
47 import com.sun.star.awt.XAdjustmentListener;
48 import com.sun.star.awt.XButton;
49 import com.sun.star.awt.XCheckBox;
50 import com.sun.star.awt.XComboBox;
51 import com.sun.star.awt.XControl;
52 import com.sun.star.awt.XControlContainer;
53 import com.sun.star.awt.XControlModel;
54 import com.sun.star.awt.XDialog;
55 import com.sun.star.awt.XFixedText;
56 import com.sun.star.awt.XFocusListener;
57 import com.sun.star.awt.XItemEventBroadcaster;
58 import com.sun.star.awt.XItemListener;
59 import com.sun.star.awt.XKeyListener;
60 import com.sun.star.awt.XListBox;
61 import com.sun.star.awt.XMouseListener;
62 import com.sun.star.awt.XPointer;
63 import com.sun.star.awt.XReschedule;
64 import com.sun.star.awt.XScrollBar;
65 import com.sun.star.awt.XSpinField;
66 import com.sun.star.awt.XSpinListener;
67 import com.sun.star.awt.XTextComponent;
68 import com.sun.star.awt.XTextListener;
69 import com.sun.star.awt.XToolkit;
70 import com.sun.star.awt.XTopWindow;
71 import com.sun.star.awt.XWindow;
72 import com.sun.star.awt.XWindowPeer;
73 import com.sun.star.beans.XMultiPropertySet;
74 import com.sun.star.beans.XPropertySet;
75 import com.sun.star.container.XIndexContainer;
76 import com.sun.star.container.XNameAccess;
77 import com.sun.star.container.XNameContainer;
78 import com.sun.star.frame.XDesktop;
79 import com.sun.star.frame.XFrame;
80 import com.sun.star.frame.XModel;
81 import com.sun.star.lang.EventObject;
82 import com.sun.star.lang.XComponent;
83 import com.sun.star.lang.XMultiComponentFactory;
84 import com.sun.star.lang.XMultiServiceFactory;
85 import com.sun.star.lang.XSingleServiceFactory;
86 import com.sun.star.ucb.XFileIdentifierConverter;
87 import com.sun.star.uno.AnyConverter;
88 import com.sun.star.uno.UnoRuntime;
89 import com.sun.star.uno.XComponentContext;
90 import com.sun.star.util.XNumberFormats;
91 import com.sun.star.util.XNumberFormatsSupplier;
92 import com.sun.star.util.Date;
93 import com.sun.star.util.Time;
94 import com.sun.star.util.thePathSettings;
97 // Anregung von DV:
98 // Position und Weite als Parameter uebergeben
100 public class UnoDialogSample implements XTextListener, XSpinListener, XActionListener, XFocusListener, XMouseListener, XItemListener, XAdjustmentListener, XKeyListener {
101 protected XComponentContext m_xContext = null;
102 protected com.sun.star.lang.XMultiComponentFactory m_xMCF;
103 protected XMultiServiceFactory m_xMSFDialogModel;
104 private XModel m_xModel;
105 protected XNameContainer m_xDlgModelNameContainer;
106 protected XControlContainer m_xDlgContainer;
107 // protected XNameAccess m_xDlgModelNameAccess;
108 protected XControl m_xDialogControl;
109 protected XDialog xDialog;
111 protected XWindowPeer m_xWindowPeer = null;
113 protected XFrame m_xFrame = null;
114 protected XComponent m_xComponent = null;
118 * Creates a new instance of UnoDialogSample
120 public UnoDialogSample(XComponentContext _xContext, XMultiComponentFactory _xMCF) {
121 m_xContext = _xContext;
122 m_xMCF = _xMCF;
123 createDialog(m_xMCF);
127 public static void main(String args[]) {
128 UnoDialogSample oUnoDialogSample = null;
130 try {
131 XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
132 if(xContext != null )
133 System.out.println("Connected to a running office ...");
134 XMultiComponentFactory xMCF = xContext.getServiceManager();
135 oUnoDialogSample = new UnoDialogSample(xContext, xMCF);
136 oUnoDialogSample.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"},
137 new Object[] { Integer.valueOf(380), Boolean.TRUE, "MyTestDialog", Integer.valueOf(102),Integer.valueOf(41), Integer.valueOf(0), Short.valueOf((short) 0), "OpenOffice", Integer.valueOf(380)});
138 Object oFTHeaderModel = oUnoDialogSample.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
139 XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel);
140 xFTHeaderModelMPSet.setPropertyValues(
141 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
142 new Object[] { Integer.valueOf(8), "This code-sample demonstrates how to create various controls in a dialog", "HeaderLabel", Integer.valueOf(106), Integer.valueOf(6), Integer.valueOf(300)});
143 // add the model to the NameContainer of the dialog model
144 oUnoDialogSample.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel);
145 oUnoDialogSample.insertFixedText(oUnoDialogSample, 106, 18, 100, 0, "My ~Label");
146 oUnoDialogSample.insertCurrencyField(oUnoDialogSample, 106, 30, 60);
147 oUnoDialogSample.insertProgressBar(106, 44, 100, 100);
148 oUnoDialogSample.insertHorizontalFixedLine(106, 58, 100, "My FixedLine");
149 oUnoDialogSample.insertEditField(oUnoDialogSample, oUnoDialogSample, 106, 72, 60);
150 oUnoDialogSample.insertTimeField(106, 96, 50, new Time(0,(short)0,(short)0,(short)10,false), new Time((short)0,(short)0,(short)0,(short)0,false), new Time((short)0,(short)0,(short)0,(short)17,false));
151 oUnoDialogSample.insertDateField(oUnoDialogSample, 166, 96, 50);
152 oUnoDialogSample.insertGroupBox(102, 124, 70, 100);
153 oUnoDialogSample.insertPatternField(106, 136, 50);
154 oUnoDialogSample.insertNumericField(106, 152, 50, 0.0, 1000.0, 500.0, 100.0, (short) 1);
155 oUnoDialogSample.insertCheckBox(oUnoDialogSample, 106, 168, 150);
156 oUnoDialogSample.insertRadioButtonGroup((short) 50, 130, 200, 150);
157 oUnoDialogSample.insertListBox(106, 230, 50, 0, new String[]{"First Item", "Second Item"});
158 oUnoDialogSample.insertComboBox(106, 250, 50);
159 oUnoDialogSample.insertFormattedField(oUnoDialogSample, 106, 270, 100);
160 oUnoDialogSample.insertVerticalScrollBar(oUnoDialogSample, 230, 230, 52);
161 oUnoDialogSample.insertFileControl(oUnoDialogSample, 106, 290, 200 );
162 oUnoDialogSample.insertButton(oUnoDialogSample, 106, 320, 50, "~Close dialog", (short) PushButtonType.OK_value);
163 oUnoDialogSample.createWindowPeer();
164 oUnoDialogSample.addRoadmap();
165 oUnoDialogSample.insertRoadmapItem(0, true, "Introduction", 1);
166 oUnoDialogSample.insertRoadmapItem(1, true, "Documents", 2);
167 oUnoDialogSample.xDialog = UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample.m_xDialogControl);
168 oUnoDialogSample.executeDialog();
169 }catch( Exception e ) {
170 System.err.println( e + e.getMessage());
171 e.printStackTrace();
172 } finally{
173 //make sure always to dispose the component and free the memory!
174 if (oUnoDialogSample != null){
175 if (oUnoDialogSample.m_xComponent != null){
176 oUnoDialogSample.m_xComponent.dispose();
181 System.exit( 0 );
185 protected void createDialog(XMultiComponentFactory _xMCF) {
186 try {
187 Object oDialogModel = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", m_xContext);
189 // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls...
190 m_xMSFDialogModel = UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel);
192 // The named container is used to insert the created controls into...
193 m_xDlgModelNameContainer = UnoRuntime.queryInterface(XNameContainer.class, oDialogModel);
195 // create the dialog...
196 Object oUnoDialog = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", m_xContext);
197 m_xDialogControl = UnoRuntime.queryInterface(XControl.class, oUnoDialog);
199 // The scope of the control container is public...
200 m_xDlgContainer = UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog);
202 UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer);
204 // link the dialog and its model...
205 XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, oDialogModel);
206 m_xDialogControl.setModel(xControlModel);
207 } catch (com.sun.star.uno.Exception exception) {
208 exception.printStackTrace(System.err);
217 public short executeDialog() {
218 if (m_xWindowPeer == null) {
219 createWindowPeer();
221 xDialog = UnoRuntime.queryInterface(XDialog.class, m_xDialogControl);
222 m_xComponent = UnoRuntime.queryInterface(XComponent.class, m_xDialogControl);
223 return xDialog.execute();
229 public XItemListener getRoadmapItemStateChangeListener(){
230 return new RoadmapItemStateChangeListener(m_xMSFDialogModel);
234 public void initialize(String[] PropertyNames, Object[] PropertyValues) {
235 try{
236 XMultiPropertySet xMultiPropertySet = UnoRuntime.queryInterface(XMultiPropertySet.class, m_xDlgModelNameContainer);
237 xMultiPropertySet.setPropertyValues(PropertyNames, PropertyValues);
238 } catch (com.sun.star.uno.Exception ex) {
239 ex.printStackTrace(System.err);
245 * create a peer for this
246 * dialog, using the given
247 * peer as a parent.
249 private XWindowPeer createWindowPeer(XWindowPeer _xWindowParentPeer) {
250 try{
251 if (_xWindowParentPeer == null){
252 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer);
253 xWindow.setVisible(false);
254 Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext);
255 XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, tk);
256 UnoRuntime.queryInterface(XReschedule.class, xToolkit);
257 m_xDialogControl.createPeer(xToolkit, _xWindowParentPeer);
258 m_xWindowPeer = m_xDialogControl.getPeer();
259 return m_xWindowPeer;
261 } catch (com.sun.star.uno.Exception exception) {
262 exception.printStackTrace(System.err);
264 return null;
273 * Creates a peer for this
274 * dialog, using the active OO frame
275 * as the parent window.
277 public XWindowPeer createWindowPeer() {
278 return createWindowPeer(null);
287 private XFixedText insertFixedText(XMouseListener _xMouseListener, int _nPosX, int _nPosY, int _nWidth, int _nStep, String _sLabel){
288 XFixedText xFixedText = null;
289 try{
290 // create a unique name by means of an own implementation...
291 String sName = createUniqueName(m_xDlgModelNameContainer, "Label");
293 // create a controlmodel at the multiservicefactory of the dialog model...
294 Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
295 XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel);
296 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
298 xFTModelMPSet.setPropertyValues(
299 new String[] {"Height", "Name", "PositionX", "PositionY", "Step", "Width"},
300 new Object[] { Integer.valueOf(8), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nStep), Integer.valueOf(_nWidth)});
301 // add the model to the NameContainer of the dialog model
302 m_xDlgModelNameContainer.insertByName(sName, oFTModel);
304 // The following property may also be set with XMultiPropertySet but we
305 // use the XPropertySet interface merely for reasons of demonstration
306 XPropertySet xFTPSet = UnoRuntime.queryInterface(XPropertySet.class, oFTModel);
307 xFTPSet.setPropertyValue("Label", _sLabel);
309 // reference the control by the Name
310 XControl xFTControl = m_xDlgContainer.getControl(sName);
311 xFixedText = UnoRuntime.queryInterface(XFixedText.class, xFTControl);
312 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xFTControl);
313 xWindow.addMouseListener(_xMouseListener);
314 } catch (com.sun.star.uno.Exception ex) {
315 /* perform individual exception handling here.
316 * Possible exception types are:
317 * com.sun.star.lang.IllegalArgumentException,
318 * com.sun.star.lang.WrappedTargetException,
319 * com.sun.star.container.ElementExistException,
320 * com.sun.star.beans.PropertyVetoException,
321 * com.sun.star.beans.UnknownPropertyException,
322 * com.sun.star.uno.Exception
324 ex.printStackTrace(System.err);
326 return xFixedText;
330 private XTextComponent insertCurrencyField(XTextListener _xTextListener, int _nPositionX, int _nPositionY, int _nWidth){
331 XTextComponent xTextComponent = null;
332 try{
333 // create a unique name by means of an own implementation...
334 String sName = createUniqueName(m_xDlgModelNameContainer, "CurrencyField");
336 // create a controlmodel at the multiservicefactory of the dialog model...
337 Object oCFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCurrencyFieldModel");
338 XMultiPropertySet xCFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel);
340 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
341 xCFModelMPSet.setPropertyValues(
342 new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
343 new Object[] { Integer.valueOf(12), sName, Integer.valueOf(_nPositionX), Integer.valueOf(_nPositionY), Integer.valueOf(_nWidth)});
345 // The controlmodel is not really available until inserted to the Dialog container
346 m_xDlgModelNameContainer.insertByName(sName, oCFModel);
347 XPropertySet xCFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oCFModel);
349 // The following properties may also be set with XMultiPropertySet but we
350 // use the XPropertySet interface merely for reasons of demonstration
351 xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Boolean.TRUE);
352 xCFModelPSet.setPropertyValue("CurrencySymbol", "$");
353 xCFModelPSet.setPropertyValue("Value", new Double(2.93));
355 // add a textlistener that is notified on each change of the controlvalue...
356 Object oCFControl = m_xDlgContainer.getControl(sName);
357 xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, oCFControl);
358 xTextComponent.addTextListener(_xTextListener);
359 } catch (com.sun.star.uno.Exception ex) {
360 /* perform individual exception handling here.
361 * Possible exception types are:
362 * com.sun.star.lang.IllegalArgumentException,
363 * com.sun.star.lang.WrappedTargetException,
364 * com.sun.star.container.ElementExistException,
365 * com.sun.star.beans.PropertyVetoException,
366 * com.sun.star.beans.UnknownPropertyException,
367 * com.sun.star.uno.Exception
369 ex.printStackTrace(System.err);
371 return xTextComponent;
376 private XPropertySet insertProgressBar(int _nPosX, int _nPosY, int _nWidth, int _nProgressMax){
377 XPropertySet xPBModelPSet = null;
378 try{
379 // create a unique name by means of an own implementation...
380 String sName = createUniqueName(m_xDlgModelNameContainer, "ProgressBar");
382 // create a controlmodel at the multiservicefactory of the dialog model...
383 Object oPBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlProgressBarModel");
385 XMultiPropertySet xPBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oPBModel);
386 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
387 xPBModelMPSet.setPropertyValues(
388 new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
389 new Object[] { Integer.valueOf(8), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
391 // The controlmodel is not really available until inserted to the Dialog container
392 m_xDlgModelNameContainer.insertByName(sName, oPBModel);
393 xPBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oPBModel);
395 // The following properties may also be set with XMultiPropertySet but we
396 // use the XPropertySet interface merely for reasons of demonstration
397 xPBModelPSet.setPropertyValue("ProgressValueMin", Integer.valueOf(0));
398 xPBModelPSet.setPropertyValue("ProgressValueMax", Integer.valueOf(_nProgressMax));
399 } catch (com.sun.star.uno.Exception ex) {
400 /* perform individual exception handling here.
401 * Possible exception types are:
402 * com.sun.star.lang.IllegalArgumentException,
403 * com.sun.star.lang.WrappedTargetException,
404 * com.sun.star.container.ElementExistException,
405 * com.sun.star.beans.PropertyVetoException,
406 * com.sun.star.beans.UnknownPropertyException,
407 * com.sun.star.uno.Exception
409 ex.printStackTrace(System.err);
411 return xPBModelPSet;
416 public void insertHorizontalFixedLine(int _nPosX, int _nPosY, int _nWidth, String _sLabel){
417 try{
418 // create a unique name by means of an own implementation...
419 String sName = createUniqueName(m_xDlgModelNameContainer, "FixedLine");
421 // create a controlmodel at the multiservicefactory of the dialog model...
422 Object oFLModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedLineModel");
423 XMultiPropertySet xFLModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFLModel);
425 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
426 xFLModelMPSet.setPropertyValues(
427 new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"},
428 new Object[] { Integer.valueOf(8), sName, Integer.valueOf(0), Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
430 // The controlmodel is not really available until inserted to the Dialog container
431 m_xDlgModelNameContainer.insertByName(sName, oFLModel);
433 // The following property may also be set with XMultiPropertySet but we
434 // use the XPropertySet interface merely for reasons of demonstration
435 XPropertySet xFLPSet = UnoRuntime.queryInterface(XPropertySet.class, oFLModel);
436 xFLPSet.setPropertyValue("Label", _sLabel);
437 } catch (com.sun.star.uno.Exception ex) {
438 /* perform individual exception handling here.
439 * Possible exception types are:
440 * com.sun.star.lang.IllegalArgumentException,
441 * com.sun.star.lang.WrappedTargetException,
442 * com.sun.star.container.ElementExistException,
443 * com.sun.star.beans.PropertyVetoException,
444 * com.sun.star.beans.UnknownPropertyException,
445 * com.sun.star.uno.Exception
447 ex.printStackTrace(System.err);
453 private void insertGroupBox(int _nPosX, int _nPosY, int _nHeight, int _nWidth){
454 try{
455 // create a unique name by means of an own implementation...
456 String sName = createUniqueName(m_xDlgModelNameContainer, "FrameControl");
458 // create a controlmodel at the multiservicefactory of the dialog model...
459 Object oGBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlGroupBoxModel");
460 XMultiPropertySet xGBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oGBModel);
462 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
463 xGBModelMPSet.setPropertyValues(
464 new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
465 new Object[] { Integer.valueOf(_nHeight), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
467 // The controlmodel is not really available until inserted to the Dialog container
468 m_xDlgModelNameContainer.insertByName(sName, oGBModel);
470 // The following property may also be set with XMultiPropertySet but we
471 // use the XPropertySet interface merely for reasons of demonstration
472 XPropertySet xGBPSet = UnoRuntime.queryInterface(XPropertySet.class, oGBModel);
473 xGBPSet.setPropertyValue("Label", "~My GroupBox");
474 } catch (com.sun.star.uno.Exception ex) {
475 /* perform individual exception handling here.
476 * Possible exception types are:
477 * com.sun.star.lang.IllegalArgumentException,
478 * com.sun.star.lang.WrappedTargetException,
479 * com.sun.star.container.ElementExistException,
480 * com.sun.star.beans.PropertyVetoException,
481 * com.sun.star.beans.UnknownPropertyException,
482 * com.sun.star.uno.Exception
484 ex.printStackTrace(System.err);
490 private XTextComponent insertEditField(XTextListener _xTextListener, XFocusListener _xFocusListener, int _nPosX, int _nPosY, int _nWidth){
491 XTextComponent xTextComponent = null;
492 try{
493 // create a unique name by means of an own implementation...
494 String sName = createUniqueName(m_xDlgModelNameContainer, "TextField");
496 // create a controlmodel at the multiservicefactory of the dialog model...
497 Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel");
498 XMultiPropertySet xTFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel);
500 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
501 xTFModelMPSet.setPropertyValues(
502 new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"},
503 new Object[] { Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), "MyText", Integer.valueOf(_nWidth)});
505 // The controlmodel is not really available until inserted to the Dialog container
506 m_xDlgModelNameContainer.insertByName(sName, oTFModel);
507 XPropertySet xTFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oTFModel);
509 // The following property may also be set with XMultiPropertySet but we
510 // use the XPropertySet interface merely for reasons of demonstration
511 xTFModelPSet.setPropertyValue("EchoChar", Short.valueOf((short) '*'));
512 XControl xTFControl = m_xDlgContainer.getControl(sName);
514 // add a textlistener that is notified on each change of the controlvalue...
515 xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xTFControl);
516 XWindow xTFWindow = UnoRuntime.queryInterface(XWindow.class, xTFControl);
517 xTFWindow.addFocusListener(_xFocusListener);
518 xTextComponent.addTextListener(_xTextListener);
519 xTFWindow.addKeyListener(this);
520 } catch (com.sun.star.uno.Exception ex) {
521 /* perform individual exception handling here.
522 * Possible exception types are:
523 * com.sun.star.lang.IllegalArgumentException,
524 * com.sun.star.lang.WrappedTargetException,
525 * com.sun.star.container.ElementExistException,
526 * com.sun.star.beans.PropertyVetoException,
527 * com.sun.star.beans.UnknownPropertyException,
528 * com.sun.star.uno.Exception
530 ex.printStackTrace(System.err);
532 return xTextComponent;
535 private XPropertySet insertTimeField(int _nPosX, int _nPosY, int _nWidth, Time _aTime, Time _aTimeMin, Time _aTimeMax){
536 XPropertySet xTFModelPSet = null;
537 try{
538 // create a unique name by means of an own implementation...
539 String sName = createUniqueName(m_xDlgModelNameContainer, "TimeField");
541 // create a controlmodel at the multiservicefactory of the dialog model...
542 Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlTimeFieldModel");
543 XMultiPropertySet xTFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel);
545 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
546 xTFModelMPSet.setPropertyValues(
547 new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "Width"},
548 new Object[] { Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Boolean.TRUE, Integer.valueOf(_nWidth)});
550 // The controlmodel is not really available until inserted to the Dialog container
551 m_xDlgModelNameContainer.insertByName(sName, oTFModel);
552 xTFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oTFModel);
554 // The following properties may also be set with XMultiPropertySet but we
555 // use the XPropertySet interface merely for reasons of demonstration
556 xTFModelPSet.setPropertyValue("TimeFormat", Short.valueOf((short) 5));
557 xTFModelPSet.setPropertyValue("TimeMin", _aTimeMin);
558 xTFModelPSet.setPropertyValue("TimeMax", _aTimeMax);
559 xTFModelPSet.setPropertyValue("Time", _aTime);
560 } catch (com.sun.star.uno.Exception ex) {
561 /* perform individual exception handling here.
562 * Possible exception types are:
563 * com.sun.star.lang.IllegalArgumentException,
564 * com.sun.star.lang.WrappedTargetException,
565 * com.sun.star.container.ElementExistException,
566 * com.sun.star.beans.PropertyVetoException,
567 * com.sun.star.beans.UnknownPropertyException,
568 * com.sun.star.uno.Exception
570 ex.printStackTrace(System.err);
572 return xTFModelPSet;
577 private XPropertySet insertDateField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth){
578 XPropertySet xDFModelPSet = null;
579 try{
580 // create a unique name by means of an own implementation...
581 String sName = createUniqueName(m_xDlgModelNameContainer, "DateField");
583 // create a controlmodel at the multiservicefactory of the dialog model...
584 Object oDFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlDateFieldModel");
585 XMultiPropertySet xDFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oDFModel);
587 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
588 xDFModelMPSet.setPropertyValues(
589 new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Width"},
590 new Object[] {Boolean.TRUE, Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
592 // The controlmodel is not really available until inserted to the Dialog container
593 m_xDlgModelNameContainer.insertByName(sName, oDFModel);
594 xDFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oDFModel);
596 // The following properties may also be set with XMultiPropertySet but we
597 // use the XPropertySet interface merely for reasons of demonstration
598 xDFModelPSet.setPropertyValue("DateFormat", Short.valueOf((short) 7));
599 xDFModelPSet.setPropertyValue("DateMin", new Date((short)1, (short)4, (short)2007));
600 xDFModelPSet.setPropertyValue("DateMax", new Date((short)1, (short)5, (short)2007));
601 xDFModelPSet.setPropertyValue("Date", new Date((short)15, (short)4, (short)2000));
602 Object oDFControl = m_xDlgContainer.getControl(sName);
604 // add a SpinListener that is notified on each change of the controlvalue...
605 XSpinField xSpinField = UnoRuntime.queryInterface(XSpinField.class, oDFControl);
606 xSpinField.addSpinListener(_xSpinListener);
607 } catch (com.sun.star.uno.Exception ex) {
608 /* perform individual exception handling here.
609 * Possible exception types are:
610 * com.sun.star.lang.IllegalArgumentException,
611 * com.sun.star.lang.WrappedTargetException,
612 * com.sun.star.container.ElementExistException,
613 * com.sun.star.beans.PropertyVetoException,
614 * com.sun.star.beans.UnknownPropertyException,
615 * com.sun.star.uno.Exception
617 ex.printStackTrace(System.err);
619 return xDFModelPSet;
623 private XPropertySet insertPatternField(int _nPosX, int _nPosY, int _nWidth){
624 XPropertySet xPFModelPSet = null;
625 try{
626 // create a unique name by means of an own implementation...
627 String sName = createUniqueName(m_xDlgModelNameContainer, "PatternField");
629 // create a controlmodel at the multiservicefactory of the dialog model...
630 Object oPFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlPatternFieldModel");
631 XMultiPropertySet xPFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oPFModel);
633 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
634 xPFModelMPSet.setPropertyValues(
635 new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
636 new Object[] { Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
638 // The controlmodel is not really available until inserted to the Dialog container
639 m_xDlgModelNameContainer.insertByName(sName, oPFModel);
640 xPFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oPFModel);
642 // The following properties may also be set with XMultiPropertySet but we
643 // use the XPropertySet interface merely for reasons of demonstration
644 xPFModelPSet.setPropertyValue("LiteralMask", "__.05.2007");
645 // Allow only numbers for the first two digits...
646 xPFModelPSet.setPropertyValue("EditMask", "NNLLLLLLLL");
647 // verify the user input immediately...
648 xPFModelPSet.setPropertyValue("StrictFormat", Boolean.TRUE);
649 } catch (com.sun.star.uno.Exception ex) {
650 /* perform individual exception handling here.
651 * Possible exception types are:
652 * com.sun.star.lang.IllegalArgumentException,
653 * com.sun.star.lang.WrappedTargetException,
654 * com.sun.star.container.ElementExistException,
655 * com.sun.star.beans.PropertyVetoException,
656 * com.sun.star.beans.UnknownPropertyException,
657 * com.sun.star.uno.Exception
659 ex.printStackTrace(System.err);
661 return xPFModelPSet;
665 private XPropertySet insertNumericField( int _nPosX, int _nPosY, int _nWidth,
666 double _fValueMin, double _fValueMax, double _fValue,
667 double _fValueStep, short _nDecimalAccuracy){
668 XPropertySet xNFModelPSet = null;
669 try{
670 // create a unique name by means of an own implementation...
671 String sName = createUniqueName(m_xDlgModelNameContainer, "NumericField");
673 // create a controlmodel at the multiservicefactory of the dialog model...
674 Object oNFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel");
675 XMultiPropertySet xNFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oNFModel);
676 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
677 xNFModelMPSet.setPropertyValues(
678 new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "StrictFormat", "Width"},
679 new Object[] { Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Boolean.TRUE, Boolean.TRUE, Integer.valueOf(_nWidth)});
681 // The controlmodel is not really available until inserted to the Dialog container
682 m_xDlgModelNameContainer.insertByName(sName, oNFModel);
683 xNFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oNFModel);
684 // The following properties may also be set with XMultiPropertySet but we
685 // use the XPropertySet interface merely for reasons of demonstration
686 xNFModelPSet.setPropertyValue("ValueMin", new Double(_fValueMin));
687 xNFModelPSet.setPropertyValue("ValueMax", new Double(_fValueMax));
688 xNFModelPSet.setPropertyValue("Value", new Double(_fValue));
689 xNFModelPSet.setPropertyValue("ValueStep", new Double(_fValueStep));
690 xNFModelPSet.setPropertyValue("ShowThousandsSeparator", Boolean.TRUE);
691 xNFModelPSet.setPropertyValue("DecimalAccuracy", Short.valueOf(_nDecimalAccuracy));
692 } catch (com.sun.star.uno.Exception ex) {
693 /* perform individual exception handling here.
694 * Possible exception types are:
695 * com.sun.star.lang.IllegalArgumentException,
696 * com.sun.star.lang.WrappedTargetException,
697 * com.sun.star.container.ElementExistException,
698 * com.sun.star.beans.PropertyVetoException,
699 * com.sun.star.beans.UnknownPropertyException,
700 * com.sun.star.uno.Exception
702 ex.printStackTrace(System.err);
704 return xNFModelPSet;
709 private XPropertySet insertVerticalScrollBar(XAdjustmentListener _xAdjustmentListener, int _nPosX, int _nPosY, int _nHeight){
710 XPropertySet xSBModelPSet = null;
711 try{
712 // create a unique name by means of an own implementation...
713 String sName = createUniqueName(m_xDlgModelNameContainer, "ScrollBar");
715 Integer NOrientation = Integer.valueOf(com.sun.star.awt.ScrollBarOrientation.VERTICAL);
717 // create a controlmodel at the multiservicefactory of the dialog model...
718 Object oSBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel");
719 XMultiPropertySet xSBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oSBModel);
720 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
721 xSBModelMPSet.setPropertyValues(
722 new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"},
723 new Object[] { Integer.valueOf(_nHeight), sName, NOrientation, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(8)});
725 // The controlmodel is not really available until inserted to the Dialog container
726 m_xDlgModelNameContainer.insertByName(sName, oSBModel);
728 xSBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oSBModel);
729 // The following properties may also be set with XMultiPropertySet but we
730 // use the XPropertySet interface merely for reasons of demonstration
731 xSBModelPSet.setPropertyValue("ScrollValueMin", Integer.valueOf(0));
732 xSBModelPSet.setPropertyValue("ScrollValueMax", Integer.valueOf(100));
733 xSBModelPSet.setPropertyValue("ScrollValue", Integer.valueOf(5));
734 xSBModelPSet.setPropertyValue("LineIncrement", Integer.valueOf(2));
735 xSBModelPSet.setPropertyValue("BlockIncrement", Integer.valueOf(10));
737 // Add an Adjustment that will listen to changes of the scrollbar...
738 XControl xSBControl = m_xDlgContainer.getControl(sName);
739 XScrollBar xScrollBar = UnoRuntime.queryInterface(XScrollBar.class, xSBControl);
740 xScrollBar.addAdjustmentListener(_xAdjustmentListener);
741 } catch (com.sun.star.uno.Exception ex) {
742 /* perform individual exception handling here.
743 * Possible exception types are:
744 * com.sun.star.lang.IllegalArgumentException,
745 * com.sun.star.lang.WrappedTargetException,
746 * com.sun.star.container.ElementExistException,
747 * com.sun.star.beans.PropertyVetoException,
748 * com.sun.star.beans.UnknownPropertyException,
749 * com.sun.star.uno.Exception
751 ex.printStackTrace(System.err);
753 return xSBModelPSet;
757 /** makes a String unique by appending a numerical suffix
758 * @param _xElementContainer the com.sun.star.container.XNameAccess container
759 * that the new Element is going to be inserted to
760 * @param _sElementName the StemName of the Element
762 public static String createUniqueName(XNameAccess _xElementContainer, String _sElementName) {
763 boolean bElementexists = true;
764 int i = 1;
765 String BaseName = _sElementName;
766 while (bElementexists) {
767 bElementexists = _xElementContainer.hasByName(_sElementName);
768 if (bElementexists) {
769 i += 1;
770 _sElementName = BaseName + Integer.toString(i);
773 return _sElementName;
777 private XCheckBox insertCheckBox(XItemListener _xItemListener, int _nPosX, int _nPosY, int _nWidth){
778 XCheckBox xCheckBox = null;
779 try{
780 // create a unique name by means of an own implementation...
781 String sName = createUniqueName(m_xDlgModelNameContainer, "CheckBox");
783 // create a controlmodel at the multiservicefactory of the dialog model...
784 Object oCBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel");
786 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
787 XMultiPropertySet xCBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oCBModel);
788 xCBMPSet.setPropertyValues(
789 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width" } ,
790 new Object[] {Integer.valueOf(8), "~Include page number", sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nWidth)});
792 // The following property may also be set with XMultiPropertySet but we
793 // use the XPropertySet interface merely for reasons of demonstration
794 XPropertySet xCBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xCBMPSet);
795 xCBModelPSet.setPropertyValue("TriState", Boolean.TRUE);
796 xCBModelPSet.setPropertyValue("State", Short.valueOf((short) 1));
798 // add the model to the NameContainer of the dialog model
799 m_xDlgModelNameContainer.insertByName(sName, oCBModel);
800 XControl xCBControl = m_xDlgContainer.getControl(sName);
801 xCheckBox = UnoRuntime.queryInterface(XCheckBox.class, xCBControl);
802 // An ActionListener will be notified on the activation of the button...
803 xCheckBox.addItemListener(_xItemListener);
804 } catch (com.sun.star.uno.Exception ex) {
805 /* perform individual exception handling here.
806 * Possible exception types are:
807 * com.sun.star.lang.IllegalArgumentException,
808 * com.sun.star.lang.WrappedTargetException,
809 * com.sun.star.container.ElementExistException,
810 * com.sun.star.beans.PropertyVetoException,
811 * com.sun.star.beans.UnknownPropertyException,
812 * com.sun.star.uno.Exception
814 ex.printStackTrace(System.err);
816 return xCheckBox;
822 private void insertRadioButtonGroup(short _nTabIndex, int _nPosX, int _nPosY, int _nWidth){
823 try{
824 // create a unique name by means of an own implementation...
825 String sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton");
827 // create a controlmodel at the multiservicefactory of the dialog model...
828 Object oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel");
829 XMultiPropertySet xRBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel);
830 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
831 xRBMPSet.setPropertyValues(
832 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "State", "TabIndex", "Width" } ,
833 new Object[] {Integer.valueOf(8), "~First Option", sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Short.valueOf((short) 1), Short.valueOf(_nTabIndex++),Integer.valueOf(_nWidth)});
834 // add the model to the NameContainer of the dialog model
835 m_xDlgModelNameContainer.insertByName(sName, oRBModel);
837 // create a unique name by means of an own implementation...
838 sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton");
840 oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel");
841 xRBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel);
842 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
843 xRBMPSet.setPropertyValues(
844 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width" } ,
845 new Object[] {Integer.valueOf(8), "~Second Option", sName, Integer.valueOf(130), Integer.valueOf(214), Short.valueOf(_nTabIndex), Integer.valueOf(150)});
846 // add the model to the NameContainer of the dialog model
847 m_xDlgModelNameContainer.insertByName(sName, oRBModel);
848 } catch (com.sun.star.uno.Exception ex) {
849 /* perform individual exception handling here.
850 * Possible exception types are:
851 * com.sun.star.lang.IllegalArgumentException,
852 * com.sun.star.lang.WrappedTargetException,
853 * com.sun.star.container.ElementExistException,
854 * com.sun.star.beans.PropertyVetoException,
855 * com.sun.star.beans.UnknownPropertyException,
856 * com.sun.star.uno.Exception
858 ex.printStackTrace(System.err);
863 private XListBox insertListBox(int _nPosX, int _nPosY, int _nWidth, int _nStep, String[] _sStringItemList){
864 XListBox xListBox = null;
865 try{
866 // create a unique name by means of an own implementation...
867 String sName = createUniqueName(m_xDlgModelNameContainer, "ListBox");
869 // create a controlmodel at the multiservicefactory of the dialog model...
870 Object oListBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel");
871 XMultiPropertySet xLBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel);
872 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
873 xLBModelMPSet.setPropertyValues(
874 new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Step", "StringItemList", "Width" } ,
875 new Object[] {Boolean.TRUE, Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Integer.valueOf(_nStep), _sStringItemList, Integer.valueOf(_nWidth)});
876 // The following property may also be set with XMultiPropertySet but we
877 // use the XPropertySet interface merely for reasons of demonstration
878 XPropertySet xLBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xLBModelMPSet);
879 xLBModelPSet.setPropertyValue("MultiSelection", Boolean.TRUE);
880 short[] nSelItems = new short[] {(short) 1, (short) 3};
881 xLBModelPSet.setPropertyValue("SelectedItems", nSelItems);
882 // add the model to the NameContainer of the dialog model
883 m_xDlgModelNameContainer.insertByName(sName, xLBModelMPSet);
884 XControl xControl = m_xDlgContainer.getControl(sName);
885 // retrieve a ListBox that is more convenient to work with than the Model of the ListBox...
886 xListBox = UnoRuntime.queryInterface(XListBox.class, xControl);
887 } catch (com.sun.star.uno.Exception ex) {
888 /* perform individual exception handling here.
889 * Possible exception types are:
890 * com.sun.star.lang.IllegalArgumentException,
891 * com.sun.star.lang.WrappedTargetException,
892 * com.sun.star.container.ElementExistException,
893 * com.sun.star.beans.PropertyVetoException,
894 * com.sun.star.beans.UnknownPropertyException,
895 * com.sun.star.uno.Exception
897 ex.printStackTrace(System.err);
899 return xListBox;
903 private XComboBox insertComboBox(int _nPosX, int _nPosY, int _nWidth){
904 XComboBox xComboBox = null;
905 try{
906 // create a unique name by means of an own implementation...
907 String sName = createUniqueName(m_xDlgModelNameContainer, "ComboBox");
909 String[] sStringItemList = new String[]{"First Entry", "Second Entry", "Third Entry", "Fourth Entry"};
911 // create a controlmodel at the multiservicefactory of the dialog model...
912 Object oComboBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlComboBoxModel");
913 XMultiPropertySet xCbBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oComboBoxModel);
914 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
915 xCbBModelMPSet.setPropertyValues(
916 new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "StringItemList", "Width" } ,
917 new Object[] {Boolean.TRUE, Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), sStringItemList, Integer.valueOf(_nWidth)});
919 // The following property may also be set with XMultiPropertySet but we
920 // use the XPropertySet interface merely for reasons of demonstration
921 XPropertySet xCbBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xCbBModelMPSet);
922 xCbBModelPSet.setPropertyValue("MaxTextLen", Short.valueOf((short) 10));
923 xCbBModelPSet.setPropertyValue("ReadOnly", Boolean.FALSE);
925 // add the model to the NameContainer of the dialog model
926 m_xDlgModelNameContainer.insertByName(sName, xCbBModelMPSet);
927 XControl xControl = m_xDlgContainer.getControl(sName);
929 // retrieve a ListBox that is more convenient to work with than the Model of the ListBox...
930 xComboBox = UnoRuntime.queryInterface(XComboBox.class, xControl);
931 } catch (com.sun.star.uno.Exception ex) {
932 /* perform individual exception handling here.
933 * Possible exception types are:
934 * com.sun.star.lang.IllegalArgumentException,
935 * com.sun.star.lang.WrappedTargetException,
936 * com.sun.star.container.ElementExistException,
937 * com.sun.star.beans.PropertyVetoException,
938 * com.sun.star.beans.UnknownPropertyException,
939 * com.sun.star.uno.Exception
941 ex.printStackTrace(System.err);
943 return xComboBox;
948 private XPropertySet insertFormattedField(XSpinListener _xSpinListener, int _nPosX, int _nPosY, int _nWidth){
949 XPropertySet xFFModelPSet = null;
950 try{
951 // create a unique name by means of an own implementation...
952 String sName = createUniqueName(m_xDlgModelNameContainer, "FormattedField");
954 // create a controlmodel at the multiservicefactory of the dialog model...
955 Object oFFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFormattedFieldModel");
956 XMultiPropertySet xFFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFFModel);
957 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
958 xFFModelMPSet.setPropertyValues(
959 new String[] {"EffectiveValue", "Height", "Name", "PositionX", "PositionY", "StrictFormat", "Spin", "Width"},
960 new Object[] { new Double(12348), Integer.valueOf(12), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Boolean.TRUE, Boolean.TRUE, Integer.valueOf(_nWidth)});
962 xFFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oFFModel);
963 // to define a numberformat you always need a locale...
964 com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale();
965 aLocale.Country = "US";
966 aLocale.Language = "en";
967 // this Format is only compliant to the english locale!
968 String sFormatString = "NNNNMMMM DD, YYYY";
970 // a NumberFormatsSupplier has to be created first "in the open countryside"...
971 Object oNumberFormatsSupplier = m_xMCF.createInstanceWithContext("com.sun.star.util.NumberFormatsSupplier", m_xContext);
972 XNumberFormatsSupplier xNumberFormatsSupplier = UnoRuntime.queryInterface(XNumberFormatsSupplier.class, oNumberFormatsSupplier);
973 XNumberFormats xNumberFormats = xNumberFormatsSupplier.getNumberFormats();
974 // is the numberformat already defined?
975 int nFormatKey = xNumberFormats.queryKey(sFormatString, aLocale, true);
976 if (nFormatKey == -1){
977 // if not then add it to the NumberFormatsSupplier
978 nFormatKey = xNumberFormats.addNew(sFormatString, aLocale);
981 // The following property may also be set with XMultiPropertySet but we
982 // use the XPropertySet interface merely for reasons of demonstration
983 xFFModelPSet.setPropertyValue("FormatsSupplier", xNumberFormatsSupplier);
984 xFFModelPSet.setPropertyValue("FormatKey", Integer.valueOf(nFormatKey));
986 // The controlmodel is not really available until inserted to the Dialog container
987 m_xDlgModelNameContainer.insertByName(sName, oFFModel);
989 // finally we add a Spin-Listener to the control
990 XControl xFFControl = m_xDlgContainer.getControl(sName);
991 // add a SpinListener that is notified on each change of the controlvalue...
992 XSpinField xSpinField = UnoRuntime.queryInterface(XSpinField.class, xFFControl);
993 xSpinField.addSpinListener(_xSpinListener);
995 } catch (com.sun.star.uno.Exception ex) {
996 /* perform individual exception handling here.
997 * Possible exception types are:
998 * com.sun.star.lang.IllegalArgumentException,
999 * com.sun.star.lang.WrappedTargetException,
1000 * com.sun.star.container.ElementExistException,
1001 * com.sun.star.beans.PropertyVetoException,
1002 * com.sun.star.beans.UnknownPropertyException,
1003 * com.sun.star.uno.Exception
1005 ex.printStackTrace(System.err);
1007 return xFFModelPSet;
1013 private XTextComponent insertFileControl(XTextListener _xTextListener, int _nPosX, int _nPosY, int _nWidth){
1014 XTextComponent xTextComponent = null;
1015 try{
1016 // create a unique name by means of an own implementation...
1017 String sName = createUniqueName(m_xDlgModelNameContainer, "FileControl");
1019 // retrieve the configured Work path...
1020 Object oPathSettings = thePathSettings.get(m_xContext);
1021 XPropertySet xPropertySet = com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings);
1022 String sWorkUrl = (String) xPropertySet.getPropertyValue("Work");
1024 // convert the Url to a system path that is "human readable"...
1025 Object oFCProvider = m_xMCF.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", m_xContext);
1026 XFileIdentifierConverter xFileIdentifierConverter = UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider);
1027 String sSystemWorkPath = xFileIdentifierConverter.getSystemPathFromFileURL(sWorkUrl);
1029 // create a controlmodel at the multiservicefactory of the dialog model...
1030 Object oFCModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFileControlModel");
1032 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
1033 XMultiPropertySet xFCModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFCModel);
1034 xFCModelMPSet.setPropertyValues(
1035 new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"},
1036 new Object[] { Integer.valueOf(14), sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), sSystemWorkPath, Integer.valueOf(_nWidth)});
1038 // The controlmodel is not really available until inserted to the Dialog container
1039 m_xDlgModelNameContainer.insertByName(sName, oFCModel);
1040 XPropertySet xFCModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oFCModel);
1042 // add a textlistener that is notified on each change of the controlvalue...
1043 XControl xFCControl = m_xDlgContainer.getControl(sName);
1044 xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xFCControl);
1045 XWindow xFCWindow = UnoRuntime.queryInterface(XWindow.class, xFCControl);
1046 xTextComponent.addTextListener(_xTextListener);
1047 } catch (com.sun.star.uno.Exception ex) {
1048 /* perform individual exception handling here.
1049 * Possible exception types are:
1050 * com.sun.star.lang.IllegalArgumentException,
1051 * com.sun.star.lang.WrappedTargetException,
1052 * com.sun.star.container.ElementExistException,
1053 * com.sun.star.beans.PropertyVetoException,
1054 * com.sun.star.beans.UnknownPropertyException,
1055 * com.sun.star.uno.Exception
1057 ex.printStackTrace(System.err);
1059 return xTextComponent;
1063 public XButton insertButton(XActionListener _xActionListener, int _nPosX, int _nPosY, int _nWidth, String _sLabel, short _nPushButtonType){
1064 XButton xButton = null;
1065 try{
1066 // create a unique name by means of an own implementation...
1067 String sName = createUniqueName(m_xDlgModelNameContainer, "CommandButton");
1069 // create a controlmodel at the multiservicefactory of the dialog model...
1070 Object oButtonModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel");
1071 XMultiPropertySet xButtonMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oButtonModel);
1072 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
1073 xButtonMPSet.setPropertyValues(
1074 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "PushButtonType", "Width" } ,
1075 new Object[] {Integer.valueOf(14), _sLabel, sName, Integer.valueOf(_nPosX), Integer.valueOf(_nPosY), Short.valueOf(_nPushButtonType), Integer.valueOf(_nWidth)});
1077 // add the model to the NameContainer of the dialog model
1078 m_xDlgModelNameContainer.insertByName(sName, oButtonModel);
1079 XControl xButtonControl = m_xDlgContainer.getControl(sName);
1080 xButton = UnoRuntime.queryInterface(XButton.class, xButtonControl);
1081 // An ActionListener will be notified on the activation of the button...
1082 xButton.addActionListener(_xActionListener);
1083 } catch (com.sun.star.uno.Exception ex) {
1084 /* perform individual exception handling here.
1085 * Possible exception types are:
1086 * com.sun.star.lang.IllegalArgumentException,
1087 * com.sun.star.lang.WrappedTargetException,
1088 * com.sun.star.container.ElementExistException,
1089 * com.sun.star.beans.PropertyVetoException,
1090 * com.sun.star.beans.UnknownPropertyException,
1091 * com.sun.star.uno.Exception
1093 ex.printStackTrace(System.err);
1095 return xButton;
1100 public XFrame getCurrentFrame(){
1101 XFrame xRetFrame = null;
1102 try {
1103 Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
1104 XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
1105 xRetFrame = xDesktop.getCurrentFrame();
1106 } catch (com.sun.star.uno.Exception ex) {
1107 ex.printStackTrace();
1109 return xRetFrame;
1113 public void textChanged(TextEvent textEvent) {
1114 try {
1115 // get the control that has fired the event,
1116 XControl xControl = UnoRuntime.queryInterface(XControl.class, textEvent.Source);
1117 XControlModel xControlModel = xControl.getModel();
1118 XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel);
1119 String sName = (String) xPSet.getPropertyValue("Name");
1120 // just in case the listener has been added to several controls,
1121 // we make sure we refer to the right one
1122 if (sName.equals("TextField1")){
1123 String sText = (String) xPSet.getPropertyValue("Text");
1124 System.out.println(sText);
1125 // insert your code here to validate the text of the control...
1127 }catch (com.sun.star.uno.Exception ex){
1128 /* perform individual exception handling here.
1129 * Possible exception types are:
1130 * com.sun.star.lang.WrappedTargetException,
1131 * com.sun.star.beans.UnknownPropertyException,
1132 * com.sun.star.uno.Exception
1134 ex.printStackTrace(System.err);
1140 public void up(SpinEvent spinEvent) {
1141 try {
1142 // get the control that has fired the event,
1143 XControl xControl = UnoRuntime.queryInterface(XControl.class, spinEvent.Source);
1144 XControlModel xControlModel = xControl.getModel();
1145 XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel);
1146 String sName = (String) xPSet.getPropertyValue("Name");
1147 // just in case the listener has been added to several controls,
1148 // we make sure we refer to the right one
1149 if (sName.equals("FormattedField1")){
1150 double fvalue = AnyConverter.toDouble(xPSet.getPropertyValue("EffectiveValue"));
1151 System.out.println("Controlvalue: " + fvalue);
1152 // insert your code here to validate the value of the control...
1154 }catch (com.sun.star.uno.Exception ex){
1155 /* perform individual exception handling here.
1156 * Possible exception types are:
1157 * com.sun.star.lang.WrappedTargetException,
1158 * com.sun.star.beans.UnknownPropertyException,
1159 * com.sun.star.uno.Exception
1161 ex.printStackTrace(System.err);
1166 public void down(SpinEvent spinEvent) {
1169 public void last(SpinEvent spinEvent) {
1172 public void first(SpinEvent spinEvent) {
1175 public void disposing(EventObject rEventObject) {
1179 public void actionPerformed(ActionEvent rEvent) {
1180 try{
1181 // get the control that has fired the event,
1182 XControl xControl = UnoRuntime.queryInterface(XControl.class, rEvent.Source);
1183 XControlModel xControlModel = xControl.getModel();
1184 XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel);
1185 String sName = (String) xPSet.getPropertyValue("Name");
1186 // just in case the listener has been added to several controls,
1187 // we make sure we refer to the right one
1188 if (sName.equals("CommandButton1")) {
1191 }catch (com.sun.star.uno.Exception ex){
1192 /* perform individual exception handling here.
1193 * Possible exception types are:
1194 * com.sun.star.lang.WrappedTargetException,
1195 * com.sun.star.beans.UnknownPropertyException,
1196 * com.sun.star.uno.Exception
1198 ex.printStackTrace(System.err);
1203 public void focusLost(FocusEvent _focusEvent) {
1204 short nFocusFlags = _focusEvent.FocusFlags;
1205 int nFocusChangeReason = nFocusFlags & FocusChangeReason.TAB;
1206 if (nFocusChangeReason == FocusChangeReason.TAB) {
1207 // get the window of the Window that has gained the Focus...
1208 // Note that the xWindow is just a representation of the controlwindow
1209 // but not of the control itself
1210 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, _focusEvent.NextFocus);
1215 public void focusGained(FocusEvent focusEvent) {
1218 public void mouseReleased(MouseEvent mouseEvent) {
1221 public void mousePressed(MouseEvent mouseEvent) {
1224 public void mouseExited(MouseEvent mouseEvent) {
1227 public void mouseEntered(MouseEvent _mouseEvent) {
1228 try {
1229 // retrieve the control that the event has been invoked at...
1230 XControl xControl = UnoRuntime.queryInterface(XControl.class, _mouseEvent.Source);
1231 Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext);
1232 XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, tk);
1233 // create the peer of the control by passing the windowpeer of the parent
1234 // in this case the windowpeer of the control
1235 xControl.createPeer(xToolkit, m_xWindowPeer);
1236 // create a pointer object "in the open countryside" and set the type accordingly...
1237 Object oPointer = this.m_xMCF.createInstanceWithContext("com.sun.star.awt.Pointer", this.m_xContext);
1238 XPointer xPointer = UnoRuntime.queryInterface(XPointer.class, oPointer);
1239 xPointer.setType(com.sun.star.awt.SystemPointer.REFHAND);
1240 // finally set the created pointer at the windowpeer of the control
1241 xControl.getPeer().setPointer(xPointer);
1242 } catch (com.sun.star.uno.Exception ex) {
1243 throw new java.lang.RuntimeException("cannot happen...", ex);
1249 public void itemStateChanged(ItemEvent itemEvent) {
1250 try{
1251 // retrieve the control that the event has been invoked at...
1252 XCheckBox xCheckBox = UnoRuntime.queryInterface(XCheckBox.class, itemEvent.Source);
1253 // retrieve the control that we want to disable or enable
1254 XControl xControl = UnoRuntime.queryInterface(XControl.class, m_xDlgContainer.getControl("CommandButton1"));
1255 XPropertySet xModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel());
1256 short nState = xCheckBox.getState();
1257 boolean bdoEnable = true;
1258 switch (nState){
1259 case 1: // checked
1260 bdoEnable = true;
1261 break;
1262 case 0: // not checked
1263 case 2: // don't know
1264 bdoEnable = false;
1265 break;
1267 // Alternatively we could have done it also this way:
1268 // bdoEnable = (nState == 1);
1269 xModelPropertySet.setPropertyValue("Enabled", Boolean.valueOf(bdoEnable));
1270 }catch (com.sun.star.uno.Exception ex){
1271 /* perform individual exception handling here.
1272 * Possible exception types are:
1273 * com.sun.star.lang.IllegalArgumentException
1274 * com.sun.star.lang.WrappedTargetException,
1275 * com.sun.star.beans.UnknownPropertyException,
1276 * com.sun.star.beans.PropertyVetoException
1277 * com.sun.star.uno.Exception
1279 ex.printStackTrace(System.err);
1284 public void adjustmentValueChanged(AdjustmentEvent _adjustmentEvent) {
1285 switch (_adjustmentEvent.Type.getValue()){
1286 case AdjustmentType.ADJUST_ABS_value:
1287 System.out.println( "The event has been triggered by dragging the thumb..." );
1288 break;
1289 case AdjustmentType.ADJUST_LINE_value:
1290 System.out.println( "The event has been triggered by a single line move.." );
1291 break;
1292 case AdjustmentType.ADJUST_PAGE_value:
1293 System.out.println( "The event has been triggered by a block move..." );
1294 break;
1296 System.out.println( "The value of the scrollbar is: " + _adjustmentEvent.Value);
1301 // Globally available object variables of the roadmapmodel
1302 XPropertySet m_xRMPSet;
1303 private XSingleServiceFactory m_xSSFRoadmap;
1304 private XIndexContainer m_xRMIndexCont;
1306 public void addRoadmap() {
1307 XPropertySet xDialogModelPropertySet = null;
1308 try {
1309 // create a unique name by means of an own implementation...
1310 String sRoadmapName = createUniqueName(m_xDlgModelNameContainer, "Roadmap");
1312 xDialogModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel);
1313 // Similar to the office assistants the roadmap is adjusted to the height of the dialog
1314 // where a certain space is left at the bottom for the buttons...
1315 int nDialogHeight = ((Integer) xDialogModelPropertySet.getPropertyValue("Height")).intValue();
1317 // instantiate the roadmapmodel...
1318 Object oRoadmapModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRoadmapModel");
1320 // define the properties of the roadmapmodel
1321 XMultiPropertySet xRMMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRoadmapModel);
1322 xRMMPSet.setPropertyValues( new String[] {"Complete", "Height", "Name", "PositionX", "PositionY", "Text", "Width" },
1323 new Object[] {Boolean.FALSE, Integer.valueOf(nDialogHeight - 26), sRoadmapName, Integer.valueOf(0), Integer.valueOf(0), "Steps", Integer.valueOf(85)});
1324 m_xRMPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmapModel);
1326 // add the roadmapmodel to the dialog container..
1327 m_xDlgModelNameContainer.insertByName(sRoadmapName, oRoadmapModel);
1329 // the roadmapmodel is a SingleServiceFactory to instantiate the roadmapitems...
1330 m_xSSFRoadmap = UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmapModel);
1331 m_xRMIndexCont = UnoRuntime.queryInterface(XIndexContainer.class, oRoadmapModel);
1333 // add the itemlistener to the control...
1334 XControl xRMControl = this.m_xDlgContainer.getControl(sRoadmapName);
1335 XItemEventBroadcaster xRMBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRMControl);
1336 xRMBroadcaster.addItemListener( getRoadmapItemStateChangeListener() );
1337 } catch (java.lang.Exception jexception) {
1338 jexception.printStackTrace(System.err);
1343 *To fully understand the example one has to be aware that the passed ???Index??? parameter
1344 * refers to the position of the roadmap item in the roadmapmodel container
1345 * whereas the variable ???_ID??? directyl references to a certain step of dialog.
1347 public void insertRoadmapItem(int Index, boolean _bEnabled, String _sLabel, int _ID) {
1348 try {
1349 // a roadmap is a SingleServiceFactory that can only create roadmapitems that are the only possible
1350 // element types of the container
1351 Object oRoadmapItem = m_xSSFRoadmap.createInstance();
1352 XPropertySet xRMItemPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmapItem);
1353 xRMItemPSet.setPropertyValue("Label", _sLabel);
1354 // sometimes steps are supposed to be set disabled depending on the program logic...
1355 xRMItemPSet.setPropertyValue("Enabled", Boolean.valueOf(_bEnabled));
1356 // in this context the "ID" is meant to refer to a step of the dialog
1357 xRMItemPSet.setPropertyValue("ID", Integer.valueOf(_ID));
1358 m_xRMIndexCont.insertByIndex(Index, oRoadmapItem);
1359 } catch (com.sun.star.uno.Exception exception) {
1360 exception.printStackTrace(System.err);
1365 public void keyReleased(KeyEvent keyEvent) {
1368 public void keyPressed(KeyEvent keyEvent) {