View Javadoc
1   package org.opentrafficsim.core.network.animation;
2   
3   import java.awt.Color;
4   import java.awt.Graphics2D;
5   import java.awt.geom.Path2D;
6   import java.awt.image.ImageObserver;
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.lane.Shoulder;
16  
17  import com.vividsolutions.jts.geom.Coordinate;
18  import com.vividsolutions.jts.geom.Geometry;
19  
20  /**
21   * <p>
22   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
24   * <p>
25   * @version Oct 17, 2014 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   */
28  public class ShoulderAnimation extends Renderable2D
29  {
30      /**
31       * @param source s
32       * @param simulator s
33       * @throws NamingException ne
34       * @throws RemoteException re
35       */
36      public ShoulderAnimation(final Shoulder source, final OTSSimulatorInterface simulator) throws NamingException,
37          RemoteException
38      {
39          super(source, simulator);
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
45      {
46          graphics.setColor(Color.GREEN);
47          Shoulder shoulder = (Shoulder) getSource();
48          DirectedPoint p = shoulder.getLocation();
49          Geometry g = shoulder.getContour();
50          Coordinate[] coordinates = g.getCoordinates();
51          Path2D.Double path = new Path2D.Double();
52          boolean start = false;
53          for (Coordinate c : coordinates)
54          {
55              if (!start)
56              {
57                  start = true;
58                  path.moveTo(c.x - p.x, -c.y + p.y);
59              }
60              else
61              {
62                  path.lineTo(c.x - p.x, -c.y + p.y);
63              }
64          }
65          path.closePath();
66          graphics.fill(path);
67      }
68  }