1 package org.opentrafficsim.road.network.animation;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.Shape;
6 import java.awt.geom.Ellipse2D;
7 import java.awt.image.ImageObserver;
8 import java.rmi.RemoteException;
9
10 import javax.naming.NamingException;
11
12 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
13
14 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15 import org.opentrafficsim.core.network.animation.PaintLine;
16 import org.opentrafficsim.core.network.animation.PaintPolygons;
17 import org.opentrafficsim.road.network.lane.Lane;
18
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 private final boolean drawCenterLine;
35
36
37
38
39
40
41
42
43
44 public LaneAnimation(final Lane source, final OTSSimulatorInterface simulator, final Color color,
45 final boolean drawCenterLine) throws NamingException, RemoteException
46 {
47 super(source, simulator);
48 this.color = color;
49 this.drawCenterLine = drawCenterLine;
50 }
51
52
53 @Override
54 public final void paint(final Graphics2D graphics, final ImageObserver observer)
55 {
56 Lane lane = (Lane) getSource();
57 if (this.color != null)
58 {
59 PaintPolygons.paintMultiPolygon(graphics, this.color, lane.getLocation(), lane.getContour(), true);
60 }
61
62 if (this.drawCenterLine)
63 {
64 PaintLine.paintLine(graphics, Color.RED, 0.25, lane.getLocation(), lane.getCenterLine());
65 Shape startCircle =
66 new Ellipse2D.Double(lane.getCenterLine().getFirst().x - lane.getLocation().x - 0.25, -lane
67 .getCenterLine().getFirst().y + lane.getLocation().y - 0.25, 0.5, 0.5);
68 Shape endCircle =
69 new Ellipse2D.Double(lane.getCenterLine().getLast().x - lane.getLocation().x - 0.25, -lane
70 .getCenterLine().getLast().y + lane.getLocation().y - 0.25, 0.5, 0.5);
71 graphics.setColor(Color.BLUE);
72 graphics.fill(startCircle);
73 graphics.setColor(Color.RED);
74 graphics.fill(endCircle);
75 }
76 }
77 }