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.core.dsol.OtsSimulatorInterface;
14 import org.opentrafficsim.draw.core.TextAlignment;
15 import org.opentrafficsim.draw.core.TextAnimation;
16 import org.opentrafficsim.road.network.lane.object.BusStop;
17
18 import nl.tudelft.simulation.dsol.animation.Locatable;
19 import nl.tudelft.simulation.naming.context.Contextualized;
20
21 /**
22 * <p>
23 * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
25 * </p>
26 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
27 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
28 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
29 */
30 public class BusStopAnimation extends AbstractLineAnimation<BusStop> implements Serializable
31 {
32
33 /** */
34 private static final long serialVersionUID = 20170125L;
35
36 /** Text label. */
37 private final Text text;
38
39 /**
40 * @param source BusStop; source
41 * @param simulator OtsSimulatorInterface; simulator
42 * @throws NamingException when animation context cannot be created or retrieved
43 * @throws RemoteException when remote context cannot be found
44 */
45 public BusStopAnimation(final BusStop source, final OtsSimulatorInterface simulator) throws NamingException, RemoteException
46 {
47 super(source, simulator, .8, new Length(0.5, LengthUnit.SI));
48
49 this.text = new Text(source, source.getId(), 0.0f, (float) getHalfLength() + 0.2f, TextAlignment.CENTER, Color.BLACK,
50 simulator);
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public final void paint(final Graphics2D graphics, final ImageObserver observer)
56 {
57 graphics.setColor(Color.white);
58 super.paint(graphics, observer);
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public void destroy(final Contextualized contextProvider)
64 {
65 super.destroy(contextProvider);
66 this.text.destroy(contextProvider);
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 public final String toString()
72 {
73 return "BusStopAnimation [getSource()=" + getSource() + "]";
74 }
75
76 /**
77 * Text animation for the BusStop. Separate class to be able to turn it on and off...
78 * <p>
79 * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
80 * <br>
81 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
82 * </p>
83 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
84 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
85 * @author <a href="https://dittlab.tudelft.nl">Wouter Schakel</a>
86 */
87 public class Text extends TextAnimation
88 {
89 /** */
90 private static final long serialVersionUID = 20161211L;
91
92 /**
93 * @param source Locatable; the object for which the text is displayed
94 * @param text String; the text to display
95 * @param dx float; the horizontal movement of the text, in meters
96 * @param dy float; the vertical movement of the text, in meters
97 * @param textPlacement TextAlignment; where to place the text
98 * @param color Color; the color of the text
99 * @param simulator OtsSimulatorInterface; the simulator
100 * @throws NamingException when animation context cannot be created or retrieved
101 * @throws RemoteException - when remote context cannot be found
102 */
103 public Text(final Locatable source, final String text, final float dx, final float dy,
104 final TextAlignment textPlacement, final Color color, final OtsSimulatorInterface simulator)
105 throws RemoteException, NamingException
106 {
107 super(source, text, dx, dy, textPlacement, color, simulator, TextAnimation.RENDERALWAYS);
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public final String toString()
113 {
114 return "Text []";
115 }
116 }
117
118 }