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