1 package org.opentrafficsim.draw.road;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Graphics2D;
6 import java.awt.geom.Path2D;
7 import java.awt.image.ImageObserver;
8 import java.rmi.RemoteException;
9 import java.util.Set;
10
11 import javax.naming.NamingException;
12
13 import org.djutils.draw.line.PolyLine2d;
14 import org.opentrafficsim.base.geometry.OtsLocatable;
15 import org.opentrafficsim.base.geometry.OtsRenderable;
16 import org.opentrafficsim.draw.DrawLevel;
17 import org.opentrafficsim.draw.PaintPolygons;
18 import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
19
20 import nl.tudelft.simulation.naming.context.Contextualized;
21
22
23
24
25
26
27
28
29
30
31
32 public class CrossSectionElementAnimation<L extends CrossSectionElementData> extends OtsRenderable<L>
33 {
34
35 private static final long serialVersionUID = 20141017L;
36
37
38 private final Color color;
39
40
41 private final Set<Path2D.Float> paths;
42
43
44
45
46
47
48
49
50 public CrossSectionElementAnimation(final L source, final Contextualized contextualized, final Color color)
51 throws NamingException, RemoteException
52 {
53 super(source, contextualized);
54 this.color = color;
55 this.paths = PaintPolygons.getPaths(getSource().getBounds().asPolygon().getPointList());
56 }
57
58
59 @Override
60 public void paint(final Graphics2D graphics, final ImageObserver observer)
61 {
62 setRendering(graphics);
63 PaintPolygons.paintPaths(graphics, this.color, this.paths, true);
64
65 double scale = Math.min(Math.max(3.0 / graphics.getTransform().getDeterminant(), 0.1), 0.5);
66 graphics.setStroke(new BasicStroke((float) scale, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
67 PaintPolygons.paintPaths(graphics, this.color, this.paths, false);
68 resetRendering(graphics);
69 }
70
71
72 @Override
73 public String toString()
74 {
75 return "CrossSectionElementAnimation [source = " + getSource().toString() + ", color=" + this.color + "]";
76 }
77
78
79
80
81
82
83
84
85
86
87 public interface CrossSectionElementData extends OtsLocatable
88 {
89
90
91
92
93 PolyLine2d getCenterLine();
94
95
96
97
98
99 String getLinkId();
100 }
101
102
103
104
105
106
107
108
109
110
111 public interface ShoulderData extends CrossSectionElementData
112 {
113
114 @Override
115 default public double getZ()
116 {
117 return DrawLevel.SHOULDER.getZ();
118 }
119 }
120 }