View Javadoc
1   package org.opentrafficsim.road.gtu.lane.object.animation;
2   
3   import java.awt.Color;
4   import java.awt.Graphics2D;
5   import java.awt.image.ImageObserver;
6   import java.rmi.RemoteException;
7   
8   import javax.naming.NamingException;
9   
10  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
11  import nl.tudelft.simulation.language.d3.DirectedPoint;
12  
13  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
14  import org.opentrafficsim.core.network.animation.PaintPolygons;
15  import org.opentrafficsim.road.gtu.lane.object.CSEBlock;
16  
17  /**
18   * Draw a road block.
19   * <p>
20   * Copyright (c) 2013-2015 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 CSEBlockAnimation extends Renderable2D
29  {
30      /** The fill color of the block. */
31      private Color fillColor;
32  
33      /** The point (0,0,0). */
34      private static final DirectedPoint POINT_000 = new DirectedPoint();
35  
36      /**
37       * Construct the DefaultCarAnimation for a LaneBlock (road block).
38       * @param source the CSEBlock to draw
39       * @param simulator the simulator to schedule on
40       * @param fillColor the fill color
41       * @throws NamingException in case of registration failure of the animation
42       * @throws RemoteException on communication failure
43       */
44      public CSEBlockAnimation(final CSEBlock source, final OTSSimulatorInterface simulator, final Color fillColor)
45          throws NamingException, RemoteException
46      {
47          super(source, simulator);
48          setFillColor(fillColor);
49          setTranslate(false);
50          setRotate(false);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public final void paint(final Graphics2D graphics, final ImageObserver observer)
56      {
57          graphics.setColor(this.fillColor);
58          PaintPolygons.paintMultiPolygon(graphics, this.fillColor, POINT_000, ((CSEBlock) this.source).getGeometry(),
59              true);
60      }
61  
62      /**
63       * @return fillColor
64       */
65      public final Color getFillColor()
66      {
67          return this.fillColor;
68      }
69  
70      /**
71       * @param fillColor set fillColor
72       */
73      public final void setFillColor(Color fillColor)
74      {
75          this.fillColor = fillColor;
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public final String toString()
81      {
82          return "CSEBlockAnimation [getSource()=" + this.getSource() + "]";
83      }
84  
85  }