1ae15d43aSAndrew Rist /**************************************************************
2ae15d43aSAndrew Rist  *
3ae15d43aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ae15d43aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ae15d43aSAndrew Rist  * distributed with this work for additional information
6ae15d43aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ae15d43aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ae15d43aSAndrew Rist  * "License"); you may not use this file except in compliance
9ae15d43aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ae15d43aSAndrew Rist  *
11ae15d43aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ae15d43aSAndrew Rist  *
13ae15d43aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ae15d43aSAndrew Rist  * software distributed under the License is distributed on an
15ae15d43aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ae15d43aSAndrew Rist  * KIND, either express or implied.  See the License for the
17ae15d43aSAndrew Rist  * specific language governing permissions and limitations
18ae15d43aSAndrew Rist  * under the License.
19ae15d43aSAndrew Rist  *
20ae15d43aSAndrew Rist  *************************************************************/
21ae15d43aSAndrew Rist 
22cdf0e10cSrcweir import com.sun.star.awt.MouseEvent;
23*31d843d7SAriel Constenla-Haile import com.sun.star.awt.Rectangle;
24cdf0e10cSrcweir import com.sun.star.awt.XControl;
25cdf0e10cSrcweir import com.sun.star.awt.XMouseListener;
26cdf0e10cSrcweir import com.sun.star.awt.XTopWindow;
27cdf0e10cSrcweir import com.sun.star.awt.XWindow;
28cdf0e10cSrcweir import com.sun.star.beans.XMultiPropertySet;
29cdf0e10cSrcweir import com.sun.star.lang.EventObject;
30cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
31cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
32cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir public class UnoMenu2 extends UnoMenu implements XMouseListener{
36cdf0e10cSrcweir 
UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF)37cdf0e10cSrcweir public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) {
38cdf0e10cSrcweir     super(_xContext, _xMCF);
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
main(String args[])41cdf0e10cSrcweir     public static void main(String args[]){
42cdf0e10cSrcweir         UnoMenu2 oUnoMenu2 = null;
43cdf0e10cSrcweir         try {
44cdf0e10cSrcweir         XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
45cdf0e10cSrcweir         if(xContext != null )
46cdf0e10cSrcweir             System.out.println("Connected to a running office ...");
47cdf0e10cSrcweir         XMultiComponentFactory xMCF = xContext.getServiceManager();
48cdf0e10cSrcweir         oUnoMenu2 = new UnoMenu2(xContext, xMCF);
49cdf0e10cSrcweir         oUnoMenu2.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"},
50cdf0e10cSrcweir                                     new Object[] { new Integer(140), Boolean.TRUE, "Dialog1", new Integer(102),new Integer(41), new Integer(1), new Short((short) 0), "Menu-Dialog", new Integer(200)});
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
53cdf0e10cSrcweir         XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel);
54cdf0e10cSrcweir         xFTHeaderModelMPSet.setPropertyValues(
55cdf0e10cSrcweir             new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
56cdf0e10cSrcweir             new Object[] { new Integer(8), "This code-sample demonstrates the creation of a popup-menu", "HeaderLabel", new Integer(6), new Integer(6), new Integer(200)});
57cdf0e10cSrcweir         // add the model to the NameContainer of the dialog model
58cdf0e10cSrcweir         oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel);
59cdf0e10cSrcweir         oUnoMenu2.addLabelForPopupMenu();
60cdf0e10cSrcweir         oUnoMenu2.executeDialog();
61cdf0e10cSrcweir         }catch( Exception ex ) {
62cdf0e10cSrcweir             ex.printStackTrace(System.out);
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir         finally{
65cdf0e10cSrcweir         //make sure always to dispose the component and free the memory!
66cdf0e10cSrcweir         if (oUnoMenu2 != null) {
67cdf0e10cSrcweir             if (oUnoMenu2.m_xComponent != null){
68cdf0e10cSrcweir                 oUnoMenu2.m_xComponent.dispose();
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir         System.exit( 0 );
72cdf0e10cSrcweir     }}
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
addLabelForPopupMenu()75cdf0e10cSrcweir     public void addLabelForPopupMenu(){
76cdf0e10cSrcweir     try{
77cdf0e10cSrcweir         String sName = "lblPopup";
78cdf0e10cSrcweir         Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel");
79cdf0e10cSrcweir         XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel);
80cdf0e10cSrcweir         // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
81cdf0e10cSrcweir         xFTModelMPSet.setPropertyValues(
82cdf0e10cSrcweir             new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"},
83cdf0e10cSrcweir             new Object[] { new Integer(8), "Right-click here", sName, new Integer(50), new Integer(50), new Integer(100)});
84cdf0e10cSrcweir         // add the model to the NameContainer of the dialog model
85cdf0e10cSrcweir         m_xDlgModelNameContainer.insertByName(sName, oFTModel);
86cdf0e10cSrcweir         XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName));
87cdf0e10cSrcweir         xWindow.addMouseListener(this);
88cdf0e10cSrcweir     }catch( Exception e ) {
89cdf0e10cSrcweir         System.err.println( e + e.getMessage());
90cdf0e10cSrcweir         e.printStackTrace();
91cdf0e10cSrcweir     }}
92cdf0e10cSrcweir 
closeDialog()93cdf0e10cSrcweir     protected void closeDialog(){
94cdf0e10cSrcweir         xDialog.endExecute();
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
mouseReleased(MouseEvent mouseEvent)97cdf0e10cSrcweir     public void mouseReleased(MouseEvent mouseEvent) {
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
mousePressed(MouseEvent mouseEvent)100cdf0e10cSrcweir     public void mousePressed(MouseEvent mouseEvent) {
101cdf0e10cSrcweir         if (mouseEvent.PopupTrigger){
102*31d843d7SAriel Constenla-Haile             Rectangle aPos = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0);
103cdf0e10cSrcweir             XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, mouseEvent.Source);
104d026be40SAriel Constenla-Haile             getPopupMenu().execute( xControl.getPeer(), aPos, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT);
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
mouseExited(MouseEvent mouseEvent)108cdf0e10cSrcweir     public void mouseExited(MouseEvent mouseEvent) {
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
mouseEntered(MouseEvent mouseEvent)111cdf0e10cSrcweir     public void mouseEntered(MouseEvent mouseEvent) {
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
disposing(EventObject eventObject)114cdf0e10cSrcweir     public void disposing(EventObject eventObject) {
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir }
117