View Javadoc
1   package org.opentrafficsim.road.network.lane.object;
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 nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
12  import nl.tudelft.simulation.language.d3.DirectedPoint;
13  
14  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
15  import org.opentrafficsim.core.network.animation.PaintPolygons;
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: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 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 LaneBlockAnimation extends Renderable2D implements Serializable
29  {
30      /** */
31      private static final long serialVersionUID = 20160400L;
32  
33      /** The fill color of the block. */
34      private Color fillColor;
35  
36      /** The point (0,0,0). */
37      private static final DirectedPoint POINT_000 = new DirectedPoint();
38  
39      /**
40       * Construct the DefaultCarAnimation for a LaneBlock (road block).
41       * @param source the CSEBlock to draw
42       * @param simulator the simulator to schedule on
43       * @param fillColor the fill color
44       * @throws NamingException in case of registration failure of the animation
45       * @throws RemoteException on communication failure
46       */
47      public LaneBlockAnimation(final LaneBlock source, final OTSSimulatorInterface simulator, final Color fillColor)
48          throws NamingException, RemoteException
49      {
50          super(source, simulator);
51          setFillColor(fillColor);
52          setTranslate(false);
53          setRotate(false);
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public final void paint(final Graphics2D graphics, final ImageObserver observer)
59      {
60          graphics.setColor(this.fillColor);
61          PaintPolygons.paintMultiPolygon(graphics, this.fillColor, POINT_000, ((LaneBlock) this.source).getGeometry(),
62              true);
63      }
64  
65      /**
66       * @return fillColor
67       */
68      public final Color getFillColor()
69      {
70          return this.fillColor;
71      }
72  
73      /**
74       * @param fillColor set fillColor
75       */
76      public final void setFillColor(final Color fillColor)
77      {
78          this.fillColor = fillColor;
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final String toString()
84      {
85          return "CSEBlockAnimation [getSource()=" + this.getSource() + "]";
86      }
87  
88  }