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.io.Serializable;
9 import java.rmi.RemoteException;
10
11 import javax.naming.NamingException;
12
13 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
14
15 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
16 import org.opentrafficsim.core.network.animation.PaintLine;
17 import org.opentrafficsim.core.network.animation.PaintPolygons;
18 import org.opentrafficsim.road.network.lane.Lane;
19
20
21
22
23
24
25
26
27
28
29 public class LaneAnimation extends Renderable2D implements Serializable
30 {
31
32 private static final long serialVersionUID = 20141017L;
33
34
35 private final Color color;
36
37
38 private final boolean drawCenterLine;
39
40
41
42
43
44
45
46
47
48 public LaneAnimation(final Lane source, final OTSSimulatorInterface simulator, final Color color,
49 final boolean drawCenterLine) throws NamingException, RemoteException
50 {
51 super(source, simulator);
52 this.color = color;
53 this.drawCenterLine = drawCenterLine;
54 }
55
56
57 @Override
58 public final void paint(final Graphics2D graphics, final ImageObserver observer)
59 {
60 Lane lane = (Lane) getSource();
61 if (this.color != null)
62 {
63 PaintPolygons.paintMultiPolygon(graphics, this.color, lane.getLocation(), lane.getContour(), true);
64 }
65
66 if (this.drawCenterLine)
67 {
68 PaintLine.paintLine(graphics, Color.RED, 0.25, lane.getLocation(), lane.getCenterLine());
69 Shape startCircle =
70 new Ellipse2D.Double(lane.getCenterLine().getFirst().x - lane.getLocation().x - 0.25, -lane
71 .getCenterLine().getFirst().y + lane.getLocation().y - 0.25, 0.5, 0.5);
72 Shape endCircle =
73 new Ellipse2D.Double(lane.getCenterLine().getLast().x - lane.getLocation().x - 0.25, -lane
74 .getCenterLine().getLast().y + lane.getLocation().y - 0.25, 0.5, 0.5);
75 graphics.setColor(Color.BLUE);
76 graphics.fill(startCircle);
77 graphics.setColor(Color.RED);
78 graphics.fill(endCircle);
79 }
80 }
81
82
83 @Override
84 public final String toString()
85 {
86 return "LaneAnimation [lane = " + getSource().toString() + ", color=" + this.color + ", drawCenterLine=" + this.drawCenterLine + "]";
87 }
88 }