From 666af916495c406fc01cb0e05ff60a3822f1aad5 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Fri, 18 Jan 2019 12:06:23 +0100 Subject: [PATCH] Update on variable setting in avatar simulation --- .../java/avatartranslator/AvatarBlock.java | 8 +++ .../AvatarSimulationBlock.java | 9 +++ .../AvatarSimulationTransaction.java | 9 +++ .../AvatarSpecificationSimulation.java | 4 +- .../java/tmltranslator/TMLArchitecture.java | 2 +- .../JFrameAvatarInteractiveSimulation.java | 56 +++++++++++++++++-- .../VariableTableModel.java | 42 +++++++------- 7 files changed, 101 insertions(+), 29 deletions(-) diff --git a/src/main/java/avatartranslator/AvatarBlock.java b/src/main/java/avatartranslator/AvatarBlock.java index 58c022392b..b159cc3223 100644 --- a/src/main/java/avatartranslator/AvatarBlock.java +++ b/src/main/java/avatartranslator/AvatarBlock.java @@ -232,6 +232,14 @@ public class AvatarBlock extends AvatarElement implements AvatarStateMachineOwne 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) { int cpt = 0; diff --git a/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java b/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java index c5c5564faf..453287db78 100644 --- a/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java +++ b/src/main/java/avatartranslator/directsimulation/AvatarSimulationBlock.java @@ -135,6 +135,15 @@ public class AvatarSimulationBlock { 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() { return transactions; } diff --git a/src/main/java/avatartranslator/directsimulation/AvatarSimulationTransaction.java b/src/main/java/avatartranslator/directsimulation/AvatarSimulationTransaction.java index f806ac5dc4..38b52722c0 100644 --- a/src/main/java/avatartranslator/directsimulation/AvatarSimulationTransaction.java +++ b/src/main/java/avatartranslator/directsimulation/AvatarSimulationTransaction.java @@ -169,4 +169,13 @@ public class AvatarSimulationTransaction { } return res; } + + public boolean setAttributeValue(int _index, String _value) { + if (_index >= attributeValues.size()) { + return false; + } + attributeValues.set(_index, _value); + return true; + + } } diff --git a/src/main/java/avatartranslator/directsimulation/AvatarSpecificationSimulation.java b/src/main/java/avatartranslator/directsimulation/AvatarSpecificationSimulation.java index ead12d0a8b..6f45749f49 100644 --- a/src/main/java/avatartranslator/directsimulation/AvatarSpecificationSimulation.java +++ b/src/main/java/avatartranslator/directsimulation/AvatarSpecificationSimulation.java @@ -98,12 +98,12 @@ public class AvatarSpecificationSimulation { private boolean executeStateEntering; private boolean silentTransactionExecuted; - private IntExpressionEvaluator iee; + //private IntExpressionEvaluator iee; public AvatarSpecificationSimulation(AvatarSpecification _avspec, AvatarSimulationInteraction _asi) { avspec = _avspec; asi = _asi; - iee = new IntExpressionEvaluator(); + //iee = new IntExpressionEvaluator(); executeEmptyTransition = true; executeStateEntering = true; diff --git a/src/main/java/tmltranslator/TMLArchitecture.java b/src/main/java/tmltranslator/TMLArchitecture.java index 466aef7eee..1804f6ee9b 100755 --- a/src/main/java/tmltranslator/TMLArchitecture.java +++ b/src/main/java/tmltranslator/TMLArchitecture.java @@ -260,7 +260,7 @@ public class TMLArchitecture { } return cpt; } - + public int getNbOfMem() { int cpt = 0; diff --git a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java index 08b1adc069..26b722873b 100755 --- a/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java +++ b/src/main/java/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java @@ -42,10 +42,7 @@ package ui.avatarinteractivesimulation; import avatartranslator.*; import avatartranslator.directsimulation.*; import common.ConfigurationTTool; -import myutil.FileUtils; -import myutil.GraphicLib; -import myutil.TableSorter; -import myutil.TraceManager; +import myutil.*; import myutilsvg.SVGGeneration; import ui.*; import ui.avatarbd.AvatarBDPortConnector; @@ -811,12 +808,12 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS JTablejtablePIV.clearSelection(); } - int selectedRow = JTablejtablePIV.getSelectedRow(); + selectedRow = JTablejtablePIV.getSelectedRow(); if (selectedRow < 0) return; 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(); popup.show(e.getComponent(), e.getX(), e.getY()); } @@ -2164,6 +2161,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS downAsyncMsg(); } else if (evt.getSource() == edit) { TraceManager.addDev("Edit variable at index: " + selectedRow); + editVariableValue(selectedRow); } // Check for source of jcheckbox @@ -2288,6 +2286,52 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS 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) { TraceManager.addDev("Windows closed!"); close(); diff --git a/src/main/java/ui/avatarinteractivesimulation/VariableTableModel.java b/src/main/java/ui/avatarinteractivesimulation/VariableTableModel.java index 66b7a0624d..713411a169 100755 --- a/src/main/java/ui/avatarinteractivesimulation/VariableTableModel.java +++ b/src/main/java/ui/avatarinteractivesimulation/VariableTableModel.java @@ -169,6 +169,27 @@ public class VariableTableModel extends AbstractTableModel { 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 private String getBlockName(int row) { @@ -195,26 +216,7 @@ public class VariableTableModel extends AbstractTableModel { private String getVariableValue(int 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() { nbOfRows = 0; if (ass == null) { -- GitLab