public void showInfoBoxMessage( String Title, String Message, String type) { // type can be: infobox, XComponent xComponent = null; try { Object oToolkit = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.Toolkit", xComponentContext); XWindowPeer xParentWindowPeer = ((XToolkit) UnoRuntime.queryInterface(XToolkit.class, oToolkit)).getDesktopWindow(); XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox( xParentWindowPeer, aRectangle, type, com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, Title, Message); xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null) { short nResult = xMessageBox.execute(); } } catch (Exception ex) { SpeechOO.logger = org.apache.log4j.Logger.getLogger(TrainingDialog.class.getName()); SpeechOO.logger.error(ex); } finally { // make sure always to dispose the component and free the memory! if (xComponent != null) { xComponent.dispose(); } } }
/** * Shows an messagebox * * @param _xParentWindowPeer the windowpeer of the parent window * @param _sTitle the title of the messagebox * @param _sMessage the message of the messagebox * @param _aType string which determines the message box type: * (infobox|warningbox|errorbox|querybox|messbox) * @param _aButtons MessageBoxButtons which buttons should be available on the message box */ public short showMessageBox( XWindowPeer _xParentWindowPeer, String _sTitle, String _sMessage, String _aType, int _aButtons) { short nResult = -1; XComponent xComponent = null; try { Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox( _xParentWindowPeer, aRectangle, _aType, _aButtons, _sTitle, _sMessage); xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null) { nResult = xMessageBox.execute(); } } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(System.out); } finally { // make sure always to dispose the component and free the memory! if (xComponent != null) { xComponent.dispose(); } } return nResult; }
public short executeDialog(String _sTitle, String _sMessage, int _nType, int _nDefault) { XComponent xComponent = null; short nResult = 0; try { Object oToolkit = m_axMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCC); XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); if (m_xFrame == null) { Object oDesktop = null; try { oDesktop = m_axMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xCC); XFramesSupplier xFramesSupplier = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop); m_xFrame = (XFrame) xFramesSupplier.getActiveFrame(); // println("default Frame..."); } catch (com.sun.star.uno.Exception oException) { oException.printStackTrace(); } } XWindow xWindow = m_xFrame.getContainerWindow(); XWindowPeer xWPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWindow); if (xWPeer != null) { // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox( xWPeer, MessageBoxType.QUERYBOX, _nType | _nDefault, _sTitle, _sMessage); xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null) { nResult = xMessageBox.execute(); } } else System.out.println("no peer"); } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(System.out); } finally { // make sure always to dispose the component and free the memory! if (xComponent != null) { xComponent.dispose(); } } return nResult; }