Browse Source
Further improvements to the simulator.
Further improvements to the simulator.
git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@1860 bbc10eb1-c90d-0410-af57-cb519fbb1720master
7 changed files with 748 additions and 495 deletions
-
1prism/src/parser/Values.java
-
23prism/src/parser/ast/ModulesFile.java
-
6prism/src/parser/visitor/Simplify.java
-
432prism/src/simulator/SimulatorEngine.java
-
233prism/src/userinterface/simulator/GUISimLabelFormulaeList.java
-
294prism/src/userinterface/simulator/GUISimLabelList.java
-
254prism/src/userinterface/simulator/GUISimulator.java
@ -1,233 +0,0 @@ |
|||||
//============================================================================== |
|
||||
// |
|
||||
// Copyright (c) 2002- |
|
||||
// Authors: |
|
||||
// * Andrew Hinton <ug60axh@cs.bham.ac.uk> (University of Birmingham) |
|
||||
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford, formerly University of Birmingham) |
|
||||
// |
|
||||
//------------------------------------------------------------------------------ |
|
||||
// |
|
||||
// This file is part of PRISM. |
|
||||
// |
|
||||
// PRISM is free software; you can redistribute it and/or modify |
|
||||
// it under the terms of the GNU General Public License as published by |
|
||||
// the Free Software Foundation; either version 2 of the License, or |
|
||||
// (at your option) any later version. |
|
||||
// |
|
||||
// PRISM 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 General Public License for more details. |
|
||||
// |
|
||||
// You should have received a copy of the GNU General Public License |
|
||||
// along with PRISM; if not, write to the Free Software Foundation, |
|
||||
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||
// |
|
||||
//============================================================================== |
|
||||
|
|
||||
package userinterface.simulator; |
|
||||
|
|
||||
import java.awt.*; |
|
||||
import javax.swing.*; |
|
||||
|
|
||||
import parser.ast.*; |
|
||||
import prism.PrismLangException; |
|
||||
import userinterface.properties.*; |
|
||||
import simulator.*; |
|
||||
|
|
||||
/** |
|
||||
* |
|
||||
* @author ug60axh |
|
||||
*/ |
|
||||
public class GUISimLabelFormulaeList extends JList |
|
||||
{ |
|
||||
private static final Color background = new Color(202, 225, 255); |
|
||||
private GUISimulator sim; |
|
||||
private SimulatorEngine engine; |
|
||||
private DefaultListModel listModel; |
|
||||
|
|
||||
/** Creates a new instance of GUISimLabelFormulaeList */ |
|
||||
public GUISimLabelFormulaeList(GUISimulator sim) |
|
||||
{ |
|
||||
this.sim = sim; |
|
||||
this.engine = sim.getPrism().getSimulator(); |
|
||||
listModel = new DefaultListModel(); |
|
||||
setModel(listModel); |
|
||||
|
|
||||
setCellRenderer(new SimLabelRenderer()); |
|
||||
} |
|
||||
|
|
||||
public void addLabel(String name, Expression expr, ModulesFile mf) |
|
||||
{ |
|
||||
int index = engine.addLabel(expr); |
|
||||
SimLabel sl = new SimLabel(name, index); |
|
||||
listModel.addElement(sl); |
|
||||
} |
|
||||
|
|
||||
public void addDeadlockAndInit() |
|
||||
{ |
|
||||
listModel.addElement(new InitSimLabel()); |
|
||||
listModel.addElement(new DeadlockSimLabel()); |
|
||||
} |
|
||||
|
|
||||
public void clearLabels() |
|
||||
{ |
|
||||
listModel.clear(); |
|
||||
} |
|
||||
|
|
||||
class SimLabel |
|
||||
{ |
|
||||
String formula; |
|
||||
int formulaIndex; |
|
||||
|
|
||||
public SimLabel(String formula, int formulaIndex) |
|
||||
{ |
|
||||
this.formula = formula; |
|
||||
this.formulaIndex = formulaIndex; |
|
||||
} |
|
||||
|
|
||||
public String toString() |
|
||||
{ |
|
||||
return formula; |
|
||||
} |
|
||||
|
|
||||
public int getResult() |
|
||||
{ |
|
||||
try { |
|
||||
boolean b = engine.queryLabel(formulaIndex); |
|
||||
return b ? 1 : 0; |
|
||||
} catch (PrismLangException e) { |
|
||||
return -1; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public int getResult(int step) |
|
||||
{ |
|
||||
try { |
|
||||
boolean b = engine.queryLabel(formulaIndex, step); |
|
||||
return b ? 1 : 0; |
|
||||
} catch (PrismLangException e) { |
|
||||
return -1; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
class InitSimLabel extends SimLabel |
|
||||
{ |
|
||||
public InitSimLabel() |
|
||||
{ |
|
||||
super("init", 0); |
|
||||
} |
|
||||
|
|
||||
public int getResult() |
|
||||
{ |
|
||||
return engine.queryIsInitial(); |
|
||||
} |
|
||||
|
|
||||
public int getResult(int step) |
|
||||
{ |
|
||||
return engine.queryIsInitial(step); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
class DeadlockSimLabel extends SimLabel |
|
||||
{ |
|
||||
public DeadlockSimLabel() |
|
||||
{ |
|
||||
super("deadlock", 0); |
|
||||
} |
|
||||
|
|
||||
public int getResult() |
|
||||
{ |
|
||||
return engine.queryIsDeadlock(); |
|
||||
} |
|
||||
|
|
||||
public int getResult(int step) |
|
||||
{ |
|
||||
return engine.queryIsDeadlock(step); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
//RENDERERS |
|
||||
|
|
||||
class SimLabelRenderer extends JLabel implements ListCellRenderer |
|
||||
{ |
|
||||
String lastText; |
|
||||
|
|
||||
public SimLabelRenderer() |
|
||||
{ |
|
||||
setOpaque(true); |
|
||||
lastText = "Unknown"; |
|
||||
} |
|
||||
|
|
||||
public String getToolTipText() |
|
||||
{ |
|
||||
return lastText; |
|
||||
} |
|
||||
|
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, |
|
||||
boolean cellHasFocus) |
|
||||
{ |
|
||||
setBorder(new BottomBorder()); |
|
||||
SimLabel l = (SimLabel) value; |
|
||||
|
|
||||
setText(l.toString()); |
|
||||
if (!sim.isOldUpdate()) { |
|
||||
|
|
||||
if (l.getResult() == 1) { |
|
||||
lastText = "True"; |
|
||||
setIcon(GUIProperty.IMAGE_TICK); |
|
||||
} else if (l.getResult() == 0) { |
|
||||
lastText = "False"; |
|
||||
setIcon(GUIProperty.IMAGE_CROSS); |
|
||||
} else { |
|
||||
lastText = "Unknown"; |
|
||||
setIcon(GUIProperty.IMAGE_NOT_DONE); |
|
||||
} |
|
||||
} else { |
|
||||
if (l.getResult(sim.getOldUpdateStep()) == 1) { |
|
||||
lastText = "True"; |
|
||||
setIcon(GUIProperty.IMAGE_TICK); |
|
||||
} else if (l.getResult(sim.getOldUpdateStep()) == 0) { |
|
||||
lastText = "False"; |
|
||||
setIcon(GUIProperty.IMAGE_CROSS); |
|
||||
} else { |
|
||||
lastText = "Unknown"; |
|
||||
setIcon(GUIProperty.IMAGE_NOT_DONE); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if (isSelected) { |
|
||||
setBackground(background); |
|
||||
|
|
||||
} else { |
|
||||
setBackground(Color.white); |
|
||||
} |
|
||||
|
|
||||
repaint(); |
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
class BottomBorder implements javax.swing.border.Border |
|
||||
{ |
|
||||
public Insets getBorderInsets(Component c) |
|
||||
{ |
|
||||
return new Insets(0, 0, 0, 0); |
|
||||
} |
|
||||
|
|
||||
public boolean isBorderOpaque() |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) |
|
||||
{ |
|
||||
g.setColor(Color.lightGray); |
|
||||
g.drawLine(x, (y + height - 1), (x + width), (y + height - 1)); |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,294 @@ |
|||||
|
//============================================================================== |
||||
|
// |
||||
|
// Copyright (c) 2002- |
||||
|
// Authors: |
||||
|
// * Andrew Hinton <ug60axh@cs.bham.ac.uk> (University of Birmingham) |
||||
|
// * Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford, formerly University of Birmingham) |
||||
|
// |
||||
|
//------------------------------------------------------------------------------ |
||||
|
// |
||||
|
// This file is part of PRISM. |
||||
|
// |
||||
|
// PRISM is free software; you can redistribute it and/or modify |
||||
|
// it under the terms of the GNU General Public License as published by |
||||
|
// the Free Software Foundation; either version 2 of the License, or |
||||
|
// (at your option) any later version. |
||||
|
// |
||||
|
// PRISM 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 General Public License for more details. |
||||
|
// |
||||
|
// You should have received a copy of the GNU General Public License |
||||
|
// along with PRISM; if not, write to the Free Software Foundation, |
||||
|
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||||
|
// |
||||
|
//============================================================================== |
||||
|
|
||||
|
package userinterface.simulator; |
||||
|
|
||||
|
import java.awt.*; |
||||
|
import javax.swing.*; |
||||
|
|
||||
|
import parser.ast.*; |
||||
|
import prism.PrismLangException; |
||||
|
import userinterface.properties.*; |
||||
|
import simulator.*; |
||||
|
|
||||
|
/** |
||||
|
* List of labels in the simulator GUI. |
||||
|
*/ |
||||
|
public class GUISimLabelList extends JList |
||||
|
{ |
||||
|
// Default serial ID |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
// Background colour of selected list items |
||||
|
private static final Color background = new Color(202, 225, 255); |
||||
|
// Pointers to simulator and GUI |
||||
|
private GUISimulator sim; |
||||
|
private SimulatorEngine engine; |
||||
|
// The list of labels |
||||
|
private DefaultListModel listModel; |
||||
|
|
||||
|
/** |
||||
|
* Create a new instance of GUISimLabelList |
||||
|
*/ |
||||
|
public GUISimLabelList(GUISimulator sim) |
||||
|
{ |
||||
|
this.sim = sim; |
||||
|
this.engine = sim.getPrism().getSimulator(); |
||||
|
listModel = new DefaultListModel(); |
||||
|
setModel(listModel); |
||||
|
setCellRenderer(new SimLabelRenderer()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Clear the list of labels. |
||||
|
*/ |
||||
|
public void clearLabels() |
||||
|
{ |
||||
|
listModel.clear(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Add a (model file) label to the list. |
||||
|
* Any required formulas/labels will be in the associated model, already in the simulator. |
||||
|
*/ |
||||
|
public void addModelLabel(String name, Expression expr) |
||||
|
{ |
||||
|
try { |
||||
|
int index = engine.addLabel(expr); |
||||
|
SimLabel sl = new SimLabel(name, index); |
||||
|
listModel.addElement(sl); |
||||
|
} |
||||
|
catch (PrismLangException e) { |
||||
|
// Silently ignore any problems - just don't add label to list |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Add a (properties file) label to the list. |
||||
|
* The associated properties file is also (optionally) passed in so that |
||||
|
* any required formulas/labels (not in the model file) can be obtained. |
||||
|
*/ |
||||
|
public void addPropertyLabel(String name, Expression expr, PropertiesFile pf) |
||||
|
{ |
||||
|
try { |
||||
|
int index = engine.addLabel(expr, pf); |
||||
|
SimLabel sl = new SimLabel(name, index); |
||||
|
listModel.addElement(sl); |
||||
|
} |
||||
|
catch (PrismLangException e) { |
||||
|
// Silently ignore any problems - just don't add label to list |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Add the special deadlock/init labels to the list. |
||||
|
*/ |
||||
|
public void addDeadlockAndInit() |
||||
|
{ |
||||
|
listModel.addElement(new InitSimLabel()); |
||||
|
listModel.addElement(new DeadlockSimLabel()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Class to store a normal label, that has been loaded into the simulator. |
||||
|
*/ |
||||
|
class SimLabel |
||||
|
{ |
||||
|
// Label name |
||||
|
private String name; |
||||
|
// Index of the label in the simulator engine |
||||
|
private int index; |
||||
|
|
||||
|
public SimLabel(String name, int index) |
||||
|
{ |
||||
|
this.name = name; |
||||
|
this.index = index; |
||||
|
} |
||||
|
|
||||
|
public String toString() |
||||
|
{ |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the value of the label in the current state of the simulator. |
||||
|
* 1 denotes true, 0 false, and -1 error/unknown |
||||
|
*/ |
||||
|
public int getResult() |
||||
|
{ |
||||
|
try { |
||||
|
boolean b = engine.queryLabel(index); |
||||
|
return b ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the value of the label in a particular step of the current simulator path. |
||||
|
* 1 denotes true, 0 false, and -1 error/unknown |
||||
|
*/ |
||||
|
public int getResult(int step) |
||||
|
{ |
||||
|
try { |
||||
|
return engine.queryLabel(index, step) ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Class to store the special "init" label. |
||||
|
*/ |
||||
|
class InitSimLabel extends SimLabel |
||||
|
{ |
||||
|
public InitSimLabel() |
||||
|
{ |
||||
|
super("init", 0); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getResult() |
||||
|
{ |
||||
|
try { |
||||
|
return engine.queryIsInitial() ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getResult(int step) |
||||
|
{ |
||||
|
try { |
||||
|
return engine.queryIsInitial(step) ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Class to store the special "deadlock" label. |
||||
|
*/ |
||||
|
class DeadlockSimLabel extends SimLabel |
||||
|
{ |
||||
|
public DeadlockSimLabel() |
||||
|
{ |
||||
|
super("deadlock", 0); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getResult() |
||||
|
{ |
||||
|
try { |
||||
|
return engine.queryIsDeadlock() ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getResult(int step) |
||||
|
{ |
||||
|
try { |
||||
|
return engine.queryIsDeadlock(step) ? 1 : 0; |
||||
|
} catch (PrismLangException e) { |
||||
|
return -1; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// RENDERERS |
||||
|
|
||||
|
class SimLabelRenderer extends JLabel implements ListCellRenderer |
||||
|
{ |
||||
|
// Default serial ID |
||||
|
private static final long serialVersionUID = 1L; |
||||
|
// Tooltip text |
||||
|
private String text; |
||||
|
|
||||
|
public SimLabelRenderer() |
||||
|
{ |
||||
|
setOpaque(true); |
||||
|
text = "Unknown"; |
||||
|
} |
||||
|
|
||||
|
public String getToolTipText() |
||||
|
{ |
||||
|
return text; |
||||
|
} |
||||
|
|
||||
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) |
||||
|
{ |
||||
|
setBorder(new BottomBorder()); |
||||
|
// Get label |
||||
|
SimLabel l = (SimLabel) value; |
||||
|
setText(l.toString()); |
||||
|
// Extract value of label (either for current state or an earlier path step). |
||||
|
int val = sim.isOldUpdate() ? l.getResult(sim.getOldUpdateStep()) : l.getResult(); |
||||
|
switch (val) { |
||||
|
case 1: |
||||
|
text = "True"; |
||||
|
setIcon(GUIProperty.IMAGE_TICK); |
||||
|
break; |
||||
|
case 0: |
||||
|
text = "False"; |
||||
|
setIcon(GUIProperty.IMAGE_CROSS); |
||||
|
break; |
||||
|
default: |
||||
|
text = "Unknown"; |
||||
|
setIcon(GUIProperty.IMAGE_NOT_DONE); |
||||
|
break; |
||||
|
} |
||||
|
// Set BG colour |
||||
|
setBackground(isSelected ? background : Color.white); |
||||
|
repaint(); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
class BottomBorder implements javax.swing.border.Border |
||||
|
{ |
||||
|
public Insets getBorderInsets(Component c) |
||||
|
{ |
||||
|
return new Insets(0, 0, 0, 0); |
||||
|
} |
||||
|
|
||||
|
public boolean isBorderOpaque() |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) |
||||
|
{ |
||||
|
g.setColor(Color.lightGray); |
||||
|
g.drawLine(x, (y + height - 1), (x + width), (y + height - 1)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue