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