1 package org.opentrafficsim.road.network.lane.object.trafficlight;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.image.ImageObserver;
6 import java.io.Serializable;
7 import java.rmi.RemoteException;
8
9 import javax.naming.NamingException;
10
11 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
12 import org.opentrafficsim.core.network.animation.PaintPolygons;
13
14 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
15
16
17
18
19
20
21
22
23
24
25
26
27 public class TrafficLightAnimation extends Renderable2D implements Serializable
28 {
29
30 private static final long serialVersionUID = 20160000L;
31
32
33
34
35
36
37
38
39 public TrafficLightAnimation(final TrafficLight source, final OTSSimulatorInterface simulator)
40 throws NamingException, RemoteException
41 {
42 super(source, simulator);
43
44
45 }
46
47
48
49
50 @Override
51 public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
52 {
53 TrafficLight trafficLight = (TrafficLight) this.getSource();
54 Color fillColor;
55 switch (trafficLight.getTrafficLightColor())
56 {
57 case RED:
58 fillColor = Color.red;
59 break;
60
61 case YELLOW:
62 fillColor = Color.yellow;
63 break;
64
65 case GREEN:
66 fillColor = Color.green;
67 break;
68
69 default:
70 fillColor = Color.black;
71 break;
72 }
73
74 PaintPolygons.paintMultiPolygon(graphics, fillColor, trafficLight.getLocation(), trafficLight.getGeometry(), true);
75 }
76
77
78 @Override
79 public final String toString()
80 {
81 return "TrafficLightAnimation [getSource()=" + this.getSource() + "]";
82 }
83
84 }