From 543ebb342276ffa808212da8bda809cd7ba36d7c Mon Sep 17 00:00:00 2001 From: "le.truong" <le.truong@telecom-paris.fr> Date: Mon, 15 Jun 2020 09:22:48 +0200 Subject: [PATCH] update on show real time simulation html trace --- .../InteractiveSimulationActions.java | 4 +- .../JFrameInteractiveSimulation.java | 30 +++- .../JFrameTMLSimulationPanelHtml.java | 161 ++++++++++++++++++ 3 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java diff --git a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java index ed9ed4ee53..144ea396e7 100755 --- a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java +++ b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java @@ -112,7 +112,8 @@ 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 NB_ACTION = 42; + public static final int ACT_SHOW_TRACE_HTML = 42; + public static final int NB_ACTION = 43; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -199,6 +200,7 @@ 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_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'); diff --git a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java index 0a7b2f215c..49f1e196ea 100644 --- a/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java +++ b/src/main/java/ui/interactivesimulation/JFrameInteractiveSimulation.java @@ -114,7 +114,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene private String hostSystemC; private String pathExecute; - protected JButton buttonClose, buttonStart, buttonStopAndClose, buttonShowTrace; + protected JButton buttonClose, buttonStart, buttonStopAndClose, buttonShowTrace, buttonShowTraceHtml; protected JTextArea jta; protected JScrollPane jsp; @@ -257,6 +257,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene private PipedOutputStream pos; private PipedInputStream pis; private JFrameTMLSimulationPanel tmlSimPanel; + private JFrameTMLSimulationPanelHtml tmlSimPanelHtml; private BufferedWriter bw; private int simIndex=0; @@ -332,6 +333,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]); //buttonStopAndClose = new JButton(buttonStopAndCloseS, IconManager.imgic27); @@ -351,12 +353,15 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene JPanel jp = new JPanel(); //jp.setBackground(ColorManager.InteractiveSimulationBackground); - //jp.setPreferredSize(new Dimension(800, 75)); + jp.setPreferredSize(new Dimension(800, 80)); jp.add(buttonStart); jp.add(buttonStopAndClose); jp.add(buttonClose); jp.add(buttonShowTrace); + jp.add(buttonShowTraceHtml); mainpanel.add(jp, BorderLayout.NORTH); +// mainpanel.setSize(mainpanel.getPreferredSize()); +// validate(); GridBagLayout gridbag02 = new GridBagLayout(); @@ -1493,7 +1498,7 @@ public class JFrameInteractiveSimulation extends JFrame implements ActionListene return i.compareTo(j); } }); - // + //r // if (simtraces.size()>2000){ //Only write last 2000 simulations @@ -1522,6 +1527,21 @@ 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()); + } + 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(){ } @@ -3553,7 +3573,9 @@ 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(); + } } private String formatString(String input) { diff --git a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java new file mode 100644 index 0000000000..f2c56c154f --- /dev/null +++ b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanelHtml.java @@ -0,0 +1,161 @@ +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(false); +// String temp = "<!DOCTYPE html>\n" + "<html>\n" + "<body>"; +// sdpanel.setContentType("text/html"); +// +// for (int i = 0; i < trans.size(); i ++){ +// temp += "<h1> --Device name" + trans.get(i).deviceName + "--Task name " + trans.get(i).taskName + "--Command " + trans.get(i).command + +// "--end </h1>\n"; +// +// } +// temp += "</body>\n" + "</html>"; +// 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(); + } + } +} -- GitLab