From e4866e6b2bdff4549238b5162f39c2c060dac82f Mon Sep 17 00:00:00 2001 From: leesangyoon Date: Thu, 2 Jun 2016 14:26:51 +0900 Subject: [PATCH] Fix & Add minor UI issue --- VFT/src/vft/views/VFTGraph.java | 106 +++++++++++++++++++++++--------- VFT/src/vft/views/VFTView.java | 100 +++++++++++++++++++++++------- 2 files changed, 153 insertions(+), 53 deletions(-) diff --git a/VFT/src/vft/views/VFTGraph.java b/VFT/src/vft/views/VFTGraph.java index be7d905..e41f091 100644 --- a/VFT/src/vft/views/VFTGraph.java +++ b/VFT/src/vft/views/VFTGraph.java @@ -2,8 +2,10 @@ import org.jgrapht.ListenableGraph; import org.jgrapht.graph.ListenableDirectedGraph; +import org.jgrapht.graph.DirectedMultigraph; import java.util.ArrayList; + import vft.filter.FilterWrapper; import vft.filter.Filter.GraphNode; @@ -14,7 +16,10 @@ public static ListenableGraph init(int filteringRule, ArrayList< // create a JGraphT graph ListenableGraph g = new ListenableDirectedGraph( - String.class); + String.class); + //DirectedMultigraph g = + // new DirectedMultigraph( + // String.class); ArrayList graphNode = new ArrayList(); ArrayList componentList; @@ -73,33 +78,73 @@ public static ListenableGraph init(int filteringRule, ArrayList< // 2nd step : select package or file or test case if (filteringRule == Filter.INTER_COMPONENT_FILTER) { - Filter.selectComponent(Filter.INTER_COMPONENT_FILTER, options.get(0), options.get(1)); - graphNode = Filter.getGraphNode(); - - System.out.println("VFTGraph : ##### Interface between Atm <-> Simulation #####"); - GraphNode gNodeToDebug = Filter.new GraphNode(); - for (i = 0; i < graphNode.size(); i++) { - gNodeToDebug = graphNode.get(i); - g.addVertex(gNodeToDebug.caller); - g.addVertex(gNodeToDebug.callee); - g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); - System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); - } + if (options.size() != 0) { + Filter.selectComponent(Filter.INTER_COMPONENT_FILTER, options.get(0), options.get(1)); + graphNode = Filter.getGraphNode(); + + System.out.println("VFTGraph : ##### Interface between Atm <-> Simulation #####"); + GraphNode gNodeToDebug = Filter.new GraphNode(); + for (i = 0; i < graphNode.size(); i++) { + gNodeToDebug = graphNode.get(i); + g.addVertex(gNodeToDebug.caller); + g.addVertex(gNodeToDebug.callee); + g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); + System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); + } + } else { + componentList = Filter.setFilterRule(Filter.INTER_COMPONENT_FILTER); + for(int j = 0; j < componentList.size(); j++) { + if (j != componentList.size() - 1) { + Filter.selectComponent(Filter.INTER_COMPONENT_FILTER, componentList.get(j),componentList.get(j+1)); + } else { + Filter.selectComponent(Filter.INTER_COMPONENT_FILTER, componentList.get(j),componentList.get(0)); + } + graphNode = Filter.getGraphNode(); + + System.out.println("VFTGraph : ##### Interface between Atm <-> Simulation #####"); + GraphNode gNodeToDebug = Filter.new GraphNode(); + for (i = 0; i < graphNode.size(); i++) { + gNodeToDebug = graphNode.get(i); + g.addVertex(gNodeToDebug.caller); + g.addVertex(gNodeToDebug.callee); + g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); + System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); + } + } + } } else if (filteringRule == Filter.FILE_FILTER) { - Filter.selectComponent(Filter.FILE_FILTER, options.get(0), null); - graphNode = Filter.getGraphNode(); - - System.out.println("VFTGraph : ##### Interface with this file #####"); - GraphNode gNodeToDebug = Filter.new GraphNode(); - for (i = 0; i < graphNode.size(); i++) { - gNodeToDebug = graphNode.get(i); - g.addVertex(gNodeToDebug.caller); - g.addVertex(gNodeToDebug.callee); - g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); - System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); - } + if (options.size() != 0) { + Filter.selectComponent(Filter.FILE_FILTER, options.get(0), null); + graphNode = Filter.getGraphNode(); + + System.out.println("VFTGraph : ##### Interface with this file #####"); + GraphNode gNodeToDebug = Filter.new GraphNode(); + for (i = 0; i < graphNode.size(); i++) { + gNodeToDebug = graphNode.get(i); + g.addVertex(gNodeToDebug.caller); + g.addVertex(gNodeToDebug.callee); + g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); + System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); + } + } else { + componentList = Filter.setFilterRule(Filter.FILE_FILTER); + for(int j = 0; j < componentList.size(); j++) { + Filter.selectComponent(Filter.FILE_FILTER, componentList.get(j), null); + graphNode = Filter.getGraphNode(); + + System.out.println("VFTGraph : ##### Interface with this file #####"); + GraphNode gNodeToDebug = Filter.new GraphNode(); + for (i = 0; i < graphNode.size(); i++) { + gNodeToDebug = graphNode.get(i); + g.addVertex(gNodeToDebug.caller); + g.addVertex(gNodeToDebug.callee); + g.addEdge(gNodeToDebug.caller, gNodeToDebug.callee, gNodeToDebug.functionName); + System.out.println("VFTGraph : " + gNodeToDebug.caller + " -> " + gNodeToDebug.functionName + " -> " + gNodeToDebug.callee); + } + } + } } else if (filteringRule == Filter.TEST_CASE_FILTER) { @@ -144,15 +189,16 @@ public static ListenableGraph init(int filteringRule, ArrayList< g.addVertex(v3); g.addVertex(v4); - g.addEdge(v1, v2); - g.addEdge(v2, v3); - g.addEdge(v3, v1); - g.addEdge(v4, v3); + g.addEdge(v1, v2, v1 + v2); + g.addEdge(v1, v2, v1 + v1); + g.addEdge(v2, v3, v2 + v3); + g.addEdge(v3, v1, v3 + v4); + g.addEdge(v4, v3, v4 + v3); } long end = System.currentTimeMillis(); System.out.println("VFTGraph : Filter (ms) " + (end - start)); - + System.out.println(g.toString()); return g; diff --git a/VFT/src/vft/views/VFTView.java b/VFT/src/vft/views/VFTView.java index fa83ee6..f4efc76 100644 --- a/VFT/src/vft/views/VFTView.java +++ b/VFT/src/vft/views/VFTView.java @@ -3,14 +3,24 @@ import vft.views.VFTGraph; import vft.views.VFTTree; +import vft.filter.FilterWrapper; +import java.awt.BorderLayout; import java.awt.Button; +import java.awt.Dimension; import java.awt.Frame; +import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import javax.swing.JComboBox; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; @@ -22,15 +32,13 @@ // Import Lib for Graph import org.jgrapht.ListenableGraph; import org.jgrapht.ext.JGraphXAdapter; +import org.jgrapht.graph.DirectedMultigraph; -import com.mxgraph.layout.mxCircleLayout; -import com.mxgraph.layout.mxIGraphLayout; +import com.mxgraph.layout.hierarchical.mxHierarchicalLayout; import com.mxgraph.swing.mxGraphComponent; import java.util.ArrayList; -import vft.filter.FilterWrapper; - /** * This sample class demonstrates how to plug-in a new * workbench view. The view shows data obtained from the @@ -59,6 +67,7 @@ public class VFTView extends ViewPart { private JPanel graphPanel; private JPanel treePanel; private JPanel selectPane; + private JTabbedPane tabPane; private Integer filterRule; private ArrayList options; @@ -67,6 +76,8 @@ public class VFTView extends ViewPart { private String file; private String testCase; private String testMethod; + + private double zoom = 1.0; /** * The constructor. @@ -83,41 +94,62 @@ public void createPartControl(Composite parent) { // Add JFrame in plug-in view Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND); Frame frame = SWT_AWT.new_Frame(composite); - JSplitPane splitPaneV = new JSplitPane( JSplitPane.VERTICAL_SPLIT); + JSplitPane splitPaneV = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPaneV.setDividerLocation(500); - JTabbedPane tabPane = new JTabbedPane(); + tabPane = new JTabbedPane(); // Add Panel for graph - graphPanel = new JPanel(); + graphPanel = new JPanel(new BorderLayout()); // Add Graph filterRule = 0; options = new ArrayList(); - ListenableGraph g = VFTGraph.init(filterRule, options); - JGraphXAdapter graphAdapter = - new JGraphXAdapter(g); - mxIGraphLayout layout = new mxCircleLayout(graphAdapter); - layout.execute(graphAdapter.getDefaultParent()); - graphPanel.add(new mxGraphComponent(graphAdapter)); + drawGraph(filterRule, options); // Add Panel for Tree - treePanel = new JPanel(); + treePanel = new JPanel(new BorderLayout()); // Add Tree treePanel.add(VFTTree.init(filterRule, options)); - tabPane.addTab("VFT Graph", graphPanel); + tabPane.addTab("VFT Graph", new JScrollPane(graphPanel)); tabPane.addTab("VFT Tree", treePanel); selectPane = new JPanel(); drawInitialSelectPane(); - splitPaneV.setLeftComponent(tabPane); - splitPaneV.setRightComponent(selectPane); + splitPaneV.setTopComponent(tabPane); + splitPaneV.setBottomComponent(selectPane); + frame.add(splitPaneV); } + private void drawGraph(int filterRule, ArrayList options) { + + ListenableGraph g = VFTGraph.init(filterRule, options); + JGraphXAdapter graphAdapter = + new JGraphXAdapter(g); + + Object[] edgeCellArray = new Object[graphAdapter.getEdgeToCellMap().size()]; + for (int i = 0; i < graphAdapter.getEdgeToCellMap().size(); ++i) { + edgeCellArray[i] = (Object)(graphAdapter.getEdgeToCellMap().get(g.edgeSet().toArray()[i])); + } + graphAdapter.setCellStyle("fontSize=5", edgeCellArray); + + mxHierarchicalLayout layout = new mxHierarchicalLayout(graphAdapter); + layout.setInterHierarchySpacing(5.0); + layout.setInterRankCellSpacing(150.0); + layout.setIntraCellSpacing(15.0); + layout.execute(graphAdapter.getDefaultParent()); + + mxGraphComponent test = new mxGraphComponent(graphAdapter); + + graphPanel.add(test); + + } + private void drawInitialSelectPane() { String[] filterRules = { "NONE", "INTER_COMPONENT_FILTER", "FILE_FILTER", "TEST_CASE_FILTE", "TEST_METHOD_FILTER"}; @@ -153,6 +185,13 @@ public void actionPerformed(ActionEvent e) { packageTo = packageBoxTo.getSelectedItem().toString(); } }); + options.clear(); + if (packageFrom == null && packageTo == null) { + graphPanel.removeAll(); + drawGraph(filterRule, options); + graphPanel.revalidate(); + graphPanel.repaint(); + } selectPane.add(packageBoxFrom); selectPane.add(packageBoxTo); } else if (filterRule == Filter.FILE_FILTER) { @@ -164,6 +203,13 @@ public void actionPerformed(ActionEvent e) { file = fileBox.getSelectedItem().toString(); } }); + options.clear(); + if (file == null) { + graphPanel.removeAll(); + drawGraph(filterRule, options); + graphPanel.revalidate(); + graphPanel.repaint(); + } selectPane.add(fileBox); } else if (filterRule == Filter.TEST_CASE_FILTER) { ArrayList componentList = Filter.setFilterRule(Filter.TEST_CASE_FILTER); @@ -232,12 +278,7 @@ public void actionPerformed(ActionEvent e) { } graphPanel.removeAll(); - ListenableGraph g = VFTGraph.init(filterRule, options); - JGraphXAdapter graphAdapter = - new JGraphXAdapter(g); - mxIGraphLayout layout = new mxCircleLayout(graphAdapter); - layout.execute(graphAdapter.getDefaultParent()); - graphPanel.add(new mxGraphComponent(graphAdapter)); + drawGraph(filterRule, options); graphPanel.revalidate(); graphPanel.repaint(); @@ -249,8 +290,20 @@ public void actionPerformed(ActionEvent e) { } }); + /* + Button b = new Button("Zoom"); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.out.println(graphPanel.getWidth()); + } + }); + Button c = new Button("Export"); + */ + selectPane.add(a); selectPane.add(comboBox); + //selectPane.add(b); } /** @@ -259,4 +312,5 @@ public void actionPerformed(ActionEvent e) { public void setFocus() { //viewer.getControl().setFocus(); } + } \ No newline at end of file