From 31d965e581dbc77ccc55c41258b8c4f311ccfc77 Mon Sep 17 00:00:00 2001 From: Letitia Li <letitia.li@telecom-paristech.fr> Date: Mon, 21 Nov 2016 08:36:40 +0100 Subject: [PATCH] interactive simulation classes added --- .../JFrameInteractiveSimulation.java | 77 ++++++----- .../LatencyTableModel.java | 122 ++++++++++++++++++ .../SimulationLatency.java | 64 +++++++++ 3 files changed, 232 insertions(+), 31 deletions(-) create mode 100755 src/ui/interactivesimulation/LatencyTableModel.java create mode 100644 src/ui/interactivesimulation/SimulationLatency.java diff --git a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java index ae29f1b464..27f9a8c49d 100755 --- a/src/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -71,6 +71,7 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.HashMap; import java.util.Vector; +import java.util.Collections; import javax.swing.AbstractButton; import javax.swing.Action; @@ -970,31 +971,37 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen GridBagConstraints c0 = new GridBagConstraints(); latencyPanel.setLayout(gridbag0); infoTab.addTab("Latency", null, latencyPanel, "Latency Measurements"); - c0.gridwidth = GridBagConstraints.REMAINDER; + + c0.gridwidth=1; + transaction1 = new JComboBox(checkedTransactions); + latencyPanel.add(transaction1, c0); + + c0.gridwidth= GridBagConstraints.REMAINDER; + transaction2 = new JComboBox(checkedTransactions); + latencyPanel.add(transaction2, c0); + + + addLatencyCheckButton = new JButton(actions[InteractiveSimulationActions.ACT_ADD_LATENCY]); + latencyPanel.add(addLatencyCheckButton,c0); + latm = new LatencyTableModel(this); latm.setData(latencies); sorterPI = new TableSorter(latm); jtablePI = new JTable(sorterPI); sorterPI.setTableHeader(jtablePI.getTableHeader()); - ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(200); - ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(200); + ((jtablePI.getColumnModel()).getColumn(0)).setPreferredWidth(100); + ((jtablePI.getColumnModel()).getColumn(1)).setPreferredWidth(100); ((jtablePI.getColumnModel()).getColumn(2)).setPreferredWidth(50); jtablePI.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jspLatency = new JScrollPane(jtablePI); jspLatency.setWheelScrollingEnabled(true); jspLatency.getVerticalScrollBar().setUnitIncrement(10); - jspLatency.setMinimumSize(new Dimension(300, 300)); - jspLatency.setPreferredSize(new Dimension(300, 300)); + jspLatency.setMinimumSize(new Dimension(250, 300)); + jspLatency.setPreferredSize(new Dimension(250, 300)); latencyPanel.add(jspLatency, c0); - transaction1 = new JComboBox(checkedTransactions); - transaction2 = new JComboBox(checkedTransactions); - latencyPanel.add(transaction1, c0); - latencyPanel.add(transaction2, c0); - addLatencyCheckButton = new JButton(actions[InteractiveSimulationActions.ACT_ADD_LATENCY]); - latencyPanel.add(addLatencyCheckButton,c0); updateLatencyButton = new JButton(actions[InteractiveSimulationActions.ACT_UPDATE_LATENCY]); latencyPanel.add(updateLatencyButton,c0); @@ -1726,6 +1733,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen //TraceManager.addDev("Command handled"); st.startTime = elt.getAttribute("starttime"); st.endTime = elt.getAttribute("endtime"); + // System.out.println("command " +commandT); if (checkTable.containsKey(commandT)){ //System.out.println("added trans " + commandT + " " +st.endTime); if (!transTimes.containsKey(commandT)){ @@ -1741,6 +1749,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen st.length = elt.getAttribute("length"); st.virtualLength = elt.getAttribute("virtuallength"); st.channelName = elt.getAttribute("ch"); + // st.id = id; if (trans == null) { trans = new Vector<SimulationTransaction>(); @@ -1845,6 +1854,10 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen if (transactionPanel != null) { transactionPanel.setData(trans); } + if (latencyPanel !=null){ + System.out.println("Processing latencies..."); + processLatency(); + } //ttm.setData(trans); } } catch (Exception e) { @@ -2310,37 +2323,39 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen updateLatency(); latm.setData(latencies); } - private void updateLatency(){ + //sendCommand("lt 100"); + } + + private void processLatency(){ + System.out.println(transTimes); for (Object o: latencies){ - SimulationLatency sl = (SimulationLatency) o; - for (String st1:transTimes.keySet()){ - if (checkTable.containsKey(st1)){ + SimulationLatency sl = (SimulationLatency) o; + for (String st1:transTimes.keySet()){ for (String st2:transTimes.keySet()){ if (st1!=st2){ - if (checkTable.containsKey(st2)){ - if (checkTable.get(st2).contains(sl.trans2) && checkTable.get(st1).contains(sl.trans1)){ - int time = 0; - for(String time1: transTimes.get(st1)){ - for (String time2: transTimes.get(st2)){ - int diff = Integer.valueOf(time1) - Integer.valueOf(time2); - if (diff > time && diff >0){ - time=diff; - } - } + if (checkTable.get(st2).contains(sl.trans2) && checkTable.get(st1).contains(sl.trans1)){ + ArrayList<Integer> minTimes = new ArrayList<Integer>(); + for(String time1: transTimes.get(st1)){ + //Find the first subsequent transaction + int time = Integer.MAX_VALUE; + for (String time2: transTimes.get(st2)){ + int diff = Integer.valueOf(time1) - Integer.valueOf(time2); + if (diff < time && diff >0){ + time=diff; + } } - sl.time=Integer.toString(time); - //System.out.println(sl.trans2 + " "+sl.trans1 + " " + time); - //sl.time= Integer.toString(Math.abs(Integer.valueOf(st.startTime)-Integer.valueOf(st2.startTime))); - + minTimes.add(time); } + sl.time=Integer.toString(Collections.max(minTimes)); } + } } + } } - } latm.setData(latencies); } @@ -3030,7 +3045,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListen return; } - System.out.println(tmap.getTMLModeling().getCheckedComps()); + //System.out.println(tmap.getTMLModeling().getCheckedComps()); for (String s: tmap.getTMLModeling().getCheckedActivities()){ TraceManager.addDev(s); checkedTransactions.add(s.split("__")[s.split("__").length-1]); diff --git a/src/ui/interactivesimulation/LatencyTableModel.java b/src/ui/interactivesimulation/LatencyTableModel.java new file mode 100755 index 0000000000..97eb848eb8 --- /dev/null +++ b/src/ui/interactivesimulation/LatencyTableModel.java @@ -0,0 +1,122 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class TransactionTableModel + * Recent transactions + * Creation: 20/05/2016 + * @version 1.0 20/05/2016 + * @author Ludovic APVRILLE + * @see + */ + +package ui.interactivesimulation; + +import java.util.*; +import javax.swing.table.*; + +import myutil.*; +import tmltranslator.*; + +public class LatencyTableModel extends AbstractTableModel { + private JFrameInteractiveSimulation jfis; + private int nbOfRows; + private SimulationLatency data[]; + + //private String [] names; + public LatencyTableModel(JFrameInteractiveSimulation _jfis) { + jfis = jfis; + SimulationLatency sl = new SimulationLatency(); + data = new SimulationLatency[]{sl}; + + } + + // From AbstractTableModel + public synchronized int getRowCount() { + if (data == null) { + return 0; + } + return data.length; + } + + public int getColumnCount() { + return 3; + } + + public synchronized Object getValueAt(int row, int column) { + if (data == null) { + return ""; + } + + if (row >= data.length) { + return ""; + } + + SimulationLatency st = data[row]; + + switch(column) { + case 0: + return st.trans1; + case 1: + return st.trans2; + case 2: + return st.time; + } + return "unknown"; + } + + public String getColumnName(int columnIndex) { + switch(columnIndex) { + case 0: + return "Transaction 1"; + case 1: + return "Transaction 2"; + case 2: + return "Time"; + } + return "unknown"; + } + + public synchronized void setData(Vector<SimulationLatency> _trans) { + data = new SimulationLatency[_trans.size()]; + for(int i=0; i<_trans.size(); i++) { + data[i] = _trans.get(i); + } + fireTableStructureChanged(); + } + +} diff --git a/src/ui/interactivesimulation/SimulationLatency.java b/src/ui/interactivesimulation/SimulationLatency.java new file mode 100644 index 0000000000..75a3c125e7 --- /dev/null +++ b/src/ui/interactivesimulation/SimulationLatency.java @@ -0,0 +1,64 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class SimulationTransaction + * Transaction as defined by the simulation engine + * Creation: 20/05/2016 + * @version 1.0 20/05/2016 + * @author Ludovic APVRILLE + * @see + */ + +package ui.interactivesimulation; + +import java.util.*; +import javax.swing.table.*; + +import myutil.*; +import tmltranslator.*; + +public class SimulationLatency { + + public String trans1; + public String trans2; + public String time=""; + + public SimulationLatency() { + } + +} -- GitLab