diff options
Diffstat (limited to 'scripting/java/com/sun/star/script/framework/browse/DialogFactory.java')
-rw-r--r-- | scripting/java/com/sun/star/script/framework/browse/DialogFactory.java | 135 |
1 files changed, 59 insertions, 76 deletions
diff --git a/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java b/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java index 1708bdc60888..1883b0d2e05a 100644 --- a/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java +++ b/scripting/java/com/sun/star/script/framework/browse/DialogFactory.java @@ -31,26 +31,20 @@ import com.sun.star.container.XNameContainer; import com.sun.star.awt.*; -public class DialogFactory -{ +public class DialogFactory { private static DialogFactory factory; private XComponentContext xComponentContext; // singleton - private DialogFactory(XComponentContext xComponentContext) - { + private DialogFactory(XComponentContext xComponentContext) { this.xComponentContext = xComponentContext; factory = this; - } - - public static void createDialogFactory(XComponentContext xComponentContext) - { - if (factory == null) - { - synchronized(DialogFactory.class) - { - if (factory == null) - { + } + + public static void createDialogFactory(XComponentContext xComponentContext) { + if (factory == null) { + synchronized (DialogFactory.class) { + if (factory == null) { factory = new DialogFactory(xComponentContext); } } @@ -58,65 +52,58 @@ public class DialogFactory } public static DialogFactory getDialogFactory() - throws java.lang.Exception - { - if (factory == null) - { + throws java.lang.Exception { + if (factory == null) { throw new java.lang.Exception("DialogFactory not initialized"); } + return factory; } - public String showInputDialog(String title, String prompt) - { + public String showInputDialog(String title, String prompt) { final XDialog xDialog; - try - { + + try { xDialog = createInputDialog(title, prompt); - } - catch (com.sun.star.uno.Exception e) - { + } catch (com.sun.star.uno.Exception e) { return null; } // add an action listener to the button controls - XControlContainer controls = UnoRuntime.queryInterface(XControlContainer.class, xDialog); + XControlContainer controls = UnoRuntime.queryInterface(XControlContainer.class, + xDialog); XButton okButton = UnoRuntime.queryInterface( - XButton.class, controls.getControl("Ok")); + XButton.class, controls.getControl("Ok")); okButton.setActionCommand("Ok"); XButton cancelButton = UnoRuntime.queryInterface( - XButton.class, controls.getControl("Cancel")); + XButton.class, controls.getControl("Cancel")); cancelButton.setActionCommand("Cancel"); final XTextComponent textField = UnoRuntime.queryInterface( - XTextComponent.class, controls.getControl("NameField")); + XTextComponent.class, controls.getControl("NameField")); final ResultHolder resultHolder = new ResultHolder(); com.sun.star.awt.XActionListener listener = - new com.sun.star.awt.XActionListener() - { - public void actionPerformed(com.sun.star.awt.ActionEvent e) { - if (e.ActionCommand.equals("Cancel")) - { - resultHolder.setResult(null); - xDialog.endExecute(); - } - else - { - resultHolder.setResult(textField.getText()); - xDialog.endExecute(); - } + new com.sun.star.awt.XActionListener() { + public void actionPerformed(com.sun.star.awt.ActionEvent e) { + if (e.ActionCommand.equals("Cancel")) { + resultHolder.setResult(null); + xDialog.endExecute(); + } else { + resultHolder.setResult(textField.getText()); + xDialog.endExecute(); } + } - public void disposing(EventObject o) { - // does nothing - } - }; + public void disposing(EventObject o) { + // does nothing + } + }; okButton.addActionListener(listener); cancelButton.addActionListener(listener); @@ -127,8 +114,7 @@ public class DialogFactory } private void setDimensions(Object o, int x, int y, int width, int height) - throws com.sun.star.uno.Exception - { + throws com.sun.star.uno.Exception { XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, o); props.setPropertyValue("PositionX", Integer.valueOf(x)); @@ -138,15 +124,12 @@ public class DialogFactory } private XDialog createInputDialog(String title, String prompt) - throws com.sun.star.uno.Exception - { - if (title == null || title.length() == 0) - { + throws com.sun.star.uno.Exception { + if (title == null || title.length() == 0) { title = "Scripting Framework"; } - if (prompt == null || prompt.length() == 0) - { + if (prompt == null || prompt.length() == 0) { prompt = "Enter name"; } @@ -156,64 +139,65 @@ public class DialogFactory // create the dialog model and set the properties Object dialogModel = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialogModel", xComponentContext); + "com.sun.star.awt.UnoControlDialogModel", xComponentContext); setDimensions(dialogModel, 100, 100, 157, 58); XPropertySet props = UnoRuntime.queryInterface( - XPropertySet.class, dialogModel); + XPropertySet.class, dialogModel); props.setPropertyValue("Title", title); // get the service manager from the dialog model XMultiServiceFactory xMultiServiceFactory = UnoRuntime.queryInterface( - XMultiServiceFactory.class, dialogModel); + XMultiServiceFactory.class, dialogModel); // create the label model and set the properties Object label = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlFixedTextModel"); + "com.sun.star.awt.UnoControlFixedTextModel"); setDimensions(label, 15, 5, 134, 12); XPropertySet labelProps = UnoRuntime.queryInterface( - XPropertySet.class, label); + XPropertySet.class, label); labelProps.setPropertyValue("Name", "PromptLabel"); labelProps.setPropertyValue("Label", prompt); // create the text field Object edit = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlEditModel"); + "com.sun.star.awt.UnoControlEditModel"); setDimensions(edit, 15, 18, 134, 12); XPropertySet editProps = UnoRuntime.queryInterface( - XPropertySet.class, edit); + XPropertySet.class, edit); editProps.setPropertyValue("Name", "NameField"); // create the OK button Object okButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); + "com.sun.star.awt.UnoControlButtonModel"); setDimensions(okButtonModel, 40, 39, 38, 15); XPropertySet buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, okButtonModel); + XPropertySet.class, okButtonModel); buttonProps.setPropertyValue("Name", "Ok"); buttonProps.setPropertyValue("Label", "Ok"); // create the Cancel button Object cancelButtonModel = xMultiServiceFactory.createInstance( - "com.sun.star.awt.UnoControlButtonModel"); + "com.sun.star.awt.UnoControlButtonModel"); setDimensions(cancelButtonModel, 83, 39, 38, 15); buttonProps = UnoRuntime.queryInterface( - XPropertySet.class, cancelButtonModel); + XPropertySet.class, cancelButtonModel); buttonProps.setPropertyValue("Name", "Cancel"); buttonProps.setPropertyValue("Label", "Cancel"); // insert the control models into the dialog model - XNameContainer xNameCont = UnoRuntime.queryInterface(XNameContainer.class, dialogModel); + XNameContainer xNameCont = UnoRuntime.queryInterface(XNameContainer.class, + dialogModel); xNameCont.insertByName("PromptLabel", label); xNameCont.insertByName("NameField", edit); @@ -222,20 +206,21 @@ public class DialogFactory // create the dialog control and set the model Object dialog = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.UnoControlDialog", xComponentContext); + "com.sun.star.awt.UnoControlDialog", xComponentContext); XControl xControl = UnoRuntime.queryInterface( - XControl.class, dialog); + XControl.class, dialog); - XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, dialogModel); + XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, + dialogModel); xControl.setModel(xControlModel); // create a peer Object toolkit = xMultiComponentFactory.createInstanceWithContext( - "com.sun.star.awt.ExtToolkit", xComponentContext); + "com.sun.star.awt.ExtToolkit", xComponentContext); XToolkit xToolkit = UnoRuntime.queryInterface( - XToolkit.class, toolkit); + XToolkit.class, toolkit); XWindow xWindow = UnoRuntime.queryInterface( - XWindow.class, xControl); + XWindow.class, xControl); xWindow.setVisible(false); xControl.createPeer(xToolkit, null); @@ -245,13 +230,11 @@ public class DialogFactory private static class ResultHolder { private Object result = null; - public Object getResult() - { + public Object getResult() { return result; } - public void setResult(Object result) - { + public void setResult(Object result) { this.result = result; } } |