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.Stroke;
7 import java.awt.geom.AffineTransform;
8 import java.awt.image.ImageObserver;
9 import java.io.Serializable;
10 import java.rmi.RemoteException;
11
12 import javax.naming.NamingException;
13
14 import org.djunits.unit.LengthUnit;
15 import org.djunits.value.vdouble.scalar.Length;
16 import org.opentrafficsim.draw.core.PaintPolygons;
17 import org.opentrafficsim.road.network.lane.conflict.Conflict;
18 import org.opentrafficsim.road.network.lane.conflict.ConflictType;
19
20 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
21
22
23
24
25
26
27
28
29
30
31
32
33 public class ConflictAnimation extends AbstractLineAnimation<Conflict> implements Serializable
34 {
35
36
37
38 private static final long serialVersionUID = 20161207L;
39
40
41
42
43
44
45
46 public ConflictAnimation(final Conflict source, final SimulatorInterface.TimeDoubleUnit simulator)
47 throws NamingException, RemoteException
48 {
49 super(source, simulator, .9, new Length(0.5, LengthUnit.SI));
50 }
51
52
53 @Override
54 public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
55 {
56 Conflict conflict = this.getSource();
57 Color fillColor;
58 switch (conflict.conflictPriority())
59 {
60 case SPLIT:
61 fillColor = Color.blue;
62 break;
63
64 case PRIORITY:
65 fillColor = Color.green;
66 break;
67
68 case YIELD:
69 fillColor = Color.orange;
70 break;
71
72 default:
73
74 fillColor = Color.red;
75 break;
76 }
77
78 graphics.setColor(fillColor);
79 super.paint(graphics, observer);
80
81 Stroke oldStroke = graphics.getStroke();
82
83 BasicStroke stroke;
84 float factor = conflict.isPermitted() ? .5f : 1f;
85 if (conflict.getConflictType().equals(ConflictType.CROSSING))
86 {
87 stroke = new BasicStroke(.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
88 new float[] {factor * 1.0f, factor * 2.0f}, 0.0f);
89 }
90 else
91 {
92 stroke = new BasicStroke(.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
93 new float[] {factor * 1.0f, factor * 0.95f, factor * 0.1f, factor * 0.95f}, 0.0f);
94 }
95 graphics.setStroke(stroke);
96 AffineTransform saveAT = graphics.getTransform();
97 double angle = -getSource().getLocation().getRotZ();
98 if (isRotate() && angle != 0.0)
99 {
100 graphics.rotate(-angle);
101 }
102 if (conflict.getGeometry() != null)
103 {
104 PaintPolygons.paintMultiPolygon(graphics, fillColor, conflict.getLocation(), conflict.getGeometry(), false);
105 }
106 if (isRotate() && angle != 0.0)
107 {
108 graphics.rotate(+angle);
109 }
110 graphics.setStroke(oldStroke);
111 graphics.setTransform(saveAT);
112 }
113
114
115 @Override
116 public final String toString()
117 {
118 return "ConflictAnimation [getSource()=" + getSource() + "]";
119 }
120
121 }