View Javadoc
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   * Draw bus stop.
24   * <p>
25   * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
26   * All rights reserved. <br>
27   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
28   * </p>
29   * @author Alexander Verbraeck
30   * @author Peter Knoppers
31   * @author Wouter Schakel
32   */
33  public class BusStopAnimation extends AbstractLineAnimation<BusStopData, Text>
34  {
35  
36      /**
37       * Constructor.
38       * @param laneDetector the lane detector to draw
39       * @param contextualized context provider
40       * @throws NamingException in case of registration failure of the animation
41       * @throws RemoteException in case of remote registration failure of the animation
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       * Text animation for the bus stop.
71       */
72      public static class Text extends RenderableTextSource<BusStopData, Text>
73      {
74  
75          /**
76           * Constructor.
77           * @param source the object for which the text is displayed
78           * @param text the text to display
79           * @param dx the horizontal movement of the text, in meters
80           * @param dy the vertical movement of the text, in meters
81           * @param contextualized context provider
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       * Provides the information required to draw a bus stop.
99       */
100     public interface BusStopData extends LaneBasedObjectData, LineLocatable
101     {
102     }
103 
104 }