OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

non-modal dialog(sloved in Java)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
stme
Power User
Power User


Joined: 22 Aug 2006
Posts: 50
Location: Beijing,China

PostPosted: Thu Sep 14, 2006 8:12 pm    Post subject: non-modal dialog(sloved in Java) Reply with quote

Hi everyone,
With the help of members in OOoForum.org,I hava solved the problem that create the modeless dialog in OOo by Java.
And the main idea of it is that.The dialog which created in Developer' Guide is modal, and the the Toolkit could create the modeless window which is a container.so we could put the modal dialog into a modeless container window , it is well simple.
the whole code is below :
Code:
public void lemmaDialog(XScriptContext xScriptContext)
         throws com.sun.star.uno.Exception {

      // 从ComponentContext获取ServiceManager
      XMultiComponentFactory xMultiComponentFactory = xScriptContext
            .getComponentContext().getServiceManager();

      // 建立dialog model并设置属性
      Object dialogModel = xMultiComponentFactory.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialogModel", xScriptContext
                  .getComponentContext());
      XPropertySet xPSetDialog = (XPropertySet) UnoRuntime.queryInterface(
            XPropertySet.class, dialogModel);
      xPSetDialog.setPropertyValue("PositionX", new Integer(100));
      xPSetDialog.setPropertyValue("PositionY", new Integer(100));
      xPSetDialog.setPropertyValue("Width", new Integer(200));
      xPSetDialog.setPropertyValue("Height", new Integer(160));
      xPSetDialog.setPropertyValue("Title", new String("中医词条查询"));

      // get service manager from  dialog model
      XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, dialogModel);

      // 建立dialog control并设置model
      Object dialog = xMultiComponentFactory.createInstanceWithContext(
            "com.sun.star.awt.UnoControlDialog", xScriptContext
                  .getComponentContext());
      XControl xControl = (XControl) UnoRuntime.queryInterface(
            XControl.class, dialog);
      XControlModel xControlModel = (XControlModel) UnoRuntime
            .queryInterface(XControlModel.class, dialogModel);
      xControl.setModel(xControlModel);

      // 给button control加入 action listener
      XControlContainer xControlContainer = (XControlContainer) UnoRuntime
            .queryInterface(XControlContainer.class, dialog);
      Object objectButton = xControlContainer.getControl(buttonName);
      XButton xButton = (XButton) UnoRuntime.queryInterface(XButton.class,
            objectButton);
      xButton.addActionListener(new ActionListenerImpl(searchString,
            xControlContainer));
              // get ComponentContext form ServiceManager
      
      XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(
            XToolkit.class, xMultiComponentFactory
                  .createInstanceWithContext("com.sun.star.awt.Toolkit",
                        xScriptContext.getComponentContext()));

      WindowDescriptor aDescriptor = new WindowDescriptor();
      aDescriptor.Type = WindowClass.TOP;
      aDescriptor.WindowServiceName = "";
      aDescriptor.ParentIndex = -1;
      aDescriptor.Parent = xToolkit.getDesktopWindow();
      aDescriptor.Bounds = new Rectangle(100, 200, 300, 400);

      aDescriptor.WindowAttributes = WindowAttribute.BORDER
            | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE
            | WindowAttribute.CLOSEABLE;

      XWindowPeer xPeer = xToolkit.createWindow(aDescriptor);

      XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
            xPeer);
      xWindow.setVisible(false);
      xControl.createPeer(xToolkit, xPeer);

      // execute the dialog
      XDialog xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class,
            dialog);
      xDialog.execute();

      // dispose the dialog
      XComponent xComponent = (XComponent) UnoRuntime.queryInterface(
            XComponent.class, dialog);
      xComponent.dispose();

   }


In the end , thanks the person who helped me especially creaivemanhan, SergeM, pitomyak, 9point9,zarus.

regards
stme
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Sep 15, 2006 7:46 am    Post subject: Reply with quote

You are welcome.
It would be better if you post your working code in "Code snippets Forum". "OpenOffice.org Macros and API" forum is for questions and "Code snippets Forum" is for working code.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
stme
Power User
Power User


Joined: 22 Aug 2006
Posts: 50
Location: Beijing,China

PostPosted: Sun Sep 17, 2006 4:38 pm    Post subject: Reply with quote

Thanx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group