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.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-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
25   * <p>
26   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 25 jan. 2017 <br>
27   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
28   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
29   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
30   */
31  public class BusStopAnimation extends AbstractLineAnimation<BusStop> implements Serializable
32  {
33  
34      /** */
35      private static final long serialVersionUID = 20170125L;
36  
37      /** Text label. */
38      private final Text text;
39  
40      /**
41       * @param source BusStop; source
42       * @param simulator OTSSimulatorInterface; simulator
43       * @throws NamingException when animation context cannot be created or retrieved
44       * @throws RemoteException when remote context cannot be found
45       */
46      public BusStopAnimation(final BusStop source, final OTSSimulatorInterface simulator)
47              throws NamingException, RemoteException
48      {
49          super(source, simulator, .8, new Length(0.5, LengthUnit.SI));
50  
51          this.text = new Text(source, source.getId(), 0.0f, (float) getHalfLength() + 0.2f, TextAlignment.CENTER, Color.BLACK,
52                  simulator);
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public final void paint(final Graphics2D graphics, final ImageObserver observer)
58      {
59          graphics.setColor(Color.white);
60          super.paint(graphics, observer);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public void destroy(final Contextualized contextProvider)
66      {
67          super.destroy(contextProvider);
68          this.text.destroy(contextProvider);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public final String toString()
74      {
75          return "BusStopAnimation [getSource()=" + getSource() + "]";
76      }
77  
78      /**
79       * Text animation for the BusStop. Separate class to be able to turn it on and off...
80       * <p>
81       * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
82       * <br>
83       * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
84       * </p>
85       * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
86       * initial version Dec 11, 2016 <br>
87       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
88       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
89       * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
90       */
91      public class Text extends TextAnimation
92      {
93          /** */
94          private static final long serialVersionUID = 20161211L;
95  
96          /**
97           * @param source Locatable; the object for which the text is displayed
98           * @param text String; the text to display
99           * @param dx float; the horizontal movement of the text, in meters
100          * @param dy float; the vertical movement of the text, in meters
101          * @param textPlacement TextAlignment; where to place the text
102          * @param color Color; the color of the text
103          * @param simulator OTSSimulatorInterface; the simulator
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 Locatable source, final String text, final float dx, final float dy,
108                 final TextAlignment textPlacement, final Color color, final OTSSimulatorInterface simulator)
109                 throws RemoteException, NamingException
110         {
111             super(source, text, dx, dy, textPlacement, color, simulator, TextAnimation.RENDERALWAYS);
112         }
113 
114         /** {@inheritDoc} */
115         @Override
116         @SuppressWarnings("checkstyle:designforextension")
117         public TextAnimation clone(final Locatable newSource, final OTSSimulatorInterface newSimulator)
118                 throws RemoteException, NamingException
119         {
120             return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
121         }
122 
123         /** {@inheritDoc} */
124         @Override
125         public final String toString()
126         {
127             return "Text []";
128         }
129     }
130 
131 }