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