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
22
23
24
25
26
27
28 public class ShoulderAnimation extends Renderable2D
29 {
30
31
32
33
34
35
36 public ShoulderAnimation(final Shoulder source, final OTSSimulatorInterface simulator) throws NamingException,
37 RemoteException
38 {
39 super(source, simulator);
40 }
41
42
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 }