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 System.out.println("Drawing lane " + source);
55 }
56
57
58 @Override
59 public final void paint(final Graphics2D graphics, final ImageObserver observer)
60 {
61 Lane lane = (Lane) getSource();
62 if (this.color != null)
63 {
64 PaintPolygons.paintMultiPolygon(graphics, this.color, lane.getLocation(), lane.getContour(), true);
65 }
66
67 if (this.drawCenterLine)
68 {
69 PaintLine.paintLine(graphics, Color.RED, 0.25, lane.getLocation(), lane.getCenterLine());
70 Shape startCircle =
71 new Ellipse2D.Double(lane.getCenterLine().getFirst().x - lane.getLocation().x - 0.25, -lane
72 .getCenterLine().getFirst().y + lane.getLocation().y - 0.25, 0.5, 0.5);
73 Shape endCircle =
74 new Ellipse2D.Double(lane.getCenterLine().getLast().x - lane.getLocation().x - 0.25, -lane
75 .getCenterLine().getLast().y + lane.getLocation().y - 0.25, 0.5, 0.5);
76 graphics.setColor(Color.BLUE);
77 graphics.fill(startCircle);
78 graphics.setColor(Color.RED);
79 graphics.fill(endCircle);
80 }
81 }
82
83
84 @Override
85 public final String toString()
86 {
87 return "LaneAnimation [lane = " + getSource().toString() + ", color=" + this.color + ", drawCenterLine=" + this.drawCenterLine + "]";
88 }
89 }