diff --git a/prism/src/prism/PrismSettings.java b/prism/src/prism/PrismSettings.java index 15edcb97..541f319b 100644 --- a/prism/src/prism/PrismSettings.java +++ b/prism/src/prism/PrismSettings.java @@ -119,6 +119,7 @@ public class PrismSettings implements Observer public static final String SIMULATOR_SIMULTANEOUS = "simulator.simultaneous"; public static final String SIMULATOR_FIELD_CHOICE = "simulator.fieldChoice"; public static final String SIMULATOR_NEW_PATH_ASK_INITIAL = "simulator.newPathAskDefault"; + public static final String SIMULATOR_NEW_PATH_ASK_VIEW = "simulator.newPathAskView"; public static final String SIMULATOR_RENDER_ALL_VALUES = "simulator.renderAllValues"; public static final String SIMULATOR_NETWORK_FILE = "simulator.networkFile"; @@ -207,6 +208,7 @@ public class PrismSettings implements Observer { BOOLEAN_TYPE, SIMULATOR_SIMULTANEOUS, "check properties simultaneously?", "3.0", new Boolean(true), "", "When set to true, all relevant properties are checked over the same execution paths, meaning only one set of sample paths need be generated. This feature is only supported by the PRISM simulator." }, { CHOICE_TYPE, SIMULATOR_FIELD_CHOICE, "values used in dialog", "3.0", "Last used values", "Last used values,Always use defaults", "This setting allows the choice between whether the values used in the simulation dialog are taken from the defaults every time, or from the last used values." }, { BOOLEAN_TYPE, SIMULATOR_NEW_PATH_ASK_INITIAL, "ask for initial state?", "3.0", new Boolean(true), "", "When set to true, creating a new path in the simulator user interface prompts for an initial state rather than using default values for the model." }, + { BOOLEAN_TYPE, SIMULATOR_NEW_PATH_ASK_VIEW, "ask for view configuration?", "3.0", new Boolean(false), "", "When set to true, creating a new path in the simulator user interface prompts for an initial state rather than using default values for the model." }, { CHOICE_TYPE, SIMULATOR_RENDER_ALL_VALUES, "path render style", "3.0", "Render changes", "Render changes,Render all values", "How the execution path in the simulator user interface should display the different states. The \'render changes\' option displays a value only if it has changed." }, { FILE_TYPE, SIMULATOR_NETWORK_FILE, "network profile", "3.0", new File(""), "", "This file is used to specify the network profile which should be used by the distributed PRISM simulator." } }, diff --git a/prism/src/userinterface/simulator/GUIInitialStatePicker.form b/prism/src/userinterface/simulator/GUIInitialStatePicker.form index 0165c88b..d0515617 100644 --- a/prism/src/userinterface/simulator/GUIInitialStatePicker.form +++ b/prism/src/userinterface/simulator/GUIInitialStatePicker.form @@ -1,48 +1,30 @@ -
+ - + - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + @@ -51,66 +33,89 @@ - - - - - - - - + - + - + - - - - - - - - - - + - - + + - + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + - - + + diff --git a/prism/src/userinterface/simulator/GUIInitialStatePicker.java b/prism/src/userinterface/simulator/GUIInitialStatePicker.java index 98bad523..e9406f47 100644 --- a/prism/src/userinterface/simulator/GUIInitialStatePicker.java +++ b/prism/src/userinterface/simulator/GUIInitialStatePicker.java @@ -23,6 +23,7 @@ package userinterface.simulator; import parser.*; import prism.*; + import javax.swing.*; import java.awt.*; import javax.swing.border.*; @@ -32,19 +33,15 @@ import java.awt.event.*; import userinterface.*; public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyListener -{ - - //STATICS - +{ + //STATICS public static final int NO_VALUES = 0; public static final int VALUES_DONE = 1; public static final int CANCELLED = 2; - - - - //ATTRIBUTES - + + //ATTRIBUTES private boolean cancelled = true; + private boolean askOption; private JTable initValuesTable; private DefineValuesTable initValuesModel; @@ -52,25 +49,21 @@ public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyLis private Action okAction; private Action cancelAction; - Values initialState; - - + Values initialState; private GUIPrism gui; private ModulesFile mf; // Variables declaration - do not modify//GEN-BEGIN:variables - javax.swing.JButton cancelButton; - javax.swing.JPanel jPanel1; - javax.swing.JPanel jPanel2; - javax.swing.JPanel jPanel3; - javax.swing.JPanel jPanel4; - javax.swing.JPanel jPanel5; - javax.swing.JPanel jPanel6; - javax.swing.JPanel jPanel7; - javax.swing.JButton okayButton; - javax.swing.JPanel topPanel; + private javax.swing.JPanel allPanel; + private javax.swing.JPanel bottomPanel; + private javax.swing.JPanel buttonPanel; + private javax.swing.JButton cancelButton; + private javax.swing.JPanel innerPanel; + private javax.swing.JButton okayButton; + private javax.swing.JCheckBox optionCheckBox; + private javax.swing.JPanel topPanel; // End of variables declaration//GEN-END:variables /** Creates new form GUIConstantsPicker */ @@ -83,30 +76,26 @@ public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyLis //setup tables initValuesModel = new DefineValuesTable(); - initValuesTable = new JTable(); + initValuesTable = new JTable(); + initValuesTable.setModel(initValuesModel); + initValuesTable.setSelectionMode(DefaultListSelectionModel.SINGLE_INTERVAL_SELECTION); + initValuesTable.setCellSelectionEnabled(true); - initValuesTable.setModel(initValuesModel); - - initValuesTable.setSelectionMode(DefaultListSelectionModel.SINGLE_INTERVAL_SELECTION); - - initValuesTable.setCellSelectionEnabled(true); - - - this.initialState = defaultInitial; - - + this.initialState = defaultInitial; + //initialise initComponents(); this.getRootPane().setDefaultButton(okayButton); initTable(); - initValues(); - - - setResizable(false); - - pack(); + initValues(); + + super.setBounds(new Rectangle(550, 300)); + setResizable(true); setLocationRelativeTo(getParent()); // centre + + this.askOption = gui.getPrism().getSettings().getBoolean(PrismSettings.SIMULATOR_NEW_PATH_ASK_INITIAL); + optionCheckBox.setSelected(this.askOption); } /** This method is called from within the constructor to @@ -114,94 +103,80 @@ public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyLis * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - private void initComponents()//GEN-BEGIN:initComponents - { - java.awt.GridBagConstraints gridBagConstraints; - - jPanel6 = new javax.swing.JPanel(); + // //GEN-BEGIN:initComponents + private void initComponents() { + allPanel = new javax.swing.JPanel(); + bottomPanel = new javax.swing.JPanel(); + buttonPanel = new javax.swing.JPanel(); okayButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); - jPanel7 = new javax.swing.JPanel(); - jPanel1 = new javax.swing.JPanel(); - jPanel2 = new javax.swing.JPanel(); - jPanel3 = new javax.swing.JPanel(); - jPanel4 = new javax.swing.JPanel(); - jPanel5 = new javax.swing.JPanel(); + optionCheckBox = new javax.swing.JCheckBox(); topPanel = new javax.swing.JPanel(); + innerPanel = new javax.swing.JPanel(); - addWindowListener(new java.awt.event.WindowAdapter() - { - public void windowClosing(java.awt.event.WindowEvent evt) - { + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); - jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); + allPanel.setLayout(new java.awt.BorderLayout()); + + allPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(5, 5, 5, 5))); + bottomPanel.setLayout(new java.awt.BorderLayout()); + + buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); okayButton.setText("Okay"); - okayButton.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { + okayButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { okayButtonActionPerformed(evt); } }); - jPanel6.add(okayButton); + buttonPanel.add(okayButton); cancelButton.setText("Cancel"); - cancelButton.addActionListener(new java.awt.event.ActionListener() - { - public void actionPerformed(java.awt.event.ActionEvent evt) - { + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); - jPanel6.add(cancelButton); + buttonPanel.add(cancelButton); - getContentPane().add(jPanel6, java.awt.BorderLayout.SOUTH); + bottomPanel.add(buttonPanel, java.awt.BorderLayout.EAST); - jPanel7.setLayout(new java.awt.BorderLayout()); + optionCheckBox.setLabel("Always prompt for initial state on path creation"); + optionCheckBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + optionCheckBoxActionPerformed(evt); + } + }); - jPanel1.setLayout(new java.awt.GridBagLayout()); + bottomPanel.add(optionCheckBox, java.awt.BorderLayout.WEST); + optionCheckBox.getAccessibleContext().setAccessibleName("optionCheckBox"); - jPanel1.setBorder(new javax.swing.border.TitledBorder("Initial State")); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 0; - jPanel1.add(jPanel2, gridBagConstraints); + allPanel.add(bottomPanel, java.awt.BorderLayout.SOUTH); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 2; - gridBagConstraints.gridy = 0; - jPanel1.add(jPanel3, gridBagConstraints); + topPanel.setLayout(new java.awt.BorderLayout()); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 2; - jPanel1.add(jPanel4, gridBagConstraints); + topPanel.setBorder(new javax.swing.border.TitledBorder("Initial state")); + innerPanel.setLayout(new java.awt.BorderLayout()); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 4; - jPanel1.add(jPanel5, gridBagConstraints); + innerPanel.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(5, 5, 5, 5))); + topPanel.add(innerPanel, java.awt.BorderLayout.CENTER); - topPanel.setLayout(new java.awt.BorderLayout()); + allPanel.add(topPanel, java.awt.BorderLayout.CENTER); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 3; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - jPanel1.add(topPanel, gridBagConstraints); + getContentPane().add(allPanel, java.awt.BorderLayout.CENTER); - jPanel7.add(jPanel1, java.awt.BorderLayout.CENTER); + } + // //GEN-END:initComponents - getContentPane().add(jPanel7, java.awt.BorderLayout.CENTER); - - pack(); - }//GEN-END:initComponents + private void optionCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionCheckBoxActionPerformed +// TODO add your handling code here: + }//GEN-LAST:event_optionCheckBoxActionPerformed @@ -215,9 +190,9 @@ public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyLis JScrollPane sp = new JScrollPane(); sp.setViewportView(initValuesTable); - topPanel.add(sp); + innerPanel.add(sp); - topPanel.setPreferredSize(new Dimension(300,300)); + innerPanel.setPreferredSize(new Dimension(300,300)); } private void initValues() @@ -296,7 +271,18 @@ public class GUIInitialStatePicker extends javax.swing.JDialog implements KeyLis int i, n; Value c; - + if (optionCheckBox.isSelected() != this.askOption) + { + this.askOption = !this.askOption; + try + { + gui.getPrism().getSettings().set(PrismSettings.SIMULATOR_NEW_PATH_ASK_INITIAL, this.askOption); + } + catch (PrismException e) + { + + } + } if(initValuesTable.getCellEditor() != null)initValuesTable.getCellEditor().stopCellEditing(); diff --git a/prism/src/userinterface/simulator/GUISimulator.form b/prism/src/userinterface/simulator/GUISimulator.form index ed843b82..ba819b51 100644 --- a/prism/src/userinterface/simulator/GUISimulator.form +++ b/prism/src/userinterface/simulator/GUISimulator.form @@ -6,6 +6,10 @@ + + + + @@ -107,9 +111,6 @@ - - - @@ -124,8 +125,8 @@ - + @@ -160,8 +161,8 @@ - + @@ -180,8 +181,8 @@ - + @@ -212,8 +213,8 @@ - + @@ -266,8 +267,8 @@ - + @@ -278,8 +279,8 @@ - + @@ -312,9 +313,6 @@ - - - @@ -323,8 +321,8 @@ - + @@ -354,8 +352,8 @@ - + @@ -384,8 +382,8 @@ - + @@ -449,9 +447,6 @@ - - - @@ -460,8 +455,8 @@ - + @@ -477,8 +472,8 @@ - + @@ -514,9 +509,6 @@ - - - @@ -525,8 +517,8 @@ - + @@ -542,8 +534,8 @@ - + @@ -560,8 +552,8 @@ - + @@ -578,8 +570,8 @@ - + @@ -699,8 +691,8 @@ - + @@ -805,9 +797,6 @@ - - - @@ -819,8 +808,8 @@ - + @@ -830,9 +819,6 @@ - - - @@ -844,8 +830,8 @@ - + @@ -855,9 +841,6 @@ - - - @@ -869,8 +852,8 @@ - + diff --git a/prism/src/userinterface/simulator/GUISimulator.java b/prism/src/userinterface/simulator/GUISimulator.java index 2a755ff5..51b2f351 100644 --- a/prism/src/userinterface/simulator/GUISimulator.java +++ b/prism/src/userinterface/simulator/GUISimulator.java @@ -61,39 +61,21 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect private GUISimulator.UpdateTableModel updateTableModel; private Values lastConstants, lastPropertyConstants, lastInitialState; - - private ArrayList hiddenColumns; - - - //private int maxPathLength; - - //External state - private boolean computing; - - //Options - - //private boolean verifyAllPropertiesAtOnce; - //private GUISimulatorOptions options; private boolean displayStyleFast; - //private boolean askForInitialState; private boolean displayPathLoops; //Actions - private Action backtrackToHere, removeToHere; - - private JMenu showColumnMenu; - + private Action backtrackToHere, removeToHere, newPath, resetPath, exportPath, configureView; /** Creates a new instance of GUISimulator */ public GUISimulator(GUIPrism gui) { super(gui, true); - pathTableModel = new PathTableModel(); + pathTableModel = new PathTableModel(this); updateTableModel = new UpdateTableModel(); - hiddenColumns = new ArrayList(); this.gui = gui; this.engine = gui.getPrism().getSimulator(); initComponents(); @@ -105,28 +87,17 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect pathTable.getTableHeader().addMouseListener(this); pathTable.getParent().addMouseListener(this); - pathTable.getTableHeader().setReorderingAllowed(false); + pathTable.getTableHeader().setReorderingAllowed(true); pathTable.addComponentListener(new ComponentListener() { - public void componentHidden(ComponentEvent e) - { - } - - public void componentMoved(ComponentEvent e) - { - } - - public void componentResized(ComponentEvent e) - { + public void componentHidden(ComponentEvent e){} + public void componentMoved(ComponentEvent e){} + public void componentResized(ComponentEvent e) { sortOutColumnSizes(); } - public void componentShown(ComponentEvent e) - { - } - - + public void componentShown(ComponentEvent e){} }); @@ -386,6 +357,7 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect lastInitialState = defaultInitialState; } } + initialState = GUIInitialStatePicker.defineInitalValuesWithDialog(getGUI(), lastInitialState, mf); // if user clicked cancel from dialog... if (initialState == null) { @@ -421,10 +393,16 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect repopulateFormulae(); stateLabelList.repaint(); pathFormulaeList.repaint(); - //pathTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); - + // store inital state for next time lastInitialState = initialState; + + if (getPrism().getSettings().getBoolean(PrismSettings.SIMULATOR_NEW_PATH_ASK_VIEW)) + { + new GUIViewDialog(gui, pathTableModel, mf); + } + + } catch(PrismException e) { @@ -684,6 +662,11 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect } } + public void a_configureView() + { + new GUIViewDialog(gui, pathTableModel, mf); + } + public void repopulateFormulae() { ((GUISimPathFormulaeList)pathFormulaeList).clearList(); @@ -1893,7 +1876,46 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect }//GEN-END:initComponents private void initPopups() - { + { + newPath = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_newPath(); + } + }; + + newPath.putValue(Action.LONG_DESCRIPTION, "Creates a new path."); + newPath.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_N)); + newPath.putValue(Action.NAME, "New Path"); + newPath.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallNewPath.gif")); + + resetPath = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_restartPath(); + } + }; + + resetPath.putValue(Action.LONG_DESCRIPTION, "Resets the path."); + resetPath.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R)); + resetPath.putValue(Action.NAME, "Reset Path"); + resetPath.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallResetPath.gif")); + + exportPath = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_exportPath(); + } + }; + + exportPath.putValue(Action.LONG_DESCRIPTION, "Exports the path."); + exportPath.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X)); + exportPath.putValue(Action.NAME, "Export Path"); + exportPath.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallExport.gif")); + backtrackToHere = new AbstractAction() { public void actionPerformed(ActionEvent e) @@ -1933,19 +1955,27 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect removeToHere.putValue(Action.NAME, "Remove preceding steps"); removeToHere.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallRemovePreceding.gif")); - //item to dynamically add checkboxes for each column - showColumnMenu = new JMenu("Show Column"); + configureView = new AbstractAction() + { + public void actionPerformed(ActionEvent e) + { + a_configureView(); + } + }; + configureView.putValue(Action.LONG_DESCRIPTION, "Configures the view."); + configureView.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_C)); + configureView.putValue(Action.NAME, "Configure View"); + configureView.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFind.gif")); pathPopup = new JPopupMenu(); - - pathPopup.add(showColumnMenu); + pathPopup.add(newPath); + pathPopup.add(resetPath); + pathPopup.add(exportPath); pathPopup.addSeparator(); pathPopup.add(backtrackToHere); pathPopup.add(removeToHere); - - - - + pathPopup.addSeparator(); + pathPopup.add(configureView); } @@ -2059,9 +2089,16 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect backtrackToHere.setEnabled(!(e.getSource() == pathTable.getTableHeader() || e.getSource() == pathTable.getParent())); removeToHere.setEnabled(!(e.getSource() == pathTable.getTableHeader() || e.getSource() == pathTable.getParent())); + newPath.setEnabled(newPathButton.isEnabled()); + resetPath.setEnabled(resetPathButton.isEnabled()); + exportPath.setEnabled(exportPathButton.isEnabled()); + configureView.setEnabled(pathActive); + int index = pathTable.rowAtPoint(e.getPoint()); pathTable.getSelectionModel().setSelectionInterval(index, index); + + /* showColumnMenu.removeAll(); //Now populate showColumnMenu with all columns @@ -2106,6 +2143,9 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect showColumnMenu.add(showColumn); } + + */ + /* showColumnMenu.addSeparator(); JMenuItem showAll = new JMenuItem("Show all columns"); @@ -2125,7 +2165,7 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect } }); showColumnMenu.add(showAll); - + */ pathPopup.show(e.getComponent(), e.getX(), e.getY()); @@ -2389,32 +2429,120 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect private javax.swing.JLabel transitionTotalRewardsLabel; // End of variables declaration//GEN-END:variables - class PathTableModel extends AbstractTableModel + + /** + * @author mxk + * Represents a in the model. + */ + public class Variable { + private int index; + private String name; + private int type; - public int getColumnCount() + public Variable(int index, String name, int type) { - int colCount; - if(pathActive) - colCount = 1+engine.getNumVariables(); - else colCount = 0; - - if(mf == null) return colCount; - if(mf.getType() == ModulesFile.STOCHASTIC) - colCount +=1; - - colCount += (2*mf.getNumRewardStructs()); - - return colCount; + this.index = index; + this.name = name; + this.type = type; } - public int getRowCount() + public int getIndex() { + return index; + } + + public String getName() + { + return name; + } + + public int getType() + { + return type; + } + + public String toString() + { + return name; + } + + public boolean equals(Object o) + { + return (o instanceof Variable && ((Variable)o).getIndex() == index); + } + } + + class PathTableModel extends AbstractTableModel + { + private boolean SHOW_STEP = true; + + ArrayList visibleVariables; + ArrayList hiddenVariables; + + GUISimulator simulator; + + public PathTableModel(GUISimulator simulator) + { + this.simulator = simulator; + } + + public SimulatorEngine getEngine() + { + return engine; + } + + public ArrayList getVisibleVariables() + { + return visibleVariables; + } + + public ArrayList getHiddenVariables() + { + return hiddenVariables; + } + + public void setVisibility(ArrayList visibleVariables, ArrayList hiddenVariables) + { + this.visibleVariables = visibleVariables; + this.hiddenVariables = hiddenVariables; - if(pathActive) - return engine.getPathSize(); - else return 0; - + if (pathActive) + { fireTableStructureChanged(); } + } + + /** + * Returns the number of columns. + * @see javax.swing.table.TableModel#getColumnCount() + */ + public int getColumnCount() + { + if (!pathActive) + { return 0; } + else + { + // At least we have the step count and s. + int colCount = 1 + visibleVariables.size(); + + // Add state and transitions rewards for each reward structure. + colCount += (2*mf.getNumRewardStructs()); + + // Add a column for time if CTMC. + if (mf.getType() == ModulesFile.STOCHASTIC) + { colCount += 1; } + + return colCount; + } + } + + /** + * Returns the number of rows. + * @see javax.swing.table.TableModel#getRowCount() + */ + public int getRowCount() + { + // Return current path size if there is an active path. + return (pathActive ? SimulatorEngine.getPathSize() : 0); } public boolean shouldColourRow(int row) @@ -2444,41 +2572,57 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect { if(pathActive) { - if (columnIndex == 0) return ""+rowIndex; + int stepStart = 0; + int varStart = (SHOW_STEP) ? stepStart + 1 : stepStart; + int timeStart = varStart + visibleVariables.size(); + + // The step column + if (stepStart <= columnIndex && columnIndex < varStart) + { + return "" + rowIndex; + } + // A variable column + else if (varStart <= columnIndex && columnIndex < timeStart) + { + int varIndex = ((Variable)visibleVariables.get(columnIndex - varStart)).getIndex(); + + int type = engine.getVariableType(varIndex); + int result = SimulatorEngine.getPathData(varIndex, rowIndex); + + if(type == Expression.BOOLEAN) + { return new Boolean(result != 0); } + else if (type == Expression.INT) + { return new Integer(result); } + } + + + // todo: tidy rest up. if (mf == null) return null; if(mf.getType() == ModulesFile.STOCHASTIC) { - int n = engine.getNumVariables(); + int n = visibleVariables.size(); if(columnIndex == n+1) //where time should be { - return new Double(engine.getTimeSpentInPathState(rowIndex)); + return new Double(SimulatorEngine.getTimeSpentInPathState(rowIndex)); } else if(columnIndex > n+1) //rewards { int i = columnIndex-(n+2); - if (i%2 == 0) return new Double(engine.getStateRewardOfPathState(rowIndex,i/2)); - else return new Double(engine.getTransitionRewardOfPathState(rowIndex,i/2)); + if (i%2 == 0) return new Double(SimulatorEngine.getStateRewardOfPathState(rowIndex,i/2)); + else return new Double(SimulatorEngine.getTransitionRewardOfPathState(rowIndex,i/2)); } } else { - int n = engine.getNumVariables(); + int n = visibleVariables.size(); if(columnIndex > n) { int i = columnIndex-(n+1); - if (i%2 == 0) return new Double(engine.getStateRewardOfPathState(rowIndex,i/2)); - else return new Double(engine.getTransitionRewardOfPathState(rowIndex,i/2)); + if (i%2 == 0) return new Double(SimulatorEngine.getStateRewardOfPathState(rowIndex,i/2)); + else return new Double(SimulatorEngine.getTransitionRewardOfPathState(rowIndex,i/2)); } } - int type = engine.getVariableType(columnIndex-1); - int result = engine.getPathData(columnIndex-1, rowIndex); - if(type == Expression.BOOLEAN) - { - if(result == 0) return new Boolean(false); - else return new Boolean(true); - } - else - return new Integer(result); + return null; } else return null; } @@ -2495,11 +2639,26 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect { if(pathActive) { - if (column == 0) return "Step"; + int stepStart = 0; + int varStart = (SHOW_STEP) ? stepStart + 1 : stepStart; + int timeStart = varStart + visibleVariables.size(); + + // The step column + if (column == stepStart && SHOW_STEP) + { + return "#"; + } + // A variable column + else if (varStart <= column && column < timeStart) + { + return ((Variable)visibleVariables.get(column - varStart)).getName(); + } + + if (mf == null) return null; if (mf.getType() == ModulesFile.STOCHASTIC) { - int n = engine.getNumVariables(); + int n = visibleVariables.size(); if(column == n+1) //where time should be { return "Time"; @@ -2512,7 +2671,7 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect } else { - int n = engine.getNumVariables(); + int n = visibleVariables.size(); if(column > n) //rewards { int i = column-(n+1); @@ -2529,13 +2688,35 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect } } + /** + * Method is called when a new path is created. + * The structure of the path may be for a different model etc. + */ public void restartPathTable() - { + { + visibleVariables = new ArrayList(); + hiddenVariables = new ArrayList(); + + if (pathActive) + { + try + { + for (int i = 0; i < engine.getNumVariables(); i++) + { + visibleVariables.add(new Variable(i, engine.getVariableName(i), engine.getVariableType(i))); } + } + catch (SimulatorException e) {} + } + fireTableStructureChanged(); + //Sort out the minimum widths for each column sortOutColumnSizes(); } + /** + * Method is called whenever a path is modified. + */ public void updatePathTable() { fireTableDataChanged(); @@ -2560,7 +2741,6 @@ public class GUISimulator extends GUIPlugin implements MouseListener, ListSelect { return displayPathLoops; } - } public void sortOutColumnSizes() diff --git a/prism/src/userinterface/simulator/GUISimulatorPathTable.java b/prism/src/userinterface/simulator/GUISimulatorPathTable.java index a2f50711..a61dd468 100644 --- a/prism/src/userinterface/simulator/GUISimulatorPathTable.java +++ b/prism/src/userinterface/simulator/GUISimulatorPathTable.java @@ -364,7 +364,7 @@ public class GUISimulatorPathTable extends JTable column = table.convertColumnIndexToModel(column); bg = Color.white; - if(column == 0 || column > engine.getNumVariables()) + if(column == 0 || column > ptm.getVisibleVariables().size()) { if(value instanceof Double) {