1 package org.opentrafficsim.draw.road;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Graphics2D;
6 import java.awt.geom.Path2D;
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 org.opentrafficsim.core.dsol.OtsSimulatorInterface;
14 import org.opentrafficsim.core.geometry.OtsGeometryException;
15 import org.opentrafficsim.core.geometry.OtsLine3d;
16 import org.opentrafficsim.road.network.lane.object.detector.TrafficLightDetector;
17
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19
20
21
22
23
24
25
26
27
28
29
30 public class TrafficLightDetectorAnimation extends Renderable2D<TrafficLightDetector> implements Serializable
31 {
32
33 private static final long serialVersionUID = 20150130L;
34
35
36 private final TrafficLightDetector detector;
37
38
39 private final Path2D.Float polygon;
40
41
42
43
44
45
46
47
48
49 public TrafficLightDetectorAnimation(final TrafficLightDetector detector, final OtsSimulatorInterface simulator)
50 throws NamingException, RemoteException, OtsGeometryException
51 {
52 super(detector, simulator);
53 this.detector = detector;
54 OtsLine3d coordinates = this.detector.getGeometry();
55 this.polygon = new Path2D.Float();
56 this.polygon.moveTo(coordinates.get(0).x, coordinates.get(0).y);
57 for (int i = 1; i < coordinates.size(); i++)
58 {
59 this.polygon.lineTo(coordinates.get(i).x, coordinates.get(i).y);
60 }
61 }
62
63
64 @Override
65 public final void paint(final Graphics2D graphics, final ImageObserver observer)
66 {
67 graphics.setColor(this.detector.getOccupancy() ? Color.BLUE : Color.BLACK);
68 graphics.setStroke(new BasicStroke(0.2f));
69 graphics.draw(this.polygon);
70 }
71
72
73 @Override
74 public final String toString()
75 {
76 return "TrafficLightDetectorAnimation [getSource()=" + this.getSource() + "]";
77 }
78
79 }