Bladeren bron

Documented code

dominik 8 jaren geleden
bovenliggende
commit
88b79c1184

+ 26 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ToolboxManager.java

@@ -59,7 +59,7 @@ public final class ToolboxManager {
 	}
 
 	/**
-	 * 
+	 * Create Row Elements for underlay toolbox view
 	 */
 	public static void setUnderlayItems() {
 
@@ -72,6 +72,9 @@ public final class ToolboxManager {
 		controller.toolbox.getItems().setAll(data);
 	}
 
+	/**
+	 * create row elements for operator toolbox view
+	 */
 	public static void setOperatorItems() {
 
 		@SuppressWarnings("unchecked")
@@ -84,6 +87,9 @@ public final class ToolboxManager {
 
 	}
 
+	/**
+	 * create row elements for mapping toolbox view
+	 */
 	public static void setMappingItems() {
 
 		@SuppressWarnings("unchecked")
@@ -164,12 +170,20 @@ public final class ToolboxManager {
 			Main.getInstance().setCreationMode(currentMode);
 	}
 
-	// TODO: Create Documentation for this, together with Dominik, ich versteh
-	// das zeug hier net.
+	/**
+	 * create a pair object under given picture and name
+	 * @param picture
+	 * @param name
+	 * @return
+	 */
 	private static Pair<Object, String> pair(Object picture, String name) {
 		return new Pair<>(picture, name);
 	}
 
+	/**
+	 * Class for getting the string out of the pair elements in each row
+	 *
+	 */
 	public static class PairKeyFactory
 			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, String>, ObservableValue<String>> {
 		@Override
@@ -178,6 +192,10 @@ public final class ToolboxManager {
 		}
 	}
 
+	/**
+	 * Class for getting the picture out of the pair elements in each row
+	 *
+	 */
 	public static class PairValueFactory
 			implements Callback<TableColumn.CellDataFeatures<Pair<Object, String>, Object>, ObservableValue<Object>> {
 		@SuppressWarnings("unchecked")
@@ -189,6 +207,11 @@ public final class ToolboxManager {
 		}
 	}
 
+	/**
+	 * The actual TableCell, that renders the images of nodes and edges. (Image, String)-Cell
+	 * additional support for (String, String), (Integer, String), (Boolean, String), ("N/A", String) table cells
+	 *
+	 */
 	public static class PairValueCell extends TableCell<Pair<Object, String>, Object> {
 		@Override
 		protected void updateItem(Object item, boolean empty) {

+ 10 - 2
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomTile.java

@@ -9,7 +9,7 @@ import org.jxmapviewer.viewer.Tile;
  * The Tile class represents a particular square image piece of the world bitmap
  * at a particular zoom level.
  * 
- * @author joshy
+ * @author Dominik Renkel
  */
 
 public class CustomTile extends Tile {
@@ -18,13 +18,21 @@ public class CustomTile extends Tile {
 	 * Indicates that loading has succeeded. A PropertyChangeEvent will be fired
 	 * when the loading is completed
 	 */
-
 	private boolean loaded = false;
 
+	/**
+	 * loading priority
+	 */
 	private Priority priority = Priority.High;
 
+	/**
+	 * the tileFactory this tile is referenced to
+	 */
 	private CustomTileFactory dtf;
 
+	/**
+	 * is tile currently loading
+	 */
 	private boolean isLoading = false;
 
 	/**

+ 45 - 20
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/CustomTileFactory.java

@@ -31,6 +31,12 @@ import org.jxmapviewer.viewer.TileCache;
 import org.jxmapviewer.viewer.TileFactoryInfo;
 import org.jxmapviewer.viewer.util.GeoUtil;
 
+/**
+ * Custom tile factory for handling connection problems
+ * 
+ * @author Dominik Renkel
+ *
+ */
 public class CustomTileFactory extends AbstractTileFactory {
 
 	/**
@@ -40,17 +46,36 @@ public class CustomTileFactory extends AbstractTileFactory {
 	private static final String DEFAULT_USER_AGENT = ProjectProperties.INSTANCE.getName() + "/"
 			+ ProjectProperties.INSTANCE.getVersion();
 
+	/**
+	 * userAgent needed to request data from OpenStreetMap servers
+	 */
 	private String userAgent = DEFAULT_USER_AGENT;
 
+	/**
+	 * standard thread count, that are used to load tiles
+	 */
 	private int threadPoolSize = 4;
+
+	/**
+	 * Handling Threads
+	 */
 	private ExecutorService service;
 
-	// TODO the tile map should be static ALWAYS, regardless of the number
-	// of GoogleTileFactories because each tile is, really, a singleton.
+	/**
+	 * saves loaded tiles
+	 */
 	private Map<String, Tile> tileMap = new HashMap<String, Tile>();
 
+	/**
+	 * Actual Loaded Tile chache
+	 */
 	private TileCache cache = new TileCache();
 
+	/**
+	 * constructor with super reference
+	 * 
+	 * @param info
+	 */
 	public CustomTileFactory(TileFactoryInfo info) {
 		super(info);
 	}
@@ -66,6 +91,16 @@ public class CustomTileFactory extends AbstractTileFactory {
 		return (CustomTile) getTile(x, y, zoom, true);
 	}
 
+	/**
+	 * Get a tile like above, but load image when not already in TileCache
+	 * 
+	 * @param tpx
+	 * @param tpy
+	 * @param zoom
+	 * @param eagerLoad
+	 *            load all tiles with same priority
+	 * @return
+	 */
 	private CustomTile getTile(int tpx, int tpy, int zoom, boolean eagerLoad) {
 		// wrap the tiles horizontally --> mod the X with the max width
 		// and use that
@@ -77,17 +112,14 @@ public class CustomTileFactory extends AbstractTileFactory {
 
 		tileX = tileX % numTilesWide;
 		int tileY = tpy;
-		// TilePoint tilePoint = new TilePoint(tileX, tpy);
-		String url = getInfo().getTileUrl(tileX, tileY, zoom);// tilePoint);
-		// System.out.println("loading: " + url);
+		String url = getInfo().getTileUrl(tileX, tileY, zoom);
 
 		Tile.Priority pri = Tile.Priority.High;
 		if (!eagerLoad) {
 			pri = Tile.Priority.Low;
 		}
 		CustomTile tile;
-		// System.out.println("testing for validity: " + tilePoint + " zoom = "
-		// + zoom);
+
 		if (!tileMap.containsKey(url)) {
 			if (!GeoUtil.isValidTile(tileX, tileY, zoom, getInfo())) {
 				tile = new CustomTile(tileX, tileY, zoom);
@@ -101,22 +133,12 @@ public class CustomTileFactory extends AbstractTileFactory {
 			// if its in the map but is low and isn't loaded yet
 			// but we are in high mode
 			if (tile.getPriority() == Tile.Priority.Low && eagerLoad && !tile.isLoaded()) {
-				// System.out.println("in high mode and want a low");
+
 				// tile.promote();
 				promote(tile);
 			}
 		}
 
-		/*
-		 * if (eagerLoad && doEagerLoading) { for (int i = 0; i<1; i++) { for
-		 * (int j = 0; j<1; j++) { // preload the 4 tiles under the current one
-		 * if(zoom > 0) { eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2,
-		 * zoom-1); eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2,
-		 * zoom-1); eagerlyLoad(tilePoint.getX()*2, tilePoint.getY()*2+1,
-		 * zoom-1); eagerlyLoad(tilePoint.getX()*2+1, tilePoint.getY()*2+1,
-		 * zoom-1); } } } }
-		 */
-
 		return tile;
 	}
 
@@ -284,13 +306,14 @@ public class CustomTileFactory extends AbstractTileFactory {
 					URI uri = getURI(tile);
 					img = cache.get(uri);
 					if (img == null) {
+						// put image in chache when loaded
 						byte[] bimg = cacheInputStream(uri.toURL());
 						img = ImageIO.read(new ByteArrayInputStream(bimg));
 						cache.put(uri, bimg, img);
 						img = cache.get(uri);
 					}
 					if (img != null) {
-
+						// set image to tile when loaded
 						final BufferedImage i = img;
 						SwingUtilities.invokeAndWait(new Runnable() {
 							@Override
@@ -301,11 +324,12 @@ public class CustomTileFactory extends AbstractTileFactory {
 							}
 						});
 					} else {
+						// something has not been loaded correctly
 						trys--;
 					}
 
 				} catch (OutOfMemoryError memErr) {
-					// Cache out of memory
+					// Cache out of memory order more
 					cache.needMoreMemory();
 
 				} catch (Throwable e) {
@@ -341,6 +365,7 @@ public class CustomTileFactory extends AbstractTileFactory {
 			tile.setLoading(false);
 		}
 
+		// fetch data from OpenStreetMap server
 		private byte[] cacheInputStream(URL url) throws IOException {
 			URLConnection connection = url.openConnection();
 			connection.setRequestProperty("User-Agent", userAgent);

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

@@ -8,15 +8,33 @@ import org.jxmapviewer.viewer.GeoPosition;
 /**
  * A waypoint that also has a color and a label
  * 
- * @author Martin Steiger
+ * @author Dominik Renkel
  */
 public class CustomWaypoint extends DefaultWaypoint {
 
+	/**
+	 * Label of the referenced graph node
+	 */
 	private final String label;
+
+	/**
+	 * Resource of the shown picture (device type picture)
+	 */
 	private final URL resource;
+
+	/**
+	 * the referenced, graph based, node id
+	 */
 	private final String nodeID;
+
+	/**
+	 * the device type of the referenced node
+	 */
 	private final String deviceType;
 
+	/**
+	 * is the node currently selected -> show it in red
+	 */
 	private Boolean isSelected = false;
 
 	/**

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

@@ -8,27 +8,44 @@ import java.awt.RenderingHints;
 import java.awt.geom.Point2D;
 import java.awt.image.BufferedImage;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jxmapviewer.JXMapViewer;
 import org.jxmapviewer.viewer.WaypointRenderer;
 
 public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint> {
 
-	private static final Log log = LogFactory.getLog(CustomWaypointRenderer.class);
-
+	/**
+	 * The font in which labels are drawn
+	 */
 	private final Font font = new Font("Lucida Sans", Font.BOLD, 15);
 
+	/**
+	 * show labels property
+	 */
 	private Boolean showLabels = true;
 
+	/**
+	 * the standard background color of images
+	 */
 	public static final Color STANDARD = Color.BLACK;
 
+	/**
+	 * the color of an image, when it was clicked
+	 */
 	public static final Color CLICKED = Color.RED;
 
+	/**
+	 * an rgb alpha value for computing only
+	 */
 	public static final int ALPHA = 255;
 
+	/**
+	 * the standard width of the shown images, after scaling it
+	 */
 	public static final int SCALEWIDTH = 60;
 
+	/**
+	 * the standard height of the shwon images, after scaling it
+	 */
 	public static final int SCALEHEIGHT = 60;
 
 	@Override
@@ -50,6 +67,7 @@ public class CustomWaypointRenderer implements WaypointRenderer<CustomWaypoint>
 		int x = (int) point.getX();
 		int y = (int) point.getY();
 
+		// draw image on map
 		g.drawImage(loadedImg, x - loadedImg.getWidth() / 2, y - loadedImg.getHeight(), null);
 
 		if (showLabels) {

+ 19 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/EdgePainter.java

@@ -21,16 +21,34 @@ import org.jxmapviewer.viewer.GeoPosition;
  */
 public class EdgePainter implements Painter<JXMapViewer> {
 
+	/**
+	 * show edges property
+	 */
 	private boolean showEdges = true;
 
+	/**
+	 * standard color in which edges are drawn
+	 */
 	private static final Color STANDARD = Color.BLACK;
 
+	/**
+	 * color in which edges are drawn when clicked
+	 */
 	private static final Color CLICKED = Color.RED;
 
+	/**
+	 * anti aliasing property
+	 */
 	private boolean antiAlias = true;
 
+	/**
+	 * the edges of the currently shown graph
+	 */
 	private static HashSet<Edge> edges;
 
+	/**
+	 * show weights property
+	 */
 	private Boolean showWeights = true;
 
 	/**
@@ -169,7 +187,7 @@ public class EdgePainter implements Painter<JXMapViewer> {
 	}
 
 	/**
-	 * Sets the removeEdges attribute
+	 * Sets the showEdges attribute
 	 * 
 	 * @param showEdges
 	 */

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

@@ -32,7 +32,9 @@ public final class MapViewFunctions {
 
 	private static final Log log = LogFactory.getLog(MapViewFunctions.class);
 
-	// Hash map to save, scaled images
+	/**
+	 * Hash map to save, scaled images
+	 */
 	public static HashMap<String, BufferedImage> imageMap = new HashMap<String, BufferedImage>(
 			WorldView.waypoints.size());
 

+ 0 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/mapView/WorldView.java

@@ -51,8 +51,6 @@ public class WorldView {
 	 */
 	public static HashSet<Edge> edges;
 
-	public static Thread threadBeforeMapViewLoaded;
-
 	/**
 	 * private constructor to avoid instantiation
 	 */
@@ -77,8 +75,6 @@ public class WorldView {
 	 */
 	public static void loadWorldView() throws IOException {
 
-		threadBeforeMapViewLoaded = Thread.currentThread();
-
 		HashSet<GeoPosition> nodePositions = new HashSet<GeoPosition>();
 		waypoints = new HashSet<CustomWaypoint>();
 		edges = new HashSet<Edge>();