Skip to content
Snippets Groups Projects
Commit 666af916 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Update on variable setting in avatar simulation

parent 4dea8849
No related branches found
No related tags found
No related merge requests found
...@@ -232,6 +232,14 @@ public class AvatarBlock extends AvatarElement implements AvatarStateMachineOwne ...@@ -232,6 +232,14 @@ public class AvatarBlock extends AvatarElement implements AvatarStateMachineOwne
return attributes.get(_index); return attributes.get(_index);
} }
public boolean setAttributeValue(int _index, String _value) {
AvatarAttribute aa = attributes.get(_index);
if (aa == null) {
return false;
}
aa.setInitialValue(_value);
return true;
}
public int getIndexOfAvatarAttributeWithName(String _name) { public int getIndexOfAvatarAttributeWithName(String _name) {
int cpt = 0; int cpt = 0;
......
...@@ -135,6 +135,15 @@ public class AvatarSimulationBlock { ...@@ -135,6 +135,15 @@ public class AvatarSimulationBlock {
return lastTransaction.attributeValues.get(_index); return lastTransaction.attributeValues.get(_index);
} }
public boolean setAttributeValue(int _index, String _value) {
if (lastTransaction == null) {
return block.setAttributeValue(_index, _value);
}
return lastTransaction.setAttributeValue(_index, _value);
}
public Vector<AvatarSimulationTransaction> getTransactions() { public Vector<AvatarSimulationTransaction> getTransactions() {
return transactions; return transactions;
} }
......
...@@ -169,4 +169,13 @@ public class AvatarSimulationTransaction { ...@@ -169,4 +169,13 @@ public class AvatarSimulationTransaction {
} }
return res; return res;
} }
public boolean setAttributeValue(int _index, String _value) {
if (_index >= attributeValues.size()) {
return false;
}
attributeValues.set(_index, _value);
return true;
}
} }
...@@ -98,12 +98,12 @@ public class AvatarSpecificationSimulation { ...@@ -98,12 +98,12 @@ public class AvatarSpecificationSimulation {
private boolean executeStateEntering; private boolean executeStateEntering;
private boolean silentTransactionExecuted; private boolean silentTransactionExecuted;
private IntExpressionEvaluator iee; //private IntExpressionEvaluator iee;
public AvatarSpecificationSimulation(AvatarSpecification _avspec, AvatarSimulationInteraction _asi) { public AvatarSpecificationSimulation(AvatarSpecification _avspec, AvatarSimulationInteraction _asi) {
avspec = _avspec; avspec = _avspec;
asi = _asi; asi = _asi;
iee = new IntExpressionEvaluator(); //iee = new IntExpressionEvaluator();
executeEmptyTransition = true; executeEmptyTransition = true;
executeStateEntering = true; executeStateEntering = true;
......
...@@ -260,7 +260,7 @@ public class TMLArchitecture { ...@@ -260,7 +260,7 @@ public class TMLArchitecture {
} }
return cpt; return cpt;
} }
public int getNbOfMem() { public int getNbOfMem() {
int cpt = 0; int cpt = 0;
......
...@@ -42,10 +42,7 @@ package ui.avatarinteractivesimulation; ...@@ -42,10 +42,7 @@ package ui.avatarinteractivesimulation;
import avatartranslator.*; import avatartranslator.*;
import avatartranslator.directsimulation.*; import avatartranslator.directsimulation.*;
import common.ConfigurationTTool; import common.ConfigurationTTool;
import myutil.FileUtils; import myutil.*;
import myutil.GraphicLib;
import myutil.TableSorter;
import myutil.TraceManager;
import myutilsvg.SVGGeneration; import myutilsvg.SVGGeneration;
import ui.*; import ui.*;
import ui.avatarbd.AvatarBDPortConnector; import ui.avatarbd.AvatarBDPortConnector;
...@@ -811,12 +808,12 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS ...@@ -811,12 +808,12 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
JTablejtablePIV.clearSelection(); JTablejtablePIV.clearSelection();
} }
int selectedRow = JTablejtablePIV.getSelectedRow(); selectedRow = JTablejtablePIV.getSelectedRow();
if (selectedRow < 0) if (selectedRow < 0)
return; return;
if (e.getComponent() instanceof JTable) { if (e.getComponent() instanceof JTable) {
TraceManager.addDev("Popup at x=" + e.getX() + " y=" + e.getY()); TraceManager.addDev("Popup at x=" + e.getX() + " y=" + e.getY() + " row=" + selectedRow);
JPopupMenu popup = createVariablePopup(); JPopupMenu popup = createVariablePopup();
popup.show(e.getComponent(), e.getX(), e.getY()); popup.show(e.getComponent(), e.getX(), e.getY());
} }
...@@ -2164,6 +2161,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS ...@@ -2164,6 +2161,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
downAsyncMsg(); downAsyncMsg();
} else if (evt.getSource() == edit) { } else if (evt.getSource() == edit) {
TraceManager.addDev("Edit variable at index: " + selectedRow); TraceManager.addDev("Edit variable at index: " + selectedRow);
editVariableValue(selectedRow);
} }
// Check for source of jcheckbox // Check for source of jcheckbox
...@@ -2288,6 +2286,52 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS ...@@ -2288,6 +2286,52 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
return menu; return menu;
} }
private void editVariableValue(int rowIndex) {
// Show dialog
String variableValue = (String)(variabletm.getValueAt(rowIndex, 3));
String blockName = (String)(variabletm.getValueAt(rowIndex, 0));
String variableName = (String)(variabletm.getValueAt(rowIndex, 2));
String type = ((String)(variabletm.getValueAt(rowIndex, 1))).toLowerCase();
String s = (String)JOptionPane.showInputDialog(this, "Block: " + blockName + ". Value of " + variableName,
"Variable modification", JOptionPane.PLAIN_MESSAGE, IconManager.imgic101,
null,
variableValue);
s = s.trim();
boolean ret;
try {
// Verifie the value is correct
if (type.startsWith("int")) {
int value = Integer.parseInt(s);
} else {
// We assume this is a boolean
boolean b = Boolean.parseBoolean(s);
}
ret = variabletm.setAttributeValueByRow(rowIndex, s);
variablePanel.repaint();
} catch (Exception e) {
// Not a correct value: show an error
TraceManager.addDev("Error in new variable value:" + e.getMessage());
ret = false;
}
if (!ret) {
// Show error on value change
JOptionPane.showMessageDialog(this,
"Could not change the value of " + variableName + ": the new value is incorrect",
"Error",
JOptionPane.INFORMATION_MESSAGE);
}
}
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
TraceManager.addDev("Windows closed!"); TraceManager.addDev("Windows closed!");
close(); close();
......
...@@ -169,6 +169,27 @@ public class VariableTableModel extends AbstractTableModel { ...@@ -169,6 +169,27 @@ public class VariableTableModel extends AbstractTableModel {
return ERROR_STRING; return ERROR_STRING;
} }
public boolean setAttributeValueByRow(int _row, String _value) {
int indexBlock = 0;
Vector<AvatarSimulationBlock> blocks = ass.getSimulationBlocks();
if (blocks.size() == 0) {
return false;
}
AvatarSimulationBlock block;
while(_row >= 0) {
block = blocks.get(indexBlock);
if (_row < block.getBlock().attributeNb()) {
return block.setAttributeValue(_row, _value);
}
_row = _row - block.getBlock().attributeNb();
indexBlock ++;
}
return false;
}
// Assumes tmlm != null // Assumes tmlm != null
private String getBlockName(int row) { private String getBlockName(int row) {
...@@ -195,26 +216,7 @@ public class VariableTableModel extends AbstractTableModel { ...@@ -195,26 +216,7 @@ public class VariableTableModel extends AbstractTableModel {
private String getVariableValue(int row) { private String getVariableValue(int row) {
return getAttributeValueByRow(row); return getAttributeValueByRow(row);
} }
public String getBlockStatus(int row) {
int status = ass.getSimulationBlocks().get(row).getStatus();
switch(status) {
case AvatarSimulationBlock.NOT_STARTED:
return "not started";
case AvatarSimulationBlock.STARTED:
return "running";
case AvatarSimulationBlock.COMPLETED:
return "terminated";
}
return "unknown";
}
public String getBlockNbOfTransactions(int row) {
return ""+ ass.getSimulationBlocks().get(row).getTransactions().size();
}
private void computeData() { private void computeData() {
nbOfRows = 0; nbOfRows = 0;
if (ass == null) { if (ass == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment