Browse Source

Merge remote-tracking branch 'origin/Jascha'

Jan Enders 8 years ago
parent
commit
103031f4bd

+ 30 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MyViewerListener.java

@@ -0,0 +1,30 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import org.graphstream.ui.view.ViewerListener;
+
+import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
+
+public class MyViewerListener implements ViewerListener {
+	private Visualizer v;
+	public MyViewerListener(Visualizer viz) {
+		v=viz;
+	}
+
+	@Override
+	public void buttonPushed(String id) {
+		v.setSelectedNodeID(id);
+	}
+
+	@Override
+	public void buttonReleased(String id) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void viewClosed(String viewName) {
+		// TODO Auto-generated method stub
+		
+	}
+
+}

+ 78 - 21
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/Visualizer.java

@@ -8,33 +8,46 @@ import org.graphstream.graph.Graph;
 import org.graphstream.graph.Node;
 import org.graphstream.ui.swingViewer.ViewPanel;
 import org.graphstream.ui.view.Viewer;
+import org.graphstream.ui.view.ViewerPipe;
+
+import de.tu_darmstadt.informatik.tk.scopviz.main.MyViewerListener;
 
 /**
  * Interface between GUI and internal Graph representation.
  * 
- * @version 2.0.0.0
+ * @version 3.0.0.0
  * @author jascha-b
  *
  */
 public class Visualizer {
+	//The graph of this Visualizer
+	Graph g;
+	
+	//last deleted elements for undelete
 	private Node deletedNode;
 	private LinkedList<Edge> deletedEdges = new LinkedList<>();
 	
+	//Currently selected Edge or Node at least on of these is always null
+	private String selectedNodeID = null;
+	//TODO figure out how to do this
+	private String selectedEdgeID = null;
 	
-	// TODO add getview with size
-	/**
-	 * returns a View of the Graph. The View is in the Swing Thread and the
-	 * Graph in the Main thread.
-	 * 
-	 * @param g
-	 *            the Graph that the view is based on
-	 * @return a View of the Graph, inheriting from JPanel
-	 */
-	public static ViewPanel getView(final Graph g) {
+	//View Panel of the Graph
+	private ViewPanel view;
+	
+	
+	public Visualizer(Graph graph){
+		g=graph;
 		Viewer viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
-		ViewPanel view = viewer.addDefaultView(false);
-		return view;
+		view = viewer.addDefaultView(false);
+		viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
+		ViewerPipe fromViewer = viewer.newViewerPipe();
+		fromViewer.addViewerListener(new MyViewerListener(this));
+		fromViewer.addSink(graph);
 	}
+
+	
+	
 	
 	/**
 	 * deletes the Node corresponding to the given ID from the Graph.
@@ -45,12 +58,12 @@ public class Visualizer {
 	 * @param g the Graph with the Node that shall be removed
 	 * @param id the ID of the node that will be removed 
 	 */
-	public void deleteNode (Graph g, final String id) {
+	public void deleteNode (final String id) {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		//Edges have to be deleted first because they clear deletedNode 
 		//and need the Node to still be in the Graph
-		deleteEdgesOfNode(g, id);
+		deleteEdgesOfNode(id);
 		deletedNode = g.removeNode(id);
 	}
 	
@@ -62,7 +75,7 @@ public class Visualizer {
 	 * @param g the Graph with the Edge that shall be removed
 	 * @param id the ID of the Edge that will be removed 
 	 */
-	public void deleteEdge (Graph g, final String id) {
+	public void deleteEdge (final String id) {
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
 		deletedEdges.add(g.removeEdge(id));
@@ -76,17 +89,14 @@ public class Visualizer {
 	 * @param g the Graph containing the Node
 	 * @param id the Id of the Node, whose Edges shall be removed
 	 */
-	public void deleteEdgesOfNode (Graph g, final String id) {
+	public void deleteEdgesOfNode (final String id) {
 		Node node = g.getNode(id); 
 		deletedEdges.removeAll(deletedEdges);
 		deletedNode = null;
-		//EdgeSet has to be converted to Array or else it will not be completely traversed
 		Edge[] temp = new Edge[0];
 		temp = g.getEdgeSet().toArray(temp);
 		
 		for (Edge e : temp){
-			//Edge e = temp[0]
-			System.out.println(e);
 			if (e.getSourceNode().equals(node) || e.getTargetNode().equals(node)){
 				//adds the Edge to the list of deleted Edges and remove sit from the Graph 
 				deletedEdges.add(g.removeEdge(e));
@@ -102,7 +112,7 @@ public class Visualizer {
 	 *  
 	 * @param g the Graph, whose Elements shall be undeleted
 	 */
-	public void undelete (final Graph g) {
+	public void undelete () {
 		HashMap<String, Object> attributes =  new HashMap<String, Object>();
 		if(deletedNode!=null){
 			for (String s : deletedNode.getAttributeKeySet()){
@@ -121,4 +131,51 @@ public class Visualizer {
 			g.getEdge(e.getId()).addAttributes(attributes);
 		}
 	}
+	
+	
+	/**
+	 * returns a View of the Graph. The View is in the Swing Thread and the
+	 * Graph in the Main thread.
+	 * 
+	 * 
+	 * @return a View of the Graph, inheriting from JPanel
+	 */
+	public ViewPanel getView (){
+		return this.view;
+	}
+
+
+
+
+	public String getSelectedNodeID() {
+		return selectedNodeID;
+	}
+
+
+
+
+	public void setSelectedNodeID(String selectedNodeID) {
+		this.selectedNodeID = selectedNodeID;
+	}
+
+
+
+
+	public String getSelectedEdgeID() {
+		return selectedEdgeID;
+	}
+
+
+
+
+	public void setSelectedEdgeID(String selectedEdgeID) {
+		this.selectedEdgeID = selectedEdgeID;
+	}
+
+
+
+
+	public Graph getGraph() {
+		return g;
+	}
 }