Browse Source

Merged Matthias and Jascha, fixed and refactored some things

Jan Enders 8 years ago
parent
commit
74273cf35d

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

@@ -46,7 +46,6 @@ public class GraphMLExporter {
 	 *            The parent window of the save Window
 	 */
 	public void writeGraph(final Graph g, final Stage stage) {
-		FileSinkGraphML writer = new FileSinkGraphML();
 		String fileName;
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("Saving graph");

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

@@ -15,7 +15,7 @@ import javafx.stage.Stage;
  * Importer to import a graph from a GraphML file and return it as a Graph
  * object.
  * 
- * @author jascha-b
+ * @author Jascha Bohne
  * @version 1.1
  */
 public class GraphMLImporter {
@@ -44,19 +44,19 @@ public class GraphMLImporter {
 	}
 
 	/**
-	 * Imports a GraphML file.
-	 * Opens a open dialog
+	 * Imports a GraphML file. Opens a open dialog
 	 * 
 	 * @param stage
 	 *            the parent window of the open file window
 	 * @return the imported Graphstream-Graph
 	 */
-	public Graph readGraph(final Stage stage) {
+	public Graph readGraph(final String id, final Stage stage) {
 		FileChooser fileChooser = new FileChooser();
 		fileChooser.setTitle("open graph");
 		String fileName = fileChooser.showOpenDialog(stage).getPath();
-		return readGraph(fileName);
+		return readGraph(id, fileName);
 	}
+
 	/**
 	 * Imports a GraphML file.
 	 * 

+ 0 - 8
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/package-info.java

@@ -1,8 +0,0 @@
-/**
- * 
- */
-/**
- * @author jascha-b
- *
- */
-package de.tu_darmstadt.informatik.tk.scopviz.io;

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/main/Main.java

@@ -50,13 +50,13 @@ public final class Main {
 
 	private int iid = 0;
 
+	// TODO: for Demo Purposes only
 	public void load2ndGraph() {
 		if (iid == 0)
 			iid = 1;
 		else
 			iid = 0;
 		GraphManager.switchActiveGraph(iid);
-		Debug.out("done");
 	}
 
 	/**

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

@@ -21,7 +21,7 @@ import javafx.stage.WindowEvent;
 public class MainApp extends Application {
 
 	private static final boolean exportOnClose = false;
-	
+
 	/**
 	 * Primary Stage for the UI Scene.
 	 */
@@ -79,11 +79,11 @@ public class MainApp extends Application {
 		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
 			@Override
 			public void handle(WindowEvent event) {
-				if (exportOnClose){
+				if (exportOnClose) {
 					GraphMLExporter exporter = new GraphMLExporter();
 					exporter.writeGraph(Main.getInstance().getVisualizer().getGraph(), "shutdown.graphml");
 				}
-				
+
 				System.exit(0);
 			}
 		});

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

@@ -1,30 +0,0 @@
-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
-		
-	}
-
-}

+ 34 - 34
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/KeyValuePair.java

@@ -2,42 +2,42 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
 import javafx.beans.property.SimpleStringProperty;
 
-
 /**
- * Key-Value Class for TableViews 
+ * Key-Value Class for TableViews
+ * 
  * @author Dominik Renkel, Julian Ohl
  *
  */
-public class KeyValuePair{
-	 
-	 private final SimpleStringProperty key;
-	 private final SimpleStringProperty value;
-	 
-	 private final Object classType;
-	 
-	 public KeyValuePair(String key, String value, Object classType){
-		 this.key = new SimpleStringProperty(key);
-		 this.value = new SimpleStringProperty(value);
-		 this.classType = classType;
-	 }
-	 
-	 public String getKey() {
-		 return key.get();
-	 }
-
-	 public void setKey(String fName) {
-		 key.set(fName);
-	 }
-
-	 public String getValue() {
-		 return value.get();
-	 }
-
-	 public void setValue(String fName) {
-		 value.set(fName);
-	 }
-	 
-	 public Object getClassType(){
-		 return classType;
-	 }
+public class KeyValuePair {
+
+	private final SimpleStringProperty key;
+	private final SimpleStringProperty value;
+
+	private final Object classType;
+
+	public KeyValuePair(String key, String value, Object classType) {
+		this.key = new SimpleStringProperty(key);
+		this.value = new SimpleStringProperty(value);
+		this.classType = classType;
+	}
+
+	public String getKey() {
+		return key.get();
+	}
+
+	public void setKey(String fName) {
+		key.set(fName);
+	}
+
+	public String getValue() {
+		return value.get();
+	}
+
+	public void setValue(String fName) {
+		value.set(fName);
+	}
+
+	public Object getClassType() {
+		return classType;
+	}
 }

+ 76 - 77
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/PropertiesManager.java

@@ -22,7 +22,7 @@ import javafx.scene.control.TableView;
 public class PropertiesManager {
 
 	private static TableView<KeyValuePair> properties;
-	
+
 	/**
 	 * Initializes the Manager by adding the List of properties to display into
 	 * the properties pane.
@@ -31,108 +31,107 @@ public class PropertiesManager {
 	 *            The list of properties to display
 	 */
 	public static void initializeItems(TableView<KeyValuePair> propertiesInput) {
-		
+
 		properties = propertiesInput;
-		
+
 	}
-	
+
 	/**
 	 * Update Properties of selected Node/Edge, if a any Property was changed
 	 */
-	public static EventHandler<CellEditEvent<KeyValuePair, String>> setOnEditCommitHandler = 
-			new EventHandler<CellEditEvent<KeyValuePair, String>>() {
-		
-        @Override
-        public void handle(CellEditEvent<KeyValuePair, String> t) {
-        	
-            KeyValuePair editedPair = t.getTableView().getItems().get(t.getTablePosition().getRow());
-            
-            Object classType = editedPair.getClassType();
-            String key = editedPair.getKey();
-            
-            editedPair.setValue(t.getNewValue());
-            
-            Visualizer viz = Main.getInstance().getVisualizer();
-            Element selected;
-            
-            String nid = viz.getSelectedNodeID();
-            String eid = viz.getSelectedEdgeID();
-            
-            if(nid != null){
-            	selected = viz.getGraph().getNode(nid);
-            }else if(eid != null){
-            	selected = viz.getGraph().getEdge(eid);
-            }else
-            	return;
-          
-            
-            if(classType.equals(Integer.class)){
-            	selected.changeAttribute(key, Integer.valueOf(editedPair.getValue()));
-            	
-            }else if(classType.equals(Boolean.class)){
-            	selected.changeAttribute(key, Boolean.valueOf(editedPair.getValue()));
-            	
-            }else if(classType.equals(Float.class)){
-            	selected.changeAttribute(key, Float.valueOf(editedPair.getValue()));
-            	
-            }else if(classType.equals(Double.class)){
-            	selected.changeAttribute(key, Double.valueOf(editedPair.getValue()));
-            	
-            }else if(classType.equals(String.class)){
-            	selected.changeAttribute(key, editedPair.getValue());
-            
-            }
-        }
-    };
-	
+	public static EventHandler<CellEditEvent<KeyValuePair, String>> setOnEditCommitHandler = new EventHandler<CellEditEvent<KeyValuePair, String>>() {
+
+		@Override
+		public void handle(CellEditEvent<KeyValuePair, String> t) {
+
+			KeyValuePair editedPair = t.getTableView().getItems().get(t.getTablePosition().getRow());
+
+			Object classType = editedPair.getClassType();
+			String key = editedPair.getKey();
+
+			editedPair.setValue(t.getNewValue());
+
+			Visualizer viz = Main.getInstance().getVisualizer();
+			Element selected;
+
+			String nid = viz.getSelectedNodeID();
+			String eid = viz.getSelectedEdgeID();
+
+			if (nid != null) {
+				selected = viz.getGraph().getNode(nid);
+			} else if (eid != null) {
+				selected = viz.getGraph().getEdge(eid);
+			} else
+				return;
+
+			if (classType.equals(Integer.class)) {
+				selected.changeAttribute(key, Integer.valueOf(editedPair.getValue()));
+
+			} else if (classType.equals(Boolean.class)) {
+				selected.changeAttribute(key, Boolean.valueOf(editedPair.getValue()));
+
+			} else if (classType.equals(Float.class)) {
+				selected.changeAttribute(key, Float.valueOf(editedPair.getValue()));
+
+			} else if (classType.equals(Double.class)) {
+				selected.changeAttribute(key, Double.valueOf(editedPair.getValue()));
+
+			} else if (classType.equals(String.class)) {
+				selected.changeAttribute(key, editedPair.getValue());
+
+			}
+		}
+	};
+
 	/**
 	 * Sets Property-TableView Elements to selected Node or Edge Properties
 	 */
-	public static void setItemsProperties(){
-		
+	public static void setItemsProperties() {
+
 		String nid = Main.getInstance().getVisualizer().getSelectedNodeID();
 		String eid = Main.getInstance().getVisualizer().getSelectedEdgeID();
-		
-		if (nid != null){
+
+		if (nid != null) {
 			Node selectedNode = Main.getInstance().getVisualizer().getGraph().getNode(nid);
 			showNewDataSet(selectedNode);
-			
-		} else if (eid != null){
+
+		} else if (eid != null) {
 			Edge selectedEdge = Main.getInstance().getVisualizer().getGraph().getEdge(eid);
 			showNewDataSet(selectedEdge);
-			
-		} else return;
+
+		} else
+			return;
 	}
-	
-	
-	
+
 	/**
 	 * Add properties of selected Node or Edge to Properties TableView
-	 * @param selected selected Node or Edge
-	 * @param newData 
+	 * 
+	 * @param selected
+	 *            selected Node or Edge
+	 * @param newData
 	 */
-	private static void showNewDataSet(Element selected){
-		
+	private static void showNewDataSet(Element selected) {
+
 		ObservableList<KeyValuePair> newData = FXCollections.observableArrayList();
-		
-		for(String key : selected.getAttributeKeySet()){
-			
-			if(key.equals("xyz") && selected instanceof Node){
-				
-				double[] pos = Toolkit.nodePosition((Node)selected);
-				
+
+		for (String key : selected.getAttributeKeySet()) {
+
+			if (key.equals("xyz") && selected instanceof Node) {
+
+				double[] pos = Toolkit.nodePosition((Node) selected);
+
 				newData.add(new KeyValuePair("x", String.valueOf(pos[0]), double.class));
 				newData.add(new KeyValuePair("y", String.valueOf(pos[1]), double.class));
 				newData.add(new KeyValuePair("z", String.valueOf(pos[2]), double.class));
-				
-			}else{	
+
+			} else {
 				Object actualAttribute = selected.getAttribute(key);
-				
+
 				newData.add(new KeyValuePair(key, String.valueOf(actualAttribute), actualAttribute.getClass()));
 			}
-			
+
 		}
-		
+
 		properties.setItems(newData);
 	}
 }

+ 61 - 62
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java

@@ -30,75 +30,74 @@ public class ToolboxManager {
 	 *            the list of entries to add to the toolbox
 	 */
 	public static void initializeItems(TableView<Pair<Object, String>> toolbox) {
-		
+
 		@SuppressWarnings("unchecked")
 		ObservableList<Pair<Object, String>> data = FXCollections.observableArrayList(
-                pair(new Image(MainApp.class.getResource("/png/node.png").toString()), "Standard"),
-                pair(new Image(MainApp.class.getResource("/png/source.png").toString()),"Source"),
-                pair(new Image(MainApp.class.getResource("/png/sink.png").toString()), "Sink"),
-                pair(new Image(MainApp.class.getResource("/png/enProc.png").toString()), "EnProc"),
-                pair("", ""),
-                pair(new Image(MainApp.class.getResource("/png/dirEdge.png").toString()), "Directed"),
-                pair(new Image(MainApp.class.getResource("/png/undirEdge.png").toString()), "Undirected")
-        );
-		
+				pair(new Image(MainApp.class.getResource("/png/node.png").toString()), "Standard"),
+				pair(new Image(MainApp.class.getResource("/png/source.png").toString()), "Source"),
+				pair(new Image(MainApp.class.getResource("/png/sink.png").toString()), "Sink"),
+				pair(new Image(MainApp.class.getResource("/png/enProc.png").toString()), "EnProc"), pair("", ""),
+				pair(new Image(MainApp.class.getResource("/png/dirEdge.png").toString()), "Directed"),
+				pair(new Image(MainApp.class.getResource("/png/undirEdge.png").toString()), "Undirected"));
+
 		toolbox.getItems().setAll(data);
 	}
-	
-	 private static Pair<Object, String> pair(Object picture, String name) {
-	        return new Pair<>(picture, name);
-	    }
-	 
-	 public static class PairKeyFactory implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, String>, ObservableValue<String>> {
-		    @Override
-		    public ObservableValue<String> call(TableColumn.CellDataFeatures<Pair<Object, String>, String> data) {
-		        return new ReadOnlyObjectWrapper<>(data.getValue().getValue());
-		    }
+
+	private static Pair<Object, String> pair(Object picture, String name) {
+		return new Pair<>(picture, name);
+	}
+
+	public static class PairKeyFactory
+			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, String>, ObservableValue<String>> {
+		@Override
+		public ObservableValue<String> call(TableColumn.CellDataFeatures<Pair<Object, String>, String> data) {
+			return new ReadOnlyObjectWrapper<>(data.getValue().getValue());
 		}
+	}
 
-	 public static class PairValueFactory implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, Object>, ObservableValue<Object>> {
-		    @SuppressWarnings("unchecked")
-		    @Override
-		    public ObservableValue<Object> call(TableColumn.CellDataFeatures<Pair<Object, String>, Object> data) {
-		        Object value = data.getValue().getKey();
-		        return (value instanceof ObservableValue)
-		                ? (ObservableValue<Object>) value
-		                : new ReadOnlyObjectWrapper<>(value);
-		    }
+	public static class PairValueFactory
+			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, Object>, ObservableValue<Object>> {
+		@SuppressWarnings("unchecked")
+		@Override
+		public ObservableValue<Object> call(TableColumn.CellDataFeatures<Pair<Object, String>, Object> data) {
+			Object value = data.getValue().getKey();
+			return (value instanceof ObservableValue) ? (ObservableValue<Object>) value
+					: new ReadOnlyObjectWrapper<>(value);
 		}
-		
-	 public static class PairValueCell extends TableCell<Pair<Object, String>, Object> {
-		    @Override
-		    protected void updateItem(Object item, boolean empty) {
-		        super.updateItem(item, empty);
+	}
 
-		        if (item != null) {
-		            if (item instanceof String) {
-		                setText((String) item);
-		                setGraphic(null);
-		            } else if (item instanceof Integer) {
-		                setText(Integer.toString((Integer) item));
-		                setGraphic(null);
-		            } else if (item instanceof Boolean) {
-		                CheckBox checkBox = new CheckBox();
-		                checkBox.setSelected((boolean) item);
-		                setGraphic(checkBox);
-		            } else if (item instanceof Image) {
-		                setText(null);
-		                ImageView imageView = new ImageView((Image) item);
-		                imageView.setFitWidth(20);
-		                imageView.setFitHeight(20);
-		                imageView.setPreserveRatio(true);
-		                imageView.setSmooth(true);
-		                setGraphic(imageView);
-		            } else {
-		                setText("N/A");
-		                setGraphic(null);
-		            }
-		        } else {
-		            setText(null);
-		            setGraphic(null);
-		        }
-		    }
+	public static class PairValueCell extends TableCell<Pair<Object, String>, Object> {
+		@Override
+		protected void updateItem(Object item, boolean empty) {
+			super.updateItem(item, empty);
+
+			if (item != null) {
+				if (item instanceof String) {
+					setText((String) item);
+					setGraphic(null);
+				} else if (item instanceof Integer) {
+					setText(Integer.toString((Integer) item));
+					setGraphic(null);
+				} else if (item instanceof Boolean) {
+					CheckBox checkBox = new CheckBox();
+					checkBox.setSelected((boolean) item);
+					setGraphic(checkBox);
+				} else if (item instanceof Image) {
+					setText(null);
+					ImageView imageView = new ImageView((Image) item);
+					imageView.setFitWidth(20);
+					imageView.setFitHeight(20);
+					imageView.setPreserveRatio(true);
+					imageView.setSmooth(true);
+					setGraphic(imageView);
+				} else {
+					setText("N/A");
+					setGraphic(null);
+				}
+			} else {
+				setText(null);
+				setGraphic(null);
+			}
 		}
+	}
 }

+ 11 - 10
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/Visualizer.java

@@ -48,10 +48,10 @@ public class Visualizer {
 	 */
 	public Visualizer(Graph graph) {
 		g = graph;
-		/*Viewer*/ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
+		/* Viewer */ viewer = new Viewer(g, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
 		view = viewer.addDefaultView(false);
 		viewer.setCloseFramePolicy(Viewer.CloseFramePolicy.EXIT);
-		/*ViewerPipe */fromViewer = viewer.newViewerPipe();
+		/* ViewerPipe */fromViewer = viewer.newViewerPipe();
 		fromViewer.addViewerListener(new MyViewerListener(this));
 		fromViewer.addSink(graph);
 		fromViewer.removeElementSink(graph);
@@ -95,8 +95,8 @@ public class Visualizer {
 
 	/**
 	 * Deletes all Edges connected to the given Node. The referenced Graph is
-	 * modified directly. Will throw an ElementNotFoundException if the Node
-	 * is not Found
+	 * modified directly. Will throw an ElementNotFoundException if the Node is
+	 * not Found
 	 * 
 	 * @param g
 	 *            the Graph containing the Node
@@ -121,9 +121,10 @@ public class Visualizer {
 
 	// TODO make undelete Graph specific
 	/**
-	 * Undoes the last deleting operation on the given Graph. Deleting operations
-	 * are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes the last
-	 * deleting operation even if that operation didn't change the Graph
+	 * Undoes the last deleting operation on the given Graph. Deleting
+	 * operations are: deleteNode, deleteEdge and deleteEdgesOfNode. Only undoes
+	 * the last deleting operation even if that operation didn't change the
+	 * Graph
 	 * 
 	 * @param g
 	 *            the Graph, whose Elements shall be undeleted
@@ -229,12 +230,12 @@ public class Visualizer {
 	public void zoomOut() {
 		view.getCamera().setViewPercent(view.getCamera().getViewPercent() * 1.05);
 	}
-	
+
 	public ViewerPipe getFromViewer() {
 		return fromViewer;
 	}
-	
-	public void pumpIt(){
+
+	public void pumpIt() {
 		fromViewer.pump();
 	}
 

+ 3 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/MyAnimationTimer.java

@@ -4,18 +4,19 @@ import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import javafx.animation.AnimationTimer;
 
-public class MyAnimationTimer extends AnimationTimer{
+public class MyAnimationTimer extends AnimationTimer {
 
 	long time = -1;
+
 	@Override
 	public void handle(long now) {
 		Main.getInstance().getVisualizer().pumpIt();
+		// TODO: For Demo purposes only
 		if (time == -1)
 			time = now;
 		else {
 			if (time + 2000000000 < now) {
 				Main.getInstance().load2ndGraph();
-				Debug.out("blub");
 				time += 2000000000;
 			}
 		}

+ 2 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/handlers/ResizeListener.java

@@ -41,10 +41,9 @@ public class ResizeListener implements ChangeListener<Number> {
 	}
 
 	@Override
-	public void changed(ObservableValue< ? extends Number> arg0, Number arg1, Number arg2) {
+	public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
 		Main.getInstance().getVisualizer().getView()
-				.setPreferredSize(new Dimension((int) pane.getWidth() - 5, 
-												(int) pane.getHeight() - 5));
+				.setPreferredSize(new Dimension((int) pane.getWidth() - 5, (int) pane.getHeight() - 5));
 		swingNode.setContent(Main.getInstance().getVisualizer().getView());
 	}