View Javadoc
1   package org.opentrafficsim.draw.road;
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 org.opentrafficsim.core.dsol.OtsSimulatorInterface;
12  import org.opentrafficsim.draw.core.PaintPolygons;
13  import org.opentrafficsim.road.network.lane.CrossSectionElement;
14  
15  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
16  
17  /**
18   * <p>
19   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
21   * </p>
22   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
23   */
24  public class CrossSectionElementAnimation extends Renderable2D<CrossSectionElement> implements Serializable
25  {
26      /** */
27      private static final long serialVersionUID = 20141017L;
28  
29      /** The animation color. */
30      private final Color color;
31  
32      /**
33       * @param source CrossSectionElement; cross section element
34       * @param simulator OtsSimulatorInterface; simulator
35       * @param color Color; the color to draw the shoulder with
36       * @throws NamingException ne
37       * @throws RemoteException on communication failure
38       */
39      public CrossSectionElementAnimation(final CrossSectionElement source, final OtsSimulatorInterface simulator,
40              final Color color) throws NamingException, RemoteException
41      {
42          super(source, simulator);
43          this.color = color;
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public final void paint(final Graphics2D graphics, final ImageObserver observer)
49      {
50          CrossSectionElement shoulder = getSource();
51          PaintPolygons.paintMultiPolygon(graphics, this.color, shoulder.getLocation(), shoulder.getContour(), true);
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public final String toString()
57      {
58          return "CrossSectionElementAnimation [source = " + getSource().toString() + ", color=" + this.color + "]";
59      }
60  }