diff --git a/simulators/c++2/src_simulator/TMLTransaction.cpp b/simulators/c++2/src_simulator/TMLTransaction.cpp index bf38c3d9004428443267d9e1c73ec4e1ea4c0c67..16ded39761df4a777d24cb340902c41ccb4186cb 100755 --- a/simulators/c++2/src_simulator/TMLTransaction.cpp +++ b/simulators/c++2/src_simulator/TMLTransaction.cpp @@ -93,9 +93,9 @@ std::string TMLTransaction::toShortString() const{ void TMLTransaction::toXML(std::ostringstream& glob, int deviceID, std::string deviceName, ID uniqueID) const { if (_command==0) { - glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" id=\"" << _command->getID() << "\" runnableTime=\"" << _runnableTime << "\" command=\"0\""; + glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" corenumber=\"" << _transactCoreNumber << "\" id=\"" << _command->getID() << "\" runnableTime=\"" << _runnableTime << "\" command=\"0\""; } else { - glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" command=\"" << _command->toShortString() << "\""; + glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" corenumber=\"" << _transactCoreNumber << "\" command=\"" << _command->toShortString() << "\""; std::cout << "Info transaction:" << " starttime=\"" << _startTime << "\" endtime=\"" << getEndTime() << " length" << _length << "\" virtuallength=" << _virtualLength << " getStartTime:" << getStartTime() << "\n"; glob << " starttime=\"" << _startTime << "\" endtime=\"" << getEndTime() << "\" length=\"" << _length << "\" virtuallength=\"" << _virtualLength << "\" id=\"" << _command->getID() << "\""<< " runnableTime=\"" << _runnableTime << "\"" ; if (_channel!=0) glob << " ch=\"" << _channel->toShortString() << "\"" ; @@ -108,11 +108,11 @@ void TMLTransaction::toXML(std::ostringstream& glob, int deviceID, std::string d void TMLTransaction::toXMLByTask(std::ostringstream& glob, int deviceID, std::string deviceName, ID uniqueID, std::string taskName) const { if (_command==0) { - glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" id=\"" << _command->getID() << "\" runnableTime=\"" << _runnableTime << "\" command=\"0\""; + glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" corenumber=\"" << _transactCoreNumber << "\" id=\"" << _command->getID() << "\" runnableTime=\"" << _runnableTime << "\" command=\"0\""; } else { if (_command->getTask()->toString() == taskName){ std::cout << "Info transaction: "<< "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" command=\"" << _command->toShortString() << "\"" << std::endl; - glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" command=\"" << _command->toShortString() << "\""; + glob << TAG_TRANSo << " uniqueid=\"" << uniqueID << "\" deviceid=\"" << deviceID << "\" devicename=\"" << deviceName << "\" corenumber=\"" << _transactCoreNumber << "\" command=\"" << _command->toShortString() << "\""; glob << " starttime=\"" << _startTime << "\" endtime=\"" << getEndTime() << "\" length=\"" << _length << "\" virtuallength=\"" << _virtualLength << "\" id=\"" << _command->getID() << "\""<< " runnableTime=\"" << _runnableTime << "\"" ; if (_channel!=0) glob << " ch=\"" << _channel->toShortString() << "\"" ; } diff --git a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java index 144ea396e726ca447cb184c194369fb8373b702b..f15d24b46abf9ff4b9f3a6caead2fa222ec3a07c 100755 --- a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java +++ b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java @@ -112,8 +112,9 @@ public class InteractiveSimulationActions extends AbstractAction { public static final int ACT_SAVE_SD_PNG = 39; public static final int ACT_REMOVE_ALL_TRANS = 41; - public static final int ACT_SHOW_TRACE_HTML = 42; - public static final int NB_ACTION = 43; + public static final int ACT_SHOW_TRACE_TIMELINE = 42; + public static final int ACT_SAVE_TIMELINE_HTML = 43; + public static final int NB_ACTION = 44; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -200,11 +201,12 @@ public class InteractiveSimulationActions extends AbstractAction { actions[ACT_UPDATE_LATENCY] = new TAction("update-latency", "Update latencies", IconManager.imgic75, IconManager.imgic75, "Update latencies", "Update latencies", '0'); actions[ACT_ADD_LATENCY] = new TAction("add-latency", "Measure Latency", null, null, "Measure Latency", "Measure Latency", '0'); actions[ACT_SHOW_TRACE] = new TAction("show-trace", "Show Simulation Traces", IconManager.imgic7007, IconManager.imgic7007, "Show Simulation Traces", "Show Simulation Traces", '0'); - actions[ACT_SHOW_TRACE_HTML] = new TAction("show-trace-html", "Show Simulation Traces in html", IconManager.imgic7007, IconManager.imgic7007, "Show Simulation Traces in html", "Show Simulation Traces in html format", '0'); + actions[ACT_SHOW_TRACE_TIMELINE] = new TAction("show-trace-timeline", "Simulation Trace - Timeline", IconManager.imgic8030, IconManager.imgic8030, "Show Simulation Traces in timeline", "Show Simulation Traces in timeline format", '0'); actions[ACT_QUIT_SD_WINDOW] = new TAction("close-sdpanel", "Close Window", IconManager.imgic27, IconManager.imgic27, "Close window", "Close this window", 'Q'); actions[ACT_SAVE_SD_SVG] = new TAction("svg-sdpanel", "Save in SVG Format", IconManager.imgic1310, IconManager.imgic1310, "Save in SVG Format", "Save as SVG file", 'S'); actions[ACT_SAVE_SD_PNG] = new TAction("png-sdpanel", "Save in PNG Format", IconManager.imgic1310, IconManager.imgic1310, "Save in PNG Format", "Save as PNG file", 'S'); + actions[ACT_SAVE_TIMELINE_HTML] = new TAction("html-timelinepanel", "Save in html Format", IconManager.imgic1310, IconManager.imgic1310, "Save in HTML Format", "Save as HTML file", 'S'); } diff --git a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java index 49f1e196eae2f7440fea37a311b28bcb6ed77d71..699ffef0dd38459d15d654a1ebe4b4b801fb9408 100644 --- a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -72,8 +72,6 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.*; import java.util.List; @@ -114,7 +112,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene private String hostSystemC; private String pathExecute; - protected JButton buttonClose, buttonStart, buttonStopAndClose, buttonShowTrace, buttonShowTraceHtml; + protected JButton buttonClose, buttonStart, buttonStopAndClose, buttonShowTrace, buttonShowTraceTimeline; protected JTextArea jta; protected JScrollPane jsp; @@ -257,7 +255,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene private PipedOutputStream pos; private PipedInputStream pis; private JFrameTMLSimulationPanel tmlSimPanel; - private JFrameTMLSimulationPanelHtml tmlSimPanelHtml; + private JFrameTMLSimulationPanelTimeline tmlSimPanelTimeline; private BufferedWriter bw; private int simIndex=0; @@ -333,7 +331,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene buttonClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_ALL]); buttonStopAndClose = new JButton(actions[InteractiveSimulationActions.ACT_STOP_AND_CLOSE_ALL]); buttonShowTrace = new JButton(actions[InteractiveSimulationActions.ACT_SHOW_TRACE]); - buttonShowTraceHtml = new JButton(actions[InteractiveSimulationActions.ACT_SHOW_TRACE_HTML]); + buttonShowTraceTimeline = new JButton(actions[InteractiveSimulationActions.ACT_SHOW_TRACE_TIMELINE]); //buttonStopAndClose = new JButton(buttonStopAndCloseS, IconManager.imgic27); @@ -358,7 +356,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene jp.add(buttonStopAndClose); jp.add(buttonClose); jp.add(buttonShowTrace); - jp.add(buttonShowTraceHtml); + jp.add(buttonShowTraceTimeline); mainpanel.add(jp, BorderLayout.NORTH); // mainpanel.setSize(mainpanel.getPreferredSize()); // validate(); @@ -1528,19 +1526,35 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } } - public void writeSimTraceHtml() { - tmlSimPanelHtml = new JFrameTMLSimulationPanelHtml(new Frame(), mgui, trans, "Show Trace in HTML"); - //Make a popup to select which tasks - Vector<String> tmlComponentsToValidate = new Vector<String>(); - List<String> tasks = new ArrayList<String>(); - for (TMLTask task: tmap.getTMLModeling().getTasks()){ - tasks.add(task.getName()); + public void writeSimTraceTimeline() { + if(trans != null && !trans.isEmpty()) { + try { + //Make a popup to select which tasks + Vector<String> tmlComponentsToValidate = new Vector<String>(); + List<String> tasks = new ArrayList<String>(); + for (TMLTask task : tmap.getTMLModeling().getTasks()) { + tasks.add(task.getName()); + } + JDialogSelectTasks jdstmlc = new JDialogSelectTasks(f, tmlComponentsToValidate, tasks, "Select tasks to show in trace"); + + GraphicLib.centerOnParent(jdstmlc); + jdstmlc.setVisible(true); + Vector<SimulationTransaction> _transCopy = new Vector<SimulationTransaction>(); + for (int i = 0; i < trans.size(); i++) { + for (String taskname : tmlComponentsToValidate) { + if (taskname.equals(trans.get(i).taskName)) { + _transCopy.add(trans.get(i)); + } + } + } + if(!_transCopy.isEmpty()) { + tmlSimPanelTimeline = new JFrameTMLSimulationPanelTimeline(new Frame(), mgui, _transCopy, "Show Trace - Timeline"); + tmlSimPanelTimeline.setVisible(true); + } + } catch (Exception e) { + System.out.println("Error: " + e.toString()); + } } - JDialogSelectTasks jdstmlc = new JDialogSelectTasks(f, tmlComponentsToValidate, tasks, "Select tasks to show in trace"); - - GraphicLib.centerOnParent(jdstmlc); - jdstmlc.setVisible(true); - tmlSimPanelHtml.setVisible(true); } public void writeArchitectureSimTrace(){ @@ -2225,6 +2239,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene } st.deviceName = elt.getAttribute("devicename"); + st.coreNumber = elt.getAttribute("corenumber"); + String commandT = elt.getAttribute("command"); if (commandT != null) { int index = commandT.indexOf(": "); @@ -3573,8 +3589,8 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene resetSimTrace(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_SHOW_TRACE].getActionCommand())) { writeSimTrace(); - } else if (command.equals(actions[InteractiveSimulationActions.ACT_SHOW_TRACE_HTML].getActionCommand())) { - writeSimTraceHtml(); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_SHOW_TRACE_TIMELINE].getActionCommand())) { + writeSimTraceTimeline(); } } diff --git a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java deleted file mode 100644 index eb5d0bd22a6490842c368a4088b63ccdb759c185..0000000000000000000000000000000000000000 --- a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java +++ /dev/null @@ -1,436 +0,0 @@ -package ui.interactivesimulation; - -import myutil.FileUtils; -import myutil.TraceManager; -import myutilsvg.SVGGeneration; -import ui.ColorManager; -import ui.MainGUI; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Vector; - -public class JFrameTMLSimulationPanelHtml extends JFrame implements ActionListener { - - public InteractiveSimulationActions [] actions; - private Vector<SimulationTransaction> trans; - - private static String[] unitTab = {"sec", "msec", "usec", "nsec"}; - private static int[] clockDivisers = {1000000000, 1000000, 1000, 1}; - protected JComboBox<String> units; - - private JEditorPane sdpanel; - protected JLabel status; - //, buttonStart, buttonStopAndClose; - //protected JTextArea jta; - //protected JScrollPane jsp; - - private MainGUI mgui; - - public JFrameTMLSimulationPanelHtml(Frame _f, MainGUI _mgui, Vector<SimulationTransaction> _trans, String _title) { - super(_title); - mgui = _mgui; - initActions(); - trans = _trans; - makeComponents(); - //setComponents(); -// this.addComponentListener(new ComponentAdapter() { -// @Override -// public void componentResized(ComponentEvent e) -// { -// if (JFrameTMLSimulationPanelHtml.this.sdpanel != null) -// JFrameTMLSimulationPanelHtml.this.sdpanel.resized(); -// } -// }); - } - private JLabel createStatusBar() { - status = new JLabel("Ready..."); - status.setForeground(ColorManager.InteractiveSimulationText); - status.setBorder(BorderFactory.createEtchedBorder()); - return status; - } - - public void makeComponents() { - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - Container framePanel = getContentPane(); - framePanel.setLayout(new BorderLayout()); - - // Top panel - JPanel topPanel = new JPanel(); - JButton buttonClose = new JButton(actions[InteractiveSimulationActions.ACT_QUIT_SD_WINDOW]); - topPanel.add(buttonClose); - JButton buttonSVG = new JButton(actions[InteractiveSimulationActions.ACT_SAVE_SD_SVG]); - topPanel.add(buttonSVG); - JButton buttonPNG = new JButton(actions[InteractiveSimulationActions.ACT_SAVE_SD_PNG]); - topPanel.add(buttonPNG); - - /*topPanel.add(new JLabel(" time unit:")); - units = new JComboBox<>(unitTab); - units.setSelectedIndex(1); - units.addActionListener(this); - topPanel.add(units); - JButton buttonRefresh = new JButton(actions[InteractiveSimulationActions.ACT_REFRESH]); - topPanel.add(buttonRefresh);*/ - framePanel.add(topPanel, BorderLayout.NORTH); - - // Simulation panel - sdpanel = new JEditorPane(); - sdpanel.setEditable(true); - sdpanel.setContentType("text/html"); - String temp = "<!DOCTYPE html>\n" + "<html>\n"; - temp += "<head>\n" + - "<style>"; - temp += "table{\n" + - " \tborder-collapse: collapse;\n" + - " \tempty-cells: show;\n" + - " \tmargin: 0.4cm;\n" + - " }\n" + - " td{\n" + - " \tpadding: 10px 5px;\n" + - " \tborder: 1px solid black;\n" + - " \tmax-width: 5px;\n" + - " }\n" + - " th{\n" + - " \tpadding: 5px;\n" + - " \tborder-left: 1px dotted black;\n" + - " \tborder-right: 1px dotted black;\n" + - " }\n" + - " .sc{\n" + - " \tborder-style: none;\n" + - " \tpadding: 0px;\n" + - " \tfont-size: small;\n" + - " transform: rotate(45deg);\n" + - " transform-origin: left top;\n" + - " }\n" + - " .sc1{\n" + - " \tborder-style: none;\n" + - " \tpadding: 0px;\n" + - " \tfont-size: small;\n" + - " \tcolor: red;\n" + - " transform: rotate(45deg);\n" + - " transform-origin: left top;\n" + - " }\n" + - " h2 {\n" + - " \tborder-bottom: 1px solid #666;\n" + - " }\n" + - " h2 span {\n" + - " \tposition: relative;\n" + - " \tleft: -0.3em;\n" + - " \tbottom: -0.6em;\n" + - " \tpadding: 1px 0.5em;\n" + - " \tborder-style: solid;\n" + - " \tborder-width: 1px 1px 1px 0.8em;\n" + - " \tborder-color: #666 #666 #666 #008;\n" + - " \tbackground-color: #ddd;\n" + - " }\n" + - " .space{border-style: none;}\n" + - " .not{background-color: white;}\n" + - " .notfirst {\n" + - " \tbackground-color: white;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .notmid {\n" + - " \tbackground-color: white;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .notlast {\n" + - " \tbackground-color: white;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t0{background-color: yellow;}\n" + - " .t0first {\n" + - " \tbackground-color: yellow;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t0mid {\n" + - " \tbackground-color: yellow;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t0last {\n" + - " \tbackground-color: yellow;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t1{background-color: purple;}\n" + - " .t1first {\n" + - " \tbackground-color: purple;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t1mid {\n" + - " \tbackground-color: purple;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t1last {\n" + - " \tbackground-color: purple;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t2{background-color: red;}\n" + - " .t2first {\n" + - " \tbackground-color: red;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t2mid {\n" + - " \tbackground-color: red;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t2last {\n" + - " \tbackground-color: red;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t3{background-color: silver;}\n" + - " .t3first {\n" + - " \tbackground-color: silver;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t3mid {\n" + - " \tbackground-color: silver;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t3last {\n" + - " \tbackground-color: silver;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t4{background-color: teal;}\n" + - " .t4first {\n" + - " \tbackground-color: teal;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t4mid {\n" + - " \tbackground-color: teal;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t4last {\n" + - " \tbackground-color: teal;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t5{background-color: aqua;}\n" + - " .t5first {\n" + - " \tbackground-color: aqua;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t5mid {\n" + - " \tbackground-color: aqua;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t5last {\n" + - " \tbackground-color: aqua;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t6{background-color: olive;}\n" + - " .t6first {\n" + - " \tbackground-color: olive;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t6mid {\n" + - " \tbackground-color: olive;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t6last {\n" + - " \tbackground-color: olive;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t7{background-color: navy;}\n" + - " .t7first {\n" + - " \tbackground-color: navy;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t7mid {\n" + - " \tbackground-color: navy;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t7last {\n" + - " \tbackground-color: navy;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t8{background-color: maroon;}\n" + - " .t8first {\n" + - " \tbackground-color: maroon;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t8mid {\n" + - " \tbackground-color: maroon;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t8last {\n" + - " \tbackground-color: maroon;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t9{background-color: lime;}\n" + - " .t9first {\n" + - " \tbackground-color: lime;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t9mid {\n" + - " \tbackground-color: lime;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t9last {\n" + - " \tbackground-color: lime;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t10{background-color: green;}\n" + - " .t10first {\n" + - " \tbackground-color: green;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t10mid {\n" + - " \tbackground-color: green;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t10last {\n" + - " \tbackground-color: green;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t11{background-color: gray;}\n" + - " .t11first {\n" + - " \tbackground-color: gray;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t11mid {\n" + - " \tbackground-color: gray;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t11last {\n" + - " \tbackground-color: gray;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t12{background-color: fuchsia;}\n" + - " .t12first {\n" + - " \tbackground-color: fuchsia;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t12mid {\n" + - " \tbackground-color: fuchsia;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t12last {\n" + - " \tbackground-color: fuchsia;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t13{background-color: blue;}\n" + - " .t13first {\n" + - " \tbackground-color: blue;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t13mid {\n" + - " \tbackground-color: blue;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t13last {\n" + - " \tbackground-color: blue;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .t14{\n" + - " \tbackground-color: LightGoldenRodYellow;\n" + - "}\n" + - " .t14first {\n" + - " \tbackground-color: LightGoldenRodYellow;\n" + - " \tborder-style: solid none solid solid;\n" + - " }\n" + - " .t14mid {\n" + - " \tbackground-color: LightGoldenRodYellow;\n" + - " \tborder-style: solid none solid none;\n" + - " }\n" + - " .t14last {\n" + - " \tbackground-color: LightGoldenRodYellow;\n" + - " \tborder-style: solid solid solid none;\n" + - " }\n" + - " .wrapper {\n" + - " \twidth: 256px;\n" + - " \theight: 256px;\n" + - " }\n" + - " .pie-chart-container {\n" + - " \twidth : 256px;\n" + - " \theight : 256px;\n" + - " \tfloat : left;\n" + - " \tmargin-left : 2em;\n" + - " }\n" + - " .clear {\n" + - " \tclear:both\n" + - " }"; - temp += "</style>\n" + - "</head>\n <body>"; - temp += "<table style=\"float: left\">\n<tr>"; - - for (int i = 0; i < 11; i ++){ -// temp += "<h1> --Device name " + trans.get(i).toString() + "--Task name " + trans.get(i).startTime + "--Command " + trans.get(i).endTime + -// "--end </h1>\n"; - - temp += "<td title=\"" + trans.get(i).command +"\" style = \"background-color: red;\" colspan=\"" + String.valueOf(Integer.valueOf(trans.get(i).endTime) - Integer.valueOf(trans.get(i).startTime)) + "\"></td>\n"; - - } - temp += "</tr>\n<tr><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th></tr>\n</body>\n" + "</html>"; - System.out.println(temp); - sdpanel.setText(temp); - - JScrollPane jsp = new JScrollPane(sdpanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); - jsp.setWheelScrollingEnabled(true); - jsp.getVerticalScrollBar().setUnitIncrement(MainGUI.INCREMENT); -// try { -// File file = new File("/home/levan/Desktop/TTool/simulators/c++2/test.html"); -// sdpanel.setPage(file.toURI().toURL()); -// } catch (IOException e) { -// e.printStackTrace(); -// } - framePanel.add(jsp, BorderLayout.CENTER); - - // statusBar - status = createStatusBar(); - framePanel.add(status, BorderLayout.SOUTH); - - // Mouse handler - //mouseHandler = new MouseHandler(status); - - pack(); - - // - // - } - private void initActions() { - actions = new InteractiveSimulationActions[InteractiveSimulationActions.NB_ACTION]; - for(int i=0; i<InteractiveSimulationActions.NB_ACTION; i++) { - actions[i] = new InteractiveSimulationActions(i); - actions[i].addActionListener(this); - //actions[i].addKeyListener(this); - } - } - - - public void close() { - dispose(); - setVisible(false); - } - - private void saveSVG() { - TraceManager.addDev("Saving in svg format"); - sdpanel.setText("<html>Saving in SVG format</html>"); - //newSVGSave(fileName); - } - - private void savePNG() { - TraceManager.addDev("Saving in png format"); - sdpanel.setText("<html>Saving in PNG format</html>"); - //newSVGSave(fileName); - } - - - public void actionPerformed(ActionEvent evt) { - String command = evt.getActionCommand(); - //TraceManager.addDev("Command:" + command); - - if (command.equals(actions[InteractiveSimulationActions.ACT_QUIT_SD_WINDOW].getActionCommand())) { - sdpanel=null; - close(); - } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_SD_SVG].getActionCommand())) { - saveSVG(); - } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_SD_PNG].getActionCommand())) { - savePNG(); - } - } -} diff --git a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelTimeline.java b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelTimeline.java new file mode 100644 index 0000000000000000000000000000000000000000..d82af4b5f59c62a9858cc50e67b622e9c48773c6 --- /dev/null +++ b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelTimeline.java @@ -0,0 +1,348 @@ +package ui.interactivesimulation; + +import myutil.FileUtils; +import myutil.TraceManager; +import ui.ColorManager; +import ui.MainGUI; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.io.File; +import java.io.FileOutputStream; +import java.util.*; + +public class JFrameTMLSimulationPanelTimeline extends JFrame implements ActionListener { + + public InteractiveSimulationActions[] actions; + private Vector<SimulationTransaction> trans; + + private static final int BIG_IDLE = 250; + private static String htmlContent; + private int count = 0; + protected JComboBox<String> units; + + private JTextPane sdpanel; + protected JLabel status; + + private MainGUI mgui; + + public JFrameTMLSimulationPanelTimeline(Frame _f, MainGUI _mgui, Vector<SimulationTransaction> _trans, String _title) { + super(_title); + mgui = _mgui; + initActions(); + trans = _trans; + makeComponents(); + } + + private JLabel createStatusBar() { + status = new JLabel("Ready..."); + status.setForeground(ColorManager.InteractiveSimulationText); + status.setBorder(BorderFactory.createEtchedBorder()); + return status; + } + + public void makeComponents() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Container framePanel = getContentPane(); + framePanel.setLayout(new BorderLayout()); + + // Top panel + JPanel topPanel = new JPanel(); + JButton buttonClose = new JButton(actions[InteractiveSimulationActions.ACT_QUIT_SD_WINDOW]); + topPanel.add(buttonClose); + JButton buttonHtml = new JButton(actions[InteractiveSimulationActions.ACT_SAVE_TIMELINE_HTML]); + topPanel.add(buttonHtml); + + // classify trans base on CPU and Core + Map<String, Vector<SimulationTransaction>> map = new HashMap<String, Vector<SimulationTransaction>>(); + Map<String, String> taskColors = new HashMap<String, String>(); + int taskIndex = 0; + int endTime = 0; + for (int i = 0; i < trans.size(); i++) { + //HW and task + String hwnode = (trans.get(i).deviceName.contains("Bus") ? trans.get(i).deviceName : trans.get(i).deviceName + "_core_" + trans.get(i).coreNumber); + if (map.get(hwnode) == null) { + map.put(hwnode, new Vector<SimulationTransaction>()); + } + map.get(hwnode).add(trans.get(i)); + // task color + String taskname = trans.get(i).taskName; + if (taskColors.get(taskname) == null) { + int cellIndex = taskIndex % 15; + taskIndex++; + String cellClass = "t" + String.valueOf(cellIndex); + taskColors.put(taskname, cellClass); + } + } + for (String i : map.keySet()) { + if (Integer.valueOf(map.get(i).lastElement().endTime) > endTime) endTime = Integer.valueOf(map.get(i).lastElement().endTime); + } + + framePanel.add(topPanel, BorderLayout.NORTH); + + // Simulation panel + sdpanel = new JTextPane(); + sdpanel.setEditable(false); + sdpanel.setContentType("text/html"); + htmlContent = "<!DOCTYPE html>\n" + "<html>\n"; + htmlContent += "<head>\n" + + "<style>\n"; + htmlContent += "table{\n" + + " \tborder-collapse: collapse;\n" + + " \tempty-cells: show;\n" + + " \tmargin: 0.4cm;\n" + + " }\n" + + " td{\n" + + " \tpadding: 10px 5px;\n" + + " \tborder: 1px solid black;\n" + + " \tmax-width: 5px;\n" + + " }\n" + + " th{\n" + + " \tpadding: 5px;\n" + + " }\n" + + " .sc{\n" + + " \tborder-style: none;\n" + + " \tpadding: 0px;\n" + + " \tfont-size: small;\n" + + " transform: rotate(45deg);\n" + + " transform-origin: left top;\n" + + " }\n" + + " .sc1{\n" + + " \tborder-style: none;\n" + + " \tpadding: 0px;\n" + + " \tfont-size: small;\n" + + " \tcolor: red;\n" + + " transform: rotate(45deg);\n" + + " transform-origin: left top;\n" + + " }\n" + + " h2 {\n" + + " \tborder-bottom: 1px solid #666;\n" + + " }\n" + + " h2 span {\n" + + " \tposition: relative;\n" + + " \tleft: -0.3em;\n" + + " \tbottom: -0.6em;\n" + + " \tpadding: 1px 0.5em;\n" + + " \tborder-style: solid;\n" + + " \tborder-width: 1px 1px 1px 0.8em;\n" + + " \tborder-color: #666 #666 #666 #008;\n" + + " \tbackground-color: #ddd;\n" + + " }\n" + + " .space{border-style: none;}\n" + + " .not{background-color: white; text-align: center}\n" + + ".notfirst{\n" + + " \tbackground-color: white;\n" + + " \tborder-width: 2px;\n" + + " \tborder-color: red;\n" + + " \tborder-style: none solid none none;\n" + + " }\n" + + " .notmid {\n" + + " \tbackground-color: white;\n" + + " \ttext-align: right;\n" + + " \tborder-style: solid none none none;\n" + + " }\n" + + " .notlast {\n" + + " \tbackground-color: white;\n" + + " \twidth: 5px;\n" + + " \tborder-style: none none none none;\n" + + " }\n" + + " .t0{background-color: yellow;}\n" + + " \n" + + " .t1{background-color: purple;}\n" + + " \n" + + " .t2{background-color: red;}\n" + + " \n" + + " .t3{background-color: silver;}\n" + + " \n" + + " .t4{background-color: teal;}\n" + + " \n" + + " .t5{background-color: aqua;}\n" + + " \n" + + " .t6{background-color: olive;}\n" + + " \n" + + " .t7{background-color: navy;}\n" + + "\n" + + " .t8{background-color: maroon;}\n" + + " \n" + + " .t9{background-color: lime;}\n" + + " \n" + + " .t10{background-color: green;}\n" + + " \n" + + " .t11{background-color: gray;}\n" + + "\n" + + " .t12{background-color: fuchsia;}\n" + + " \n" + + " .t13{background-color: blue;}\n" + + " \n" + + " .t14{background-color: LightGoldenRodYellow;}\n" + + " \n" + + " .wrapper {\n" + + " \twidth: 256px;\n" + + " \theight: 256px;\n" + + " }\n" + + " \n" + + " .clear {\n" + + " \tclear:both\n" + + " }\n"; + htmlContent += "</style>\n" + + "</head>\n<body>\n<table style=\"float: left;position: relative;\">"; + htmlContent += "<tr><td width=\"170px\" style=\"max-width: 170px;min-width: 170px;border-style: none none none none;\"></td>\n" + + "<td class=\"notfirst\"></td>\n" + + "<td style=\"border-style: solid none none none; border-width: 2px;border-color: red;text-align: right\" colspan=\"" + endTime + + "\"><b>Time</b></td>\n</tr>\n" + + "<tr><th></th><th class=\"notfirst\"></th></tr>\n" + + "<div class = \"clear\"></div>"; + for (String i : map.keySet()) { + count ++; + Vector<String> listScale = new Vector<String>(); + Vector<String> listScaleTime = new Vector<String>(); + listScale.add("0"); + listScaleTime.add("0"); + htmlContent += "<tr><td width=\"170px\" style=\"max-width: 170px;min-width: 170px;background-color: aqua;\">" + i + "</td>\n<td class=\"notfirst\"></td>\n<td class=\"notlast\"></td>\n"; + for (int j = 0; j < map.get(i).size(); j++) { + + if (j == 0 && Integer.valueOf(map.get(i).get(j).startTime) != 0) { + if(Integer.valueOf(map.get(i).get(j).startTime) > BIG_IDLE) { + htmlContent += "<td title=\"idle time" + "\" class = \"not\" colspan=\"10\"> <-IDLE " + map.get(i).get(j).startTime + "-> </td>\n"; + listScale.add("10"); + } else { + htmlContent += "<td title=\"idle time" + "\" class = \"not\" colspan=\"" + map.get(i).get(j).startTime + "\"></td>\n"; + listScale.add(map.get(i).get(j).startTime); + } + + if (Integer.valueOf(map.get(i).get(j).startTime) > Integer.valueOf(listScaleTime.lastElement())) { + listScaleTime.add(map.get(i).get(j).startTime); + } + if (Integer.valueOf(map.get(i).get(j).endTime) > Integer.valueOf(listScaleTime.lastElement())) { + listScaleTime.add(map.get(i).get(j).endTime); + } + } else if ((j != 0 && (Integer.valueOf(map.get(i).get(j).startTime) != Integer.valueOf(map.get(i).get(j - 1).endTime)))) { + int sub = Integer.valueOf(map.get(i).get(j).startTime) - Integer.valueOf(map.get(i).get(j - 1).endTime); + if (sub > BIG_IDLE) { + htmlContent += "<td title=\"idle time" + "\" class = \"not\" colspan=\"10\"> <-IDLE " + String.valueOf(sub) + "-> </td>\n"; + listScale.add("10"); + } else { + htmlContent += "<td title=\"idle time" + "\" class = \"not\" colspan=\"" + String.valueOf(sub) + "\"></td>\n"; + listScale.add(String.valueOf(sub)); + } + + } + + htmlContent += "<td title=\"" + map.get(i).get(j).command + "\" class = \"" + (map.get(i).get(j).command.contains("Idle") ? "not" : taskColors.get(map.get(i).get(j).taskName)) + "\" colspan=\"" + String.valueOf(Integer.valueOf(map.get(i).get(j).endTime) - Integer.valueOf(map.get(i).get(j).startTime)) + "\">" + map.get(i).get(j).command.substring(0, 1) + "</td>\n"; + listScale.add(String.valueOf(Integer.valueOf(map.get(i).get(j).endTime) - Integer.valueOf(map.get(i).get(j).startTime))); + if (Integer.valueOf(map.get(i).get(j).startTime) > Integer.valueOf(listScaleTime.lastElement())) { + listScaleTime.add(map.get(i).get(j).startTime); + } + if (Integer.valueOf(map.get(i).get(j).endTime) > Integer.valueOf(listScaleTime.lastElement())) { + listScaleTime.add(map.get(i).get(j).endTime); + } + } + htmlContent += "</tr>\n<tr>"; + for (int k = 0; k < Integer.valueOf(map.get(i).lastElement().endTime) + 2; k++) { + if( k == 1) { + htmlContent += "<th class=\"notfirst\">"; + } else { + htmlContent += "<th></th>"; + } + } + htmlContent += "</tr>\n<tr><td width=\"170px\" style=\"max-width: 170px;min-width: 170px;border-style: none none none none;\"></td>\n" + + "<td class=\"notfirst\"></td>\n<td class=\"notlast\"></td>"; + for (int l = 0; l < listScale.size(); l++) { + if (l + 1 >= listScale.size()) { + htmlContent += "<td title=\"" + listScaleTime.get(l) + "\" class = \"sc\" colspan=\"" + "5" + "\">" + listScaleTime.get(l) + "</td>\n"; + } else { + htmlContent += "<td title=\"" + listScaleTime.get(l) + "\" class = \"sc\" colspan=\"" + listScale.get(l + 1) + "\">" + listScaleTime.get(l) + "</td>\n"; + } + } + if( count >= map.size()){ + htmlContent += "</tr>\n<tr><th>HW</th><th class=\"notfirst\"></th></tr>\n<div class = \"clear\"></div>\n"; + } else { + htmlContent += "</tr>\n<tr><th></th><th class=\"notfirst\"></th></tr>\n<div class = \"clear\"></div>\n"; + } + + + } + htmlContent += "</table>\n<table>\n<tr><td width=\"170px\" style=\"max-width: 170px;min-width: 170px;border-style: none none none none;\"></td>\n" + + "<td class=\"notlast\"></td>\n"; + for (String colors : taskColors.keySet()) { + htmlContent += "<td class = \"" + taskColors.get(colors) + "\" style=\"max-width: 170px;min-width: 170px;\">" + colors + "</td>"; + htmlContent += "<td class=\"space\"></td>"; + } + + htmlContent += "</tr>\n</table>\n</body>\n" + "</html>"; + System.out.println(htmlContent); + sdpanel.setText(htmlContent); + + JScrollPane jsp = new JScrollPane(sdpanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + jsp.setWheelScrollingEnabled(true); + jsp.getVerticalScrollBar().setUnitIncrement(MainGUI.INCREMENT); + framePanel.add(jsp, BorderLayout.CENTER); + + // statusBar + status = createStatusBar(); + framePanel.add(status, BorderLayout.SOUTH); + + pack(); + + } + + private void initActions() { + actions = new InteractiveSimulationActions[InteractiveSimulationActions.NB_ACTION]; + for (int i = 0; i < InteractiveSimulationActions.NB_ACTION; i++) { + actions[i] = new InteractiveSimulationActions(i); + actions[i].addActionListener(this); + } + } + + public void close() { + dispose(); + setVisible(false); + } + + private void saveHTML() { + TraceManager.addDev("Saving in html format"); + File file = null; + JFileChooser jfcimg = new JFileChooser(); +// jfcimg.setCurrentDirectory(new File("")); + int returnVal = jfcimg.showSaveDialog(getContentPane()); + if (returnVal == JFileChooser.APPROVE_OPTION) { + file = jfcimg.getSelectedFile(); + file = FileUtils.addFileExtensionIfMissing(file, "html"); + } + boolean ok = true; + + try { + ok = FileUtils.checkFileForSave(file); + } catch (Exception e) { + ok = false; + } + if (!ok) { + JOptionPane.showMessageDialog(this, + "The capture could not be performed: the specified file is not valid", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + try { + FileOutputStream fos = new FileOutputStream(file); + fos.write(htmlContent.getBytes()); + fos.close(); + JOptionPane.showMessageDialog(getContentPane(), "The capture was correctly performed and saved in " + file.getAbsolutePath(), "Screen capture ok", JOptionPane.INFORMATION_MESSAGE); + } catch (Exception e) { + TraceManager.addDev("Error during save trace: " + e.getMessage()); + status.setText("Error during save trace: " + e.getMessage()); + return; + } + } + + public void actionPerformed(ActionEvent evt) { + String command = evt.getActionCommand(); + if (command.equals(actions[InteractiveSimulationActions.ACT_QUIT_SD_WINDOW].getActionCommand())) { + sdpanel = null; + close(); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_TIMELINE_HTML].getActionCommand())) { + saveHTML(); + } + } +} diff --git a/src/main/java/ui/interactivesimulation/SimulationTransaction.java b/src/main/java/ui/interactivesimulation/SimulationTransaction.java index a7361ff0d9f7d7342a70aa2a262439b9bcfc4053..fbe0f57fbed39997a5edd09f71feda00391ad6a0 100755 --- a/src/main/java/ui/interactivesimulation/SimulationTransaction.java +++ b/src/main/java/ui/interactivesimulation/SimulationTransaction.java @@ -52,6 +52,7 @@ public class SimulationTransaction { public String nodeType; public String deviceName; + public String coreNumber; public String taskName; public String command; public String startTime; diff --git a/src/main/java/ui/interactivesimulation/SimulationTransactionParser.java b/src/main/java/ui/interactivesimulation/SimulationTransactionParser.java index 645b46d60048b84594f73f2c1424f6c642e90227..839d87afafae2e3b9c587b217e53134ee87e7df3 100644 --- a/src/main/java/ui/interactivesimulation/SimulationTransactionParser.java +++ b/src/main/java/ui/interactivesimulation/SimulationTransactionParser.java @@ -78,6 +78,7 @@ public class SimulationTransactionParser extends DefaultHandler { } st.deviceName = attributes.getValue("devicename"); + st.coreNumber = attributes.getValue("corenumber"); String commandT = attributes.getValue("command"); if (commandT != null) { int index = commandT.indexOf(": "); diff --git a/src/main/java/ui/util/IconManager.java b/src/main/java/ui/util/IconManager.java index d014a037f05bdab989427aea27510bf1446cd266..d7192ab70f04e6c1b6f54c87b934924c6d881559 100755 --- a/src/main/java/ui/util/IconManager.java +++ b/src/main/java/ui/util/IconManager.java @@ -173,7 +173,7 @@ public class IconManager { //Safety public static ImageIcon imgic7002, imgic7003, imgic7004, imgic7005, imgic7006; //Show traces - public static ImageIcon imgic7007; + public static ImageIcon imgic7007, imgic8030; //Attacker Scenarios public static ImageIcon imgic7008; //UPPAAL Help popup @@ -715,6 +715,7 @@ public class IconManager { private static String icon8027 = "elndeisource.gif"; private static String icon8028 = "elndevsink.gif"; private static String icon8029 = "elndevsource.gif"; + private static String icon8030 = "toolbarButtonGraphics/general/timeline.png"; public IconManager() { @@ -1250,6 +1251,7 @@ public class IconManager { imgic8027 = getIcon(icon8027); imgic8028 = getIcon(icon8028); imgic8029 = getIcon(icon8029); + imgic8030 = getIcon(icon8030); } } // Class diff --git a/src/main/resources/ui/util/toolbarButtonGraphics/general/timeline.png b/src/main/resources/ui/util/toolbarButtonGraphics/general/timeline.png new file mode 100644 index 0000000000000000000000000000000000000000..c935f8a60d4a6872dd39be0fb85e46162f8d40ba Binary files /dev/null and b/src/main/resources/ui/util/toolbarButtonGraphics/general/timeline.png differ