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 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  import org.opentrafficsim.road.network.lane.object.LaneBlock;
17  
18  /**
19   * Draw a road block.
20   * <p>
21   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * <p>
24   * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
25   *          initial version 29 dec. 2014 <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   */
29  public class LaneBlockAnimation extends Renderable2D implements Serializable
30  {
31      /** */
32      private static final long serialVersionUID = 20160400L;
33  
34      /** The fill color of the block. */
35      private Color fillColor;
36  
37      /** The point (0,0,0). */
38      private static final DirectedPoint POINT_000 = new DirectedPoint();
39  
40      /**
41       * Construct the DefaultCarAnimation for a LaneBlock (road block).
42       * @param source the CSEBlock to draw
43       * @param simulator the simulator to schedule on
44       * @param fillColor the fill color
45       * @throws NamingException in case of registration failure of the animation
46       * @throws RemoteException on communication failure
47       */
48      public LaneBlockAnimation(final LaneBlock source, final OTSSimulatorInterface simulator, final Color fillColor)
49          throws NamingException, RemoteException
50      {
51          super(source, simulator);
52          setFillColor(fillColor);
53          setTranslate(false);
54          setRotate(false);
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public final void paint(final Graphics2D graphics, final ImageObserver observer)
60      {
61          graphics.setColor(this.fillColor);
62          PaintPolygons.paintMultiPolygon(graphics, this.fillColor, POINT_000, ((LaneBlock) this.source).getGeometry(),
63              true);
64      }
65  
66      /**
67       * @return fillColor
68       */
69      public final Color getFillColor()
70      {
71          return this.fillColor;
72      }
73  
74      /**
75       * @param fillColor set fillColor
76       */
77      public final void setFillColor(final Color fillColor)
78      {
79          this.fillColor = fillColor;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public final String toString()
85      {
86          return "CSEBlockAnimation [getSource()=" + this.getSource() + "]";
87      }
88  
89  }