You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
5.2 KiB
258 lines
5.2 KiB
//==============================================================================
|
|
//
|
|
// Copyright (c) 2002-
|
|
// Authors:
|
|
// * Andrew Hinton <ug60axh@cs.bham.uc.uk> (University of Birmingham)
|
|
// * Dave Parker <dxp@cs.bham.uc.uk> (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 javax.swing.*;
|
|
import userinterface.properties.*;
|
|
import simulator.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import javax.swing.event.*;
|
|
import parser.*;
|
|
import prism.*;
|
|
|
|
/**
|
|
*
|
|
* @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)
|
|
{
|
|
//create the expression in the simulator
|
|
try
|
|
{
|
|
long exprPointer = expr.toSimulator(engine);
|
|
|
|
int index = SimulatorEngine.loadProposition(exprPointer);
|
|
|
|
SimLabel sl = new SimLabel(name, index);
|
|
listModel.addElement(sl);
|
|
}
|
|
catch(SimulatorException e)
|
|
{
|
|
//System.out.println("exception "+e);
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
return SimulatorEngine.queryProposition(formulaIndex);
|
|
}
|
|
|
|
public int getResult(int step)
|
|
{
|
|
return SimulatorEngine.queryProposition(formulaIndex, step);
|
|
}
|
|
}
|
|
|
|
class InitSimLabel extends SimLabel
|
|
{
|
|
public InitSimLabel()
|
|
{
|
|
super("init", 0);
|
|
}
|
|
|
|
public int getResult()
|
|
{
|
|
return SimulatorEngine.queryIsInitial();
|
|
}
|
|
|
|
public int getResult(int step)
|
|
{
|
|
return SimulatorEngine.queryIsInitial(step);
|
|
}
|
|
}
|
|
|
|
class DeadlockSimLabel extends SimLabel
|
|
{
|
|
public DeadlockSimLabel()
|
|
{
|
|
super("deadlock", 0);
|
|
}
|
|
|
|
public int getResult()
|
|
{
|
|
return SimulatorEngine.queryIsDeadlock();
|
|
}
|
|
|
|
public int getResult(int step)
|
|
{
|
|
return SimulatorEngine.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));
|
|
|
|
}
|
|
}
|
|
|
|
}
|