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