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();
|
||||
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() {
|
||||
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.addMouseMotionListener(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
|
||||
// us
|
||||
// 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.
|
||||
double lon = ptDst.getX();
|
||||
@ -412,14 +415,14 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
*
|
||||
* @param arc Arc to draw.
|
||||
* @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) {
|
||||
List<Point> pts = arc.getPoints();
|
||||
if (!pts.isEmpty()) {
|
||||
if (palette != null) {
|
||||
this.graphGraphics.setColor(palette.getColorForType(arc.getInfo().getType()));
|
||||
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForType(arc.getInfo().getType())));
|
||||
this.graphGraphics.setColor(palette.getColorForArc(arc));
|
||||
this.graphGraphics.setStroke(new BasicStroke(palette.getWidthForArc(arc)));
|
||||
}
|
||||
Iterator<Point> it1 = pts.iterator();
|
||||
Point prev = it1.next();
|
||||
@ -449,8 +452,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
this.clear();
|
||||
|
||||
// Find minimum/maximum longitude and latitude.
|
||||
double minLon = Double.POSITIVE_INFINITY, minLat = Double.POSITIVE_INFINITY, maxLon = Double.NEGATIVE_INFINITY,
|
||||
maxLat = Double.NEGATIVE_INFINITY;
|
||||
double minLon = Double.POSITIVE_INFINITY, minLat = Double.POSITIVE_INFINITY,
|
||||
maxLon = Double.NEGATIVE_INFINITY, maxLat = Double.NEGATIVE_INFINITY;
|
||||
for (Node node: graph.getNodes()) {
|
||||
Point pt = node.getPoint();
|
||||
if (pt.getLatitude() < minLat) {
|
||||
@ -488,7 +491,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
}
|
||||
|
||||
// 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.graphGraphics = img.createGraphics();
|
||||
this.graphGraphics.setBackground(Color.WHITE);
|
||||
@ -496,10 +500,12 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
// 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.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.zoomAndPanListener.getCoordTransform().scale(scale, scale);
|
||||
this.zoomAndPanListener.setZoomLevel(0);
|
||||
@ -513,7 +519,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
this.initialize(graph);
|
||||
for (Node node: graph.getNodes()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2,96 +2,101 @@ package org.insa.graphics.drawing;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.RoadInformation.RoadType;
|
||||
|
||||
public class BasicGraphPalette implements GraphPalette {
|
||||
|
||||
// Color types for arc.
|
||||
|
||||
// Color types for arc.
|
||||
static final Color motorway = Color.RED;
|
||||
static final Color bigroad = new Color(255, 105, 0);
|
||||
static final Color smallroad = new Color(255, 234, 0);
|
||||
static final Color coastline = Color.BLUE;
|
||||
|
||||
|
||||
// Default point width
|
||||
static final int DEFAULT_POINT_WIDTH = 1;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public BasicGraphPalette() { }
|
||||
|
||||
@Override
|
||||
public int getDefaultPointWidth() {
|
||||
return 2;
|
||||
}
|
||||
public BasicGraphPalette() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getDefaultPointColor() {
|
||||
return Color.GREEN;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultPointWidth() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColorForType(RoadType type) {
|
||||
Color color = Color.BLACK;
|
||||
switch (type) {
|
||||
case MOTORWAY:
|
||||
color = motorway;
|
||||
break;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
color = bigroad;
|
||||
break;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case ROAD:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
color = smallroad;
|
||||
break;
|
||||
case COASTLINE:
|
||||
color = coastline;
|
||||
break;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
@Override
|
||||
public Color getDefaultPointColor() {
|
||||
return Color.GREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColorForArc(Arc arc) {
|
||||
RoadType type = arc.getInfo().getType();
|
||||
Color color = Color.BLACK;
|
||||
switch (type) {
|
||||
case MOTORWAY:
|
||||
color = motorway;
|
||||
break;
|
||||
case TRUNK:
|
||||
case PRIMARY:
|
||||
case SECONDARY:
|
||||
case MOTORWAY_LINK:
|
||||
case TRUNK_LINK:
|
||||
case PRIMARY_LINK:
|
||||
color = bigroad;
|
||||
break;
|
||||
case SECONDARY_LINK:
|
||||
case TERTIARY:
|
||||
case RESIDENTIAL:
|
||||
case UNCLASSIFIED:
|
||||
case ROAD:
|
||||
case LIVING_STREET:
|
||||
case SERVICE:
|
||||
case ROUNDABOUT:
|
||||
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 org.insa.graph.RoadInformation.RoadType;
|
||||
import org.insa.graph.Arc;
|
||||
|
||||
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
|
||||
public Color getDefaultPointColor() {
|
||||
return Color.BLACK;
|
||||
}
|
||||
// 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
|
||||
public Color getColorForType(RoadType type) {
|
||||
int width = getWidthForType(type);
|
||||
return ROAD_COLOR_FROM_WIDTH[width];
|
||||
}
|
||||
@Override
|
||||
public Color getDefaultPointColor() {
|
||||
return Color.BLACK;
|
||||
}
|
||||
|
||||
@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 org.insa.graph.RoadInformation.RoadType;
|
||||
import org.insa.graph.Arc;
|
||||
|
||||
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 Width associated to the given type of road.
|
||||
*/
|
||||
public int getWidthForType(RoadType type);
|
||||
/**
|
||||
* @return The default point width for this palette.
|
||||
*/
|
||||
public int getDefaultPointWidth();
|
||||
|
||||
/**
|
||||
* @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