Преглед на файлове

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/julien.gedeon/bp-scopviz.git

dominik преди 8 години
родител
ревизия
b7098b79b3

+ 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 - 5
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>
@@ -21,11 +23,6 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-    	<groupId>com.tinkerpop.blueprints</groupId>
-    	<artifactId>blueprints-core</artifactId>
-    	<version>2.6.0</version>
-    </dependency>
     <dependency>
     	<groupId>org.graphstream</groupId>
     	<artifactId>gs-core</artifactId>

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

@@ -1,25 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz;
-
-import java.io.IOException;
-
-import org.graphstream.graph.*;
-
-/**
- * Hello world!
- *
- */
-public class App {
-
-	public static void main(String[] args) {
-		
-		GraphMLImporter importer = new GraphMLImporter();
-		try {
-			Graph g = importer.readGraph("src/main/resources/TestGraphML.txt");
-			g.display();
-		} catch (IOException e) {
-			System.err.println("Error while reading or displaying test GraphML file!");
-			e.printStackTrace();
-		}
-		System.out.println("Hello World!");
-	}
-}

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

@@ -1,21 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz;
-
-import org.graphstream.graph.Graph;
-import org.graphstream.stream.file.FileSinkGraphML;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import org.graphstream.*;
-
-public class GraphMLExporter {
-	public void writeGraph (Graph g, String fileName){
-		FileSinkGraphML writer = new FileSinkGraphML();
-		try {
-			writer.writeAll(g, new FileOutputStream(fileName));
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-}

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

@@ -1,21 +0,0 @@
-package de.tu_darmstadt.informatik.tk.scopviz;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.graphstream.graph.*;
-import org.graphstream.graph.implementations.DefaultGraph;
-import org.graphstream.stream.file.*;
-
-public class GraphMLImporter {
-
-	public Graph readGraph(String fileName) throws IOException{
-		Graph g = new DefaultGraph("g");
-		FileSource fs = new FileSourceGraphML();
-		fs.addSink(g);
-		fs.readAll(fileName);
-		fs.removeSink(g);
-		return g;
-	}
-}

+ 31 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -0,0 +1,31 @@
+package de.tu_darmstadt.informatik.tk.scopviz.io;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import org.graphstream.graph.Graph;
+import org.graphstream.stream.file.FileSinkGraphML;
+
+/**
+ * @version 1.0
+ * @author jascha-b
+ * 
+ */
+public class GraphMLExporter {
+	/**
+	 * Exports the current state of the Graph to a GraphML file.
+	 * 
+	 * @param g
+	 *            The Graphstream-Graph to be exported
+	 * @param fileName
+	 *            The Location on disk the File will be saved on
+	 */
+	public void writeGraph(final Graph g, final String fileName) {
+		FileSinkGraphML writer = new FileSinkGraphML();
+		try {
+			writer.writeAll(g, new FileOutputStream(fileName));
+		} catch (IOException e) {
+			System.out.println("cannot Acces File or invalid path");
+			e.printStackTrace();
+		}
+	}
+}

+ 59 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -0,0 +1,59 @@
+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;
+import org.graphstream.stream.file.FileSource;
+import org.graphstream.stream.file.FileSourceGraphML;
+
+/**
+ * @version 1.1
+ * @author jascha-b
+ *
+ */
+public class GraphMLImporter {
+
+	/**
+	 * Imports a GraphML file.
+	 * 
+	 * @param fileName
+	 *            path to the file on disk
+	 * @return the imported Graphstream-Graph
+	 */
+	public Graph readGraph(final String fileName) {
+		Graph g = new DefaultGraph("g");
+		FileSource fs = new FileSourceGraphML();
+		fs.addSink(g);
+		try {
+			fs.readAll(fileName);
+		} catch (IOException e) {
+			System.out.println("GraphML File doesn't exist or can't be opened");
+			e.printStackTrace();
+		}
+		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);
+	}
+}

+ 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;
+	}
+}

+ 46 - 0
scopviz/src/main/resources/Example.graphml

@@ -0,0 +1,46 @@
+<?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">
+	<key id="attr0000" for="node" attr.name="Eigenschaft" attr.type="string"/>
+	<key id="attr0001" for="node" attr.name="ui.label" attr.type="string"/>
+	<key id="attr0002" for="node" attr.name="y" attr.type="int"/>
+	<key id="attr0003" for="node" attr.name="x" attr.type="int"/>
+	<graph id="Example" edgedefault="undirected">
+		<node id="A">
+			<data key="attr0000">test</data>
+			<data key="attr0001">A</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="B">
+			<data key="attr0001">B</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">100</data>
+		</node>
+		<node id="C">
+			<data key="attr0001">C</data>
+			<data key="attr0002">100</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="D">
+			<data key="attr0001">D</data>
+			<data key="attr0002">200</data>
+			<data key="attr0003">200</data>
+		</node>
+		<node id="E">
+			<data key="attr0001">E</data>
+			<data key="attr0002">185</data>
+			<data key="attr0003">135</data>
+		</node>
+		<edge id="AB" source="A" target="B" directed="false">
+		</edge>
+		<edge id="BC" source="B" target="C" directed="false">
+		</edge>
+		<edge id="CD" source="C" target="D" directed="false">
+		</edge>
+		<edge id="DB" source="D" target="B" directed="false">
+		</edge>
+	</graph>
+</graphml>

+ 101 - 0
scopviz/src/main/resources/MainWindow.fxml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.embed.swing.SwingNode?>
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Menu?>
+<?import javafx.scene.control.MenuBar?>
+<?import javafx.scene.control.MenuItem?>
+<?import javafx.scene.control.ScrollPane?>
+<?import javafx.scene.control.SeparatorMenuItem?>
+<?import javafx.scene.layout.AnchorPane?>
+<?import javafx.scene.layout.Pane?>
+<?import javafx.scene.layout.VBox?>
+<?import javafx.scene.text.Text?>
+
+<VBox minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
+  <children>
+    <MenuBar VBox.vgrow="NEVER">
+      <menus>
+        <Menu mnemonicParsing="false" text="File">
+          <items>
+            <MenuItem mnemonicParsing="false" text="New" />
+            <MenuItem mnemonicParsing="false" text="Open…" />
+            <Menu mnemonicParsing="false" text="Open Recent" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <MenuItem mnemonicParsing="false" text="Close" />
+            <MenuItem mnemonicParsing="false" text="Save" />
+            <MenuItem mnemonicParsing="false" text="Save As…" />
+            <MenuItem mnemonicParsing="false" text="Revert" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <MenuItem mnemonicParsing="false" text="Preferences…" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <MenuItem mnemonicParsing="false" text="Quit" />
+          </items>
+        </Menu>
+        <Menu mnemonicParsing="false" text="Edit">
+          <items>
+            <MenuItem mnemonicParsing="false" text="Undo" />
+            <MenuItem mnemonicParsing="false" text="Redo" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <MenuItem mnemonicParsing="false" text="Cut" />
+            <MenuItem mnemonicParsing="false" text="Copy" />
+            <MenuItem mnemonicParsing="false" text="Paste" />
+            <MenuItem mnemonicParsing="false" text="Delete" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <MenuItem mnemonicParsing="false" text="Select All" />
+            <MenuItem mnemonicParsing="false" text="Unselect All" />
+          </items>
+        </Menu>
+        <Menu mnemonicParsing="false" text="Help">
+          <items>
+            <MenuItem mnemonicParsing="false" text="About MyHelloApp" />
+          </items>
+        </Menu>
+      </menus>
+    </MenuBar>
+    <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
+      <children>
+            <ScrollPane prefHeight="371.0" prefWidth="130.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
+              <content>
+                <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
+                     <children>
+                        <Text layoutX="42.0" layoutY="26.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Toolbox" />
+                     </children>
+                  </AnchorPane>
+              </content>
+            </ScrollPane>
+            <Pane layoutX="131.0" prefHeight="371.0" prefWidth="379.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="131.0" AnchorPane.rightAnchor="130.0" AnchorPane.topAnchor="0.0">
+               <children>
+                  <SwingNode />
+               </children>
+               <opaqueInsets>
+                  <Insets />
+               </opaqueInsets>
+            </Pane>
+            <ScrollPane layoutX="510.0" layoutY="186.0" prefHeight="112.0" prefWidth="130.0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
+               <content>
+                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
+                     <children>
+                        <Text layoutX="28.0" layoutY="52.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Metriken" />
+                     </children>
+                  </AnchorPane>
+               </content>
+            </ScrollPane>
+            <ScrollPane layoutX="510.0" layoutY="113.0" prefHeight="145.0" prefWidth="130.0" AnchorPane.rightAnchor="0.0">
+               <content>
+                  <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="144.0" prefWidth="200.0">
+                     <children>
+                        <Text layoutX="31.0" layoutY="58.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Attribute" />
+                     </children>
+                  </AnchorPane>
+               </content>
+            </ScrollPane>
+            <Pane layoutX="510.0" prefHeight="112.0" prefWidth="130.0">
+               <children>
+                  <Text layoutX="51.0" layoutY="52.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Layer" />
+               </children>
+            </Pane>
+      </children>
+    </AnchorPane>
+  </children>
+</VBox>

+ 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>