From 7e8c4017bbb1ddd227aa62951f4f0975a299e9ee Mon Sep 17 00:00:00 2001 From: Maysam Zoor <maysam.zoor@telecom-paristech.fr> Date: Sun, 7 Jul 2019 15:20:26 +0200 Subject: [PATCH] compare xml functions added --- src/main/java/ui/MainGUI.java | 17 ++ .../JPanelCompareXmlGraph.java | 254 ++++++++++++++++++ .../SAXParserHandler.java | 94 +++++++ .../interactivesimulation/TableRenderer.java | 82 ++++++ src/main/java/ui/tree/JDiagramTree.java | 13 + 5 files changed, 460 insertions(+) create mode 100644 src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java create mode 100644 src/main/java/ui/interactivesimulation/SAXParserHandler.java create mode 100644 src/main/java/ui/interactivesimulation/TableRenderer.java diff --git a/src/main/java/ui/MainGUI.java b/src/main/java/ui/MainGUI.java index 8487e2990e..588f7205a8 100644 --- a/src/main/java/ui/MainGUI.java +++ b/src/main/java/ui/MainGUI.java @@ -72,6 +72,7 @@ import ui.ebrdd.EBRDDPanel; import ui.eln.ELNDiagramPanel; import ui.file.*; import ui.ftd.FaultTreeDiagramPanel; +import ui.interactivesimulation.JFrameCompareSimulationTraces; import ui.interactivesimulation.JFrameInteractiveSimulation; import ui.interactivesimulation.SimulationTransaction; import ui.iod.InteractionOverviewDiagramPanel; @@ -330,6 +331,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per private ConcurrentHashMap<String, String> statusMap = new ConcurrentHashMap<String, String>(); private JFrameInteractiveSimulation jfis; private JFrameAvatarInteractiveSimulation jfais; + private JFrameCompareSimulationTraces cSimTrace; // Help private HelpManager helpManager; @@ -9706,6 +9708,21 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Per } + public void compareSimulationTraces(SimulationTrace selectedST, boolean b) { + // TODO Auto-generated method stub + //System.out.println("Maysam : compare Function"); + cSimTrace = new JFrameCompareSimulationTraces( this, "Compare Simulation simulation",selectedST); + + cSimTrace.setIconImage(IconManager.img9); + + GraphicLib.centerOnParent(cSimTrace, 900, 600); + cSimTrace.setVisible(true); + + + + + } + } // Class MainGUI diff --git a/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java b/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java new file mode 100644 index 0000000000..cd4e57745b --- /dev/null +++ b/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java @@ -0,0 +1,254 @@ +package ui.interactivesimulation; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridLayout; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Vector; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +import javafx.collections.FXCollections; +import javafx.scene.Scene; +import javafx.scene.chart.BarChart; +import javafx.scene.chart.CategoryAxis; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.NumberAxis; + +public class JPanelCompareXmlGraph extends JPanel { + + private int[] graphSource; + + private boolean DEBUG = false; + + public JPanelCompareXmlGraph(Vector<SimulationTransaction> transFile1, Vector<SimulationTransaction> transFile2) { + super(new GridLayout(1, 0)); + + int maxTime = -1; + + int rowIndex = 0; + int totalrows = 0; + Vector<String> deviceNames1 = new Vector(); + Vector<String> deviceNames2 = new Vector(); + + for (SimulationTransaction st : transFile1) { + if (Integer.parseInt(st.endTime) > maxTime) { + maxTime = Integer.parseInt(st.endTime); + } + if (!deviceNames1.contains(st.deviceName)) { + deviceNames1.add(st.deviceName); + + } + + } + + for (SimulationTransaction st : transFile2) { + if (Integer.parseInt(st.endTime) > maxTime) { + maxTime = Integer.parseInt(st.endTime); + } + if (!deviceNames2.contains(st.deviceName)) { + deviceNames2.add(st.deviceName); + + } + } + + totalrows = deviceNames1.size() + deviceNames2.size(); + + Vector<String> allDevices = new Vector(); + + for (String device : deviceNames1) { + if (!deviceNames2.contains(device)) { + allDevices.add(device.concat("1")); + } else { + allDevices.add(device.concat("1")); + allDevices.add(device.concat("2")); + + } + } + for (String device : deviceNames2) { + if (!deviceNames1.contains(device)) { + allDevices.add(device.concat("2")); + } + + } + System.out.println("-------------------------- " + "all devices Done" + " ---------------------------------"); + + String[] columnNames = new String[maxTime + 2]; + Object[][] data = new Object[deviceNames1.size() + deviceNames2.size()][maxTime + 2]; + + columnNames[0] = "Device Name"; + columnNames[1] = "Trace Name"; + + // columnNames[2]="Trace"; + + for (SimulationTransaction st : transFile1) { + + for (String dName : deviceNames1) { + + if (st.deviceName.equals(dName)) { + // maxTime = Integer.parseInt(st.endTime); + + for (int i = 0; i < Integer.parseInt(st.length); i++) { + + data[allDevices.indexOf(dName.concat("1"))][Integer.parseInt(st.startTime) + i + + 2] = st.command; + data[allDevices.indexOf(dName.concat("1"))][1] = "transFile 1"; + } + } + + } + + } + System.out.println( + "-------------------------- " + "all transactions 1 Done" + " ---------------------------------"); + + for (SimulationTransaction st : transFile2) { + + for (String dName : deviceNames2) { + + if (st.deviceName.equals(dName)) { + // maxTime = Integer.parseInt(st.endTime); + + for (int i = 0; i < Integer.parseInt(st.length); i++) { + + data[allDevices.indexOf(dName.concat("2"))][Integer.parseInt(st.startTime) + i + + 2] = st.command; + data[allDevices.indexOf(dName.concat("2"))][1] = "transFile 2"; + } + } + + } + + } + + System.out.println( + "-------------------------- " + "all transactions 2 Done" + " ---------------------------------"); + + for (String dName : allDevices) { + data[allDevices.indexOf(dName)][0] = dName.substring(0, dName.length() - 1); + ; + } + + System.out.println("-------------------------- " + maxTime + " ---------------------------------"); + + System.out.println("-------------------------- " + deviceNames1 + " ---------------------------------"); + + System.out.println("----------*****---------------- " + deviceNames2 + " ---------------------------------"); + + for (int i = 2; i < maxTime + 2; i++) { + + columnNames[i] = Integer.toString(i - 2); + + } + + final JTable table = new JTable(data, columnNames); + table.setPreferredScrollableViewportSize(new Dimension(500, 70)); + table.setFillsViewportHeight(true); + // table.setBackground(Color.YELLOW); + table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); + TableRenderer tr = new TableRenderer(); + int nrows = table.getRowCount(); + int ncols = table.getColumnCount(); + + TableColumnModel tcm = table.getColumnModel (); + + // For each table column, sets its renderer to the previously + // created table renderer. + + System.out.println("ncols : " + ncols ); + + for (int c = 0; c < ncols; c++) + { + TableColumn tc = tcm.getColumn (c); + tc.setCellRenderer (tr); + } + + // table.getCellRenderer(1, 3).setCellRenderer(ColorRenderer()); + + // Create the scroll pane and add the table to it. + JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + // Add the scroll pane to this panel. + + // scrollPane.setBackground(Color.blue); + + scrollPane.setVisible(true); + add(scrollPane); + System.out.println("table added :"); + } + + private TableCellRenderer ColorRenderer() { + // TODO Auto-generated method stub + return null; + } + + private void printDebugData(JTable table) { + int numRows = table.getRowCount(); + int numCols = table.getColumnCount(); + javax.swing.table.TableModel model = table.getModel(); + + System.out.println("Value of data: "); + for (int i = 0; i < numRows; i++) { + System.out.print(" row " + i + ":"); + for (int j = 0; j < numCols; j++) { + System.out.print(" " + model.getValueAt(i, j)); + } + System.out.println(); + } + System.out.println("--------------------------"); + } + +} + +/* + * + * public JPanelCompareXmlGraph() { { graphSource = new int[] { 2, 4, 20, 40 + * ,100, 130 }; setupPanel(); System.out.println( + * "JPanelCompareXmlGraph called") ; } + * + * private void setupPanel() { // TODO Auto-generated method stub + * this.setBackground(Color.LIGHT_GRAY); System.out.println( + * "setupPanel called") ; + * + * + * } + * + * @Override protected void paintComponent(Graphics currentGraphics) { + * super.paintComponent(currentGraphics); System.out.println( + * "the graph function is called" + this.getHeight()) ; Graphics2D mainGraphics + * = (Graphics2D) currentGraphics; + * + * for (int index = 0; index < graphSource.length; index=index+2) { //int height + * = this.getHeight() / graphSource.length; //int width = (int) + * ((graphSource[index] / 200.00) * this.getWidth()); int height =20; int width= + * (int)graphSource[index+1] - graphSource[index]; int xPosition = + * graphSource[index]; int yPosistion = 0; + * + * int red = (int) (Math.random() * 256); int green = (int) (Math.random() * + * 256); int blue = (int) (Math.random() * 256); int alpha = (int) + * (Math.random() * 256); + * + * mainGraphics.setColor(new Color(red, green, blue, alpha)); + * + * mainGraphics.fill(new Rectangle(xPosition, yPosistion, width, height)); + * System.out.println(index +"--"+xPosition + "--"+ yPosistion+ "--"+ width + * +"--"+ height) ; + * + * + * } + * + * + * } + * + */ diff --git a/src/main/java/ui/interactivesimulation/SAXParserHandler.java b/src/main/java/ui/interactivesimulation/SAXParserHandler.java new file mode 100644 index 0000000000..56d8b0e2d1 --- /dev/null +++ b/src/main/java/ui/interactivesimulation/SAXParserHandler.java @@ -0,0 +1,94 @@ +package ui.interactivesimulation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Vector; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class SAXParserHandler extends DefaultHandler { + + private Vector<SimulationTransaction> trans; + private SimulationTransaction st = new SimulationTransaction(); + + // List to hold Employees object + // private List<Employee> empList = null; + // private Employee emp = null; + private StringBuilder data = null; + + // getter method for employee list + public Vector<SimulationTransaction> getStList() { + return trans; + } + + boolean bAge = false; + boolean bName = false; + boolean bGender = false; + boolean bRole = false; + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + + if (qName.equals("transinfo")) { + + st = new SimulationTransaction(); + st.nodeType = attributes.getValue("deviceid"); + + try { + st.uniqueID = new Integer(attributes.getValue("uniqueid")); + } catch (Exception e) { + + } + + st.deviceName = attributes.getValue("devicename"); + String commandT = attributes.getValue("command"); + if (commandT != null) { + int index = commandT.indexOf(": "); + if (index == -1){ + st.taskName = "Unknown"; + st.command = commandT; + } else { + st.taskName = commandT.substring(0, index).trim(); + st.command = commandT.substring(index+1, commandT.length()).trim(); + } + } + + //TraceManager.addDev("Command handled"); + st.startTime = attributes.getValue("starttime"); + st.endTime = attributes.getValue("endtime"); + String taskId= attributes.getValue("id"); + + st.length = attributes.getValue("length"); + st.virtualLength = attributes.getValue("virtuallength"); + st.channelName = attributes.getValue("ch"); + + // initialize list + + if (trans == null) { + trans = new Vector<SimulationTransaction>(); + } + trans.add(st); + + } + + // create the data container + data = new StringBuilder(); + + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + + /* + * if (qName.equals("transinfo")) { // add Employee object to list + * trans.add(st); } + */ + } + + @Override + public void characters(char ch[], int start, int length) throws SAXException { + data.append(new String(ch, start, length)); + } +} \ No newline at end of file diff --git a/src/main/java/ui/interactivesimulation/TableRenderer.java b/src/main/java/ui/interactivesimulation/TableRenderer.java new file mode 100644 index 0000000000..1b0cf7b5a7 --- /dev/null +++ b/src/main/java/ui/interactivesimulation/TableRenderer.java @@ -0,0 +1,82 @@ +package ui.interactivesimulation; + +import java.awt.Color; +import java.awt.Component; + +import javax.swing.JTable; +import javax.swing.UIManager; +import javax.swing.table.DefaultTableCellRenderer; + +class TableRenderer extends DefaultTableCellRenderer +{ + private int row, col; + + public Component getTableCellRendererComponent (JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) + { + // Save row and column information for use in setValue(). + + this.row = row; + this.col = column; + + // Allow superclass to return rendering component. + + return super.getTableCellRendererComponent (table, value, + isSelected, hasFocus, + row, column); + } + + protected void setValue (Object v) + { + // Allow superclass to set the value. + + super.setValue (v); + + // If in names column, color cell with even row number white on + // dark green, and cell with odd row number black on white. + + if (col == 0) + { + if (row % 2 == 0) + { + setForeground (Color.white); + setBackground (new Color (0, 128, 0)); + } + else + { + setForeground (UIManager.getColor ("Table.foreground")); + setBackground (UIManager.getColor ("Table.background")); + } + + return; + } + + // Must be in balances column. Make sure v is valid. + + if (v == null) + return; + + // Extract the cell's numeric value. + + // Double d = (Double) v; + + // If numeric value is less than zero, color cell yellow on red. + // Otherwise, color cell black on white. + + if (v.equals("Request reqChannel_AppC_simplified_sec__SmartCard")) + { + setForeground (Color.yellow); + setBackground (Color.red); + } + else + { + setForeground (UIManager.getColor ("Table.foreground")); + setBackground (UIManager.getColor ("Table.background")); + } + } +} + diff --git a/src/main/java/ui/tree/JDiagramTree.java b/src/main/java/ui/tree/JDiagramTree.java index ef61ebf5cd..780a75b112 100755 --- a/src/main/java/ui/tree/JDiagramTree.java +++ b/src/main/java/ui/tree/JDiagramTree.java @@ -95,6 +95,7 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M protected JMenuItem jmiShowInFinder; protected JMenuItem jmiShowST; protected JMenuItem jmiShowInFinderST; + protected JMenuItem jmiCompareST; protected JPopupMenu popupTree; protected JPopupMenu popupTreeST; protected RG selectedRG; @@ -248,14 +249,22 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M } else { jmiShowST = new JMenuItem("Show (default app)"); } + jmiShowST.addActionListener(this); popupTreeST.add(jmiShowST); if(selectedST.hasFile()) { jmiShowInFinderST = new JMenuItem("Show in File Explorer"); jmiShowInFinderST.addActionListener(this); } + popupTreeST.add(jmiShowInFinderST); + + if (selectedST.getType() == SimulationTrace.XML_DIPLO) { + jmiCompareST = new JMenuItem("Compare"); + jmiCompareST.addActionListener(this); + } + popupTreeST.add(jmiCompareST); //} popupTreeST.show(tree, x, y); @@ -503,6 +512,10 @@ public class JDiagramTree extends javax.swing.JTree implements ActionListener, M } else if (ae.getSource() == jmiShowInFinderST) { mgui.showInFinder(selectedST, true); } + else if (ae.getSource() == jmiCompareST) { + mgui.compareSimulationTraces(selectedST, true); + + } } if (selectedGT != null) { -- GitLab