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.TextAlignment;
15 import org.opentrafficsim.draw.core.TextAnimation;
16 import org.opentrafficsim.road.network.lane.object.detector.LaneDetector;
17 import nl.tudelft.simulation.dsol.animation.Locatable;
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
19 import nl.tudelft.simulation.naming.context.Contextualized;
20
21
22
23
24
25
26
27
28
29
30
31 public class DetectorAnimation extends AbstractLineAnimation<LaneDetector> implements Renderable2DInterface<LaneDetector>, Serializable
32 {
33
34 private static final long serialVersionUID = 20150130L;
35
36
37 private final Color color;
38
39
40 private final Text text;
41
42
43
44
45
46
47
48
49
50 public DetectorAnimation(final LaneDetector detector, final OtsSimulatorInterface simulator, final Color color)
51 throws NamingException, RemoteException
52 {
53 super(detector, simulator, .9, new Length(0.5, LengthUnit.SI));
54 this.color = color;
55
56 this.text = new Text(detector,
57 detector.getLane().getParentLink().getId() + "." + detector.getLane().getId() + detector.getId(), 0.0f,
58 (float) getHalfLength() + 0.2f, TextAlignment.CENTER, Color.BLACK, simulator);
59 }
60
61
62
63
64 public final Text getText()
65 {
66 return this.text;
67 }
68
69
70 @Override
71 public final void paint(final Graphics2D graphics, final ImageObserver observer)
72 {
73 graphics.setColor(this.color);
74 super.paint(graphics, observer);
75 }
76
77
78 @Override
79 public void destroy(final Contextualized contextProvider)
80 {
81 super.destroy(contextProvider);
82 this.text.destroy(contextProvider);
83 }
84
85
86 @Override
87 public final String toString()
88 {
89 return "DetectorAnimation [getSource()=" + this.getSource() + "]";
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103 public class Text extends TextAnimation
104 {
105
106 private static final long serialVersionUID = 20161211L;
107
108
109
110
111
112
113
114
115
116
117
118
119 public Text(final Locatable source, final String text, final float dx, final float dy,
120 final TextAlignment textPlacement, final Color color, final OtsSimulatorInterface simulator)
121 throws RemoteException, NamingException
122 {
123 super(source, text, dx, dy, textPlacement, color, simulator, TextAnimation.RENDERALWAYS);
124 }
125
126
127 @Override
128 public final String toString()
129 {
130 return "Text []";
131 }
132 }
133
134 }