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