From b41b5eefb141112b524a6d25b5eb8fb37f073c9a Mon Sep 17 00:00:00 2001 From: Jens-Heiner Rechtien Date: Tue, 31 Jul 2007 12:56:13 +0000 Subject: INTEGRATION: CWS jsc18 (1.1.2); FILE ADDED 2007/07/04 08:02:31 jsc 1.1.2.1: #i78746# new --- odk/examples/DevelopersGuide/GUI/UnoMenu2.java | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 odk/examples/DevelopersGuide/GUI/UnoMenu2.java (limited to 'odk/examples/DevelopersGuide/GUI') diff --git a/odk/examples/DevelopersGuide/GUI/UnoMenu2.java b/odk/examples/DevelopersGuide/GUI/UnoMenu2.java new file mode 100644 index 000000000000..d9f9ed92c741 --- /dev/null +++ b/odk/examples/DevelopersGuide/GUI/UnoMenu2.java @@ -0,0 +1,95 @@ +import com.sun.star.awt.MouseEvent; +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.XControl; +import com.sun.star.awt.XMouseListener; +import com.sun.star.awt.XTopWindow; +import com.sun.star.awt.XWindow; +import com.sun.star.beans.XMultiPropertySet; +import com.sun.star.lang.EventObject; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + + +public class UnoMenu2 extends UnoMenu implements XMouseListener{ + +public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) { + super(_xContext, _xMCF); +} + + public static void main(String args[]){ + UnoMenu2 oUnoMenu2 = null; + try { + XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + if(xContext != null ) + System.out.println("Connected to a running office ..."); + XMultiComponentFactory xMCF = xContext.getServiceManager(); + oUnoMenu2 = new UnoMenu2(xContext, xMCF); + oUnoMenu2.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"}, + 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)}); + + Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); + XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); + xFTHeaderModelMPSet.setPropertyValues( + new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, + 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)}); + // add the model to the NameContainer of the dialog model + oUnoMenu2.m_xDlgModelNameContainer.insertByName("Headerlabel", oFTHeaderModel); + oUnoMenu2.addLabelForPopupMenu(); + oUnoMenu2.executeDialog(); + }catch( Exception ex ) { + ex.printStackTrace(System.out); + } + finally{ + //make sure always to dispose the component and free the memory! + if (oUnoMenu2 != null) { + if (oUnoMenu2.m_xComponent != null){ + oUnoMenu2.m_xComponent.dispose(); + } + } + System.exit( 0 ); + }} + + + public void addLabelForPopupMenu(){ + try{ + String sName = "lblPopup"; + Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); + XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); + // Set the properties at the model - keep in mind to pass the property names in alphabetical order! + xFTModelMPSet.setPropertyValues( + new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, + new Object[] { new Integer(8), "Right-click here", sName, new Integer(50), new Integer(50), new Integer(100)}); + // add the model to the NameContainer of the dialog model + m_xDlgModelNameContainer.insertByName(sName, oFTModel); + XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName)); + xWindow.addMouseListener(this); + }catch( Exception e ) { + System.err.println( e + e.getMessage()); + e.printStackTrace(); + }} + + protected void closeDialog(){ + xDialog.endExecute(); + } + + public void mouseReleased(MouseEvent mouseEvent) { + } + + public void mousePressed(MouseEvent mouseEvent) { + if (mouseEvent.PopupTrigger){ + Rectangle aRectangle = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0); + XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, mouseEvent.Source); + getPopupMenu().execute( xControl.getPeer(), aRectangle, com.sun.star.awt.PopupMenuDirection.DEFAULT); + } + } + + public void mouseExited(MouseEvent mouseEvent) { + } + + public void mouseEntered(MouseEvent mouseEvent) { + } + + public void disposing(EventObject eventObject) { + } +} -- cgit