View Javadoc
1   package org.opentrafficsim.road.network.lane;
2   
3   import java.awt.Color;
4   import java.awt.Graphics2D;
5   import java.awt.geom.Rectangle2D;
6   import java.awt.image.ImageObserver;
7   import java.rmi.RemoteException;
8   
9   import javax.naming.NamingException;
10  
11  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
12  
13  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
14  
15  /**
16   * sink sensor animation.
17   * <p>
18   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands.<br>
19   * All rights reserved. <br>
20   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * <p>
22   * $LastChangedDate: 2015-08-12 16:37:45 +0200 (Wed, 12 Aug 2015) $, @version $Revision: 1240 $, by $Author: averbraeck $,
23   * initial version an 30, 2015 <br>
24   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
26   */
27  public class SensorAnimation extends Renderable2D
28  {
29      /** The half width left and right of the center line that is used to draw the block. */
30      private final double halfWidth;
31  
32      /** The color of the sensor. */
33      private final Color color;
34  
35      /**
36       * Construct the DefaultCarAnimation for a LaneBlock (road block).
37       * @param source the Car to draw
38       * @param simulator the simulator to schedule on
39       * @param color the display color of the sensor
40       * @throws NamingException in case of registration failure of the animation
41       * @throws RemoteException in case of remote registration failure of the animation
42       */
43      public SensorAnimation(final Sensor source, final OTSSimulatorInterface simulator, final Color color)
44          throws NamingException, RemoteException
45      {
46          super(source, simulator);
47          this.halfWidth = 0.4 * source.getLane().getWidth(0.0).getSI();
48          this.color = color;
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public final void paint(final Graphics2D graphics, final ImageObserver observer)
54      {
55          graphics.setColor(this.color);
56          Rectangle2D rectangle = new Rectangle2D.Double(-0.25, -this.halfWidth, 0.5, 2 * this.halfWidth);
57          graphics.fill(rectangle);
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public final String toString()
63      {
64          return "SensorAnimation [getSource()=" + this.getSource() + "]";
65      }
66  }