1*cdf0e10cSrcweir import com.sun.star.awt.MouseEvent; 2*cdf0e10cSrcweir import com.sun.star.awt.Rectangle; 3*cdf0e10cSrcweir import com.sun.star.awt.XControl; 4*cdf0e10cSrcweir import com.sun.star.awt.XMouseListener; 5*cdf0e10cSrcweir import com.sun.star.awt.XTopWindow; 6*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 7*cdf0e10cSrcweir import com.sun.star.beans.XMultiPropertySet; 8*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 9*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 10*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 11*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir 14*cdf0e10cSrcweir public class UnoMenu2 extends UnoMenu implements XMouseListener{ 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) { 17*cdf0e10cSrcweir super(_xContext, _xMCF); 18*cdf0e10cSrcweir } 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir public static void main(String args[]){ 21*cdf0e10cSrcweir UnoMenu2 oUnoMenu2 = null; 22*cdf0e10cSrcweir try { 23*cdf0e10cSrcweir XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 24*cdf0e10cSrcweir if(xContext != null ) 25*cdf0e10cSrcweir System.out.println("Connected to a running office ..."); 26*cdf0e10cSrcweir XMultiComponentFactory xMCF = xContext.getServiceManager(); 27*cdf0e10cSrcweir oUnoMenu2 = new UnoMenu2(xContext, xMCF); 28*cdf0e10cSrcweir oUnoMenu2.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"}, 29*cdf0e10cSrcweir 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)}); 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); 32*cdf0e10cSrcweir XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); 33*cdf0e10cSrcweir xFTHeaderModelMPSet.setPropertyValues( 34*cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, 35*cdf0e10cSrcweir 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)}); 36*cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 37*cdf0e10cSrcweir oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel); 38*cdf0e10cSrcweir oUnoMenu2.addLabelForPopupMenu(); 39*cdf0e10cSrcweir oUnoMenu2.executeDialog(); 40*cdf0e10cSrcweir }catch( Exception ex ) { 41*cdf0e10cSrcweir ex.printStackTrace(System.out); 42*cdf0e10cSrcweir } 43*cdf0e10cSrcweir finally{ 44*cdf0e10cSrcweir //make sure always to dispose the component and free the memory! 45*cdf0e10cSrcweir if (oUnoMenu2 != null) { 46*cdf0e10cSrcweir if (oUnoMenu2.m_xComponent != null){ 47*cdf0e10cSrcweir oUnoMenu2.m_xComponent.dispose(); 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir System.exit( 0 ); 51*cdf0e10cSrcweir }} 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir public void addLabelForPopupMenu(){ 55*cdf0e10cSrcweir try{ 56*cdf0e10cSrcweir String sName = "lblPopup"; 57*cdf0e10cSrcweir Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); 58*cdf0e10cSrcweir XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); 59*cdf0e10cSrcweir // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 60*cdf0e10cSrcweir xFTModelMPSet.setPropertyValues( 61*cdf0e10cSrcweir new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, 62*cdf0e10cSrcweir new Object[] { new Integer(8), "Right-click here", sName, new Integer(50), new Integer(50), new Integer(100)}); 63*cdf0e10cSrcweir // add the model to the NameContainer of the dialog model 64*cdf0e10cSrcweir m_xDlgModelNameContainer.insertByName(sName, oFTModel); 65*cdf0e10cSrcweir XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName)); 66*cdf0e10cSrcweir xWindow.addMouseListener(this); 67*cdf0e10cSrcweir }catch( Exception e ) { 68*cdf0e10cSrcweir System.err.println( e + e.getMessage()); 69*cdf0e10cSrcweir e.printStackTrace(); 70*cdf0e10cSrcweir }} 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir protected void closeDialog(){ 73*cdf0e10cSrcweir xDialog.endExecute(); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir public void mouseReleased(MouseEvent mouseEvent) { 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir public void mousePressed(MouseEvent mouseEvent) { 80*cdf0e10cSrcweir if (mouseEvent.PopupTrigger){ 81*cdf0e10cSrcweir Rectangle aRectangle = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0); 82*cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, mouseEvent.Source); 83*cdf0e10cSrcweir getPopupMenu().execute( xControl.getPeer(), aRectangle, com.sun.star.awt.PopupMenuDirection.DEFAULT); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public void mouseExited(MouseEvent mouseEvent) { 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir public void mouseEntered(MouseEvent mouseEvent) { 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir public void disposing(EventObject eventObject) { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96