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.LineLocatable;
14 import org.opentrafficsim.draw.RenderableTextSource;
15 import org.opentrafficsim.draw.TextAlignment;
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 * Draw BusStopData.
23 * <p>
24 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
25 * All rights reserved. <br>
26 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
27 * </p>
28 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
29 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
30 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
31 */
32 public class BusStopAnimation extends AbstractLineAnimation<BusStopData>
33 {
34 /** the Text object to destroy when the animation is destroyed. */
35 private final Text text;
36
37 /**
38 * Construct a DetectorAnimation.
39 * @param laneDetector the lane detector to draw
40 * @param contextualized context provider
41 * @throws NamingException in case of registration failure of the animation
42 * @throws RemoteException in case of remote registration failure of the animation
43 */
44 public BusStopAnimation(final BusStopData laneDetector, final Contextualized contextualized)
45 throws NamingException, RemoteException
46 {
47 super(laneDetector, contextualized, new Length(0.5, LengthUnit.SI));
48 float halfLength = (float) (laneDetector.getLine().getLength() / 2.0);
49 this.text = new Text(laneDetector, laneDetector::getId, 0.0f, halfLength + 0.2f, TextAlignment.CENTER, Color.BLACK,
50 contextualized);
51 }
52
53 /**
54 * Returns text object.
55 * @return text.
56 */
57 public final Text getText()
58 {
59 return this.text;
60 }
61
62 @Override
63 public final void paint(final Graphics2D graphics, final ImageObserver observer)
64 {
65 graphics.setColor(Color.WHITE);
66 super.paint(graphics, observer);
67 }
68
69 @Override
70 public void destroy(final Contextualized contextProvider)
71 {
72 super.destroy(contextProvider);
73 this.text.destroy(contextProvider);
74 }
75
76 @Override
77 public final String toString()
78 {
79 return "DetectorAnimation [getSource()=" + this.getSource() + "]";
80 }
81
82 /**
83 * Text animation for the Detector. Separate class to be able to turn it on and off...
84 * <p>
85 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
86 * <br>
87 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
88 * </p>
89 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
90 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
91 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
92 */
93 public static class Text extends RenderableTextSource<BusStopData, Text>
94 {
95 /**
96 * Constructor.
97 * @param source the object for which the text is displayed
98 * @param text the text to display
99 * @param dx the horizontal movement of the text, in meters
100 * @param dy the vertical movement of the text, in meters
101 * @param textPlacement where to place the text
102 * @param color the color of the text
103 * @param contextualized context provider
104 * @throws NamingException when animation context cannot be created or retrieved
105 * @throws RemoteException - when remote context cannot be found
106 */
107 public Text(final BusStopData source, final Supplier<String> text, final float dx, final float dy,
108 final TextAlignment textPlacement, final Color color, final Contextualized contextualized)
109 throws RemoteException, NamingException
110 {
111 super(source, text, dx, dy, textPlacement, color, contextualized, RenderableTextSource.RENDERWHEN10);
112 }
113
114 @Override
115 public final String toString()
116 {
117 return "Text []";
118 }
119 }
120
121 /**
122 * BusStopData provides the information required to draw a bus stop.
123 * <p>
124 * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
125 * <br>
126 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
127 * </p>
128 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
129 */
130 public interface BusStopData extends LaneBasedObjectData, LineLocatable
131 {
132 }
133
134 }