tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / odk / examples / DevelopersGuide / GUI / UnoMenu2.java
blob8658fb66a5333e1a3797e4ed2b68c6869af583d3
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com.sun.star.awt.MouseEvent;
21 import com.sun.star.awt.Rectangle;
22 import com.sun.star.awt.XControl;
23 import com.sun.star.awt.XWindow;
24 import com.sun.star.beans.XMultiPropertySet;
25 import com.sun.star.lang.EventObject;
26 import com.sun.star.lang.XMultiComponentFactory;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XComponentContext;
31 public class UnoMenu2 extends UnoMenu {
33 public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) {
34 super(_xContext, _xMCF);
37 public static void main(String args[]){
38 UnoMenu2 oUnoMenu2 = null;
39 try {
40 XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
41 if(xContext != null )
42 System.out.println("Connected to a running office ...");
43 XMultiComponentFactory xMCF = xContext.getServiceManager();
44 oUnoMenu2 = new UnoMenu2(xContext, xMCF);
45 oUnoMenu2.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"},
46 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)});
48 Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
49 XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel);
50 xFTHeaderModelMPSet.setPropertyValues(
51 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
52 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)});
53 // add the model to the NameContainer of the dialog model
54 oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel);
55 oUnoMenu2.addLabelForPopupMenu();
56 oUnoMenu2.executeDialog();
57 }catch( Exception ex ) {
58 ex.printStackTrace(System.err);
60 finally{
61 //make sure always to dispose the component and free the memory!
62 if (oUnoMenu2 != null) {
63 if (oUnoMenu2.m_xComponent != null){
64 oUnoMenu2.m_xComponent.dispose();
67 System.exit( 0 );
71 public void addLabelForPopupMenu(){
72 try{
73 String sName = "lblPopup";
74 Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
75 XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel);
76 // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
77 xFTModelMPSet.setPropertyValues(
78 new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
79 new Object[] { Integer.valueOf(8), "Right-click here", sName, Integer.valueOf(50), Integer.valueOf(50), Integer.valueOf(100)});
80 // add the model to the NameContainer of the dialog model
81 m_xDlgModelNameContainer.insertByName(sName, oFTModel);
82 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName));
83 xWindow.addMouseListener(this);
84 }catch( Exception e ) {
85 System.err.println( e + e.getMessage());
86 e.printStackTrace();
89 @Override
90 protected void closeDialog(){
91 xDialog.endExecute();
94 @Override
95 public void mouseReleased(MouseEvent mouseEvent) {
98 @Override
99 public void mousePressed(MouseEvent mouseEvent) {
100 if (mouseEvent.PopupTrigger){
101 Rectangle aPos = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0);
102 XControl xControl = UnoRuntime.queryInterface(XControl.class, mouseEvent.Source);
103 getPopupMenu().execute( xControl.getPeer(), aPos, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT);
107 @Override
108 public void mouseExited(MouseEvent mouseEvent) {
111 @Override
112 public void mouseEntered(MouseEvent mouseEvent) {
115 @Override
116 public void disposing(EventObject eventObject) {
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */