瀏覽代碼

Fixed Symbol-Rep code

extracted multiple classes 
fixed some bugs
dominik 8 年之前
父節點
當前提交
2ba1ebaec6

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

@@ -41,7 +41,7 @@ public class Debug {
 		fileName = "/Example2.graphml";
 		return fileName;
 	}
-	
+
 	/**
 	 * Returns the Location of the File for the testing SymbolGraph.
 	 * 

+ 2 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSourceGraphML.java

@@ -242,8 +242,8 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 	public MyFileSourceGraphML() {
 		init();
 	}
-	
-	private void init(){
+
+	private void init() {
 		events = new Stack<XMLEvent>();
 		keys = new HashMap<String, Key>();
 		datas = new LinkedList<Data>();

+ 22 - 234
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -1,22 +1,13 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 
-import javax.swing.event.MouseInputListener;
-
 import org.graphstream.graph.Edge;
-import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.Graphs;
 import org.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.OSMTileFactoryInfo;
-import org.jxmapviewer.VirtualEarthTileFactoryInfo;
-import org.jxmapviewer.input.CenterMapListener;
-import org.jxmapviewer.input.PanKeyListener;
-import org.jxmapviewer.input.PanMouseInputListener;
-import org.jxmapviewer.input.ZoomMouseWheelListenerCursor;
 import org.jxmapviewer.painter.CompoundPainter;
 import org.jxmapviewer.painter.Painter;
 import org.jxmapviewer.viewer.DefaultTileFactory;
@@ -24,20 +15,18 @@ import org.jxmapviewer.viewer.GeoPosition;
 import org.jxmapviewer.viewer.TileFactoryInfo;
 import org.jxmapviewer.viewer.WaypointPainter;
 
-import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
-import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
 import de.tu_darmstadt.informatik.tk.scopviz.main.MyGraph;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomMapClickListener;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomWaypoint;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.CustomWaypointRenderer;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.EdgePainter;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.MapViewFunctions;
 import javafx.beans.value.ObservableValue;
 import javafx.event.ActionEvent;
-import javafx.geometry.Insets;
 import javafx.scene.control.Button;
-import javafx.scene.control.ButtonBar.ButtonData;
-import javafx.scene.control.ButtonType;
-import javafx.scene.control.Dialog;
-import javafx.scene.control.Label;
-import javafx.scene.layout.GridPane;
 
 /**
  * Manager to contain the various handlers for the buttons of the UI.
@@ -58,8 +47,6 @@ public final class ButtonManager {
 
 	private static JXMapViewer internMapViewer;
 
-	private static Boolean hostReachable = true;
-
 	/**
 	 * Private Constructor to prevent Instantiation.
 	 */
@@ -79,6 +66,10 @@ public final class ButtonManager {
 		setBorderStyle(uButton);
 	}
 
+	public static void setViewer(JXMapViewer mapViewer) {
+		internMapViewer = mapViewer;
+	}
+
 	/**
 	 * Handler for zoom in Button
 	 */
@@ -197,37 +188,6 @@ public final class ButtonManager {
 		setBorderStyle((Button) arg0.getSource());
 	}
 
-	public static void showHostNotReachableDialog() {
-		// Create new Dialog
-		Dialog<ArrayList<String>> addPropDialog = new Dialog<>();
-		addPropDialog.setTitle("Preferences");
-
-		ButtonType okButton = new ButtonType("Ok", ButtonData.OK_DONE);
-		addPropDialog.getDialogPane().getButtonTypes().add(okButton);
-
-		// create grid
-		GridPane grid = new GridPane();
-		grid.setHgap(10);
-		grid.setVgap(10);
-		grid.setPadding(new Insets(20, 150, 10, 10));
-
-		// position elements on grid
-		grid.add(new Label("Currently no OpenStreetView Host connection"), 0, 0);
-
-		// set dialog
-		addPropDialog.getDialogPane().setContent(grid);
-
-		// get new property values
-		addPropDialog.setResultConverter(dialogButton -> {
-
-			controller.underlayButton.fire();
-			return null;
-
-		});
-		addPropDialog.showAndWait();
-
-	}
-
 	/**
 	 * Initializes the WorldView, sets data and paints them
 	 */
@@ -238,7 +198,7 @@ public final class ButtonManager {
 		HashSet<Edge> edges = new HashSet<Edge>();
 
 		// Get GeoPositions of nodes and get all waypoints created
-		initializeDataSets(nodePositions, waypoints, edges);
+		MapViewFunctions.fetchGraphData(nodePositions, waypoints, edges);
 
 		// Create a line for all edges
 		EdgePainter edgePainter = new EdgePainter(edges);
@@ -255,120 +215,30 @@ public final class ButtonManager {
 
 		CompoundPainter<JXMapViewer> painter = new CompoundPainter<JXMapViewer>(painters);
 
-		JXMapViewer mapViewer = (JXMapViewer) controller.swingNodeWorldView.getContent();
-
 		// Create a TileFactoryInfo for OpenStreetMap
 		TileFactoryInfo info = new OSMTileFactoryInfo();
 		DefaultTileFactory tileFactory = new DefaultTileFactory(info);
-		mapViewer.setTileFactory(tileFactory);
+		internMapViewer.setTileFactory(tileFactory);
 
 		// Use 8 threads in parallel to load the tiles
 		tileFactory.setThreadPoolSize(8);
 
-		// Add interactions
+		// set Zoom and Center to show all node positions
+		internMapViewer.zoomToBestFit(nodePositions, 0.7);
 
-		// "Drag map around" Listener
-		MouseInputListener mia = new PanMouseInputListener(mapViewer);
-		mapViewer.addMouseListener(mia);
-		mapViewer.addMouseMotionListener(mia);
+		internMapViewer.setOverlayPainter(painter);
 
 		// "click on waypoints" listener
-		mapViewer.addMouseListener(new CustomMapClickListener(mapViewer, waypoints, edges));
-
-		// center map if double clicked / middle clicked
-		mapViewer.addMouseListener(new CenterMapListener(mapViewer));
+		internMapViewer.addMouseListener(new CustomMapClickListener(internMapViewer, waypoints, edges));
 
-		// zoom with mousewheel
-		mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mapViewer));
+		MapViewFunctions.checkVBoxChanged();
 
-		// TODO make this work
-		mapViewer.addKeyListener(new PanKeyListener(mapViewer));
-
-		// set Zoom and Center to show all node positions
-		mapViewer.zoomToBestFit(nodePositions, 0.7);
-
-		mapViewer.setOverlayPainter(painter);
-
-		// Checkboxes were changed last time symbolRep-Layer was shown
-		if (!controller.edgesVisibleCheckbox.isSelected()) {
-			edgePainter.setShowEdges(false);
-		}
-		if (!controller.nodeLabelCheckbox.isSelected()) {
-			CustomWaypointRenderer renderer = new CustomWaypointRenderer();
-			renderer.setShowLabels(false);
-			waypointPainter.setRenderer(renderer);
-		}
-		if (!controller.edgeWeightCheckbox.isSelected()) {
-			edgePainter.setShowWeights(false);
-		}
-		if (!controller.mapViewChoiceBox.getSelectionModel().getSelectedItem().equals("Default")) {
-			changeMapView();
-		}
-
-		internMapViewer = mapViewer;
 		internMapViewer.repaint();
 
 		controller.swingNodeWorldView.setContent(internMapViewer);
 		controller.swingNodeWorldView.setVisible(true);
 	}
 
-	/**
-	 * Initialize HashSets with data from graph
-	 * 
-	 * @param nodePositions
-	 *            Read node data to create GeoPositions of all nodes
-	 * @param waypoints
-	 *            Read node data to create CustomWaypoints with deviceTypes
-	 */
-	private static void initializeDataSets(HashSet<GeoPosition> nodePositions, HashSet<CustomWaypoint> waypoints,
-			HashSet<Edge> edges) {
-
-		GraphManager man = GraphDisplayManager.getGraphManager();
-
-		// add all edges from the Graph to the HashSet
-		for (Edge egde : man.getGraph().getEdgeSet()) {
-			edges.add(egde);
-		}
-
-		for (Node node : man.getGraph().getEachNode()) {
-
-			if (node.hasAttribute("lat") && node.hasAttribute("long")) {
-
-				// Fetch all geo-data from nodes
-				Double latitude = node.getAttribute("lat");
-				Double longitude = node.getAttribute("long");
-
-				GeoPosition geoPos = new GeoPosition(latitude.doubleValue(), longitude.doubleValue());
-
-				nodePositions.add(geoPos);
-
-				// Create waypoints with device type dependent pictures
-				URL resource;
-				String deviceType = (String) node.getAttribute("device.type");
-
-				// TODO add pngs for device types
-				switch (deviceType.equals(null) ? "" : deviceType) {
-
-				case "mobile":
-					resource = MainApp.class.getResource("/png/sink.png");
-					break;
-				case "desktop":
-					resource = MainApp.class.getResource("/png/computer.png");
-					break;
-				case "router":
-					resource = MainApp.class.getResource("/png/router.png");
-					break;
-				default:
-					resource = MainApp.class.getResource("/png/router.png");
-					break;
-				}
-
-				waypoints.add(new CustomWaypoint(node.getAttribute("ui.label"), node.getId(), resource, geoPos));
-
-			}
-		}
-	}
-
 	/**
 	 * Functionality for "edge visible" Checkbox
 	 * 
@@ -380,7 +250,7 @@ public final class ButtonManager {
 	 */
 	public static void edgeVisibleSwitch(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
 
-		EdgePainter edgePainter = (EdgePainter) getCurrentPainter("edge");
+		EdgePainter edgePainter = (EdgePainter) MapViewFunctions.getRequestedPainter("edge");
 
 		// Show edges
 		if (newVal) {
@@ -404,8 +274,8 @@ public final class ButtonManager {
 	 */
 	public static void labelVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal, Boolean newVal) {
 
-		WaypointPainter<CustomWaypoint> waypointPainter = (WaypointPainter<CustomWaypoint>) getCurrentPainter(
-				"waypoint");
+		WaypointPainter<CustomWaypoint> waypointPainter = (WaypointPainter<CustomWaypoint>) MapViewFunctions
+				.getRequestedPainter("waypoint");
 
 		CustomWaypointRenderer renderer = new CustomWaypointRenderer();
 
@@ -436,7 +306,7 @@ public final class ButtonManager {
 	public static void edgeWeightVisibilitySwitcher(ObservableValue<? extends Boolean> ov, Boolean oldVal,
 			Boolean newVal) {
 
-		EdgePainter edgePainter = (EdgePainter) getCurrentPainter("edge");
+		EdgePainter edgePainter = (EdgePainter) MapViewFunctions.getRequestedPainter("edge");
 		// Show Edges weights
 		if (newVal) {
 			edgePainter.setShowWeights(true);
@@ -448,64 +318,6 @@ public final class ButtonManager {
 		}
 	}
 
-	/**
-	 * Returns either an EdgePainter (case input 0) or a WaypointPainter (case
-	 * input 1) based on input
-	 * 
-	 * @param mode
-	 *            0 or 1
-	 * @return EdgePainter or WaypointPainter if existing in CompoundPainter
-	 *         otherwise null
-	 */
-	public static Painter<JXMapViewer> getCurrentPainter(String requested) {
-
-		// return types
-		EdgePainter edgePainter = null;
-		WaypointPainter<CustomWaypoint> waypointPainter = null;
-
-		// currently shown mapViewer
-		JXMapViewer mapViewer = (JXMapViewer) controller.swingNodeWorldView.getContent();
-
-		// currently used compound painter
-		CompoundPainter<JXMapViewer> compPainter = null;
-
-		if (mapViewer.getOverlayPainter() instanceof CompoundPainter) {
-			compPainter = (CompoundPainter<JXMapViewer>) mapViewer.getOverlayPainter();
-		}
-		// search all painters in compound painter until they found an edge or
-		// waypoint painter
-		for (Painter<JXMapViewer> painter : compPainter.getPainters()) {
-			if (painter instanceof EdgePainter) {
-				edgePainter = (EdgePainter) painter;
-			} else {
-				if (painter instanceof WaypointPainter) {
-					waypointPainter = (WaypointPainter<CustomWaypoint>) painter;
-				}
-			}
-		}
-
-		// return value
-		switch (requested) {
-		case "edge":
-			return edgePainter;
-		case "waypoint":
-			return waypointPainter;
-		default:
-			return null;
-
-		}
-
-	}
-
-	/**
-	 * Set the hostReachable atrribute
-	 * 
-	 * @param reachable
-	 */
-	public static void setHostReachable(Boolean reachable) {
-		hostReachable = reachable;
-	}
-
 	/**
 	 * Changes the border of the button that was pressed to red
 	 * 
@@ -533,31 +345,7 @@ public final class ButtonManager {
 	 * @param newVal
 	 */
 	public static void mapViewChoiceChange(ObservableValue<? extends String> ov, String oldVal, String newVal) {
-		changeMapView();
-	}
-
-	private static void changeMapView() {
-		String selected = controller.mapViewChoiceBox.getSelectionModel().getSelectedItem();
-
-		switch (selected) {
-		case "Default":
-			TileFactoryInfo defaultTileFactoryInfo = new OSMTileFactoryInfo();
-			internMapViewer.setTileFactory(new DefaultTileFactory(defaultTileFactoryInfo));
-			break;
-		case "Road":
-			TileFactoryInfo roadTileFactoryInfo = new VirtualEarthTileFactoryInfo(VirtualEarthTileFactoryInfo.MAP);
-			internMapViewer.setTileFactory(new DefaultTileFactory(roadTileFactoryInfo));
-			break;
-		case "Satellite":
-			TileFactoryInfo sateliteTileFactoryInfo = new VirtualEarthTileFactoryInfo(
-					VirtualEarthTileFactoryInfo.SATELLITE);
-			internMapViewer.setTileFactory(new DefaultTileFactory(sateliteTileFactoryInfo));
-			break;
-		case "Hybrid":
-			TileFactoryInfo hybridTileFactoryInfo = new VirtualEarthTileFactoryInfo(VirtualEarthTileFactoryInfo.HYBRID);
-			internMapViewer.setTileFactory(new DefaultTileFactory(hybridTileFactoryInfo));
-			break;
-		}
+		MapViewFunctions.changeMapView();
 	}
 
 }

+ 23 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/GUIController.java

@@ -5,13 +5,19 @@ import java.util.ArrayList;
 import java.util.ResourceBundle;
 
 import javax.swing.JPanel;
+import javax.swing.event.MouseInputListener;
 
 import org.jxmapviewer.JXMapViewer;
+import org.jxmapviewer.input.CenterMapListener;
+import org.jxmapviewer.input.PanKeyListener;
+import org.jxmapviewer.input.PanMouseInputListener;
+import org.jxmapviewer.input.ZoomMouseWheelListenerCursor;
 
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.KeyboardShortcuts;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.MyAnimationTimer;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.handlers.ResizeListener;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.MapViewFunctions;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
@@ -171,6 +177,23 @@ public class GUIController implements Initializable {
 
 		JXMapViewer mapViewer = new JXMapViewer();
 
+		ButtonManager.setViewer(mapViewer);
+		MapViewFunctions.initialize(this, mapViewer);
+
+		// center map if double clicked / middle clicked
+		mapViewer.addMouseListener(new CenterMapListener(mapViewer));
+
+		// zoom with mousewheel
+		mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mapViewer));
+
+		// TODO make this work
+		mapViewer.addKeyListener(new PanKeyListener(mapViewer));
+
+		// "Drag map around" Listener
+		MouseInputListener mia = new PanMouseInputListener(mapViewer);
+		mapViewer.addMouseListener(mia);
+		mapViewer.addMouseMotionListener(mia);
+
 		swingNodeWorldView.setContent(mapViewer);
 
 		// add resize Listener to the stackPane

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

@@ -27,12 +27,12 @@ public class ResizeListener implements ChangeListener<Number> {
 	 * The parent Pane of the swingnode.
 	 */
 	private Pane pane = null;
-	
+
 	/**
 	 * Parent StackPane of swingNode for WorldView
 	 */
 	private StackPane stackPane = null;
-	
+
 	/**
 	 * Indicates if pane or stackPane are used
 	 */
@@ -51,7 +51,7 @@ public class ResizeListener implements ChangeListener<Number> {
 		this.stackPane = stackPane;
 		this.paneUsed = false;
 	}
-	
+
 	/**
 	 * Creates a new ResizeListener for a swingNode and its parent Pane.
 	 * 
@@ -68,13 +68,13 @@ public class ResizeListener implements ChangeListener<Number> {
 
 	@Override
 	public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
-		if(!paneUsed){
+		if (!paneUsed) {
 			swingNode.getContent().setSize(new Dimension((int) stackPane.getWidth(), (int) stackPane.getHeight()));
-		}else{
+		} else {
 			Main.getInstance().getGraphManager().getView()
 					.setPreferredSize(new Dimension((int) pane.getWidth() - 5, (int) pane.getHeight() - 5));
 			swingNode.setContent(Main.getInstance().getGraphManager().getView());
-		
+
 		}
 	}
 }

+ 3 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/CustomMapClickListener.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomMapClickListener.java

@@ -1,4 +1,4 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
+package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
 import java.awt.geom.Line2D;
 import java.awt.geom.Point2D;
@@ -10,6 +10,8 @@ import org.jxmapviewer.input.MapClickListener;
 import org.jxmapviewer.viewer.GeoPosition;
 
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.PropertiesManager;
 
 public class CustomMapClickListener extends MapClickListener {
 

+ 1 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/CustomWaypoint.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomWaypoint.java

@@ -1,4 +1,4 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
+package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
 import java.net.URL;
 

+ 10 - 44
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/CustomWaypointRenderer.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomWaypointRenderer.java

@@ -1,4 +1,4 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
+package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
 import java.awt.Color;
 import java.awt.Font;
@@ -23,23 +23,11 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 
 	private Boolean showLabels = true;
 
-	/**
-	 * Scale a given BufferedImage down to given width w and given height h
-	 * 
-	 * @param loadImg
-	 * @param w
-	 * @param h
-	 * @return
-	 */
-	private BufferedImage scaleImage(BufferedImage loadImg, int w, int h) {
-		BufferedImage imgOut = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
-
-		Graphics2D graphics = imgOut.createGraphics();
-		graphics.drawImage(loadImg, 0, 0, w, h, null);
-		graphics.dispose();
-
-		return imgOut;
-	}
+	private static final Color STANDARD = Color.BLACK;
+
+	private static final Color CLICKED = Color.RED;
+
+	private static final int ALPHA = 255;
 
 	@Override
 	public void paintWaypoint(Graphics2D g, JXMapViewer viewer, CustomWaypoint w) {
@@ -50,7 +38,7 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 		try {
 			origImage = ImageIO.read(w.getResource());
 			if (w.getIsSelected()) {
-				origImage = colorImage(origImage);
+				origImage = MapViewFunctions.colorImage(origImage, STANDARD, CLICKED, ALPHA);
 			}
 		} catch (Exception ex) {
 			log.warn("couldn't read Waypoint png", ex);
@@ -60,7 +48,7 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 			return;
 
 		// scale image down
-		BufferedImage myImg = scaleImage(origImage, 50, 50);
+		BufferedImage myImg = MapViewFunctions.scaleImage(origImage, 50, 50);
 
 		// get waypoint position
 		Point2D point = viewer.getTileFactory().geoToPixel(w.getPosition(), viewer.getZoom());
@@ -77,9 +65,9 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 			g.setFont(font);
 
 			if (w.getIsSelected()) {
-				g.setColor(Color.RED);
+				g.setColor(CLICKED);
 			} else
-				g.setColor(Color.BLACK);
+				g.setColor(STANDARD);
 
 			// get label height and width under given font
 			FontMetrics metrics = g.getFontMetrics();
@@ -94,28 +82,6 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 		}
 	}
 
-	/**
-	 * change every black pixel to a red one
-	 * 
-	 * @param image
-	 * @return colored image
-	 */
-	private static BufferedImage colorImage(BufferedImage image) {
-		int width = image.getWidth();
-		int height = image.getHeight();
-
-		for (int xx = 0; xx < width; xx++) {
-			for (int yy = 0; yy < height; yy++) {
-				Color originalColor = new Color(image.getRGB(xx, yy), true);
-
-				if (originalColor.equals(Color.BLACK) && originalColor.getAlpha() == 255) {
-					image.setRGB(xx, yy, Color.RED.getRGB());
-				}
-			}
-		}
-		return image;
-	}
-
 	public void setShowLabels(Boolean showLabels) {
 		this.showLabels = showLabels;
 	}

+ 13 - 11
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/EdgePainter.java → scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/EdgePainter.java

@@ -1,4 +1,4 @@
-package de.tu_darmstadt.informatik.tk.scopviz.ui;
+package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
@@ -7,7 +7,6 @@ import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.RenderingHints;
 import java.awt.geom.Point2D;
-import java.util.Collection;
 import java.util.HashSet;
 
 import org.graphstream.graph.Edge;
@@ -24,10 +23,13 @@ public class EdgePainter implements Painter<JXMapViewer> {
 
 	private boolean showEdges = true;
 
-	private Color color = Color.BLACK;
+	private static final Color STANDARD = Color.BLACK;
+
+	private static final Color CLICKED = Color.RED;
+
 	private boolean antiAlias = true;
 
-	private HashSet<Edge> edges;
+	private static HashSet<Edge> edges;
 
 	private Boolean showWeights = true;
 
@@ -35,10 +37,10 @@ public class EdgePainter implements Painter<JXMapViewer> {
 	 * @param track
 	 *            the track
 	 */
-	public EdgePainter(Collection<Edge> track) {
+	public EdgePainter(HashSet<Edge> track) {
 		// copy the list so that changes in the
 		// original list do not have an effect here
-		this.edges = new HashSet<Edge>(track);
+		edges = new HashSet<Edge>(track);
 	}
 
 	@Override
@@ -55,13 +57,13 @@ public class EdgePainter implements Painter<JXMapViewer> {
 				g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
 			// do the drawing
-			g.setColor(color);
+			g.setColor(STANDARD);
 			g.setStroke(new BasicStroke(4));
 
 			drawRoute(g, mapViewer);
 
 			// do the drawing again
-			g.setColor(color);
+			g.setColor(STANDARD);
 			g.setStroke(new BasicStroke(2));
 
 			drawRoute(g, mapViewer);
@@ -97,20 +99,20 @@ public class EdgePainter implements Painter<JXMapViewer> {
 
 				// draw red line if edge is selected
 				if ((boolean) edge.getAttribute("ui.map.selected")) {
-					g.setColor(Color.RED);
+					g.setColor(CLICKED);
 					g.drawLine((int) startPoint.getX(), (int) startPoint.getY(), (int) endPoint.getX(),
 							(int) endPoint.getY());
 
 					// draw black line if not selected
 				} else {
-					g.setColor(color);
+					g.setColor(STANDARD);
 					g.drawLine((int) startPoint.getX(), (int) startPoint.getY(), (int) endPoint.getX(),
 							(int) endPoint.getY());
 				}
 
 				// edge hasnt got selected attribute
 			} else {
-				g.setColor(color);
+				g.setColor(STANDARD);
 				g.drawLine((int) startPoint.getX(), (int) startPoint.getY(), (int) endPoint.getX(),
 						(int) endPoint.getY());
 			}

+ 258 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/MapViewFunctions.java

@@ -0,0 +1,258 @@
+package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+import java.util.HashSet;
+
+import org.graphstream.graph.Edge;
+import org.graphstream.graph.Node;
+import org.jxmapviewer.JXMapViewer;
+import org.jxmapviewer.OSMTileFactoryInfo;
+import org.jxmapviewer.VirtualEarthTileFactoryInfo;
+import org.jxmapviewer.painter.CompoundPainter;
+import org.jxmapviewer.painter.Painter;
+import org.jxmapviewer.viewer.DefaultTileFactory;
+import org.jxmapviewer.viewer.GeoPosition;
+import org.jxmapviewer.viewer.TileFactoryInfo;
+import org.jxmapviewer.viewer.WaypointPainter;
+
+import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
+import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
+import de.tu_darmstadt.informatik.tk.scopviz.main.MainApp;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
+import de.tu_darmstadt.informatik.tk.scopviz.ui.GraphDisplayManager;
+
+public final class MapViewFunctions {
+
+	private static GUIController controller;
+
+	private static JXMapViewer mapViewer;
+
+	/**
+	 * private constructor to avoid instantiation
+	 */
+	private MapViewFunctions() {
+
+	}
+
+	public static void initialize(GUIController guiController, JXMapViewer viewer) {
+		controller = guiController;
+		mapViewer = viewer;
+	}
+
+	/**
+	 * Scale a given BufferedImage down to given width w and given height h
+	 * 
+	 * @param loadImg
+	 * @param w
+	 * @param h
+	 * @return
+	 */
+	public static BufferedImage scaleImage(BufferedImage loadImg, int w, int h) {
+		BufferedImage imgOut = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+
+		Graphics2D graphics = imgOut.createGraphics();
+		graphics.drawImage(loadImg, 0, 0, w, h, null);
+		graphics.dispose();
+
+		return imgOut;
+	}
+
+	/**
+	 * change all pixels from a given color to another given color (under a
+	 * given alpha value)
+	 *
+	 * @param image
+	 * @param toChange
+	 *            change all pixels with this color to another color
+	 * @param changeWith
+	 *            new color
+	 * @param alpha
+	 * @return
+	 */
+	public static BufferedImage colorImage(BufferedImage image, Color toChange, Color changeWith, int alpha) {
+		int width = image.getWidth();
+		int height = image.getHeight();
+
+		for (int xx = 0; xx < width; xx++) {
+			for (int yy = 0; yy < height; yy++) {
+				Color originalColor = new Color(image.getRGB(xx, yy), true);
+
+				// Pixel is Black -> paint it Red
+				if (originalColor.equals(toChange) && originalColor.getAlpha() == alpha) {
+					image.setRGB(xx, yy, changeWith.getRGB());
+				}
+			}
+		}
+		return image;
+	}
+
+	/**
+	 * Initialize HashSets with data from graph
+	 * 
+	 * @param nodePositions
+	 *            Read node data to create GeoPositions of all nodes
+	 * @param waypoints
+	 *            Read node data to create CustomWaypoints with deviceTypes
+	 */
+	public static void fetchGraphData(HashSet<GeoPosition> nodePositions, HashSet<CustomWaypoint> waypoints,
+			HashSet<Edge> edges) {
+
+		GraphManager man = GraphDisplayManager.getGraphManager(Layer.UNDERLAY);
+
+		// add all edges from the Graph to the HashSet
+		for (Edge edge : man.getGraph().getEdgeSet()) {
+			edges.add(edge);
+		}
+
+		// fetch all needed data from nodes
+		for (Node node : man.getGraph().getEachNode()) {
+
+			if (node.hasAttribute("lat") && node.hasAttribute("long")) {
+
+				// Fetch all geo-data from nodes
+				Double latitude = node.getAttribute("lat");
+				Double longitude = node.getAttribute("long");
+
+				GeoPosition geoPos = new GeoPosition(latitude.doubleValue(), longitude.doubleValue());
+
+				nodePositions.add(geoPos);
+
+				// Create waypoints with device type dependent pictures
+				String deviceType = (String) node.getAttribute("device.type");
+				URL resource = getDeviceType(deviceType);
+
+				// create a new waypoint with the node information
+				waypoints.add(new CustomWaypoint(node.getAttribute("ui.label"), node.getId(), resource, geoPos));
+
+			}
+		}
+	}
+
+	/**
+	 * get the png URL based on the device.type of nodes
+	 * 
+	 * @param deviceType
+	 * @return
+	 */
+	public static URL getDeviceType(String deviceType) {
+		// TODO add pngs for device types
+		switch (deviceType.equals(null) ? "" : deviceType) {
+
+		case "mobile":
+			return MainApp.class.getResource("/png/sink.png");
+
+		case "desktop":
+			return MainApp.class.getResource("/png/computer.png");
+
+		case "router":
+			return MainApp.class.getResource("/png/router.png");
+
+		default:
+			return MainApp.class.getResource("/png/router.png");
+
+		}
+	}
+
+	/**
+	 * Returns either an EdgePainter (case input "edge") or a WaypointPainter
+	 * (case input "waypoint") based on input
+	 * 
+	 * @param mode
+	 *            0 or 1
+	 * @return EdgePainter or WaypointPainter if existing in CompoundPainter
+	 *         otherwise null
+	 */
+	public static Painter<JXMapViewer> getRequestedPainter(String requested) {
+
+		// return types
+		EdgePainter edgePainter = null;
+		WaypointPainter<CustomWaypoint> waypointPainter = null;
+
+		// currently used compound painter
+		CompoundPainter<JXMapViewer> compPainter = null;
+
+		if (mapViewer.getOverlayPainter() instanceof CompoundPainter) {
+			compPainter = (CompoundPainter<JXMapViewer>) mapViewer.getOverlayPainter();
+		}
+		// search all painters in compound painter until they found an edge or
+		// waypoint painter
+		for (Painter<JXMapViewer> painter : compPainter.getPainters()) {
+			if (painter instanceof EdgePainter) {
+				edgePainter = (EdgePainter) painter;
+			} else {
+				if (painter instanceof WaypointPainter) {
+					waypointPainter = (WaypointPainter<CustomWaypoint>) painter;
+				}
+			}
+		}
+
+		// return value
+		switch (requested) {
+		case "edge":
+			return edgePainter;
+		case "waypoint":
+			return waypointPainter;
+		default:
+			return null;
+
+		}
+
+	}
+
+	/**
+	 * change the shown map based on the selected item in the ChoiceBox
+	 */
+	public static void changeMapView() {
+		String selected = controller.mapViewChoiceBox.getSelectionModel().getSelectedItem();
+
+		switch (selected) {
+		case "Default":
+			TileFactoryInfo defaultTileFactoryInfo = new OSMTileFactoryInfo();
+			mapViewer.setTileFactory(new DefaultTileFactory(defaultTileFactoryInfo));
+			break;
+
+		case "Road":
+			TileFactoryInfo roadTileFactoryInfo = new VirtualEarthTileFactoryInfo(VirtualEarthTileFactoryInfo.MAP);
+			mapViewer.setTileFactory(new DefaultTileFactory(roadTileFactoryInfo));
+			break;
+
+		case "Satellite":
+			TileFactoryInfo sateliteTileFactoryInfo = new VirtualEarthTileFactoryInfo(
+					VirtualEarthTileFactoryInfo.SATELLITE);
+			mapViewer.setTileFactory(new DefaultTileFactory(sateliteTileFactoryInfo));
+			break;
+
+		case "Hybrid":
+			TileFactoryInfo hybridTileFactoryInfo = new VirtualEarthTileFactoryInfo(VirtualEarthTileFactoryInfo.HYBRID);
+			mapViewer.setTileFactory(new DefaultTileFactory(hybridTileFactoryInfo));
+			break;
+		}
+	}
+
+	public static void checkVBoxChanged() {
+
+		EdgePainter edgePainter = (EdgePainter) getRequestedPainter("edge");
+		WaypointPainter<CustomWaypoint> waypointPainter = (WaypointPainter<CustomWaypoint>) getRequestedPainter(
+				"waypoint");
+
+		// Checkboxes were changed last time symbolRep-Layer was shown
+		if (!controller.edgesVisibleCheckbox.isSelected()) {
+			edgePainter.setShowEdges(false);
+		}
+		if (!controller.nodeLabelCheckbox.isSelected()) {
+			CustomWaypointRenderer renderer = new CustomWaypointRenderer();
+			renderer.setShowLabels(false);
+			waypointPainter.setRenderer(renderer);
+		}
+		if (!controller.edgeWeightCheckbox.isSelected()) {
+			edgePainter.setShowWeights(false);
+		}
+		if (!controller.mapViewChoiceBox.getSelectionModel().getSelectedItem().equals("Default")) {
+			MapViewFunctions.changeMapView();
+		}
+	}
+
+}