Use arc instead of only road type to find width and color for drawing.
This commit is contained in:
parent
e15d04eda9
commit
0963f4a12f
@ -126,7 +126,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
double scale = DEFAULT_MARKER_WIDTH / (double) img.getHeight();
|
double scale = DEFAULT_MARKER_WIDTH / (double) img.getHeight();
|
||||||
gr.scale(scale, scale);
|
gr.scale(scale, scale);
|
||||||
|
|
||||||
graphics.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(), BasicDrawing.this);
|
graphics.drawImage(img, px - img.getWidth() / 2, py - img.getHeight(),
|
||||||
|
BasicDrawing.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -285,7 +286,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public BasicDrawing() {
|
public BasicDrawing() {
|
||||||
this.zoomAndPanListener = new ZoomAndPanListener(this, ZoomAndPanListener.DEFAULT_MIN_ZOOM_LEVEL, 20, 1.2);
|
this.zoomAndPanListener = new ZoomAndPanListener(this,
|
||||||
|
ZoomAndPanListener.DEFAULT_MIN_ZOOM_LEVEL, 20, 1.2);
|
||||||
this.addMouseListener(zoomAndPanListener);
|
this.addMouseListener(zoomAndPanListener);
|
||||||
this.addMouseMotionListener(zoomAndPanListener);
|
this.addMouseMotionListener(zoomAndPanListener);
|
||||||
this.addMouseWheelListener(zoomAndPanListener);
|
this.addMouseWheelListener(zoomAndPanListener);
|
||||||
@ -339,7 +341,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
// Get the point using the inverse transform of the Zoom/Pan object, this gives
|
// Get the point using the inverse transform of the Zoom/Pan object, this gives
|
||||||
// us
|
// us
|
||||||
// a point within the drawing box (between [0, 0] and [width, height]).
|
// a point within the drawing box (between [0, 0] and [width, height]).
|
||||||
Point2D ptDst = this.zoomAndPanListener.getCoordTransform().inverseTransform(event.getPoint(), null);
|
Point2D ptDst = this.zoomAndPanListener.getCoordTransform()
|
||||||
|
.inverseTransform(event.getPoint(), null);
|
||||||
|
|
||||||
// Inverse the "projection" on x/y to get longitude and latitude.
|
// Inverse the "projection" on x/y to get longitude and latitude.
|
||||||
double lon = ptDst.getX();
|
double lon = ptDst.getX();
|
||||||
@ -412,14 +415,14 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
*
|
*
|
||||||
* @param arc Arc to draw.
|
* @param arc Arc to draw.
|
||||||
* @param palette Palette to use to retrieve color and width for arc, or null to
|
* @param palette Palette to use to retrieve color and width for arc, or null to
|
||||||
* use current settings.
|
* use current settings.
|
||||||
*/
|
*/
|
||||||
protected void drawArc(Arc arc, GraphPalette palette) {
|
protected void drawArc(Arc arc, GraphPalette palette) {
|
||||||
List<Point> pts = arc.getPoints();
|
List<Point> pts = arc.getPoints();
|
||||||
if (!pts.isEmpty()) {
|
if (!pts.isEmpty()) {
|
||||||
if (palette != null) {
|
if (palette != null) {
|
||||||
this.graphGraphics.setColor(palette.getColorForType(arc.getInfo().getType()));
|
this.graphGraphics.setColor(palette.getColorForArc(arc));
|
||||||
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForType(arc.getInfo().getType())));
|
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
|
||||||
}
|
}
|
||||||
Iterator<Point> it1 = pts.iterator();
|
Iterator<Point> it1 = pts.iterator();
|
||||||
Point prev = it1.next();
|
Point prev = it1.next();
|
||||||
@ -449,8 +452,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
// Find minimum/maximum longitude and latitude.
|
// Find minimum/maximum longitude and latitude.
|
||||||
double minLon = Double.POSITIVE_INFINITY, minLat = Double.POSITIVE_INFINITY, maxLon = Double.NEGATIVE_INFINITY,
|
double minLon = Double.POSITIVE_INFINITY, minLat = Double.POSITIVE_INFINITY,
|
||||||
maxLat = Double.NEGATIVE_INFINITY;
|
maxLon = Double.NEGATIVE_INFINITY, maxLat = Double.NEGATIVE_INFINITY;
|
||||||
for (Node node: graph.getNodes()) {
|
for (Node node: graph.getNodes()) {
|
||||||
Point pt = node.getPoint();
|
Point pt = node.getPoint();
|
||||||
if (pt.getLatitude() < minLat) {
|
if (pt.getLatitude() < minLat) {
|
||||||
@ -488,7 +491,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the image
|
// Create the image
|
||||||
BufferedImage img = new BufferedImage(this.width, this.height, BufferedImage.TYPE_3BYTE_BGR);
|
BufferedImage img = new BufferedImage(this.width, this.height,
|
||||||
|
BufferedImage.TYPE_3BYTE_BGR);
|
||||||
this.graphImage = img;
|
this.graphImage = img;
|
||||||
this.graphGraphics = img.createGraphics();
|
this.graphGraphics = img.createGraphics();
|
||||||
this.graphGraphics.setBackground(Color.WHITE);
|
this.graphGraphics.setBackground(Color.WHITE);
|
||||||
@ -496,10 +500,12 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
// Set the zoom and pan listener
|
// Set the zoom and pan listener
|
||||||
|
|
||||||
double scale = 1 / Math.max(this.width / (double) this.getWidth(), this.height / (double) this.getHeight());
|
double scale = 1 / Math.max(this.width / (double) this.getWidth(),
|
||||||
|
this.height / (double) this.getHeight());
|
||||||
|
|
||||||
this.zoomAndPanListener.setCoordTransform(this.graphGraphics.getTransform());
|
this.zoomAndPanListener.setCoordTransform(this.graphGraphics.getTransform());
|
||||||
this.zoomAndPanListener.getCoordTransform().translate((this.getWidth() - this.width * scale) / 2,
|
this.zoomAndPanListener.getCoordTransform().translate(
|
||||||
|
(this.getWidth() - this.width * scale) / 2,
|
||||||
(this.getHeight() - this.height * scale) / 2);
|
(this.getHeight() - this.height * scale) / 2);
|
||||||
this.zoomAndPanListener.getCoordTransform().scale(scale, scale);
|
this.zoomAndPanListener.getCoordTransform().scale(scale, scale);
|
||||||
this.zoomAndPanListener.setZoomLevel(0);
|
this.zoomAndPanListener.setZoomLevel(0);
|
||||||
@ -513,7 +519,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
this.initialize(graph);
|
this.initialize(graph);
|
||||||
for (Node node: graph.getNodes()) {
|
for (Node node: graph.getNodes()) {
|
||||||
for (Arc arc: node.getSuccessors()) {
|
for (Arc arc: node.getSuccessors()) {
|
||||||
if (arc.getInfo().isOneWay() || arc.getOrigin().compareTo(arc.getDestination()) < 0) {
|
if (arc.getInfo().isOneWay()
|
||||||
|
|| arc.getOrigin().compareTo(arc.getDestination()) < 0) {
|
||||||
drawArc(arc, palette);
|
drawArc(arc, palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,96 +2,101 @@ package org.insa.graphics.drawing;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
import org.insa.graph.Arc;
|
||||||
import org.insa.graph.RoadInformation.RoadType;
|
import org.insa.graph.RoadInformation.RoadType;
|
||||||
|
|
||||||
public class BasicGraphPalette implements GraphPalette {
|
public class BasicGraphPalette implements GraphPalette {
|
||||||
|
|
||||||
// Color types for arc.
|
// Color types for arc.
|
||||||
static final Color motorway = Color.RED;
|
static final Color motorway = Color.RED;
|
||||||
static final Color bigroad = new Color(255, 105, 0);
|
static final Color bigroad = new Color(255, 105, 0);
|
||||||
static final Color smallroad = new Color(255, 234, 0);
|
static final Color smallroad = new Color(255, 234, 0);
|
||||||
static final Color coastline = Color.BLUE;
|
static final Color coastline = Color.BLUE;
|
||||||
|
|
||||||
// Default point width
|
// Default point width
|
||||||
static final int DEFAULT_POINT_WIDTH = 1;
|
static final int DEFAULT_POINT_WIDTH = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public BasicGraphPalette() { }
|
public BasicGraphPalette() {
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public int getDefaultPointWidth() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getDefaultPointColor() {
|
public int getDefaultPointWidth() {
|
||||||
return Color.GREEN;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getColorForType(RoadType type) {
|
public Color getDefaultPointColor() {
|
||||||
Color color = Color.BLACK;
|
return Color.GREEN;
|
||||||
switch (type) {
|
}
|
||||||
case MOTORWAY:
|
|
||||||
color = motorway;
|
@Override
|
||||||
break;
|
public Color getColorForArc(Arc arc) {
|
||||||
case TRUNK:
|
RoadType type = arc.getInfo().getType();
|
||||||
case PRIMARY:
|
Color color = Color.BLACK;
|
||||||
case SECONDARY:
|
switch (type) {
|
||||||
case MOTORWAY_LINK:
|
case MOTORWAY:
|
||||||
case TRUNK_LINK:
|
color = motorway;
|
||||||
case PRIMARY_LINK:
|
break;
|
||||||
color = bigroad;
|
case TRUNK:
|
||||||
break;
|
case PRIMARY:
|
||||||
case SECONDARY_LINK:
|
case SECONDARY:
|
||||||
case TERTIARY:
|
case MOTORWAY_LINK:
|
||||||
case RESIDENTIAL:
|
case TRUNK_LINK:
|
||||||
case UNCLASSIFIED:
|
case PRIMARY_LINK:
|
||||||
case ROAD:
|
color = bigroad;
|
||||||
case LIVING_STREET:
|
break;
|
||||||
case SERVICE:
|
case SECONDARY_LINK:
|
||||||
case ROUNDABOUT:
|
case TERTIARY:
|
||||||
color = smallroad;
|
case RESIDENTIAL:
|
||||||
break;
|
case UNCLASSIFIED:
|
||||||
case COASTLINE:
|
case ROAD:
|
||||||
color = coastline;
|
case LIVING_STREET:
|
||||||
break;
|
case SERVICE:
|
||||||
}
|
case ROUNDABOUT:
|
||||||
return color;
|
color = smallroad;
|
||||||
}
|
break;
|
||||||
|
case COASTLINE:
|
||||||
|
color = coastline;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidthForArc(Arc arc) {
|
||||||
|
RoadType type = arc.getInfo().getType();
|
||||||
|
int width = 1;
|
||||||
|
switch (type) {
|
||||||
|
case MOTORWAY:
|
||||||
|
width = 2;
|
||||||
|
break;
|
||||||
|
case TRUNK:
|
||||||
|
case PRIMARY:
|
||||||
|
case SECONDARY:
|
||||||
|
case MOTORWAY_LINK:
|
||||||
|
case TRUNK_LINK:
|
||||||
|
case PRIMARY_LINK:
|
||||||
|
width = 1;
|
||||||
|
break;
|
||||||
|
case SECONDARY_LINK:
|
||||||
|
case TERTIARY:
|
||||||
|
case RESIDENTIAL:
|
||||||
|
case UNCLASSIFIED:
|
||||||
|
case ROAD:
|
||||||
|
case LIVING_STREET:
|
||||||
|
case SERVICE:
|
||||||
|
case ROUNDABOUT:
|
||||||
|
width = 1;
|
||||||
|
break;
|
||||||
|
case COASTLINE:
|
||||||
|
width = 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidthForType(RoadType type) {
|
|
||||||
int width = 1;
|
|
||||||
switch (type) {
|
|
||||||
case MOTORWAY:
|
|
||||||
width = 2;
|
|
||||||
break;
|
|
||||||
case TRUNK:
|
|
||||||
case PRIMARY:
|
|
||||||
case SECONDARY:
|
|
||||||
case MOTORWAY_LINK:
|
|
||||||
case TRUNK_LINK:
|
|
||||||
case PRIMARY_LINK:
|
|
||||||
width = 1;
|
|
||||||
break;
|
|
||||||
case SECONDARY_LINK:
|
|
||||||
case TERTIARY:
|
|
||||||
case RESIDENTIAL:
|
|
||||||
case UNCLASSIFIED:
|
|
||||||
case ROAD:
|
|
||||||
case LIVING_STREET:
|
|
||||||
case SERVICE:
|
|
||||||
case ROUNDABOUT:
|
|
||||||
width = 1;
|
|
||||||
break;
|
|
||||||
case COASTLINE:
|
|
||||||
width = 4;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,23 @@ package org.insa.graphics.drawing;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
import org.insa.graph.RoadInformation.RoadType;
|
import org.insa.graph.Arc;
|
||||||
|
|
||||||
public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
|
public class BlackAndWhiteGraphPalette extends BasicGraphPalette {
|
||||||
|
|
||||||
// Road colors (index
|
|
||||||
private final static Color[] ROAD_COLOR_FROM_WIDTH = {
|
|
||||||
null, new Color(140, 140, 140), new Color(80, 80, 80), new Color(40, 40, 40), new Color(30, 30, 30)
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
// Road colors (index
|
||||||
public Color getDefaultPointColor() {
|
private final static Color[] ROAD_COLOR_FROM_WIDTH = { null, new Color(140, 140, 140),
|
||||||
return Color.BLACK;
|
new Color(80, 80, 80), new Color(40, 40, 40), new Color(30, 30, 30) };
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color getColorForType(RoadType type) {
|
public Color getDefaultPointColor() {
|
||||||
int width = getWidthForType(type);
|
return Color.BLACK;
|
||||||
return ROAD_COLOR_FROM_WIDTH[width];
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public Color getColorForArc(Arc arc) {
|
||||||
|
int width = getWidthForArc(arc);
|
||||||
|
return ROAD_COLOR_FROM_WIDTH[width];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,32 +2,32 @@ package org.insa.graphics.drawing;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
import org.insa.graph.RoadInformation.RoadType;
|
import org.insa.graph.Arc;
|
||||||
|
|
||||||
public interface GraphPalette {
|
public interface GraphPalette {
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The default point width for this palette.
|
|
||||||
*/
|
|
||||||
public int getDefaultPointWidth();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The default point color for this palette.
|
|
||||||
*/
|
|
||||||
public Color getDefaultPointColor();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param type Type of the road.
|
|
||||||
*
|
|
||||||
* @return Color associated to the given type of road.
|
|
||||||
*/
|
|
||||||
public Color getColorForType(RoadType type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param type Type of the road.
|
* @return The default point width for this palette.
|
||||||
*
|
*/
|
||||||
* @return Width associated to the given type of road.
|
public int getDefaultPointWidth();
|
||||||
*/
|
|
||||||
public int getWidthForType(RoadType type);
|
/**
|
||||||
|
* @return The default point color for this palette.
|
||||||
|
*/
|
||||||
|
public Color getDefaultPointColor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param arc
|
||||||
|
*
|
||||||
|
* @return Color associated with the given arc.
|
||||||
|
*/
|
||||||
|
public Color getColorForArc(Arc arc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param arc
|
||||||
|
*
|
||||||
|
* @return Width associated with the given arc.
|
||||||
|
*/
|
||||||
|
public int getWidthForArc(Arc arc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user