Clean code.

This commit is contained in:
Holt59
2018-03-10 20:39:21 +01:00
parent 84f01ce47e
commit 094a2331af
20 changed files with 343 additions and 547 deletions

View File

@@ -11,11 +11,27 @@ import org.mapsforge.core.model.Point;
import org.mapsforge.map.awt.graphics.AwtBitmap;
import org.mapsforge.map.layer.overlay.Marker;
/**
* Class extending the default Mapsforge's {@link Marker} with auto-scaling.
*
* Mapsforge's Markers do not scale with zoom level, this class aims at
* correcting this. Internally, this image stores an {@link Image} instance and
* scale it when a redraw is requested.
*
* @see MarkerUtils#getMarkerForColor(java.awt.Color)
* @see PaintUtils#getStrokeWidth(int, byte)
*/
public class MarkerAutoScaling extends Marker {
// Original image.
private Image image;
/**
* Create a new MarkerAutoScaling at the given position with the given image.
*
* @param latLong Initial position of the marker.
* @param image Image for this marker.
*/
public MarkerAutoScaling(LatLong latLong, Image image) {
super(latLong, null, 0, 0);
this.image = image;

View File

@@ -5,12 +5,14 @@ import org.insa.graph.Point;
public interface MarkerOverlay extends Overlay {
/**
* @return The point associated with this marker.
* @return The current position of this marker.
*/
public Point getPoint();
/**
* Move this marker to the specified location.
*
* @param point New position for the marker.
*/
public void moveTo(Point point);

View File

@@ -11,15 +11,17 @@ public class MarkerUtils {
private static final String MARKER_MASK_FILE = "res/marker_mask.bin";
/**
* Create a Bitmap representing a marker of the given color.
* Create an Image representing a marker of the given color.
*
* @param color
* @return
* @param color Color of the marker.
*
* @return A new Image representing a marker with the given color.
*/
public static Image getMarkerForColor(Color color) {
// create image
int[][] mask = readMarkerMask();
BufferedImage image = new BufferedImage(mask[0].length, mask.length, BufferedImage.TYPE_4BYTE_ABGR);
BufferedImage image = new BufferedImage(mask[0].length, mask.length,
BufferedImage.TYPE_4BYTE_ABGR);
// Color[] map = getColorMapping(color);
int rgb = color.getRGB() & 0x00ffffff;

View File

@@ -4,6 +4,8 @@ import java.awt.Color;
import org.mapsforge.core.graphics.GraphicFactory;
import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
import org.mapsforge.map.layer.overlay.Marker;
import org.mapsforge.map.layer.overlay.Polyline;
public class PaintUtils {
@@ -13,8 +15,9 @@ public class PaintUtils {
/**
* Convert the given AWT color to a mapsforge compatible color.
*
* @param color
* @return
* @param color AWT color to convert.
*
* @return Integer value representing a corresponding mapsforge color.
*/
public static int convertColor(Color color) {
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(),
@@ -24,16 +27,23 @@ public class PaintUtils {
/**
* Convert the given mapsforge color to an AWT Color.
*
* @param color
* @return
* @param color Integer value representing a mapsforge color.
*
* @return AWT color corresponding to the given value.
*/
public static Color convertColor(int color) {
return new Color(color, true);
}
/**
* @param width
* @return
* Compute an updated value for the given width at the given zoom level. This
* function can be used to automatically scale {@link Polyline} or
* {@link Marker} when zooming (which is not done by default in Mapsforge).
*
* @param width Original width to convert.
* @param zoomLevel Zoom level for which the width should be computed.
*
* @return Actual width at the given zoom level.
*/
public static float getStrokeWidth(int width, byte zoomLevel) {
float mul = 1;

View File

@@ -9,48 +9,61 @@ public interface PointSetOverlay extends Overlay {
/**
* Set the width of this overlay for future addPoint().
*
* @param width
* @param width New default width for this overlay.
*/
public void setWidth(int width);
/**
* Set color and width for this overlay for future addPoint().
*
* @param width
* @param color
* @param width New default width for this overlay.
* @param color New default color for this overlay.
*/
public void setWidthAndColor(int width, Color color);
/**
* Add a new point using the current width and color.
*
* @param point
* @param point Position of the point to add.
*
* @see #setWidth(int)
* @see #setColor(Color)
*/
public void addPoint(Point point);
/**
* Set the current width and then add a new point.
*
* @param point
* @param width
* @param point Position of the point to add.
* @param width New default width for this overlay.
*
* @see #setWidth(int)
* @see PointSetOverlay#addPoint(Point)
*/
public void addPoint(Point point, int width);
/**
* Set the current color and then add a new point.
*
* @param point
* @param color
* @param point Position of the point to add.
* @param color New default color for this overlay.
*
* @see #setColor(Color)
* @see PointSetOverlay#addPoint(Point)
*/
public void addPoint(Point point, Color color);
/**
* Add a new point to this set at the given location, with the given color and
* width, and update the current color.
* Add a new point at the given location, with the given color and width, and
* update the current width and color.
*
* @param point
* @param width
* @param color
* @param point Position of the point to add.
* @param width New default width for this overlay.
* @param color New default color for this overlay.
*
* @see #setWidth(int)
* @see #setColor(Color)
* @see PointSetOverlay#addPoint(Point)
*/
public void addPoint(Point point, int width, Color color);

View File

@@ -12,6 +12,15 @@ import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
import org.mapsforge.map.layer.overlay.Polyline;
/**
* Class extending the default Mapsforge's {@link Polyline} with auto-scaling.
*
* Mapsforge's Polylines do not scale with zoom level, this class aims at
* correcting this. When a redraw is requested, the width of the line is
* recomputed for the current zoom level.
*
* @see PaintUtils#getStrokeWidth(int, byte)
*/
public class PolylineAutoScaling extends Polyline {
// Graphic factory.
@@ -21,8 +30,12 @@ public class PolylineAutoScaling extends Polyline {
private final int width;
/**
* @param width
* @param color
* Create a new PolylineAutoScaling with the given width and color.
*
* @param width Original width of the line (independent of the zoom level).
* @param color Color of the line.
*
* @see PaintUtils#getStrokeWidth(int, byte)
*/
public PolylineAutoScaling(int width, Color color) {
super(GRAPHIC_FACTORY.createPaint(), GRAPHIC_FACTORY);
@@ -48,14 +61,14 @@ public class PolylineAutoScaling extends Polyline {
}
/**
* @param point
* @param point Point to add to this line.
*/
public void add(Point point) {
getLatLongs().add(new LatLong(point.getLatitude(), point.getLongitude()));
}
/**
* @param points
* @param points Points to add to this line.
*/
public void add(List<Point> points) {
for (Point point: points) {