summaryrefslogtreecommitdiffstats
path: root/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs')
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java151
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/DummyEvolutionarySolverStatusDialog.java73
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java292
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/IEvolutionarySolverStatusDialog.java48
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/BaseControl.java141
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Button.java73
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Label.java78
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/LabeledControl.java46
-rw-r--r--nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/ProgressBar.java74
9 files changed, 976 insertions, 0 deletions
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java
new file mode 100644
index 000000000..d10ad3493
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/BaseDialog.java
@@ -0,0 +1,151 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs;
+
+import com.sun.star.awt.InvalidateStyle;
+import com.sun.star.awt.PosSize;
+import com.sun.star.awt.Rectangle;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.controls.BaseControl;
+import com.sun.star.awt.XControl;
+import com.sun.star.awt.XControlModel;
+import com.sun.star.awt.XDialog;
+import com.sun.star.awt.XToolkit;
+import com.sun.star.awt.XWindow;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The BaseDialog represents the base for all dialogs used within the addon.
+ * It automatically loads the necessary interfaces to access OpenOffice.org dialogs.
+ */
+public abstract class BaseDialog extends BaseControl {
+
+ private XMultiComponentFactory xMCF;
+ private XMultiServiceFactory xMSF;
+ protected XWindow xWindow;
+ protected XDialog xDialog;
+ private XWindowPeer xWindowPeer;
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ public XMultiServiceFactory getMultiServiceFactory() {
+ return xMSF;
+ }
+
+ private XFrame getCurrentFrame() throws Exception {
+ Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", context);
+ XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+ XComponent xComponent = xDesktop.getCurrentComponent();
+ XModel xModel = UnoRuntime.queryInterface(XModel.class, xComponent);
+ XController xController = xModel.getCurrentController();
+ return xController.getFrame();
+ }
+
+ private Rectangle getWorkspaceDimensions() throws Exception {
+ return getCurrentFrame().getComponentWindow().getPosSize();
+ }
+
+ public BaseDialog(XComponentContext context, String title, int x, int y, int width, int height) {
+ super(context);
+ try {
+ xMCF = context.getServiceManager();
+ setUnoModel(xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", context));
+ xMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, getUnoModel());
+
+ setProperty("Title", title);
+ setPosition(x, y);
+ setSize(width, height);
+
+ unoControl = xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", context);
+ XControl xControl = UnoRuntime.queryInterface(XControl.class, unoControl);
+ XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, getUnoModel());
+ xControl.setModel(xControlModel);
+
+ Object toolkit = xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", context);
+ XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, toolkit);
+ xWindow = UnoRuntime.queryInterface(XWindow.class, unoControl);
+ xWindow.setVisible(false);
+ XWindowPeer xParentWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, getCurrentFrame().getComponentWindow());
+ xControl.createPeer(xToolkit, xParentWindowPeer);
+ xWindowPeer = xControl.getPeer();
+
+ xDialog = UnoRuntime.queryInterface(XDialog.class, unoControl);
+
+ //center if necessary
+ if (x < 0 || y < 0) {
+ Rectangle workspacePosSize = getWorkspaceDimensions();
+ Rectangle dialogPosSize = xWindow.getPosSize();
+ if (x < 0)
+ dialogPosSize.X = workspacePosSize.X + (workspacePosSize.Width / 2) - (dialogPosSize.Width / 2);
+ if (y < 0)
+ dialogPosSize.Y = workspacePosSize.Y + (workspacePosSize.Height / 2) - (dialogPosSize.Height / 2);
+
+ xWindow.setPosSize(dialogPosSize.X, dialogPosSize.Y,
+ dialogPosSize.Width, dialogPosSize.Height, PosSize.POS);
+ }
+
+ } catch (Exception ex) {
+ Logger.getLogger(BaseDialog.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, unoControl);
+ xComponent.dispose();
+ super.finalize();
+ }
+
+
+
+
+
+ public void setCloseable(boolean closeable) {
+ setProperty("Closeable", Boolean.valueOf(closeable));
+ }
+
+ public void repaint() {
+ xWindowPeer.invalidate((short)(InvalidateStyle.CHILDREN /*| InvalidateStyle.NOERASE*/ |
+ InvalidateStyle.UPDATE | InvalidateStyle.TRANSPARENT));
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/DummyEvolutionarySolverStatusDialog.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/DummyEvolutionarySolverStatusDialog.java
new file mode 100644
index 000000000..92f45b9a8
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/DummyEvolutionarySolverStatusDialog.java
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs;
+
+public class DummyEvolutionarySolverStatusDialog
+ implements IEvolutionarySolverStatusDialog {
+
+ public int getUserState() {
+ return OK;
+ }
+
+ public void setBestSolution(double solution, boolean feasible) {
+
+ }
+
+ public void setMaxIterations(int maxIterations) {
+
+ }
+
+ public void setMaxStagnation(int maxStagnation) {
+
+ }
+
+ public void setIteration(int iteration) {
+
+ }
+
+ public void setStagnation(int stagnation) {
+
+ }
+
+ public void setRuntime(long runtime) {
+
+ }
+
+ public int waitForUser() {
+ return OK;
+ }
+
+ public void setVisible(boolean visible) {
+
+ }
+
+ public void dispose() {
+
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java
new file mode 100644
index 000000000..e3695a0c7
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/EvolutionarySolverStatusUno.java
@@ -0,0 +1,292 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs;
+
+import com.sun.star.comp.Calc.NLPSolver.BaseNLPSolver;
+import com.sun.star.awt.ActionEvent;
+import com.sun.star.awt.XActionListener;
+import com.sun.star.comp.Calc.NLPSolver.ResourceManager;
+import com.sun.star.lang.EventObject;
+import com.sun.star.lang.XComponent;
+import com.sun.star.style.VerticalAlignment;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.controls.Button;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.controls.Label;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.controls.ProgressBar;
+
+public class EvolutionarySolverStatusUno extends BaseDialog
+ implements IEvolutionarySolverStatusDialog,
+ XActionListener {
+
+ private int userState;
+ private final Label lblSolutionValue;
+ private final Label lblIteration;
+ private final ProgressBar pbIteration;
+ private final Label lblIterationValue;
+ private final Label lblStagnation;
+ private final ProgressBar pbStagnation;
+ private final Label lblStagnationValue;
+ private final Label lblRuntimeValue;
+ private final Button btnStop;
+ private final Button btnOK;
+ private final Button btnContinue;
+ private final int defaultTextColor;
+ private int maxIterations;
+ private int maxStagnation;
+
+ private final ResourceManager resourceManager;
+
+ private static final int COLOR_RED = 0xFF0000;
+
+ public EvolutionarySolverStatusUno(XComponentContext xContext) {
+ super(xContext, "Solver Status", -1, -1, 170, 95); //center the dialog on the parent
+
+ setCloseable(false);
+ userState = IEvolutionarySolverStatusDialog.OK;
+
+ resourceManager = new ResourceManager(xContext, "com.sun.star.comp.Calc.NLPSolver", "/locale", "NLPSolverStatusDialog");
+
+ try {
+ setProperty("Title", resourceManager.getLocalizedString("Dialog.Caption"));
+ } catch (com.sun.star.resource.MissingResourceException ex) {} //leave the title as it is
+
+ int y = 5;
+ Label lblSolution = new Label(this, "lblSolution");
+ lblSolution.setPosition(5, y);
+ lblSolution.setSize(60, 10);
+ lblSolution.setLabel(resourceManager.getLocalizedString("Controls.lblSolution", "Current Solution:"));
+ lblSolution.setParentControl(this);
+
+ lblSolutionValue = new Label(this, "lblSolutionValue");
+ lblSolutionValue.setPosition(65, y);
+ lblSolutionValue.setSize(100, 10);
+ lblSolutionValue.setParentControl(this);
+ defaultTextColor = lblSolutionValue.getTextColor();
+ y += 15;
+
+ lblIteration = new Label(this, "lblIteration");
+ lblIteration.setPosition(5, y);
+ lblIteration.setSize(60, 15);
+ lblIteration.setLabel(resourceManager.getLocalizedString("Controls.lblIteration", "Iteration:"));
+ lblIteration.setVerticalAlign(VerticalAlignment.MIDDLE);
+ lblIteration.setParentControl(this);
+
+ pbIteration = new ProgressBar(this, "pbIteration");
+ pbIteration.setPosition(65, y);
+ pbIteration.setSize(100, 15);
+ pbIteration.setParentControl(this);
+
+ lblIterationValue = new Label(this, "lblIterationValue");
+ lblIterationValue.setPosition(65, y);
+ lblIterationValue.setSize(100, 20);
+ lblIterationValue.setVerticalAlign(VerticalAlignment.MIDDLE);
+ lblIterationValue.setMultiLine(true);
+ lblIterationValue.setParentControl(this);
+ lblIterationValue.setVisible(false);
+ y += 20;
+
+ lblStagnation = new Label(this, "lblStagnation");
+ lblStagnation.setPosition(5, y);
+ lblStagnation.setSize(60, 15);
+ lblStagnation.setLabel(resourceManager.getLocalizedString("Controls.lblStagnation", "Stagnation:"));
+ lblStagnation.setVerticalAlign(VerticalAlignment.MIDDLE);
+ lblStagnation.setParentControl(this);
+
+ pbStagnation = new ProgressBar(this, "pbStagnation");
+ pbStagnation.setPosition(65, y);
+ pbStagnation.setSize(100, 15);
+ pbStagnation.setParentControl(this);
+
+ lblStagnationValue = new Label(this, "lblStagnationValue");
+ lblStagnationValue.setPosition(65, y);
+ lblStagnationValue.setSize(100, 20);
+ lblStagnationValue.setVerticalAlign(VerticalAlignment.MIDDLE);
+ lblStagnationValue.setMultiLine(true);
+ lblStagnationValue.setParentControl(this);
+ lblStagnationValue.setVisible(false);
+ y+= 20;
+
+ Label lblRuntime = new Label(this, "lblRuntime");
+ lblRuntime.setPosition(5, y);
+ lblRuntime.setSize(60, 10);
+ lblRuntime.setLabel(resourceManager.getLocalizedString("Controls.lblRuntime", "Runtime:"));
+ lblRuntime.setParentControl(this);
+
+ lblRuntimeValue = new Label(this, "lblRuntimeValue");
+ lblRuntimeValue.setPosition(65, y);
+ lblRuntimeValue.setSize(100, 10);
+ lblRuntimeValue.setParentControl(this);
+ y += 15;
+
+ btnStop = new Button(this, "btnStop");
+ btnStop.setPosition(5, y);
+ btnStop.setSize(45, 15);
+ btnStop.setLabel(resourceManager.getLocalizedString("Controls.btnStop", "Stop"));
+ btnStop.setParentControl(this);
+ btnStop.addActionListener(this);
+ btnStop.setActionCommand("btnStopClick");
+
+ btnOK = new Button(this, "btnOK");
+ btnOK.setPosition(65, y);
+ btnOK.setSize(40, 15);
+ btnOK.setLabel(resourceManager.getLocalizedString("Controls.btnOK", "OK"));
+ btnOK.setParentControl(this);
+ btnOK.addActionListener(this);
+ btnOK.setActionCommand("btnOKClick");
+ btnOK.setEnabled(false);
+
+ btnContinue = new Button(this, "btnContinue");
+ btnContinue.setPosition(110, y);
+ btnContinue.setSize(55, 15);
+ btnContinue.setLabel(resourceManager.getLocalizedString("Controls.btnContinue", "Continue"));
+ btnContinue.setParentControl(this);
+ btnContinue.addActionListener(this);
+ btnContinue.setActionCommand("btnContinueClick");
+ btnContinue.setEnabled(false);
+ y += 15;
+ }
+
+ public int getUserState() {
+ return userState;
+ }
+
+ public void setBestSolution(double solution, boolean feasible) {
+ lblSolutionValue.setLabel(String.format("%g", solution));
+ if (feasible)
+ lblSolutionValue.setTextColor(defaultTextColor);
+ else
+ lblSolutionValue.setTextColor(COLOR_RED); //red
+ }
+
+ public void setMaxIterations(int maxIterations) {
+ pbIteration.setRange(0, maxIterations);
+ this.maxIterations = maxIterations;
+ }
+
+ public void setMaxStagnation(int maxStagnation) {
+ pbStagnation.setRange(0, maxStagnation);
+ this.maxStagnation = maxStagnation;
+ }
+
+ public void setIteration(int iteration) {
+ pbIteration.setValue(iteration);
+ }
+
+ public void setStagnation(int stagnation) {
+ pbStagnation.setValue(stagnation);
+ }
+
+ public void setRuntime(long runtime) {
+ lblRuntimeValue.setLabel(BaseNLPSolver.nanoTimeToString(resourceManager, runtime));
+ }
+
+ public int waitForUser() {
+ btnStop.setEnabled(false);
+ btnOK.setEnabled(true);
+ btnContinue.setEnabled(true);
+
+ if (pbIteration.getValue() >= maxIterations) {
+ lblIteration.setTextColor(COLOR_RED);
+ if (userState != IEvolutionarySolverStatusDialog.CANCEL)
+ lblStagnationValue.setLabel(
+ resourceManager.getLocalizedString("Message.StopIteration",
+ "Maximum iterations reached."));
+ }
+
+ if (pbStagnation.getValue() >= maxStagnation) {
+ lblStagnation.setTextColor(COLOR_RED);
+ if (userState != IEvolutionarySolverStatusDialog.CANCEL)
+ lblStagnationValue.setLabel(
+ resourceManager.getLocalizedString("Message.StopStagnation",
+ "Process stopped due to stagnation."));
+ }
+
+ lblIterationValue.setLabel(String.format(
+ resourceManager.getLocalizedString("Message.CurrentIteration",
+ "Process stopped at iteration %d of %d."),
+ pbIteration.getValue(), maxIterations));
+ if (userState == IEvolutionarySolverStatusDialog.CANCEL)
+ lblStagnationValue.setLabel(
+ resourceManager.getLocalizedString("Message.StopUser",
+ "Process stopped due to user interruption."));
+
+ pbIteration.setVisible(false);
+ pbStagnation.setVisible(false);
+ lblIterationValue.setVisible(true);
+ lblStagnationValue.setVisible(true);
+
+ repaint();
+
+ userState = IEvolutionarySolverStatusDialog.WAITING;
+ xDialog.execute();
+
+ lblIteration.setTextColor(defaultTextColor);
+ lblStagnation.setTextColor(defaultTextColor);
+
+ lblIterationValue.setVisible(false);
+ lblStagnationValue.setVisible(false);
+ pbIteration.setVisible(true);
+ pbStagnation.setVisible(true);
+
+ btnStop.setEnabled(true);
+ btnOK.setEnabled(false);
+ btnContinue.setEnabled(false);
+
+ return userState;
+ }
+
+ @Override
+ public void setVisible(boolean visible) {
+ xWindow.setVisible(visible);
+ }
+
+ public void dispose() {
+ XComponent component = UnoRuntime.queryInterface(XComponent.class, xDialog);
+ component.dispose();
+ }
+
+ public void actionPerformed(ActionEvent actionEvent) {
+ if (userState == IEvolutionarySolverStatusDialog.WAITING) {
+ xDialog.endExecute();
+ setVisible(true);
+ }
+
+ if (actionEvent.ActionCommand.equals("btnStopClick"))
+ userState = IEvolutionarySolverStatusDialog.CANCEL;
+ else if (actionEvent.ActionCommand.equals("btnOKClick"))
+ userState = IEvolutionarySolverStatusDialog.OK;
+ else if (actionEvent.ActionCommand.equals("btnContinueClick"))
+ userState = IEvolutionarySolverStatusDialog.CONTINUE;
+ }
+
+ public void disposing(EventObject eventObject) {
+
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/IEvolutionarySolverStatusDialog.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/IEvolutionarySolverStatusDialog.java
new file mode 100644
index 000000000..9ef12e09e
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/IEvolutionarySolverStatusDialog.java
@@ -0,0 +1,48 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs;
+
+public interface IEvolutionarySolverStatusDialog {
+ int WAITING = 0;
+ int OK = 1;
+ int CONTINUE = 2;
+ int CANCEL = 3;
+
+ int getUserState();
+
+ void setBestSolution(double solution, boolean feasible);
+ void setMaxIterations(int maxIterations);
+ void setMaxStagnation(int maxStagnation);
+ void setIteration(int iteration);
+ void setStagnation(int stagnation);
+ void setRuntime(long runtime);
+ int waitForUser();
+
+ void setVisible(boolean visible);
+ void dispose();
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/BaseControl.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/BaseControl.java
new file mode 100644
index 000000000..7de59c4b0
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/BaseControl.java
@@ -0,0 +1,141 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs.controls;
+
+import com.sun.star.awt.XControlContainer;
+import com.sun.star.awt.XWindow;
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.beans.UnknownPropertyException;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.ElementExistException;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class BaseControl {
+
+ protected XComponentContext context;
+ private Object unoModel;
+ protected Object unoControl;
+ private XPropertySet properties;
+
+
+ public abstract String getName();
+
+ public Object getUnoModel() {
+ return unoModel;
+ }
+
+ /**
+ * This is used <b>internally</b> to update the UnoModel and refresh the
+ * associated PropertySet.
+ * @param unoModel The new UnoModel for this control.
+ */
+ protected void setUnoModel(Object unoModel) {
+ this.unoModel = unoModel;
+ properties = UnoRuntime.queryInterface(XPropertySet.class, unoModel);
+ }
+
+ public void setParentControl(BaseControl parentControl) {
+ //TODO : remove from existing parentControl
+ try {
+ String name = getName();
+ XNameContainer nameContainer = UnoRuntime.queryInterface(XNameContainer.class, parentControl.unoModel);
+ nameContainer.insertByName(name, unoModel);
+
+ XControlContainer controlContainer = UnoRuntime.queryInterface(XControlContainer.class, parentControl.unoControl);
+ unoControl = controlContainer.getControl(name);
+
+ } catch (IllegalArgumentException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (ElementExistException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (WrappedTargetException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ public BaseControl(XComponentContext context) {
+ this.context = context;
+ unoModel = null;
+ unoControl = null;
+ }
+
+ protected void setProperty(String name, Object value) {
+ try {
+ properties.setPropertyValue(name, value);
+ } catch (UnknownPropertyException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (PropertyVetoException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IllegalArgumentException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (WrappedTargetException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ protected Object getProperty(String name) {
+ try {
+ return properties.getPropertyValue(name);
+ } catch (UnknownPropertyException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (WrappedTargetException ex) {
+ Logger.getLogger(BaseControl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return null;
+ }
+
+ // <editor-fold defaultstate="collapsed" desc="Uno Properties">
+
+ public void setPosition(int x, int y) {
+ setProperty("PositionX", Integer.valueOf(x));
+ setProperty("PositionY", Integer.valueOf(y));
+ }
+
+ public void setSize(int width, int height) {
+ setProperty("Width", Integer.valueOf(width));
+ setProperty("Height", Integer.valueOf(height));
+ }
+
+ public void setEnabled(boolean enabled) {
+ setProperty("Enabled", Boolean.valueOf(enabled));
+ }
+
+ public void setVisible(boolean visible) {
+ XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, unoControl);
+ xWindow.setVisible(visible);
+ }
+
+ // </editor-fold>
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Button.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Button.java
new file mode 100644
index 000000000..61ae47c19
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Button.java
@@ -0,0 +1,73 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs.controls;
+
+import com.sun.star.awt.XActionListener;
+import com.sun.star.awt.XButton;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.BaseDialog;
+
+public class Button extends LabeledControl {
+
+ private String name;
+ private XButton xButton;
+
+ public Button(BaseDialog owner, String name) {
+ super(owner.context);
+ try {
+ setUnoModel(owner.getMultiServiceFactory().createInstance("com.sun.star.awt.UnoControlButtonModel"));
+ this.name = name;
+ setProperty("Name", name);
+ } catch (Exception ex) {
+ Logger.getLogger(Button.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setParentControl(BaseControl parentControl) {
+ super.setParentControl(parentControl);
+ xButton = UnoRuntime.queryInterface(XButton.class, unoControl);
+ }
+
+ public void addActionListener(XActionListener actionListener) {
+ xButton.addActionListener(actionListener);
+ }
+
+ public void setActionCommand(String actionCommand) {
+ xButton.setActionCommand(actionCommand);
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Label.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Label.java
new file mode 100644
index 000000000..689350ce2
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/Label.java
@@ -0,0 +1,78 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs.controls;
+
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.style.VerticalAlignment;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.BaseDialog;
+
+public class Label extends LabeledControl {
+
+ private String name;
+
+ public Label(BaseDialog owner, String name) {
+ super(owner.context);
+ try {
+ setUnoModel(owner.getMultiServiceFactory().createInstance("com.sun.star.awt.UnoControlFixedTextModel"));
+ this.name = name;
+ setProperty("Name", name);
+ } catch (Exception ex) {
+ Logger.getLogger(Button.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setVerticalAlign(VerticalAlignment align) {
+ setProperty("VerticalAlign", align);
+ }
+
+
+ public void setTextColor(int RGB) {
+ setProperty("TextColor", Integer.valueOf(RGB));
+ }
+
+ public int getTextColor() {
+ try {
+ Object prop = getProperty("TextColor");
+ if (AnyConverter.getType(prop) == Type.LONG)
+ return AnyConverter.toInt(prop);
+ } catch (IllegalArgumentException ex) {
+ Logger.getLogger(LabeledControl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ return 0;
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/LabeledControl.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/LabeledControl.java
new file mode 100644
index 000000000..a1c8c7674
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/LabeledControl.java
@@ -0,0 +1,46 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs.controls;
+
+import com.sun.star.uno.XComponentContext;
+
+public abstract class LabeledControl extends BaseControl {
+
+ public LabeledControl(XComponentContext context) {
+ super(context);
+ }
+
+ public void setLabel(String label) {
+ setProperty("Label", label);
+ }
+
+ public void setMultiLine(boolean multiLine) {
+ setProperty("MultiLine", Boolean.valueOf(multiLine));
+ }
+
+}
diff --git a/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/ProgressBar.java b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/ProgressBar.java
new file mode 100644
index 000000000..a62ea7d9f
--- /dev/null
+++ b/nlpsolver/src/com/sun/star/comp/Calc/NLPSolver/dialogs/controls/ProgressBar.java
@@ -0,0 +1,74 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2009 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.comp.Calc.NLPSolver.dialogs.controls;
+
+import com.sun.star.awt.XProgressBar;
+import com.sun.star.uno.UnoRuntime;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import com.sun.star.comp.Calc.NLPSolver.dialogs.BaseDialog;
+
+public class ProgressBar extends BaseControl {
+
+ private String m_name;
+ private XProgressBar m_progressBar;
+
+ public ProgressBar(BaseDialog owner, String name) {
+ super(owner.context);
+ try {
+ setUnoModel(owner.getMultiServiceFactory().createInstance("com.sun.star.awt.UnoControlProgressBarModel"));
+ m_name = name;
+ setProperty("Name", name);
+ } catch (Exception ex) {
+ Logger.getLogger(Button.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return m_name;
+ }
+
+ @Override
+ public void setParentControl(BaseControl parentControl) {
+ super.setParentControl(parentControl);
+ m_progressBar = UnoRuntime.queryInterface(XProgressBar.class, unoControl);
+ }
+
+ public void setRange(int min, int max) {
+ m_progressBar.setRange(min, max);
+ }
+
+ public void setValue(int value) {
+ m_progressBar.setValue(value);
+ }
+
+ public int getValue() {
+ return m_progressBar.getValue();
+ }
+}