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