Browse Source

Refactored and Documented all Code. MERGE CONFLICTS INCOMING

Rebase suggested
Jan Enders 7 years ago
parent
commit
0b6b3af41f

+ 6 - 3
scopviz/.settings/org.eclipse.jdt.core.prefs

@@ -1,5 +1,8 @@
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.8

+ 2 - 0
scopviz/pom.xml

@@ -12,6 +12,8 @@
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.target>1.8</maven.compiler.target>
+    <maven.compiler.source>1.8</maven.compiler.source>
   </properties>
 
   <dependencies>

+ 0 - 21
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/App.java

@@ -1,21 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz;
-
-import java.io.IOException;
-import org.graphstream.graph.*;
-import de.tu_darmstadt.informatik.tk.scopviz.io.*;
-
-/**
- * Hello world!
- *
- */
-public class App {
-
-	public static void main(String[] args) {
-
-		GraphMLImporter importer = new GraphMLImporter();
-		Graph g = importer.readGraph("src/main/resources/Example.graphml");
-		g.display(false);
-		
-		System.out.println("Hello World!");
-	}
-}

+ 0 - 26
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/Visualizer.java

@@ -1,26 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz;
-
-import org.graphstream.graph.*;
-import org.graphstream.ui.swingViewer.ViewPanel;
-import org.graphstream.ui.view.*;
-
-/**
- * Interface between GUI and internal Graph representation.
- * @version 1.0.0.0
- * @author jascha-b
- *
- */
-public class Visualizer {
-  //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){
-    Viewer viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
-    ViewPanel view = viewer.addDefaultView(false);
-    return view;
-  }
-}

+ 23 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -1,6 +1,7 @@
 package de.tu_darmstadt.informatik.tk.scopviz.io;
 
 import java.io.IOException;
+import java.net.URL;
 
 import org.graphstream.graph.Graph;
 import org.graphstream.graph.implementations.DefaultGraph;
@@ -13,7 +14,7 @@ import org.graphstream.stream.file.FileSourceGraphML;
  *
  */
 public class GraphMLImporter {
-	
+
 	/**
 	 * Imports a GraphML file.
 	 * 
@@ -34,4 +35,25 @@ public class GraphMLImporter {
 		fs.removeSink(g);
 		return g;
 	}
+
+	/**
+	 * Imports a GraphML file.
+	 * 
+	 * @param fileURL
+	 *            URL of the file
+	 * @return the imported Graphstream-Graph
+	 */
+	public Graph readGraph(final URL fileURL) {
+		Graph g = new DefaultGraph("g");
+		FileSource fs = new FileSourceGraphML();
+		fs.addSink(g);
+		try {
+			fs.readAll(fileURL);
+		} catch (IOException e) {
+			System.out.println("GraphML File doesn't exist or can't be opened");
+			e.printStackTrace();
+		}
+		fs.removeSink(g);
+		return g;
+	}
 }

+ 112 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MainApp.java

@@ -0,0 +1,112 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import java.awt.Dimension;
+import java.io.IOException;
+import javax.swing.JPanel;
+
+import org.graphstream.graph.Graph;
+import org.graphstream.ui.swingViewer.ViewPanel;
+import javafx.application.Application;
+import javafx.embed.swing.SwingNode;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.Pane;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+
+import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLImporter;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.Visualizer;
+
+/**
+ * Main Class, initializes Graph, displays UI.
+ * 
+ * @author Jan Enders (jan.enders@stud.tu-darmstadt.de)
+ * @version 1.0
+ *
+ */
+public class MainApp extends Application {
+
+	/**
+	 * Primary Stage for the UI Scene.
+	 */
+	private Stage primaryStage;
+	/**
+	 * Root Object of the Scene Graph.
+	 */
+	private VBox rootLayout;
+	/**
+	 * Graph (Network or Operator Graph) to display.
+	 */
+	private Graph graph;
+	/**
+	 * Preferred size for the Graph Viewer.
+	 */
+	private final Dimension preferredViewerSize = new Dimension(300, 300);
+
+	/**
+	 * Main Method, launches the Application.
+	 * 
+	 * @param args
+	 *            Optional String arguments (command line flags), none
+	 *            implemented
+	 */
+	public static void main(final String[] args) {
+		launch(args);
+	}
+
+	/**
+	 * Initializes the Graph by importing it from a GraphML file.
+	 */
+	@Override
+	public void init() {
+		GraphMLImporter importer = new GraphMLImporter();
+		graph = importer.readGraph(MainApp.class.getResource("/Example.graphml"));
+	}
+
+	/**
+	 * Starts the Application by initializing the UI Layout.
+	 */
+	@Override
+	public void start(final Stage stage) {
+		this.primaryStage = stage;
+
+		initRootLayout();
+
+	}
+
+	/**
+	 * initializes the UI Layout by loading it from a FXML file.
+	 */
+	public void initRootLayout() {
+
+		// Load root layout from fxml file.
+		try {
+			FXMLLoader loader = new FXMLLoader();
+			loader.setLocation(MainApp.class.getResource("/MainWindow.fxml"));
+			rootLayout = (VBox) loader.load();
+		} catch (IOException e) {
+			System.err.println("FXML File could not be loaded. Could the Path be incorrect?");
+			e.printStackTrace();
+		}
+
+		// Show the scene containing the root layout.
+		Scene scene = new Scene(rootLayout);
+
+		// Get Access to the SwingNode within the UI
+		// TODO: Make this not terrible
+		AnchorPane anchor = (AnchorPane) rootLayout.getChildren().get(1);
+		Pane pane = (Pane) anchor.getChildren().get(1);
+		SwingNode swingNode = (SwingNode) pane.getChildren().get(0);
+
+		// TODO: remove magic numbers
+		ViewPanel view = Visualizer.getView(graph);
+		view.setPreferredSize(preferredViewerSize);
+		swingNode.setContent((JPanel) view);
+
+		primaryStage.setScene(scene);
+		primaryStage.show();
+
+	}
+
+}

+ 66 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/MyGraph.java

@@ -0,0 +1,66 @@
+package de.tu_darmstadt.informatik.tk.scopviz.main;
+
+import org.graphstream.graph.implementations.SingleGraph;
+
+/**
+ * Our own Class to extend GraphStreams Graph with our own Functionality.
+ * 
+ * @author Jan Enders (jan.enders@stud.tu-darmstadt.de)
+ * @version 0.1
+ *
+ */
+public class MyGraph extends SingleGraph {
+
+	/**
+	 * Creates an empty graph with strict checking and without auto-creation.
+	 * 
+	 * @param id
+	 *            Unique identifier of the graph.
+	 */
+	public MyGraph(final String id) {
+		super(id);
+	}
+
+	/**
+	 * Creates an empty graph with default edge and node capacity.
+	 * 
+	 * @param id
+	 *            Unique identifier of the graph
+	 * @param strictChecking
+	 *            If true any non-fatal error throws an exception.
+	 * @param autoCreate
+	 *            If true (and strict checking is false), nodes are
+	 *            automatically created when referenced when creating a edge,
+	 *            even if not yet inserted in the graph.
+	 */
+	public MyGraph(final String id, final boolean strictChecking, final boolean autoCreate) {
+		super(id, strictChecking, autoCreate);
+	}
+
+	/**
+	 * Creates an empty graph.
+	 * 
+	 * @param id
+	 *            Unique identifier of the graph.
+	 * @param strictChecking
+	 *            If true any non-fatal error throws an exception.
+	 * @param autoCreate
+	 *            If true (and strict checking is false), nodes are
+	 *            automatically created when referenced when creating a edge,
+	 *            even if not yet inserted in the graph.
+	 * @param initialNodeCapacity
+	 *            Initial capacity of the node storage data structures. Use this
+	 *            if you know the approximate maximum number of nodes of the
+	 *            graph. The graph can grow beyond this limit, but storage
+	 *            reallocation is expensive operation.
+	 * @param initialEdgeCapacity
+	 *            Initial capacity of the edge storage data structures. Use this
+	 *            if you know the approximate maximum number of edges of the
+	 *            graph. The graph can grow beyond this limit, but storage
+	 *            reallocation is expensive operation.
+	 */
+	public MyGraph(final String id, final boolean strictChecking, final boolean autoCreate,
+			final int initialNodeCapacity, final int initialEdgeCapacity) {
+		super(id, strictChecking, autoCreate, initialNodeCapacity, initialEdgeCapacity);
+	}
+}

+ 0 - 81
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MainApp.java

@@ -1,81 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
-
-import java.awt.Dimension;
-import java.io.IOException;
-import java.util.Collection;
-
-import javax.swing.JButton;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-import org.graphstream.graph.Graph;
-import org.graphstream.ui.graphicGraph.GraphicElement;
-import org.graphstream.ui.graphicGraph.GraphicGraph;
-import org.graphstream.ui.swingViewer.ViewPanel;
-import org.graphstream.ui.view.Camera;
-import org.graphstream.ui.view.View;
-import org.graphstream.ui.view.util.MouseManager;
-import org.graphstream.ui.view.util.ShortcutManager;
-
-import javafx.application.Application;
-import javafx.embed.swing.SwingNode;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.*;
-import javafx.scene.Scene;
-import javafx.scene.layout.*;
-import javafx.scene.layout.BorderPane;
-import javafx.scene.layout.VBox;
-import javafx.stage.Stage;
-
-import de.tu_darmstadt.informatik.tk.scopviz.*;
-import de.tu_darmstadt.informatik.tk.scopviz.io.*;
-
-public class MainApp extends Application {
-
-	private Stage primaryStage;
-	private VBox rootLayout;
-	private Graph graph;
-
-	@Override
-	public void start(Stage primaryStage) {
-		this.primaryStage = primaryStage;
-
-		GraphMLImporter importer = new GraphMLImporter();
-		graph = importer.readGraph("src/main/resources/Example.graphml");
-		
-		initRootLayout();
-
-	}
-
-	public void initRootLayout() {
-		try {
-			// Load root layout from fxml file.
-			FXMLLoader loader = new FXMLLoader();
-			loader.setLocation(MainApp.class.getResource("/MainWindow.fxml"));
-			rootLayout = (VBox) loader.load();
-
-			// Show the scene containing the root layout.
-			Scene scene = new Scene(rootLayout);
-
-			AnchorPane anchor = (AnchorPane) rootLayout.getChildren().get(1);
-			Pane pane = (Pane) anchor.getChildren().get(1);
-			SwingNode swingNode = (SwingNode) pane.getChildren().get(0);
-			
-			//TODO: remove magic numbers
-			GraphMLImporter reader = new GraphMLImporter();
-			ViewPanel view = Visualizer.getView(reader.readGraph("src/main/resources/Example.graphml"));
-			view.setPreferredSize(new Dimension(300, 200));
-			swingNode.setContent((JPanel) view)/*new JLabel("Graph Anzeige")*/;
-
-			primaryStage.setScene(scene);
-			primaryStage.show();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public static void main(String[] args) {
-		launch(args);
-	}
-}

+ 36 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/Visualizer.java

@@ -0,0 +1,36 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui;
+
+import org.graphstream.graph.Graph;
+import org.graphstream.ui.swingViewer.ViewPanel;
+import org.graphstream.ui.view.Viewer;
+
+/**
+ * Interface between GUI and internal Graph representation.
+ * 
+ * @version 1.0.0.0
+ * @author jascha-b
+ *
+ */
+public final class Visualizer {
+
+	/**
+	 * Private Constructor to prevent instantiation.
+	 */
+	private Visualizer() {
+	}
+
+	// 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) {
+		Viewer viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
+		ViewPanel view = viewer.addDefaultView(false);
+		return view;
+	}
+}

+ 0 - 14
scopviz/src/main/resources/TestGraphML.txt

@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
-		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-		xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
-			http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
-		<graph id="g" edgedefault="undirected">
-			<node id="A">
-			</node>
-			<node id="B">
-			</node>
-			<edge id="AB" source="A" target="B">
-			</edge>
-		</graph>
-</graphml>