1 package org.opentrafficsim.road.gtu.colorer;
2
3 import java.awt.Color;
4 import java.io.Serializable;
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9 import org.opentrafficsim.core.gtu.GTU;
10 import org.opentrafficsim.road.gtu.lane.tactical.Synchronizable;
11
12
13
14
15
16
17
18
19
20
21
22
23 public class SynchronizationColorer implements GTUColorer, Serializable
24 {
25
26
27 private static final long serialVersionUID = 20180223L;
28
29
30 private static final List<LegendEntry> LEGEND;
31
32
33 private static final Color C_NONE = Color.WHITE;
34
35
36 private static final Color C_SYNCHRONIZING = Color.ORANGE;
37
38
39 private static final Color C_INDICATING = Color.RED;
40
41
42 private static final Color C_COOPERATING = new Color(0, 128, 0);
43
44
45 protected static final Color NA = Color.YELLOW;
46
47 static
48 {
49 LEGEND = new ArrayList<>(6);
50 LEGEND.add(new LegendEntry(C_NONE, "None", "None"));
51 LEGEND.add(new LegendEntry(C_SYNCHRONIZING, "Synchronizing", "Synchonizing"));
52 LEGEND.add(new LegendEntry(C_INDICATING, "Indicating", "Indicating"));
53 LEGEND.add(new LegendEntry(C_COOPERATING, "Cooperating", "Cooperating"));
54 LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
55 }
56
57
58 @Override
59 public Color getColor(final GTU gtu)
60 {
61 if (!(gtu.getTacticalPlanner() instanceof Synchronizable))
62 {
63 return NA;
64 }
65 Synchronizable.State state = ((Synchronizable) gtu.getTacticalPlanner()).getSynchronizationState();
66 if (state == null)
67 {
68 return NA;
69 }
70 switch (state)
71 {
72 case NONE:
73 return C_NONE;
74 case COOPERATING:
75 return C_COOPERATING;
76 case INDICATING:
77 return C_INDICATING;
78 case SYNCHRONIZING:
79 return C_SYNCHRONIZING;
80 default:
81 return NA;
82 }
83 }
84
85
86 @Override
87 public List<LegendEntry> getLegend()
88 {
89 return LEGEND;
90 }
91
92
93 @Override
94 public final String toString()
95 {
96 return "Sycnhronization";
97 }
98
99 }