Bladeren bron

Added Options functionality for symbol layer

- color selection
- waypoint size
- edge thickness
dominik 8 jaren geleden
bovenliggende
commit
c4a7a50204

+ 0 - 6
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -1,8 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
-import java.awt.Event;
 import java.io.IOException;
-import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.HashSet;
 
@@ -10,7 +8,6 @@ import org.graphstream.graph.implementations.Graphs;
 import org.jxmapviewer.viewer.GeoPosition;
 import org.jxmapviewer.viewer.WaypointPainter;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
@@ -24,9 +21,6 @@ import javafx.event.ActionEvent;
 import javafx.scene.control.Alert;
 import javafx.scene.control.Alert.AlertType;
 import javafx.scene.control.Button;
-import javafx.scene.control.TableRow;
-import javafx.scene.input.MouseButton;
-import javafx.scene.input.MouseEvent;
 
 /**
  * Manager to contain the various handlers for the buttons of the UI.

+ 75 - 0
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/OptionsManager.java

@@ -2,6 +2,10 @@ package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
 import java.util.ArrayList;
 
+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 de.tu_darmstadt.informatik.tk.scopviz.ui.mapView.WorldView;
 import javafx.application.Platform;
 import javafx.collections.FXCollections;
 import javafx.geometry.Insets;
@@ -68,6 +72,32 @@ public final class OptionsManager {
 
 		TextField defaultLatitudeField = new TextField(Double.toString(defaultLat));
 		TextField defaultLongitudeField = new TextField(Double.toString(defaultLong));
+		
+		
+		// Symbol Layer options
+		ChoiceBox<String> edgeSelectedColorSymbolLayer = new ChoiceBox<String>();
+		edgeSelectedColorSymbolLayer.setItems(FXCollections.observableArrayList("Red", "Black", "Blue", "Green", "Yellow", "Orange", "Gray"));
+		edgeSelectedColorSymbolLayer.getSelectionModel().select(EdgePainter.getClickedColor());
+		
+		ChoiceBox<String> edgePlacementColorSymbolLayer = new ChoiceBox<String>();
+		edgePlacementColorSymbolLayer.setItems(FXCollections.observableArrayList("Blue", "Black", "Red", "Green", "Yellow", "Orange", "Gray"));
+		edgePlacementColorSymbolLayer.getSelectionModel().select(EdgePainter.getPlacementColor());
+		
+		ChoiceBox<String> edgeStandardColorSymbolLayer = new ChoiceBox<String>();
+		edgeStandardColorSymbolLayer.setItems(FXCollections.observableArrayList("Black", "Red", "Blue", "Green", "Yellow", "Orange", "Gray"));
+		edgeStandardColorSymbolLayer.getSelectionModel().select(EdgePainter.getStandardColor());
+		
+		ChoiceBox<String> waypointStandardColorSymbolLayer = new ChoiceBox<String>();
+		waypointStandardColorSymbolLayer.setItems(FXCollections.observableArrayList("Black", "Red", "Blue", "Green", "Yellow", "Orange", "Gray"));
+		waypointStandardColorSymbolLayer.getSelectionModel().select(CustomWaypointRenderer.getStandardColor());
+		
+		ChoiceBox<String> waypointSelectedColorSymbolLayer = new ChoiceBox<String>();
+		waypointSelectedColorSymbolLayer.setItems(FXCollections.observableArrayList("Red", "Black", "Blue", "Green", "Yellow", "Orange", "Gray"));
+		waypointSelectedColorSymbolLayer.getSelectionModel().select(CustomWaypointRenderer.getClickedColor());
+		
+		TextField edgeThickness = new TextField(Integer.toString(EdgePainter.getThickness()));
+		
+		TextField waypointSize = new TextField(Integer.toString(CustomWaypointRenderer.getWaypointSize()));
 
 		// position elements on grid
 		grid.add(new Label("Default weight of edges:"), 0, 0);
@@ -83,6 +113,32 @@ public final class OptionsManager {
 		grid.add(defaultLatitudeField, 1, 4);
 		grid.add(new Label("Longitude:"), 0, 5);
 		grid.add(defaultLongitudeField, 1, 5);
+		
+		// symbol layer stuff
+		grid.add(new Label(""), 1, 6);
+		grid.add(new Label("Symbol-Layer Options"), 1, 7);
+		grid.add(new Label("Waypoint Size (int):"), 0, 8);
+		grid.add(waypointSize, 1, 8);
+		
+		grid.add(new Label("Edge thickness (int):"), 0, 9);
+		grid.add(edgeThickness, 1, 9);
+		
+		grid.add(new Label("Edge Colors"), 1, 10);
+		grid.add(new Label("Standard Edge Color"), 0, 11);
+		grid.add(edgeStandardColorSymbolLayer, 1, 11);
+		
+		grid.add(new Label("Clicked Edge Color"), 0, 12);
+		grid.add(edgeSelectedColorSymbolLayer, 1, 12);
+		
+		grid.add(new Label("Placement Edge Color"), 0, 13);
+		grid.add(edgePlacementColorSymbolLayer, 1, 13);
+		
+		grid.add(new Label("Waypoint Colors"), 1, 14);
+		grid.add(new Label("Standard Waypoint Color"), 0, 15);
+		grid.add(waypointStandardColorSymbolLayer, 1, 15);
+		
+		grid.add(new Label("Clicked Waypoint Color"), 0, 16);
+		grid.add(waypointSelectedColorSymbolLayer, 1, 16);
 
 		// set dialog
 		addPropDialog.getDialogPane().setContent(grid);
@@ -100,10 +156,29 @@ public final class OptionsManager {
 						defaultLat = Double.parseDouble(defaultLatitudeField.getText());
 						defaultLong = Double.parseDouble(defaultLongitudeField.getText());
 					}
+					
+					// symbol layer edge thickness
+					if(Integer.parseInt(edgeThickness.getText()) != EdgePainter.getThickness()) {
+						EdgePainter.setEdgeThickness(Integer.parseInt(edgeThickness.getText()));
+					}
+					// symbol layer waypoint size
+					if(Integer.parseInt(waypointSize.getText()) != CustomWaypointRenderer.getWaypointSize()) {
+						CustomWaypointRenderer.setScaleSize(Integer.parseInt(waypointSize.getText()));
+						MapViewFunctions.resetImageMap();
+						MapViewFunctions.initializeWaypointImages();
+					}
+					
 				} catch (NumberFormatException e) {
 				}
 				showWeight = showWeightButton.isSelected();
 				StylesheetManager.adjustNodeGraphics(nodeGraphicsSelector.getValue());
+				
+				// color types of waypoints and edges
+				EdgePainter.setColor(edgeStandardColorSymbolLayer.getValue(), edgePlacementColorSymbolLayer.getValue(), edgeSelectedColorSymbolLayer.getValue());
+				CustomWaypointRenderer.setColor(waypointStandardColorSymbolLayer.getValue(), waypointSelectedColorSymbolLayer.getValue());
+				
+				WorldView.internMapViewer.repaint();
+				
 				return null;
 			} else
 				return null;

+ 7 - 9
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomMapClickListener.java

@@ -109,7 +109,6 @@ public class CustomMapClickListener extends MapClickListener {
 
 		return wayPointSelected;
 	}
-	
 
 	/**
 	 * check if edge was clicked in symbolLayer
@@ -184,13 +183,13 @@ public class CustomMapClickListener extends MapClickListener {
 		}
 	}
 
-	
 	/**
 	 * select the given edge (calls deselctAll() before selecting)
+	 * 
 	 * @param edge
 	 */
 	public static void selectEdge(Edge edge) {
-		
+
 		PropertiesManager.showNewDataSet(edge);
 
 		deselectAll();
@@ -204,17 +203,17 @@ public class CustomMapClickListener extends MapClickListener {
 
 		viewer.repaint();
 	}
-	
 
 	/**
 	 * select the given waypoint (calls deselctAll() before selecting)
+	 * 
 	 * @param nodeWaypoint
 	 */
 	public static void selectWaypoint(CustomWaypoint nodeWaypoint) {
-		
-		PropertiesManager.showNewDataSet(GraphDisplayManager.getGraphManager(Layer.UNDERLAY).getGraph()
-				.getNode(nodeWaypoint.getNodeID()));
-		
+
+		PropertiesManager.showNewDataSet(
+				GraphDisplayManager.getGraphManager(Layer.UNDERLAY).getGraph().getNode(nodeWaypoint.getNodeID()));
+
 		// deselect old waypoint and select new clicked waypoint
 		deselectAll();
 		nodeWaypoint.select();
@@ -222,7 +221,6 @@ public class CustomMapClickListener extends MapClickListener {
 		viewer.repaint();
 	}
 
-	
 	/**
 	 * deselect all edges and the selected node
 	 */

+ 55 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomWaypointRenderer.java

@@ -26,12 +26,12 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 	/**
 	 * the standard background color of images
 	 */
-	public static final Color STANDARD = Color.BLACK;
+	public static Color STANDARD = Color.BLACK;
 
 	/**
 	 * the color of an image, when it was clicked
 	 */
-	public static final Color CLICKED = Color.RED;
+	public static Color CLICKED = Color.RED;
 
 	/**
 	 * an rgb alpha value for computing only
@@ -41,12 +41,12 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 	/**
 	 * the standard width of the shown images, after scaling it
 	 */
-	public static final int SCALEWIDTH = 50;
+	public static int SCALEWIDTH = 50;
 
 	/**
 	 * the standard height of the shwon images, after scaling it
 	 */
-	public static final int SCALEHEIGHT = 50;
+	public static int SCALEHEIGHT = 50;
 
 	@Override
 	public void paintWaypoint(Graphics2D g, JXMapViewer viewer, CustomWaypoint w) {
@@ -56,6 +56,13 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 		// get pre loaded image
 		BufferedImage loadedImg = MapViewFunctions.imageMap.get(w.getDeviceType());
 
+		// standard color has been changed
+		if (!getStandardColor().equals(Color.BLACK)) {
+			loadedImg = MapViewFunctions.colorImage(loadedImg, Color.BLACK, CustomWaypointRenderer.STANDARD,
+					CustomWaypointRenderer.ALPHA);
+		}
+
+		// waypoint is selected
 		if (w.getIsSelected()) {
 			loadedImg = MapViewFunctions.colorImage(loadedImg, CustomWaypointRenderer.STANDARD,
 					CustomWaypointRenderer.CLICKED, CustomWaypointRenderer.ALPHA);
@@ -98,4 +105,48 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 		this.showLabels = showLabels;
 	}
 
+	/**
+	 * sets the color types of waypoints
+	 * 
+	 * @param standard
+	 *            standard color when symbol rep. opened
+	 * @param selected
+	 *            when clicked
+	 */
+	public static void setColor(String standard, String selected) {
+		STANDARD = EdgePainter.stringToColor(standard);
+		CLICKED = EdgePainter.stringToColor(selected);
+	}
+
+	/**
+	 * sets the width and height of the scaled images
+	 * 
+	 * @param size
+	 */
+	public static void setScaleSize(int size) {
+		SCALEWIDTH = size;
+		SCALEHEIGHT = size;
+	}
+
+	/**
+	 * @return waypoint size after scaling it
+	 */
+	public static int getWaypointSize() {
+		return SCALEWIDTH;
+	}
+
+	/**
+	 * @return color when clicked
+	 */
+	public static String getClickedColor() {
+		return EdgePainter.getColorAsString(CLICKED);
+	}
+
+	/**
+	 * @return standard color
+	 */
+	public static String getStandardColor() {
+		return EdgePainter.getColorAsString(STANDARD);
+	}
+
 }

+ 118 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/EdgePainter.java

@@ -29,17 +29,22 @@ public class EdgePainter implements Painter<JXMapViewer> {
 	/**
 	 * standard color in which edges are drawn
 	 */
-	private static final Color STANDARD = Color.BLACK;
+	private static Color STANDARD = Color.BLACK;
 
 	/**
 	 * color in which edges are drawn when clicked
 	 */
-	private static final Color CLICKED = Color.RED;
+	private static Color CLICKED = Color.RED;
 
 	/**
 	 * color in which edges are drawn when they are used in a placement
 	 */
-	private static final Color PLACEMENT = Color.BLUE;
+	private static Color PLACEMENT = Color.BLUE;
+
+	/**
+	 * the thickness of edges
+	 */
+	private static int EDGE_THICKNESS = 2;
 
 	/**
 	 * anti aliasing property
@@ -81,7 +86,7 @@ public class EdgePainter implements Painter<JXMapViewer> {
 
 			// do the drawing again
 			g.setColor(STANDARD);
-			g.setStroke(new BasicStroke(2));
+			g.setStroke(new BasicStroke(EDGE_THICKNESS));
 
 			drawRoute(g, mapViewer);
 
@@ -195,4 +200,113 @@ public class EdgePainter implements Painter<JXMapViewer> {
 		this.showWeights = showWeights;
 	}
 
+	/**
+	 * sets the thickness of the drawn edges
+	 * 
+	 * @param thickness
+	 */
+	public static void setEdgeThickness(int thickness) {
+		EDGE_THICKNESS = thickness;
+	}
+
+	/**
+	 * sets the color types of edges
+	 * 
+	 * @param standard
+	 *            standard color when symbol rep. opened
+	 * @param placement
+	 *            when used in placement
+	 * @param selected
+	 *            when clicked
+	 */
+	public static void setColor(String standard, String placement, String selected) {
+		STANDARD = stringToColor(standard);
+		PLACEMENT = stringToColor(placement);
+		CLICKED = stringToColor(selected);
+
+	}
+
+	/**
+	 * 
+	 * @param string
+	 * @return color under given string
+	 */
+	public static Color stringToColor(String color) {
+
+		switch (color) {
+
+		case "Red":
+			return Color.RED;
+		case "Black":
+			return Color.BLACK;
+		case "Blue":
+			return Color.BLUE;
+		case "Yellow":
+			return Color.YELLOW;
+		case "Green":
+			return Color.GREEN;
+		case "Orange":
+			return Color.ORANGE;
+		case "Gray":
+			return Color.GRAY;
+
+		default:
+			return Color.BLACK;
+		}
+	}
+
+	/**
+	 * @return the thickness of edges
+	 */
+	public static int getThickness() {
+		return EDGE_THICKNESS;
+	}
+
+	/**
+	 * @return color when clicked
+	 */
+	public static String getClickedColor() {
+		return getColorAsString(CLICKED);
+	}
+
+	/**
+	 * @return standard color
+	 */
+	public static String getStandardColor() {
+		return getColorAsString(STANDARD);
+	}
+
+	/**
+	 * @return placement color
+	 */
+	public static String getPlacementColor() {
+		return getColorAsString(PLACEMENT);
+	}
+
+	/**
+	 * 
+	 * @param color
+	 * @return color in specific string representation
+	 */
+	public static String getColorAsString(Color color) {
+
+		if (color.equals(Color.RED))
+			return "Red";
+		if (color.equals(Color.BLACK))
+			return "Black";
+		if (color.equals(Color.BLUE))
+			return "Blue";
+		if (color.equals(Color.GREEN))
+			return "Green";
+		if (color.equals(Color.YELLOW))
+			return "Yellow";
+		if (color.equals(Color.ORANGE))
+			return "Orange";
+		if (color.equals(Color.GRAY))
+			return "Gray";
+
+		return "Unknown";
+
+	}
+
 }

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

@@ -43,7 +43,7 @@ public final class MapViewFunctions {
 	 */
 	public static HashMap<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>(
 			WorldView.waypoints.size());
-	
+
 	private static ArrayList<CustomWaypoint> waypointsAsList = new ArrayList<CustomWaypoint>();
 
 	/**
@@ -180,10 +180,11 @@ public final class MapViewFunctions {
 				URL resource = getDeviceTypeURL(deviceType);
 
 				// create a new waypoint with the node information
-				CustomWaypoint waypoint = new CustomWaypoint(node.getAttribute("ui.label"), node.getId(), resource, deviceType, geoPos);
-				
+				CustomWaypoint waypoint = new CustomWaypoint(node.getAttribute("ui.label"), node.getId(), resource,
+						deviceType, geoPos);
+
 				waypoints.add(waypoint);
-						
+
 				waypointsAsList.add(waypoint);
 			}
 		}
@@ -364,44 +365,43 @@ public final class MapViewFunctions {
 	 * switch to previous Waypoint
 	 */
 	public static void switchToPreviousWaypoint() {
-		
+
 		CustomWaypoint selectedWaypoint = CustomMapClickListener.selectedNode;
-		
-		if(selectedWaypoint == null && waypointsAsList.size() > 0) {
+
+		if (selectedWaypoint == null && waypointsAsList.size() > 0) {
 			CustomMapClickListener.selectWaypoint(waypointsAsList.get(0));
-			
-		}else {
+
+		} else {
 			int index = waypointsAsList.indexOf(selectedWaypoint);
-			
-			if(index == 0){
+
+			if (index == 0) {
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(waypointsAsList.size() - 1));
-			}else {
+			} else {
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(index - 1));
 			}
 		}
 	}
 
-	
 	/**
 	 * switch to next Waypoint
 	 */
 	public static void switchToNextWaypoint() {
-		
+
 		CustomWaypoint selectedWaypoint = CustomMapClickListener.selectedNode;
-		
-		if(selectedWaypoint == null && waypointsAsList.size() > 0) {
+
+		if (selectedWaypoint == null && waypointsAsList.size() > 0) {
 			CustomMapClickListener.selectWaypoint(waypointsAsList.get(0));
-			
+
 		} else {
 			int index = waypointsAsList.indexOf(selectedWaypoint);
-			
-			if(index == waypointsAsList.size() - 1){
+
+			if (index == waypointsAsList.size() - 1) {
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(0));
-			}else {
+			} else {
 				CustomMapClickListener.selectWaypoint(waypointsAsList.get(index + 1));
 			}
 		}
-		
+
 	}
 
 }

+ 22 - 25
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/WorldView.java

@@ -1,6 +1,5 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui.mapView;
 
-import java.awt.Rectangle;
 import java.awt.geom.Point2D;
 import java.io.IOException;
 import java.net.MalformedURLException;
@@ -15,13 +14,10 @@ import org.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.OSMTileFactoryInfo;
 import org.jxmapviewer.painter.CompoundPainter;
 import org.jxmapviewer.painter.Painter;
-import org.jxmapviewer.viewer.GeoBounds;
 import org.jxmapviewer.viewer.GeoPosition;
 import org.jxmapviewer.viewer.TileFactoryInfo;
 import org.jxmapviewer.viewer.WaypointPainter;
-import org.jxmapviewer.viewer.util.GeoUtil;
 
-import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.GUIController;
 import javafx.geometry.Rectangle2D;
 
@@ -128,11 +124,11 @@ public class WorldView {
 
 		// Use 8 threads in parallel to load the tiles
 		tileFactory.setThreadPoolSize(8);
-		
+
 		showAllWaypoints(nodePositions);
 
 		// set Zoom and Center to show all node positions
-		//internMapViewer.zoomToBestFit(nodePositions, 1);
+		// internMapViewer.zoomToBestFit(nodePositions, 1);
 
 		if (internMapViewer.getOverlayPainter() == null) {
 			internMapViewer.setOverlayPainter(painter);
@@ -162,52 +158,53 @@ public class WorldView {
 
 		}
 	}
-	
+
 	/**
 	 * centers map, so that all waypoints are shown
+	 * 
 	 * @param positions
 	 */
 	public static void showAllWaypoints(HashSet<GeoPosition> positions) {
-		
+
 		ArrayList<Point2D> points = new ArrayList<Point2D>(positions.size());
-		
+
 		internMapViewer.setZoom(1);
-		
+
 		internMapViewer.calculateZoomFrom(positions);
-		
+
 		positions.forEach((geoPos) -> points.add(internMapViewer.convertGeoPositionToPoint(geoPos)));
-		
+
 		double minX = Double.MAX_VALUE;
 		double maxX = Double.MIN_VALUE;
-		
+
 		double minY = Double.MAX_VALUE;
 		double maxY = Double.MIN_VALUE;
-		
-		for(Point2D p : points){
-			if(p.getX() < minX){
+
+		for (Point2D p : points) {
+			if (p.getX() < minX) {
 				minX = p.getX();
 			}
-			if(p.getX() > maxX){
+			if (p.getX() > maxX) {
 				maxX = p.getX();
 			}
-			
-			if(p.getY() < minY){
+
+			if (p.getY() < minY) {
 				minY = p.getY();
 			}
-			if(p.getY() > maxY){
+			if (p.getY() > maxY) {
 				maxY = p.getY();
 			}
 		}
-		
+
 		Rectangle2D rect = new Rectangle2D(minX, minY, maxY - minY, maxX - minX);
-		
+
 		double xPos = rect.getMinX() + rect.getHeight() / 2;
 		double yPos = rect.getMinY() + rect.getWidth() / 2;
-		
+
 		Point2D center = new Point2D.Double(xPos, yPos);
-		
+
 		internMapViewer.setCenterPosition(internMapViewer.convertPointToGeoPosition(center));
-		
+
 	}
 
 }