diff --git a/src/main/java/ui/interactivesimulation/JFrameCompareSimulationTraces.java b/src/main/java/ui/interactivesimulation/JFrameCompareSimulationTraces.java index 8550b2da582a51f796f0a0610f4f1a889d3fda94..60c99f924e3c35de286be4c154d0084687647c68 100644 --- a/src/main/java/ui/interactivesimulation/JFrameCompareSimulationTraces.java +++ b/src/main/java/ui/interactivesimulation/JFrameCompareSimulationTraces.java @@ -26,6 +26,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.Popup; @@ -60,7 +61,24 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe private JFileChooser fc; private File file; private SimulationTrace selectedST; - private Vector<SimulationTransaction> transFile1; + private static Vector<SimulationTransaction> transFile1; + + public Vector<SimulationTransaction> getTransFile1() { + return transFile1; + } + + public void setTransFile1(Vector<SimulationTransaction> transFile1) { + this.transFile1 = transFile1; + } + + public Vector<SimulationTransaction> getTransFile2() { + return transFile2; + } + + public void setTransFile2(Vector<SimulationTransaction> transFile2) { + this.transFile2 = transFile2; + } + private Vector<SimulationTransaction> transFile2; private SimulationTransaction st = new SimulationTransaction(); private JTextField file2 = new JTextField(); @@ -75,7 +93,6 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe super(_title); - System.out.println("in hereee"); this.selectedST = sST; GridLayout myLayout = new GridLayout(3, 1); @@ -88,7 +105,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // setIconImage(IconManager.img5100); // setBackground(Color.WHITE); - System.out.println("in main"); + fc = new JFileChooser(); JPanel buttonPanel = new JPanel(new GridBagLayout()); // use FlowLayout @@ -103,6 +120,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.gridy = 0; c.weightx = 1; c.weighty = 1; + c.anchor = GridBagConstraints.WEST; buttonPanel.add(lab1, c); JLabel lab2 = new JLabel("Secound Simulation Traces File ", JLabel.LEFT); @@ -112,6 +130,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.gridy = 1; c.weightx = 1; c.weighty = 1; + c.anchor = GridBagConstraints.WEST; buttonPanel.add(lab2, c); file1.setEditable(false); @@ -121,7 +140,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 1; c.gridy = 0; - c.weightx = 1; + c.weightx = 2; c.weighty = 1; buttonPanel.add(file1, c); @@ -152,7 +171,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 3; c.gridy = 2; - c.weightx = 1; + c.weightx = 5; c.weighty = 1; buttonPanel.add(parse, c); @@ -161,7 +180,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 3; c.gridy = 3; - c.weightx = 1; + c.weightx = 5; c.weighty = 1; buttonPanel.add(difference, c); @@ -202,7 +221,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe @Override public void actionPerformed(ActionEvent e) { - System.out.println(e.getActionCommand()); + // System.out.println(e.getActionCommand()); if (e.getSource() == browse) { // Handle open button action. @@ -216,11 +235,12 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe } else if (e.getSource() == parse) { // Handle open button action. - System.out.println("Time to parse"); - System.out.println(selectedST.getFullPath()); - System.out.println(file.getPath()); + // System.out.println("Time to parse"); + // System.out.println(selectedST.getFullPath()); + // System.out.println(file.getPath()); try { int x = parseXML(selectedST.getFullPath(), file.getPath()); + DrawSimulationResults(transFile1, transFile2); } catch (SAXException e1) { // TODO Auto-generated catch block @@ -234,12 +254,17 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe } } else if (e.getSource() == latencyDetails) { - System.out.println("Time for latency analysis"); + //System.out.println("Time for latency analysis"); + JTable table = newContentPane.getTable(); + + JFrameShowLatencyDetails showLatencyDetails = new JFrameShowLatencyDetails(transFile1, transFile2, + devicesDropDownCombo1.getSelectedItem(), tracesCombo1.getSelectedItem(), + devicesDropDownCombo2.getSelectedItem(), tracesCombo2.getSelectedItem()); } else if (e.getSource() == difference) { // Handle open button action. - System.out.println("Time to show the difference"); + //System.out.println("Time to show the difference"); newContentPane.showDifference(); // this.add(newContentPane); @@ -249,9 +274,9 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe Vector<Object> transacationsDropDown1 = newContentPane .loadTransacationsDropDown(devicesDropDownCombo1.getSelectedItem()); - System.out.println("Time to show the difference" + transacationsDropDown1.size()); + //System.out.println("Time to show the difference" + transacationsDropDown1.size()); - System.out.println("Time to show the difference" + tracesCombo1.getSelectedIndex()); + //System.out.println("Time to show the difference" + tracesCombo1.getSelectedIndex()); final DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<Object>(transacationsDropDown1); @@ -261,9 +286,9 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe Vector<Object> transacationsDropDown2 = newContentPane .loadTransacationsDropDown(devicesDropDownCombo2.getSelectedItem()); - System.out.println("Time to show the difference" + transacationsDropDown2.size()); + // System.out.println("Time to show the difference" + transacationsDropDown2.size()); - System.out.println("Time to show the difference" + tracesCombo2.getSelectedIndex()); + // System.out.println("Time to show the difference" + tracesCombo2.getSelectedIndex()); final DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<Object>(transacationsDropDown2); @@ -273,7 +298,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe } // Returns the currentY position - private int parseXML(String file1Path, String file2Path) + public int parseXML(String file1Path, String file2Path) throws SAXException, IOException, ParserConfigurationException { if (file1Path.length() == 0 || file2Path.length() == 0) @@ -290,9 +315,8 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe saxParser.parse(new File(file2Path), handler); transFile2 = handler.getStList(); - System.out.println("transFile1 :" + transFile1.size()); - System.out.println("transFile2 :" + transFile2.size()); - DrawSimulationResults(transFile1, transFile2); + //System.out.println("transFile1 :" + transFile1.size()); + // System.out.println("transFile2 :" + transFile2.size()); /* * // Print all employees. for (SimulationTransaction st1 : transFile2) { @@ -324,7 +348,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe // this.repaint(); // this.add(newContentPane); - System.out.println(" rewrite table"); + // System.out.println(" rewrite table"); } else { @@ -333,7 +357,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe newContentPane.drawTable(); - System.out.println(" New table"); + // System.out.println(" New table"); this.add(newContentPane); DrawLatencyPanel(); @@ -348,21 +372,17 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe } private void DrawLatencyPanel() { + + JPanel latencyPanel = new JPanel(new GridBagLayout()); // use FlowLayout GridBagConstraints c = new GridBagConstraints(); + latencyPanel.setBorder(new javax.swing.border.TitledBorder("Latency for Simulation Traces File")); c.fill = GridBagConstraints.NORTHWEST; JTextField file1 = new JTextField(); - JLabel lab1 = new JLabel("Latency for Simulation Traces File ", JLabel.LEFT); - c.fill = GridBagConstraints.NORTHWEST; - c.gridx = 0; - c.gridy = 0; - // c.weightx = 0; - // c.weighty = 0; - latencyPanel.add(lab1, c); - + Vector<Object> devicesDropDown1 = newContentPane.loadDevicesDropDown(); devicesDropDownCombo1 = new JComboBox<Object>(devicesDropDown1); @@ -373,9 +393,10 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 0; - c.gridy = 1; - // c.weightx = 0; - // c.weighty = 1; + c.gridy = 0; + c.weightx = 1; + c.weighty = 1; + c.anchor = GridBagConstraints.WEST; latencyPanel.add(devicesDropDownCombo1, c); // String[] choices2 = { "CHOICE 1","CHOICE 2", "CHOICE 3","CHOICE 4","CHOICE @@ -383,9 +404,9 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 0; - c.gridy = 2; - // c.weightx = 0; - // c.weighty =2; + c.gridy = 1; + c.weightx = 1; + c.weighty = 1; latencyPanel.add(tracesCombo1, c); this.add(latencyPanel); @@ -401,7 +422,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 1; - c.gridy = 1; + c.gridy = 0; // c.weightx = 1; // c.weighty = 1; latencyPanel.add(devicesDropDownCombo2, c); @@ -411,7 +432,7 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe c.fill = GridBagConstraints.NORTHWEST; c.gridx = 1; - c.gridy = 2; + c.gridy = 1; // c.weightx = 0; // c.weighty =2; latencyPanel.add(tracesCombo2, c); @@ -422,8 +443,8 @@ public class JFrameCompareSimulationTraces extends JFrame implements ActionListe latencyDetails = new JButton("latency Details"); latencyDetails.addActionListener(this); c.fill = GridBagConstraints.NORTHWEST; - c.gridx = 2; - c.gridy = 2; + c.gridx = 1; + c.gridy = 3; c.weightx = 1; c.weighty = 1; latencyPanel.add(latencyDetails, c); diff --git a/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java b/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java index b43b4f5bf518d2e4de6bb5af0784b5bb68064812..997f5c04227d59483f0dd1bca2c57f108167dcaa 100644 --- a/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java +++ b/src/main/java/ui/interactivesimulation/JPanelCompareXmlGraph.java @@ -1,39 +1,20 @@ 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.SwingUtilities; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; -import javax.swing.table.TableModel; - -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 implements TableModelListener { private int[] graphSource; - static JTable table, tableUpdated; + public static JTable table, tableUpdated; private boolean DEBUG = false; private String[] columnNames; @@ -48,8 +29,8 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener return; } - System.out.println("transFile1*****************" + transFile1.size()); - System.out.println("transFile2*******************" + transFile2.size()); + // System.out.println("transFile1*****************" + transFile1.size()); + // System.out.println("transFile2*******************" + transFile2.size()); int maxTime = -1; int rowIndex = 0; @@ -97,7 +78,8 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener } } - System.out.println("-------------------------- " + "all devices Done" + " ---------------------------------"); + // System.out.println("-------------------------- " + "all devices Done" + " + // ---------------------------------"); columnNames = new String[maxTime + 2]; data = new Object[deviceNames1.size() + deviceNames2.size()][maxTime + 2]; @@ -116,8 +98,39 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener for (int i = 0; i < Integer.parseInt(st.length); i++) { + // String[] sentences2 = st.command.split("__"); + // for (int j = 0; j < sentences2.length; j++) { + // String s1 = sentences2[j]; + // System.out.println("st.command : " + st.command); + // System.out.println("sentences2 : " + sentences2); + // System.out.println("substring : " + s1); + + // } + String[] sentences2 = null; + + sentences2 = st.command.split("__"); + + if (sentences2[0].contains(",") && sentences2.length > 1) + + { + + String[] writeCommand = sentences2[0].split(","); + + st.command = writeCommand[0] + " " + sentences2[1]; + + } else if (sentences2[0].contains(" ") && sentences2.length > 1) + + { + + String[] writeCommand = sentences2[0].split(" "); + + st.command = writeCommand[0] + " " + sentences2[1]; + + } + data[allDevices.indexOf(dName.concat("1"))][Integer.parseInt(st.startTime) + i + 2] = st.command; + ; data[allDevices.indexOf(dName.concat("1"))][1] = "transFile 1"; } } @@ -125,8 +138,9 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener } } - System.out.println( - "-------------------------- " + "all transactions 1 Done" + " ---------------------------------"); + // System.out.println( + // "-------------------------- " + "all transactions 1 Done" + " + // ---------------------------------"); for (SimulationTransaction st : transFile2) { @@ -137,6 +151,28 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener for (int i = 0; i < Integer.parseInt(st.length); i++) { + String[] sentences2 = null; + + sentences2 = st.command.split("__"); + + if (sentences2[0].contains(",") && sentences2.length > 1) + + { + + String[] writeCommand = sentences2[0].split(","); + + st.command = writeCommand[0] + " " + sentences2[1]; + + } else if (sentences2[0].contains(" ") && sentences2.length > 1) + + { + + String[] writeCommand = sentences2[0].split(" "); + + st.command = writeCommand[0] + " " + sentences2[1]; + + } + data[allDevices.indexOf(dName.concat("2"))][Integer.parseInt(st.startTime) + i + 2] = st.command; data[allDevices.indexOf(dName.concat("2"))][1] = "transFile 2"; @@ -147,19 +183,19 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener } - 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("-------------------------- " + maxTime + " + // ---------------------------------"); - System.out.println("-------------------------- " + deviceNames1 + " ---------------------------------"); + // System.out.println("-------------------------- " + deviceNames1 + " + // ---------------------------------"); - System.out.println("----------*****---------------- " + deviceNames2 + " ---------------------------------"); + // System.out.println("----------*****---------------- " + deviceNames2 + " + // ---------------------------------"); for (int i = 2; i < maxTime + 2; i++) { @@ -184,7 +220,7 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener // For each table column, sets its renderer to the previously // created table renderer. - System.out.println("ncols : " + ncols); + // System.out.println("ncols : " + ncols); for (int c = 0; c < ncols; c++) { TableColumn tc = tcm.getColumn(c); @@ -200,24 +236,24 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); - System.out.println("Value of data: "); + // 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.print(" " + model.getValueAt(i, j)); } - System.out.println(); + // System.out.println(); } - System.out.println("--------------------------"); + // System.out.println("--------------------------"); } - void showDifference() { + public void showDifference() { // TODO Auto-generated method stub int numRows = table.getRowCount(); int numCols = table.getColumnCount(); - System.out.println("Value of data: "); + // System.out.println("Value of data: "); for (int j = 2; j < numCols; j++) { @@ -231,7 +267,7 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener if (i != k && table.getValueAt(i, j) != null && table.getValueAt(k, j) != null && table.getValueAt(i, j).equals(table.getValueAt(k, j))) { - System.out.print(table.getValueAt(i, j) + " ==" + table.getValueAt(k, j)); + // System.out.print(table.getValueAt(i, j) + " ==" + table.getValueAt(k, j)); table.setValueAt(null, k, j); table.setValueAt(null, i, j); @@ -261,7 +297,7 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener scrollPane.revalidate(); scrollPane.repaint(); - System.out.println("similar eraised" + numRows + "---" + numCols); + // System.out.println("similar eraised" + numRows + "---" + numCols); } @@ -277,7 +313,7 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener scrollPane.setVisible(true); add(scrollPane); - System.out.println("table added :"); + // System.out.println("table added :"); } @@ -297,7 +333,7 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener scrollPane.revalidate(); scrollPane.repaint(); // scrollPane.setVisible(true); - System.out.println("revalidated"); + // System.out.println("revalidated"); } @@ -309,47 +345,53 @@ public class JPanelCompareXmlGraph extends JPanel implements TableModelListener public Vector<Object> loadTransacationsDropDown(Object object) { - - System.out.println(object); - Vector<Object> allTransacions = new Vector();; + // System.out.println(object); + Vector<Object> allTransacions = new Vector(); + ; int numRows = table.getRowCount(); int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); for (int i = 0; i < numRows; i++) { - for (int j = 0; j < numCols; j++) { + for (int j = 2; j < numCols; j++) { - if (table.getValueAt(i, j) != null && !allTransacions.contains(table.getValueAt(i, j)) && table.getValueAt(i, 0).equals(object)) { + if (table.getValueAt(i, j) != null && !allTransacions.contains(table.getValueAt(i, j)) + && table.getValueAt(i, 0).equals(object)) { allTransacions.add(table.getValueAt(i, j)); } } - System.out.println(); + // System.out.println(); } return allTransacions; } public Vector<Object> loadDevicesDropDown() { - Vector<Object> allDevices = new Vector();; + Vector<Object> allDevices = new Vector(); + ; int numRows = table.getRowCount(); - //int numCols = table.getColumnCount(); + // int numCols = table.getColumnCount(); javax.swing.table.TableModel model = table.getModel(); for (int i = 0; i < numRows; i++) { - - if (table.getValueAt(i, 0) != null && !allDevices.contains(table.getValueAt(i, 0))) { - allDevices.add(table.getValueAt(i, 0)); - + if (table.getValueAt(i, 0) != null && !allDevices.contains(table.getValueAt(i, 0))) { + allDevices.add(table.getValueAt(i, 0)); + } - System.out.println(); + // System.out.println(); } return allDevices; } + public JTable getTable() { + return table; + + } + } /*