1 package org.opentrafficsim.swing.gui;
2
3 import java.util.ArrayList;
4 import java.util.LinkedHashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.opentrafficsim.animation.gtu.DefaultCarAnimation;
9 import org.opentrafficsim.animation.gtu.PerceptionAnimation;
10 import org.opentrafficsim.animation.gtu.DefaultCarAnimation.GtuData;
11 import org.opentrafficsim.animation.network.LinkAnimation;
12 import org.opentrafficsim.animation.network.LinkAnimation.LinkData;
13 import org.opentrafficsim.animation.network.NodeAnimation;
14 import org.opentrafficsim.animation.network.NodeAnimation.NodeData;
15 import org.opentrafficsim.animation.road.BusStopAnimation;
16 import org.opentrafficsim.animation.road.BusStopAnimation.BusStopData;
17 import org.opentrafficsim.animation.road.ConflictAnimation.ConflictData;
18 import org.opentrafficsim.animation.road.CrossSectionElementAnimation.ShoulderData;
19 import org.opentrafficsim.animation.road.DetectorData;
20 import org.opentrafficsim.animation.road.GtuGeneratorPositionAnimation;
21 import org.opentrafficsim.animation.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
22 import org.opentrafficsim.animation.road.LaneAnimation;
23 import org.opentrafficsim.animation.road.LaneAnimation.CenterLine;
24 import org.opentrafficsim.animation.road.LaneAnimation.LaneData;
25 import org.opentrafficsim.animation.road.PriorityAnimation.PriorityData;
26 import org.opentrafficsim.animation.road.StripeAnimation.StripeData;
27 import org.opentrafficsim.animation.road.TrafficLightAnimation;
28 import org.opentrafficsim.animation.road.TrafficLightAnimation.TrafficLightData;
29
30 import nl.tudelft.simulation.dsol.animation.Locatable;
31
32
33
34
35
36
37
38
39
40
41
42 public final class AnimationToggles
43 {
44
45
46 private static final Map<String, List<Toggle>> TOGGLES = new LinkedHashMap<>();
47
48
49 private static final Map<String, Boolean> DEFAULT_VISIBLE = new LinkedHashMap<>();
50
51 static
52 {
53 List<Toggle> list = new ArrayList<>();
54 list.add(new Toggle("Node", NodeData.class, "Node24.png", "Show/hide nodes", true, false, false));
55 list.add(new Toggle("NodeId", NodeAnimation.Text.class, "Id24.png", "Show/hide node ids", false, false, true));
56 list.add(new Toggle("Link", LinkData.class, "Link24.png", "Show/hide links", true, false, false));
57 list.add(new Toggle("LinkId", LinkAnimation.Text.class, "Id24.png", "Show/hide link ids", false, false, true));
58 list.add(new Toggle("Priority", PriorityData.class, "Priority24.png", "Show/hide link priority", true, false, false));
59 DEFAULT_VISIBLE.put("network", true);
60 TOGGLES.put("network", list);
61
62 list = new ArrayList<>();
63 list.add(new Toggle("Lane", LaneData.class, "Lane24.png", "Show/hide lanes", true, true, false));
64 list.add(new Toggle("LaneId", LaneAnimation.Text.class, "Id24.png", "Show/hide lane ids", false, false, true));
65 list.add(new Toggle("Stripe", StripeData.class, "Stripe24.png", "Show/hide stripes", true, true, false));
66 list.add(new Toggle("LaneCenter", CenterLine.class, "CenterLine24.png", "Show/hide lane center lines", false, false,
67 true));
68 list.add(new Toggle("Shoulder", ShoulderData.class, "Shoulder24.png", "Show/hide shoulders", true, true, false));
69 DEFAULT_VISIBLE.put("lane", false);
70 TOGGLES.put("lane", list);
71
72 list = new ArrayList<>();
73 list.add(new Toggle("GTU", GtuData.class, "Gtu24.png", "Show/hide GTUs", true, true, false));
74 list.add(new Toggle("GTUId", DefaultCarAnimation.Text.class, "Id24.png", "Show/hide GTU ids", false, false, true));
75 list.add(new Toggle("Perception", PerceptionAnimation.PerceptionData.class, "Perception24.png",
76 "Show/hide perception (circle = attention, color = perception delay)", false, false, false));
77 DEFAULT_VISIBLE.put("GTU", false);
78 TOGGLES.put("GTU", list);
79
80 list = new ArrayList<>();
81 list.add(new Toggle("Detector", DetectorData.class, "Detector24.png", "Show/hide detectors", true, false, false));
82 list.add(new Toggle("DetectorId", DetectorData.Text.class, "Id24.png", "Show/hide detector ids", false, false, true));
83 list.add(new Toggle("Light", TrafficLightData.class, "TrafficLight24.png", "Show/hide traffic lights", true, true,
84 false));
85 list.add(new Toggle("LightId", TrafficLightAnimation.Text.class, "Id24.png", "Show/hide traffic light ids", false,
86 false, true));
87 list.add(new Toggle("Conflict", ConflictData.class, "Conflict24.png", "Show/hide conflicts", true, false, false));
88 list.add(new Toggle("Generator", GtuGeneratorPositionData.class, "Generator24.png", "Show/hide generators", true, false,
89 false));
90 list.add(new Toggle("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class, "Queue24.png",
91 "Show/hide generator queues", false, false, true));
92 list.add(new Toggle("Bus", BusStopData.class, "BusStop24.png", "Show/hide bus stops", true, false, false));
93 list.add(new Toggle("BusId", BusStopAnimation.Text.class, "Id24.png", "Show/hide bus stop ids", false, false, true));
94 DEFAULT_VISIBLE.put("objects", true);
95 TOGGLES.put("objects", list);
96 }
97
98
99
100
101 private AnimationToggles()
102 {
103
104 }
105
106
107
108
109
110 public static void setTextAnimationTogglesFull(final OtsSimulationPanel panel)
111 {
112 TOGGLES.entrySet().forEach((e) ->
113 {
114 panel.startToggleSection(e.getKey(), DEFAULT_VISIBLE.getOrDefault(e.getKey(), true));
115 e.getValue().forEach(
116 (t) -> panel.addToggleAnimationButtonText(t.name(), t.locatableClass(), t.tooltip(), t.visibleFull()));
117 });
118 }
119
120
121
122
123
124 public static void setTextAnimationTogglesStandard(final OtsSimulationPanel panel)
125 {
126 TOGGLES.entrySet().forEach((e) ->
127 {
128 panel.startToggleSection(e.getKey(), DEFAULT_VISIBLE.getOrDefault(e.getKey(), true));
129 e.getValue().forEach(
130 (t) -> panel.addToggleAnimationButtonText(t.name(), t.locatableClass(), t.tooltip(), t.visibleStandard()));
131 });
132 }
133
134
135
136
137
138 public static void setIconAnimationTogglesFull(final OtsSimulationPanel panel)
139 {
140 TOGGLES.entrySet().forEach((e) ->
141 {
142 panel.startToggleSection(e.getKey(), DEFAULT_VISIBLE.getOrDefault(e.getKey(), true));
143 e.getValue().forEach((t) -> panel.addToggleAnimationButtonIcon(t.name(), t.locatableClass(), t.icon(), t.tooltip(),
144 t.visibleFull(), t.nextToPrevious()));
145 });
146 }
147
148
149
150
151
152 public static void setIconAnimationTogglesStandard(final OtsSimulationPanel panel)
153 {
154 TOGGLES.entrySet().forEach((e) ->
155 {
156 panel.startToggleSection(e.getKey(), DEFAULT_VISIBLE.getOrDefault(e.getKey(), true));
157 e.getValue().forEach((t) -> panel.addToggleAnimationButtonIcon(t.name(), t.locatableClass(), t.icon(), t.tooltip(),
158 t.visibleStandard(), t.nextToPrevious()));
159 });
160 }
161
162
163
164
165
166
167 public static void showAnimationClass(final OtsSimulationPanel panel, final Class<? extends Locatable> locatableClass)
168 {
169 panel.getAnimationPanel().showClass(locatableClass);
170 panel.updateAnimationClassCheckBox(locatableClass);
171 }
172
173
174
175
176
177
178 public static void hideAnimationClass(final OtsSimulationPanel panel, final Class<? extends Locatable> locatableClass)
179 {
180 panel.getAnimationPanel().hideClass(locatableClass);
181 panel.updateAnimationClassCheckBox(locatableClass);
182 }
183
184
185
186
187
188 public static void showAnimationFull(final OtsSimulationPanel panel)
189 {
190 TOGGLES.values().forEach((v) -> v.forEach((t) ->
191 {
192 if (t.visibleFull())
193 {
194 showAnimationClass(panel, t.locatableClass());
195 }
196 else
197 {
198 hideAnimationClass(panel, t.locatableClass());
199 }
200 }));
201 }
202
203
204
205
206
207 public static void showAnimationStandard(final OtsSimulationPanel panel)
208 {
209 TOGGLES.values().forEach((v) -> v.forEach((t) ->
210 {
211 if (t.visibleStandard())
212 {
213 showAnimationClass(panel, t.locatableClass());
214 }
215 else
216 {
217 hideAnimationClass(panel, t.locatableClass());
218 }
219 }));
220 }
221
222
223
224
225
226
227
228
229
230
231
232 private record Toggle(String name, Class<? extends Locatable> locatableClass, String icon, String tooltip,
233 boolean visibleFull, boolean visibleStandard, boolean nextToPrevious)
234 {
235 };
236 }