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.io.Serializable;
7 import java.rmi.RemoteException;
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.core.dsol.OTSSimulatorInterface;
14 import org.opentrafficsim.draw.core.ClonableRenderable2DInterface;
15 import org.opentrafficsim.draw.core.TextAlignment;
16 import org.opentrafficsim.draw.core.TextAnimation;
17 import org.opentrafficsim.road.network.lane.object.sensor.SingleSensor;
18
19 import nl.tudelft.simulation.dsol.animation.Locatable;
20 import nl.tudelft.simulation.naming.context.Contextualized;
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class SensorAnimation extends AbstractLineAnimation<SingleSensor>
35 implements ClonableRenderable2DInterface<SingleSensor>, Serializable
36 {
37
38 private static final long serialVersionUID = 20150130L;
39
40
41 private final Length sensorPosition;
42
43
44 private final Color color;
45
46
47 private final Text text;
48
49
50
51
52
53
54
55
56
57
58 public SensorAnimation(final SingleSensor sensor, final Length sensorPosition,
59 final OTSSimulatorInterface simulator, final Color color) throws NamingException, RemoteException
60 {
61 super(sensor, simulator, .9, new Length(0.5, LengthUnit.SI));
62 this.sensorPosition = sensorPosition;
63 this.color = color;
64
65 this.text = new Text(sensor, sensor.getLane().getParentLink().getId() + "." + sensor.getLane().getId() + sensor.getId(),
66 0.0f, (float) getHalfLength() + 0.2f, TextAlignment.CENTER, Color.BLACK, simulator);
67 }
68
69
70
71
72 public final Text getText()
73 {
74 return this.text;
75 }
76
77
78 @Override
79 public final void paint(final Graphics2D graphics, final ImageObserver observer)
80 {
81 graphics.setColor(this.color);
82 super.paint(graphics, observer);
83 }
84
85
86 @Override
87 public void destroy(final Contextualized contextProvider)
88 {
89 super.destroy(contextProvider);
90 this.text.destroy(contextProvider);
91 }
92
93
94 @Override
95 @SuppressWarnings("checkstyle:designforextension")
96 public ClonableRenderable2DInterface<SingleSensor> clone(final SingleSensor newSource,
97 final OTSSimulatorInterface newSimulator) throws NamingException, RemoteException
98 {
99
100 return new SensorAnimation(newSource, this.sensorPosition, newSimulator, this.color);
101 }
102
103
104 @Override
105 public final String toString()
106 {
107 return "SensorAnimation [getSource()=" + this.getSource() + "]";
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public class Text extends TextAnimation
124 {
125
126 private static final long serialVersionUID = 20161211L;
127
128
129
130
131
132
133
134
135
136
137
138
139 public Text(final Locatable source, final String text, final float dx, final float dy,
140 final TextAlignment textPlacement, final Color color, final OTSSimulatorInterface simulator)
141 throws RemoteException, NamingException
142 {
143 super(source, text, dx, dy, textPlacement, color, simulator, TextAnimation.RENDERALWAYS);
144 }
145
146
147 @Override
148 @SuppressWarnings("checkstyle:designforextension")
149 public TextAnimation clone(final Locatable newSource, final OTSSimulatorInterface newSimulator)
150 throws RemoteException, NamingException
151 {
152 return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
153 }
154
155
156 @Override
157 public final String toString()
158 {
159 return "Text []";
160 }
161 }
162
163 }