1 package org.opentrafficsim.draw.road;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.image.ImageObserver;
6 import java.rmi.RemoteException;
7 import java.util.function.Supplier;
8
9 import javax.naming.NamingException;
10
11 import org.djunits.unit.LengthUnit;
12 import org.djunits.value.vdouble.scalar.Length;
13 import org.opentrafficsim.draw.TextAlignment;
14 import org.opentrafficsim.draw.TextAnimation;
15 import org.opentrafficsim.draw.road.AbstractLineAnimation.LaneBasedObjectData;
16 import org.opentrafficsim.draw.road.TrafficLightAnimation.TrafficLightData;
17
18 import nl.tudelft.simulation.naming.context.Contextualized;
19
20
21
22
23
24
25
26
27
28
29
30 public class TrafficLightAnimation extends AbstractLineAnimation<TrafficLightData>
31 {
32
33 private static final long serialVersionUID = 20160000L;
34
35
36 private final Text text;
37
38
39
40
41
42
43
44
45 public TrafficLightAnimation(final TrafficLightData trafficLight, final Contextualized contextualized)
46 throws NamingException, RemoteException
47 {
48 super(trafficLight, contextualized, 0.9, new Length(0.5, LengthUnit.SI));
49
50 this.text = new Text(trafficLight, trafficLight::getId, 0.0f, (float) getHalfLength() + 0.2f, TextAlignment.CENTER,
51 Color.BLACK, contextualized);
52 }
53
54
55
56
57 public final Text getText()
58 {
59 return this.text;
60 }
61
62
63
64
65 @Override
66 public final void paint(final Graphics2D graphics, final ImageObserver observer)
67 {
68 graphics.setColor(getSource().getColor());
69 super.paint(graphics, observer);
70 }
71
72
73 @Override
74 public void destroy(final Contextualized contextProvider)
75 {
76 super.destroy(contextProvider);
77 this.text.destroy(contextProvider);
78 }
79
80
81 @Override
82 public final String toString()
83 {
84 return "TrafficLightAnimation [getSource()=" + this.getSource() + "]";
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98 public class Text extends TextAnimation<TrafficLightData, Text>
99 {
100
101 private static final long serialVersionUID = 20161211L;
102
103
104
105
106
107
108
109
110
111
112
113
114 public Text(final TrafficLightData source, final Supplier<String> text, final float dx, final float dy,
115 final TextAlignment textPlacement, final Color color, final Contextualized contextualized)
116 throws RemoteException, NamingException
117 {
118 super(source, text, dx, dy, textPlacement, color, contextualized, TextAnimation.RENDERWHEN10);
119 }
120
121
122 @Override
123 public final String toString()
124 {
125 return "Text []";
126 }
127 }
128
129
130
131
132
133
134
135
136
137
138 public interface TrafficLightData extends LaneBasedObjectData
139 {
140
141
142
143
144 Color getColor();
145 }
146
147 }