BusStopAnimation.java

  1. package org.opentrafficsim.road.network.animation;

  2. import java.awt.Color;
  3. import java.awt.Graphics2D;
  4. import java.awt.image.ImageObserver;
  5. import java.io.Serializable;
  6. import java.rmi.RemoteException;

  7. import javax.naming.NamingException;

  8. import org.djunits.unit.LengthUnit;
  9. import org.djunits.value.vdouble.scalar.Length;
  10. import org.opentrafficsim.core.animation.TextAlignment;
  11. import org.opentrafficsim.core.animation.TextAnimation;
  12. import org.opentrafficsim.road.network.lane.object.BusStop;

  13. import nl.tudelft.simulation.dsol.animation.Locatable;
  14. import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;

  15. /**
  16.  * <p>
  17.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  18.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  19.  * <p>
  20.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 25 jan. 2017 <br>
  21.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  22.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  23.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  24.  */
  25. public class BusStopAnimation extends AbstractLineAnimation<BusStop> implements Serializable
  26. {

  27.     /** */
  28.     private static final long serialVersionUID = 20170125L;

  29.     /** Text label. */
  30.     private final Text text;

  31.     /**
  32.      * @param source source
  33.      * @param simulator simulator
  34.      * @throws NamingException when animation context cannot be created or retrieved
  35.      * @throws RemoteException when remote context cannot be found
  36.      */
  37.     public BusStopAnimation(final BusStop source, final SimulatorInterface.TimeDoubleUnit simulator) throws NamingException, RemoteException
  38.     {
  39.         super(source, simulator, .8, new Length(0.5, LengthUnit.SI));

  40.         this.text = new Text(source, source.getId(), 0.0f, (float) getHalfLength() + 0.2f, TextAlignment.CENTER, Color.BLACK,
  41.                 simulator);
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
  46.     {
  47.         graphics.setColor(Color.white);
  48.         super.paint(graphics, observer);
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public final void destroy() throws NamingException
  53.     {
  54.         super.destroy();
  55.         this.text.destroy();
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public final String toString()
  60.     {
  61.         return "BusStopAnimation [getSource()=" + getSource() + "]";
  62.     }

  63.     /**
  64.      * Text animation for the BusStop. Separate class to be able to turn it on and off...
  65.      * <p>
  66.      * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
  67.      * <br>
  68.      * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
  69.      * </p>
  70.      * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
  71.      * initial version Dec 11, 2016 <br>
  72.      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  73.      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  74.      * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  75.      */
  76.     public class Text extends TextAnimation
  77.     {
  78.         /** */
  79.         private static final long serialVersionUID = 20161211L;

  80.         /**
  81.          * @param source Locatable; the object for which the text is displayed
  82.          * @param text String; the text to display
  83.          * @param dx float; the horizontal movement of the text, in meters
  84.          * @param dy float; the vertical movement of the text, in meters
  85.          * @param textPlacement TextAlignment; where to place the text
  86.          * @param color Color; the color of the text
  87.          * @param simulator SimulatorInterface.TimeDoubleUnit; the simulator
  88.          * @throws NamingException when animation context cannot be created or retrieved
  89.          * @throws RemoteException - when remote context cannot be found
  90.          */
  91.         public Text(final Locatable source, final String text, final float dx, final float dy,
  92.                 final TextAlignment textPlacement, final Color color, final SimulatorInterface.TimeDoubleUnit simulator)
  93.                 throws RemoteException, NamingException
  94.         {
  95.             super(source, text, dx, dy, textPlacement, color, simulator);
  96.         }

  97.         /** {@inheritDoc} */
  98.         @Override
  99.         @SuppressWarnings("checkstyle:designforextension")
  100.         public TextAnimation clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
  101.                 throws RemoteException, NamingException
  102.         {
  103.             return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
  104.         }

  105.         /** {@inheritDoc} */
  106.         @Override
  107.         public final String toString()
  108.         {
  109.             return "Text []";
  110.         }
  111.     }

  112. }