1 package org.opentrafficsim.core.network.animation;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Path2D;
6 import java.awt.image.ImageObserver;
7 import java.rmi.RemoteException;
8
9 import javax.naming.NamingException;
10
11 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
12 import nl.tudelft.simulation.language.d3.DirectedPoint;
13
14 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15 import org.opentrafficsim.core.network.lane.Lane;
16
17 import com.vividsolutions.jts.geom.Coordinate;
18 import com.vividsolutions.jts.geom.Geometry;
19
20
21
22
23
24
25
26
27
28 public class LaneAnimation extends Renderable2D
29 {
30
31 private final Color color;
32
33
34
35
36
37
38
39
40 public LaneAnimation(final Lane source, final OTSSimulatorInterface simulator, final Color color)
41 throws NamingException, RemoteException
42 {
43 super(source, simulator);
44 this.color = color;
45 }
46
47
48 @Override
49 public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
50 {
51 graphics.setColor(this.color);
52 Lane lane = (Lane) getSource();
53 DirectedPoint p = lane.getLocation();
54 Geometry g = lane.getContour();
55 Coordinate[] coordinates = g.getCoordinates();
56 Path2D.Double path = new Path2D.Double();
57 boolean start = false;
58 for (Coordinate c : coordinates)
59 {
60 if (!start)
61 {
62 start = true;
63 path.moveTo(c.x - p.x, -c.y + p.y);
64 }
65 else
66 {
67 path.lineTo(c.x - p.x, -c.y + p.y);
68 }
69 }
70 path.closePath();
71 graphics.fill(path);
72 }
73 }