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