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 * 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 /** */
35 private static final long serialVersionUID = 20150130L;
36
37 /** the Text object to destroy when the animation is destroyed. */
38 private final Text text;
39
40 /**
41 * Construct a DetectorAnimation.
42 * @param laneDetector the lane detector to draw
43 * @param contextualized context provider
44 * @throws NamingException in case of registration failure of the animation
45 * @throws RemoteException in case of remote registration failure of the animation
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 * @return text.
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 * Text animation for the Detector. Separate class to be able to turn it on and off...
86 * <p>
87 * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
88 * <br>
89 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
90 * </p>
91 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
92 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
93 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
94 */
95 public class Text extends TextAnimation<BusStopData, Text>
96 {
97 /** */
98 private static final long serialVersionUID = 20161211L;
99
100 /**
101 * @param source the object for which the text is displayed
102 * @param text the text to display
103 * @param dx the horizontal movement of the text, in meters
104 * @param dy the vertical movement of the text, in meters
105 * @param textPlacement where to place the text
106 * @param color the color of the text
107 * @param contextualized context provider
108 * @throws NamingException when animation context cannot be created or retrieved
109 * @throws RemoteException - when remote context cannot be found
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 * BusStopData provides the information required to draw a bus stop.
127 * <p>
128 * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
129 * <br>
130 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
131 * </p>
132 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
133 */
134 public interface BusStopData extends LaneBasedObjectData, ClickableLineLocatable
135 {
136 }
137
138 }