2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com
.sun
.star
.awt
.MouseEvent
;
20 import com
.sun
.star
.awt
.Rectangle
;
21 import com
.sun
.star
.awt
.XControl
;
22 import com
.sun
.star
.awt
.XWindow
;
23 import com
.sun
.star
.beans
.XMultiPropertySet
;
24 import com
.sun
.star
.lang
.EventObject
;
25 import com
.sun
.star
.lang
.XMultiComponentFactory
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XComponentContext
;
30 public class UnoMenu2
extends UnoMenu
{
32 public UnoMenu2(XComponentContext _xContext
, XMultiComponentFactory _xMCF
) {
33 super(_xContext
, _xMCF
);
36 public static void main(String args
[]){
37 UnoMenu2 oUnoMenu2
= null;
39 XComponentContext xContext
= com
.sun
.star
.comp
.helper
.Bootstrap
.bootstrap();
41 System
.out
.println("Connected to a running office ...");
42 XMultiComponentFactory xMCF
= xContext
.getServiceManager();
43 oUnoMenu2
= new UnoMenu2(xContext
, xMCF
);
44 oUnoMenu2
.initialize( new String
[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"},
45 new Object
[] { Integer
.valueOf(140), Boolean
.TRUE
, "Dialog1", Integer
.valueOf(102),Integer
.valueOf(41), Integer
.valueOf(1), Short
.valueOf((short) 0), "Menu-Dialog", Integer
.valueOf(200)});
47 Object oFTHeaderModel
= oUnoMenu2
.m_xMSFDialogModel
.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
48 XMultiPropertySet xFTHeaderModelMPSet
= UnoRuntime
.queryInterface(XMultiPropertySet
.class, oFTHeaderModel
);
49 xFTHeaderModelMPSet
.setPropertyValues(
50 new String
[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
51 new Object
[] { Integer
.valueOf(8), "This code-sample demonstrates the creation of a popup-menu", "HeaderLabel", Integer
.valueOf(6), Integer
.valueOf(6), Integer
.valueOf(200)});
52 // add the model to the NameContainer of the dialog model
53 oUnoMenu2
.m_xDlgModelNameContainer
.insertByName("Headerlabel", oFTHeaderModel
);
54 oUnoMenu2
.addLabelForPopupMenu();
55 oUnoMenu2
.executeDialog();
56 }catch( Exception ex
) {
57 ex
.printStackTrace(System
.err
);
60 //make sure always to dispose the component and free the memory!
61 if (oUnoMenu2
!= null) {
62 if (oUnoMenu2
.m_xComponent
!= null){
63 oUnoMenu2
.m_xComponent
.dispose();
70 public void addLabelForPopupMenu(){
72 String sName
= "lblPopup";
73 Object oFTModel
= m_xMSFDialogModel
.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
74 XMultiPropertySet xFTModelMPSet
= UnoRuntime
.queryInterface(XMultiPropertySet
.class, oFTModel
);
75 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
76 xFTModelMPSet
.setPropertyValues(
77 new String
[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
78 new Object
[] { Integer
.valueOf(8), "Right-click here", sName
, Integer
.valueOf(50), Integer
.valueOf(50), Integer
.valueOf(100)});
79 // add the model to the NameContainer of the dialog model
80 m_xDlgModelNameContainer
.insertByName(sName
, oFTModel
);
81 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class, m_xDlgContainer
.getControl(sName
));
82 xWindow
.addMouseListener(this);
83 }catch( Exception e
) {
84 System
.err
.println( e
+ e
.getMessage());
89 protected void closeDialog(){
94 public void mouseReleased(MouseEvent mouseEvent
) {
98 public void mousePressed(MouseEvent mouseEvent
) {
99 if (mouseEvent
.PopupTrigger
){
100 Rectangle aPos
= new Rectangle(mouseEvent
.X
, mouseEvent
.Y
, 0, 0);
101 XControl xControl
= UnoRuntime
.queryInterface(XControl
.class, mouseEvent
.Source
);
102 getPopupMenu().execute( xControl
.getPeer(), aPos
, com
.sun
.star
.awt
.PopupMenuDirection
.EXECUTE_DEFAULT
);
107 public void mouseExited(MouseEvent mouseEvent
) {
111 public void mouseEntered(MouseEvent mouseEvent
) {
115 public void disposing(EventObject eventObject
) {