diff --git a/prism/src/userinterface/model/GUIMultiModel.java b/prism/src/userinterface/model/GUIMultiModel.java index a64bc211..388ba684 100644 --- a/prism/src/userinterface/model/GUIMultiModel.java +++ b/prism/src/userinterface/model/GUIMultiModel.java @@ -79,12 +79,13 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener //GUI private JTextField fileTextField; - private JMenu modelMenu, newMenu, viewMenu, exportMenu, computeMenu; - private JMenu exportStatesMenu, exportTransMenu, exportStateRewardsMenu, exportTransRewardsMenu, exportLabelsMenu; + private JMenu modelMenu, newMenu, viewMenu, exportMenu, computeMenu, computeExportMenu; + private JMenu exportStatesMenu, exportTransMenu, exportStateRewardsMenu, exportTransRewardsMenu, exportLabelsMenu, exportSSMenu, exportTrMenu; private AbstractAction viewStates, viewTrans, viewStateRewards, viewTransRewards, viewLabels, viewPrismCode, computeSS, computeTr, newPRISMModel, newGraphicModel, newPEPAModel, loadModel, reloadModel, saveModel, saveAsModel, parseModel, buildModel, exportStatesPlain, exportStatesMatlab, exportTransPlain, exportTransMatlab, exportTransDot, exportTransDotStates, exportTransMRMC, exportStateRewardsPlain, exportStateRewardsMatlab, - exportStateRewardsMRMC, exportTransRewardsPlain, exportTransRewardsMatlab, exportTransRewardsMRMC, exportLabelsPlain, exportLabelsMatlab; + exportStateRewardsMRMC, exportTransRewardsPlain, exportTransRewardsMatlab, exportTransRewardsMRMC, exportLabelsPlain, exportLabelsMatlab, + exportSSPlain, exportSSMatlab, exportTrPlain, exportTrMatlab; private JPopupMenu popup; //Contents private GUIMultiModelHandler handler; @@ -416,23 +417,70 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener handler.requestViewModel(); } + protected void a_exportSteadyState(int exportType) + { + // Pop up dialog to select file + int res = JFileChooser.CANCEL_OPTION; + switch (exportType) { + case Prism.EXPORT_MATLAB: + res = showSaveFileDialog(matlabFilter, matlabFilter[0]); + break; + case Prism.EXPORT_PLAIN: + default: + res = showSaveFileDialog(textFilter, textFilter[0]); + break; + } + if (res != JFileChooser.APPROVE_OPTION) + return; + // Reset warnings counter + getPrism().getMainLog().resetNumberOfWarnings(); + // Do steady-state + handler.computeSteadyState(exportType, getChooserFile()); + } + protected void a_computeSteadyState() { // Reset warnings counter getPrism().getMainLog().resetNumberOfWarnings(); // Do steady-state - handler.computeSteadyState(); + handler.computeSteadyState(Prism.EXPORT_PLAIN, null); } - protected void a_computeTransient() + protected void a_exportTransient(int exportType) { + // Get time + int result = GUITransientTime.requestTime(this.getGUI()); + if (result != GUITransientTime.OK) + return; + // Pop up dialog to select file + int res = JFileChooser.CANCEL_OPTION; + switch (exportType) { + case Prism.EXPORT_MATLAB: + res = showSaveFileDialog(matlabFilter, matlabFilter[0]); + break; + case Prism.EXPORT_PLAIN: + default: + res = showSaveFileDialog(textFilter, textFilter[0]); + break; + } + if (res != JFileChooser.APPROVE_OPTION) + return; // Reset warnings counter getPrism().getMainLog().resetNumberOfWarnings(); // Do transient + handler.computeTransient(GUITransientTime.getTime(), exportType, getChooserFile()); + } + + protected void a_computeTransient() + { + // Reset warnings counter + getPrism().getMainLog().resetNumberOfWarnings(); + // Get time int result = GUITransientTime.requestTime(this.getGUI()); - if (result == GUITransientTime.OK) { - handler.computeTransient(GUITransientTime.getTime()); - } + if (result != GUITransientTime.OK) + return; + // Do transient + handler.computeTransient(GUITransientTime.getTime(), Prism.EXPORT_PLAIN, null); } protected void a_convertToPrismTextModel() @@ -829,6 +877,54 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener computeTr.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallClockAnim1.png")); computeTr.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.CTRL_DOWN_MASK)); + exportSSPlain = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_exportSteadyState(Prism.EXPORT_PLAIN); + } + }; + exportSSPlain.putValue(Action.LONG_DESCRIPTION, "Exports the steady-state probabilities to a plain text file"); + exportSSPlain.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P)); + exportSSPlain.putValue(Action.NAME, "Plain text file"); + exportSSPlain.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileText.png")); + + exportSSMatlab = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_exportSteadyState(Prism.EXPORT_MATLAB); + } + }; + exportSSMatlab.putValue(Action.LONG_DESCRIPTION, "Exports the steady-state probabilities to a Matlab file"); + exportSSMatlab.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_M)); + exportSSMatlab.putValue(Action.NAME, "Matlab file"); + exportSSMatlab.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileMatlab.png")); + + exportTrPlain = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_exportTransient(Prism.EXPORT_PLAIN); + } + }; + exportTrPlain.putValue(Action.LONG_DESCRIPTION, "Exports the transient probabilities to a plain text file"); + exportTrPlain.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P)); + exportTrPlain.putValue(Action.NAME, "Plain text file"); + exportTrPlain.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileText.png")); + + exportTrMatlab = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_exportTransient(Prism.EXPORT_MATLAB); + } + }; + exportTrMatlab.putValue(Action.LONG_DESCRIPTION, "Exports the transient probabilities to a Matlab file"); + exportTrMatlab.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_M)); + exportTrMatlab.putValue(Action.NAME, "Matlab file"); + exportTrMatlab.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileMatlab.png")); + viewStates = new AbstractAction() { public void actionPerformed(ActionEvent e) @@ -1059,6 +1155,26 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener return computeMenu; } + private JMenu initComputeExportMenu() + { + JMenu computeExportMenu = new JMenu("Compute/export"); + computeExportMenu.setMnemonic('X'); + computeExportMenu.setIcon(GUIPrism.getIconFromImage("smallCompute.png")); + exportSSMenu = new JMenu("Steady-state probabilities"); + exportSSMenu.setMnemonic('S'); + exportSSMenu.setIcon(GUIPrism.getIconFromImage("smallSteadyState.png")); + exportSSMenu.add(exportSSPlain); + exportSSMenu.add(exportSSMatlab); + computeExportMenu.add(exportSSMenu); + exportTrMenu = new JMenu("Transient probabilities"); + exportTrMenu.setMnemonic('A'); + exportTrMenu.setIcon(GUIPrism.getIconFromImage("smallClockAnim1.png")); + exportTrMenu.add(exportTrPlain); + exportTrMenu.add(exportTrMatlab); + computeExportMenu.add(exportTrMenu); + return computeExportMenu; + } + private void initComponents() { setupActions(); @@ -1067,6 +1183,7 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener exportMenu = initExportMenu(); viewMenu = initViewMenu(); computeMenu = initComputeMenu(); + computeExportMenu = initComputeExportMenu(); JPanel topPanel = new JPanel(); { @@ -1113,6 +1230,8 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener modelMenu.add(computeMenu); + modelMenu.add(computeExportMenu); + popup = new JPopupMenu(); { popup.add(parseModel); @@ -1206,4 +1325,9 @@ public class GUIMultiModel extends GUIPlugin implements PrismSettingsListener { return initComputeMenu(); } + + public JMenu getComputeExportMenu() + { + return initComputeExportMenu(); + } } diff --git a/prism/src/userinterface/model/GUIMultiModelHandler.java b/prism/src/userinterface/model/GUIMultiModelHandler.java index 0e6dcfbf..4a31ded0 100644 --- a/prism/src/userinterface/model/GUIMultiModelHandler.java +++ b/prism/src/userinterface/model/GUIMultiModelHandler.java @@ -945,10 +945,12 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener // Compute steady-state... - public void computeSteadyState() + public void computeSteadyState(int type, File f) { // set flags/store info computeSSAfterReceiveParseNotification = true; + exportType = type; + exportFile = f; // do a parse if necessary requestParse(false); } @@ -973,17 +975,20 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener theModel.error(e.getMessage()); return; } - theModel.logToFront(); - new ComputeSteadyStateThread(this).start(); + // if the results are going to the log, switch view to there + if (exportFile == null) + theModel.logToFront(); + new ComputeSteadyStateThread(this, exportType, exportFile).start(); } // Compute transient probabilities... - public void computeTransient(double time) + public void computeTransient(double time, int type, File f) { - // set flags/store info computeTransientAfterReceiveParseNotification = true; transientTime = time; + exportType = type; + exportFile = f; // do a parse if necessary requestParse(false); } @@ -1008,8 +1013,10 @@ public class GUIMultiModelHandler extends JPanel implements PrismModelListener theModel.error(e.getMessage()); return; } - theModel.logToFront(); - new ComputeTransientThread(this, transientTime).start(); + // if the results are going to the log, switch view to there + if (exportFile == null) + theModel.logToFront(); + new ComputeTransientThread(this, transientTime, exportType, exportFile).start(); } public void requestViewModel() diff --git a/prism/src/userinterface/model/GUITextModelEditor.java b/prism/src/userinterface/model/GUITextModelEditor.java index e7377868..ac8ef8eb 100644 --- a/prism/src/userinterface/model/GUITextModelEditor.java +++ b/prism/src/userinterface/model/GUITextModelEditor.java @@ -457,6 +457,7 @@ public class GUITextModelEditor extends GUIModelEditor implements DocumentListen contextPopup.add(((GUIMultiModel)handler.getGUIPlugin()).getExportMenu()); contextPopup.add(((GUIMultiModel)handler.getGUIPlugin()).getViewMenu()); contextPopup.add(((GUIMultiModel)handler.getGUIPlugin()).getComputeMenu()); + contextPopup.add(((GUIMultiModel)handler.getGUIPlugin()).getComputeExportMenu()); //contextPopup.add(actionJumpToError); //contextPopup.add(actionSearch); diff --git a/prism/src/userinterface/model/computation/ComputeSteadyStateThread.java b/prism/src/userinterface/model/computation/ComputeSteadyStateThread.java index 02738689..caedfc99 100644 --- a/prism/src/userinterface/model/computation/ComputeSteadyStateThread.java +++ b/prism/src/userinterface/model/computation/ComputeSteadyStateThread.java @@ -27,6 +27,8 @@ package userinterface.model.computation; +import java.io.File; + import javax.swing.*; import userinterface.*; import userinterface.model.*; @@ -40,12 +42,22 @@ public class ComputeSteadyStateThread extends GUIComputationThread { @SuppressWarnings("unused") private GUIMultiModelHandler handler; + private int exportType; + private File exportFile; /** Creates a new instance of ComputeSteadyStateThread */ public ComputeSteadyStateThread(GUIMultiModelHandler handler) + { + this(handler, Prism.EXPORT_PLAIN, null); + } + + /** Creates a new instance of ComputeSteadyStateThread */ + public ComputeSteadyStateThread(GUIMultiModelHandler handler, int type, File f) { super(handler.getGUIPlugin()); this.handler = handler; + this.exportType = type; + this.exportFile = f; } public void run() @@ -63,7 +75,7 @@ public class ComputeSteadyStateThread extends GUIComputationThread // Do Computation try { - prism.doSteadyState(); + prism.doSteadyState(exportType, exportFile, null); } catch (PrismException e) { error(e.getMessage()); SwingUtilities.invokeLater(new Runnable() diff --git a/prism/src/userinterface/model/computation/ComputeTransientThread.java b/prism/src/userinterface/model/computation/ComputeTransientThread.java index 7ee186ad..df9d53bc 100644 --- a/prism/src/userinterface/model/computation/ComputeTransientThread.java +++ b/prism/src/userinterface/model/computation/ComputeTransientThread.java @@ -27,6 +27,8 @@ package userinterface.model.computation; +import java.io.File; + import javax.swing.*; import userinterface.*; import userinterface.model.*; @@ -41,13 +43,23 @@ public class ComputeTransientThread extends GUIComputationThread @SuppressWarnings("unused") private GUIMultiModelHandler handler; private double transientTime; + private int exportType; + private File exportFile; /** Creates a new instance of ComputeTransientThread */ public ComputeTransientThread(GUIMultiModelHandler handler, double transientTime) + { + this(handler, transientTime, Prism.EXPORT_PLAIN, null); + } + + /** Creates a new instance of ComputeTransientThread */ + public ComputeTransientThread(GUIMultiModelHandler handler, double transientTime, int type, File f) { super(handler.getGUIPlugin()); this.handler = handler; this.transientTime = transientTime; + this.exportType = type; + this.exportFile = f; } public void run() @@ -65,7 +77,7 @@ public class ComputeTransientThread extends GUIComputationThread // Do Computation try { - prism.doTransient(transientTime); + prism.doTransient(transientTime, exportType, exportFile, null); } catch (PrismException e) { error(e.getMessage()); SwingUtilities.invokeLater(new Runnable()