1 package org.opentrafficsim.animation.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.animation.LineLocatable;
14 import org.opentrafficsim.animation.RenderableTextSource;
15 import org.opentrafficsim.animation.TextAlignment;
16 import org.opentrafficsim.animation.road.AbstractLineAnimation.LaneBasedObjectData;
17 import org.opentrafficsim.animation.road.BusStopAnimation.BusStopData;
18 import org.opentrafficsim.animation.road.BusStopAnimation.Text;
19
20 import nl.tudelft.simulation.naming.context.Contextualized;
21
22
23
24
25
26
27
28
29
30
31
32
33 public class BusStopAnimation extends AbstractLineAnimation<BusStopData, Text>
34 {
35
36
37
38
39
40
41
42
43 public BusStopAnimation(final BusStopData laneDetector, final Contextualized contextualized)
44 throws NamingException, RemoteException
45 {
46 super(laneDetector, contextualized, new Length(0.5, LengthUnit.SI));
47 }
48
49 @Override
50 protected Text createText(final BusStopData source, final Contextualized contextualized, final String prefix)
51 {
52 float halfLength = (float) (source.getLine().getLength() / 2.0);
53 return new Text(source, source::getId, 0.0f, halfLength + 0.2f, contextualized);
54 }
55
56 @Override
57 public void paint(final Graphics2D graphics, final ImageObserver observer)
58 {
59 graphics.setColor(Color.WHITE);
60 super.paint(graphics, observer);
61 }
62
63 @Override
64 public String toString()
65 {
66 return "BusStopAnimation [source=" + this.getSource() + "]";
67 }
68
69
70
71
72 public static class Text extends RenderableTextSource<BusStopData, Text>
73 {
74
75
76
77
78
79
80
81
82
83 public Text(final BusStopData source, final Supplier<String> text, final float dx, final float dy,
84 final Contextualized contextualized)
85 {
86 super(source, text, dx, dy, TextAlignment.CENTER, Color.BLACK, contextualized, RenderableTextSource.RENDERWHEN10);
87 }
88
89 @Override
90 public String toString()
91 {
92 return "Text []";
93 }
94
95 }
96
97
98
99
100 public interface BusStopData extends LaneBasedObjectData, LineLocatable
101 {
102 }
103
104 }