View Javadoc
1   package org.opentrafficsim.road.network.animation;
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.animation.TextAlignment;
14  import org.opentrafficsim.core.animation.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-2018 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 source
41       * @param simulator 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) 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) throws RemoteException
56      {
57          graphics.setColor(Color.white);
58          super.paint(graphics, observer);
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public final void destroy() throws NamingException
64      {
65          super.destroy();
66          this.text.destroy();
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-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
80       * <br>
81       * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
82       * </p>
83       * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
84       * initial version Dec 11, 2016 <br>
85       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
86       * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
87       * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
88       */
89      public class Text extends TextAnimation
90      {
91          /** */
92          private static final long serialVersionUID = 20161211L;
93  
94          /**
95           * @param source Locatable; the object for which the text is displayed
96           * @param text String; the text to display
97           * @param dx float; the horizontal movement of the text, in meters
98           * @param dy float; the vertical movement of the text, in meters
99           * @param textPlacement TextAlignment; where to place the text
100          * @param color Color; the color of the text
101          * @param simulator SimulatorInterface.TimeDoubleUnit; the simulator
102          * @throws NamingException when animation context cannot be created or retrieved
103          * @throws RemoteException - when remote context cannot be found
104          */
105         public Text(final Locatable source, final String text, final float dx, final float dy,
106                 final TextAlignment textPlacement, final Color color, final SimulatorInterface.TimeDoubleUnit simulator)
107                 throws RemoteException, NamingException
108         {
109             super(source, text, dx, dy, textPlacement, color, simulator);
110         }
111 
112         /** {@inheritDoc} */
113         @Override
114         @SuppressWarnings("checkstyle:designforextension")
115         public TextAnimation clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
116                 throws RemoteException, NamingException
117         {
118             return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
119         }
120 
121         /** {@inheritDoc} */
122         @Override
123         public final String toString()
124         {
125             return "Text []";
126         }
127     }
128 
129 }