1 package org.opentrafficsim.swing.gui;
2
3 import java.awt.Color;
4 import java.util.LinkedHashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.djutils.immutablecollections.Immutable;
9 import org.djutils.immutablecollections.ImmutableLinkedHashMap;
10 import org.djutils.immutablecollections.ImmutableMap;
11 import org.opentrafficsim.animation.Colors;
12 import org.opentrafficsim.animation.colorer.Colorer;
13 import org.opentrafficsim.animation.colorer.FixedColorer;
14 import org.opentrafficsim.animation.data.gtu.AccelerationGtuColorer;
15 import org.opentrafficsim.animation.data.gtu.IdGtuColorer;
16 import org.opentrafficsim.animation.data.gtu.SpeedGtuColorer;
17 import org.opentrafficsim.animation.data.util.DefaultAnimationFactory;
18 import org.opentrafficsim.animation.gtu.DefaultCarAnimation.GtuData.GtuMarker;
19 import org.opentrafficsim.core.definitions.DefaultsNl;
20 import org.opentrafficsim.core.gtu.Gtu;
21 import org.opentrafficsim.core.gtu.GtuType;
22 import org.opentrafficsim.core.network.Network;
23
24
25
26
27
28
29
30
31
32
33
34
35 public interface OtsSimulationPanelDecorator
36 {
37
38
39
40 List<Colorer<? super Gtu>> DEFAULT_GTU_COLORERS = List.of(new FixedColorer<>(Colors.OTS_BLUE, "Blue"), new IdGtuColorer(),
41 new SpeedGtuColorer(), new AccelerationGtuColorer());
42
43
44 ImmutableMap<GtuType, Color> GTU_TYPE_COLORS = new ImmutableLinkedHashMap<>(new LinkedHashMap<>()
45 {
46 {
47 put(DefaultsNl.CAR, Color.BLUE);
48 put(DefaultsNl.TRUCK, Color.RED);
49 put(DefaultsNl.VEHICLE, Color.GRAY);
50 put(DefaultsNl.PEDESTRIAN, Color.YELLOW);
51 put(DefaultsNl.MOTORCYCLE, Color.PINK);
52 put(DefaultsNl.BICYCLE, Color.GREEN);
53 }
54 }, Immutable.WRAP);
55
56
57 ImmutableMap<GtuType, GtuMarker> GTU_TYPE_MARKERS = new ImmutableLinkedHashMap<>(new LinkedHashMap<>()
58 {
59 {
60 put(DefaultsNl.TRUCK, GtuMarker.SQUARE);
61 }
62 }, Immutable.WRAP);
63
64
65
66
67
68
69 default void decorate(final OtsSimulationPanel simulationPanel, final Network network)
70 {
71 setAnimationToggles(simulationPanel);
72 animateSimulation(simulationPanel, network);
73 setupDemo(simulationPanel, network);
74 addTabs(simulationPanel, network);
75 }
76
77
78
79
80
81 default void setAnimationToggles(final OtsSimulationPanel simulationPanel)
82 {
83 AnimationToggles.setIconAnimationTogglesStandard(simulationPanel);
84 }
85
86
87
88
89
90
91 default void animateSimulation(final OtsSimulationPanel simulationPanel, final Network network)
92 {
93 DefaultAnimationFactory.animateNetwork(network, network.getSimulator(), simulationPanel.getGtuColorerManager(),
94 getGtuMarkers());
95 }
96
97
98
99
100
101
102 default void addTabs(final OtsSimulationPanel simulationPanel, final Network network)
103 {
104
105 }
106
107
108
109
110
111
112 default void setupDemo(final OtsSimulationPanel simulationPanel, final Network network)
113 {
114
115 }
116
117
118
119
120
121 default List<Colorer<? super Gtu>> getGtuColorers()
122 {
123 return DEFAULT_GTU_COLORERS;
124 }
125
126
127
128
129
130 default Map<GtuType, GtuMarker> getGtuMarkers()
131 {
132 return GTU_TYPE_MARKERS.toMap();
133 }
134
135 }