View Javadoc
1   package org.opentrafficsim.swing.gui;
2   
3   import org.opentrafficsim.animation.PerceptionAnimation;
4   import org.opentrafficsim.draw.gtu.DefaultCarAnimation;
5   import org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData;
6   import org.opentrafficsim.draw.network.LinkAnimation;
7   import org.opentrafficsim.draw.network.LinkAnimation.LinkData;
8   import org.opentrafficsim.draw.network.NodeAnimation;
9   import org.opentrafficsim.draw.network.NodeAnimation.NodeData;
10  import org.opentrafficsim.draw.road.BusStopAnimation;
11  import org.opentrafficsim.draw.road.BusStopAnimation.BusStopData;
12  import org.opentrafficsim.draw.road.ConflictAnimation.ConflictData;
13  import org.opentrafficsim.draw.road.CrossSectionElementAnimation.ShoulderData;
14  import org.opentrafficsim.draw.road.DetectorData;
15  import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation;
16  import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
17  import org.opentrafficsim.draw.road.LaneAnimation;
18  import org.opentrafficsim.draw.road.LaneAnimation.CenterLine;
19  import org.opentrafficsim.draw.road.LaneAnimation.LaneData;
20  import org.opentrafficsim.draw.road.PriorityAnimation.PriorityData;
21  import org.opentrafficsim.draw.road.StripeAnimation.StripeData;
22  import org.opentrafficsim.draw.road.TrafficLightAnimation;
23  import org.opentrafficsim.draw.road.TrafficLightAnimation.TrafficLightData;
24  
25  import nl.tudelft.simulation.dsol.animation.Locatable;
26  
27  /**
28   * Set the default animation toggles for the animation panel.
29   * <p>
30   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
31   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
32   * </p>
33   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
34   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
35   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
36   */
37  public final class AnimationToggles
38  {
39  
40      /**
41       * Do not instantiate this class.
42       */
43      private AnimationToggles()
44      {
45          // static class.
46      }
47  
48      /**
49       * Set all animation on, and create the toggles on the left hand side.
50       * @param panel the WrappableAnimation.
51       */
52      public static void setTextAnimationTogglesFull(final OtsAnimationPanel panel)
53      {
54          panel.addToggleAnimationButtonText("Node", NodeData.class, "Show/hide nodes", true);
55          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node ids", false);
56          panel.addToggleAnimationButtonText("Link", LinkData.class, "Show/hide links", true);
57          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link ids", false);
58          panel.addToggleAnimationButtonText("Priority", PriorityData.class, "Show/hide link priority", true);
59          panel.addToggleAnimationButtonText("Lane", LaneData.class, "Show/hide lanes", true);
60          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane ids", false);
61          panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
62          panel.addToggleAnimationButtonText("Stripe", StripeData.class, "Show/hide stripes", true);
63          panel.addToggleAnimationButtonText("Shoulder", ShoulderData.class, "Show/hide shoulders", true);
64          panel.addToggleAnimationButtonText("GTU", GtuData.class, "Show/hide GTUs", true);
65          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU ids", false);
66          panel.addToggleAnimationButtonText("Perception", PerceptionAnimation.ChannelAttention.class,
67                  "Show/hide perception (circle = attention, color = perception delay)", false);
68          panel.addToggleAnimationButtonText("Detector", DetectorData.class, "Show/hide detectors", true);
69          panel.addToggleAnimationButtonText("DetectorId", DetectorData.Text.class, "Show/hide detector ids", false);
70          panel.addToggleAnimationButtonText("Light", TrafficLightData.class, "Show/hide traffic lights", true);
71          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide traffic light ids", false);
72          panel.addToggleAnimationButtonText("Conflict", ConflictData.class, "Show/hide conflicts", true);
73          panel.addToggleAnimationButtonText("Generator", GtuGeneratorPositionData.class, "Show/hide generators", true);
74          panel.addToggleAnimationButtonText("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class,
75                  "Show/hide generator queues", false);
76          panel.addToggleAnimationButtonText("Bus", BusStopData.class, "Show/hide bus stops", true);
77          panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop ids", false);
78      }
79  
80      /**
81       * Set the most common animation on, and create the toggles on the left hand side.
82       * @param panel the WrappableAnimation.
83       */
84      public static void setTextAnimationTogglesStandard(final OtsAnimationPanel panel)
85      {
86          panel.addToggleAnimationButtonText("Node", NodeData.class, "Show/hide nodes", false);
87          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node ids", false);
88          panel.addToggleAnimationButtonText("Link", LinkData.class, "Show/hide links", false);
89          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link ids", false);
90          panel.addToggleAnimationButtonText("Priority", PriorityData.class, "Show/hide link priority", false);
91          panel.addToggleAnimationButtonText("Lane", LaneData.class, "Show/hide lanes", true);
92          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane ids", false);
93          panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
94          panel.addToggleAnimationButtonText("Stripe", StripeData.class, "Show/hide stripes", true);
95          panel.addToggleAnimationButtonText("Shoulder", ShoulderData.class, "Show/hide shoulders", true);
96          panel.addToggleAnimationButtonText("GTU", GtuData.class, "Show/hide GTUs", true);
97          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU ids", false);
98          panel.addToggleAnimationButtonText("Perception", PerceptionAnimation.ChannelAttention.class,
99                  "Show/hide perception (circle = attention, color = perception delay)", false);
100         panel.addToggleAnimationButtonText("Detector", DetectorData.class, "Show/hide detectors", false);
101         panel.addToggleAnimationButtonText("DetectorId", DetectorData.Text.class, "Show/hide detector ids", false);
102         panel.addToggleAnimationButtonText("Light", TrafficLightData.class, "Show/hide traffic lights", true);
103         panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide traffic light ids", false);
104         panel.addToggleAnimationButtonText("Conflict", ConflictData.class, "Show/hide conflicts", false);
105         panel.addToggleAnimationButtonText("Generator", GtuGeneratorPositionData.class, "Show/hide generators", false);
106         panel.addToggleAnimationButtonText("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class,
107                 "Show/hide generator queues", false);
108         panel.addToggleAnimationButtonText("Bus", BusStopData.class, "Show/hide bus stops", false);
109         panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop ids", false);
110     }
111 
112     /**
113      * Set all animation on, and create the toggles on the left hand side.
114      * @param panel the WrappableAnimation.
115      */
116     public static void setIconAnimationTogglesFull(final OtsAnimationPanel panel)
117     {
118         panel.addToggleAnimationButtonIcon("Node", NodeData.class, "/icons/Node24.png", "Show/hide nodes", true, false);
119         panel.addToggleAnimationButtonIcon("NodeId", NodeAnimation.Text.class, "/icons/Id24.png", "Show/hide node ids", false,
120                 true);
121         panel.addToggleAnimationButtonIcon("Link", LinkData.class, "/icons/Link24.png", "Show/hide links", true, false);
122         panel.addToggleAnimationButtonIcon("LinkId", LinkAnimation.Text.class, "/icons/Id24.png", "Show/hide link ids", false,
123                 true);
124         panel.addToggleAnimationButtonIcon("Priority", PriorityData.class, "/icons/Priority24.png", "Show/hide link priority",
125                 true, false);
126         panel.addToggleAnimationButtonIcon("Lane", LaneData.class, "/icons/Lane24.png", "Show/hide lanes", true, false);
127         panel.addToggleAnimationButtonIcon("LaneId", LaneAnimation.Text.class, "/icons/Id24.png", "Show/hide lane ids", false,
128                 true);
129         panel.addToggleAnimationButtonIcon("Stripe", StripeData.class, "/icons/Stripe24.png", "Show/hide stripes", true, false);
130         panel.addToggleAnimationButtonIcon("LaneCenter", CenterLine.class, "/icons/CenterLine24.png",
131                 "Show/hide lane center lines", false, true);
132         panel.addToggleAnimationButtonIcon("Shoulder", ShoulderData.class, "/icons/Shoulder24.png", "Show/hide shoulders", true,
133                 false);
134         panel.addToggleAnimationButtonIcon("GTU", GtuData.class, "/icons/Gtu24.png", "Show/hide GTUs", true, false);
135         panel.addToggleAnimationButtonIcon("GTUId", DefaultCarAnimation.Text.class, "/icons/Id24.png", "Show/hide GTU ids",
136                 false, true);
137         panel.addToggleAnimationButtonIcon("Perception", PerceptionAnimation.ChannelAttention.class, "/icons/Perception24.png",
138                 "Show/hide perception (circle = attention, color = perception delay)", false, false);
139         panel.addToggleAnimationButtonIcon("Detector", DetectorData.class, "/icons/Detector24.png", "Show/hide detectors", true,
140                 false);
141         panel.addToggleAnimationButtonIcon("DetectorId", DetectorData.Text.class, "/icons/Id24.png", "Show/hide detector ids",
142                 false, true);
143         panel.addToggleAnimationButtonIcon("Light", TrafficLightData.class, "/icons/TrafficLight24.png",
144                 "Show/hide traffic lights", true, false);
145         panel.addToggleAnimationButtonIcon("LightId", TrafficLightAnimation.Text.class, "/icons/Id24.png",
146                 "Show/hide traffic light ids", false, true);
147         panel.addToggleAnimationButtonIcon("Conflict", ConflictData.class, "/icons/Conflict24.png", "Show/hide conflicts", true,
148                 false);
149         panel.addToggleAnimationButtonIcon("Generator", GtuGeneratorPositionData.class, "/icons/Generator24.png",
150                 "Show/hide generators", true, false);
151         panel.addToggleAnimationButtonIcon("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class, "/icons/Queue24.png",
152                 "Show/hide generator queues", false, true);
153         panel.addToggleAnimationButtonIcon("Bus", BusStopData.class, "/icons/BusStop24.png", "Show/hide bus stops", true,
154                 false);
155         panel.addToggleAnimationButtonIcon("BusId", BusStopAnimation.Text.class, "/icons/Id24.png", "Show/hide bus stop ids",
156                 false, true);
157     }
158 
159     /**
160      * Set the most common animation on, and create the toggles on the left hand side.
161      * @param panel the WrappableAnimation.
162      */
163     public static void setIconAnimationTogglesStandard(final OtsAnimationPanel panel)
164     {
165         panel.addToggleAnimationButtonIcon("Node", NodeData.class, "/icons/Node24.png", "Show/hide nodes", false, false);
166         panel.addToggleAnimationButtonIcon("NodeId", NodeAnimation.Text.class, "/icons/Id24.png", "Show/hide node ids", false,
167                 true);
168         panel.addToggleAnimationButtonIcon("Link", LinkData.class, "/icons/Link24.png", "Show/hide links", false, false);
169         panel.addToggleAnimationButtonIcon("LinkId", LinkAnimation.Text.class, "/icons/Id24.png", "Show/hide link ids", false,
170                 true);
171         panel.addToggleAnimationButtonIcon("Priority", PriorityData.class, "/icons/Priority24.png", "Show/hide link priority",
172                 false, false);
173         panel.addToggleAnimationButtonIcon("Lane", LaneData.class, "/icons/Lane24.png", "Show/hide lanes", true, false);
174         panel.addToggleAnimationButtonIcon("LaneId", LaneAnimation.Text.class, "/icons/Id24.png", "Show/hide lane ids", false,
175                 true);
176         panel.addToggleAnimationButtonIcon("Stripe", StripeData.class, "/icons/Stripe24.png", "Show/hide stripes", true, false);
177         panel.addToggleAnimationButtonIcon("LaneCenter", CenterLine.class, "/icons/CenterLine24.png",
178                 "Show/hide lane center lines", false, true);
179         panel.addToggleAnimationButtonIcon("Shoulder", ShoulderData.class, "/icons/Shoulder24.png", "Show/hide shoulders", true,
180                 false);
181         panel.addToggleAnimationButtonIcon("GTU", GtuData.class, "/icons/Gtu24.png", "Show/hide GTUs", true, false);
182         panel.addToggleAnimationButtonIcon("GTUId", DefaultCarAnimation.Text.class, "/icons/Id24.png", "Show/hide GTU ids",
183                 false, true);
184         panel.addToggleAnimationButtonIcon("Perception", PerceptionAnimation.ChannelAttention.class, "/icons/Perception24.png",
185                 "Show/hide perception (circle = attention, color = perception delay)", false, false);
186         panel.addToggleAnimationButtonIcon("Detector", DetectorData.class, "/icons/Detector24.png", "Show/hide detectors",
187                 false, false);
188         panel.addToggleAnimationButtonIcon("DetectorId", DetectorData.Text.class, "/icons/Id24.png", "Show/hide detector ids",
189                 false, true);
190         panel.addToggleAnimationButtonIcon("Light", TrafficLightData.class, "/icons/TrafficLight24.png",
191                 "Show/hide traffic lights", true, false);
192         panel.addToggleAnimationButtonIcon("LightId", TrafficLightAnimation.Text.class, "/icons/Id24.png",
193                 "Show/hide traffic light ids", false, true);
194         panel.addToggleAnimationButtonIcon("Conflict", ConflictData.class, "/icons/Conflict24.png", "Show/hide conflicts",
195                 false, false);
196         panel.addToggleAnimationButtonIcon("Generator", GtuGeneratorPositionData.class, "/icons/Generator24.png",
197                 "Show/hide generators", false, false);
198         panel.addToggleAnimationButtonIcon("GeneratorQ", GtuGeneratorPositionAnimation.Queue.class, "/icons/Queue24.png",
199                 "Show/hide generator queues", false, true);
200         panel.addToggleAnimationButtonIcon("Bus", BusStopData.class, "/icons/BusStop24.png", "Show/hide bus stops", false,
201                 false);
202         panel.addToggleAnimationButtonIcon("BusId", BusStopAnimation.Text.class, "/icons/Id24.png", "Show/hide bus stop ids",
203                 false, true);
204     }
205 
206     /**
207      * Set a class to be shown in the animation to true.
208      * @param panel the OtsAnimationPanel where the animation of a class has to be switched off
209      * @param locatableClass the class for which the animation has to be shown.
210      */
211     public static void showAnimationClass(final OtsAnimationPanel panel, final Class<? extends Locatable> locatableClass)
212     {
213         panel.getAnimationPanel().showClass(locatableClass);
214         panel.updateAnimationClassCheckBox(locatableClass);
215     }
216 
217     /**
218      * Set a class to be shown in the animation to false.
219      * @param panel the OtsAnimationPanel where the animation of a class has to be switched off
220      * @param locatableClass the class for which the animation has to be shown.
221      */
222     public static void hideAnimationClass(final OtsAnimationPanel panel, final Class<? extends Locatable> locatableClass)
223     {
224         panel.getAnimationPanel().hideClass(locatableClass);
225         panel.updateAnimationClassCheckBox(locatableClass);
226     }
227 
228     /**
229      * Set all animation on, and create the toggles on the left hand side.
230      * @param panel the WrappableAnimation.
231      */
232     public static void showAnimationFull(final OtsAnimationPanel panel)
233     {
234         showAnimationClass(panel, NodeData.class);
235         hideAnimationClass(panel, NodeAnimation.Text.class);
236         showAnimationClass(panel, LinkData.class);
237         hideAnimationClass(panel, LinkAnimation.Text.class);
238         showAnimationClass(panel, PriorityData.class);
239         showAnimationClass(panel, LaneData.class);
240         hideAnimationClass(panel, LaneAnimation.Text.class);
241         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
242         showAnimationClass(panel, StripeData.class);
243         showAnimationClass(panel, ShoulderData.class);
244         showAnimationClass(panel, GtuData.class);
245         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
246         showAnimationClass(panel, DetectorData.class);
247         hideAnimationClass(panel, DetectorData.Text.class);
248         showAnimationClass(panel, TrafficLightData.class);
249         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
250         showAnimationClass(panel, ConflictData.class);
251         showAnimationClass(panel, GtuGeneratorPositionData.class);
252         hideAnimationClass(panel, GtuGeneratorPositionAnimation.Queue.class);
253         showAnimationClass(panel, BusStopData.class);
254         hideAnimationClass(panel, BusStopAnimation.Text.class);
255     }
256 
257     /**
258      * Set the most common animation on, and create the toggles on the left hand side.
259      * @param panel the WrappableAnimation.
260      */
261     public static void showAnimationStandard(final OtsAnimationPanel panel)
262     {
263         hideAnimationClass(panel, NodeData.class);
264         hideAnimationClass(panel, NodeAnimation.Text.class);
265         hideAnimationClass(panel, LinkData.class);
266         hideAnimationClass(panel, LinkAnimation.Text.class);
267         hideAnimationClass(panel, PriorityData.class);
268         showAnimationClass(panel, LaneData.class);
269         hideAnimationClass(panel, LaneAnimation.Text.class);
270         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
271         showAnimationClass(panel, StripeData.class);
272         showAnimationClass(panel, ShoulderData.class);
273         showAnimationClass(panel, GtuData.class);
274         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
275         hideAnimationClass(panel, DetectorData.class);
276         hideAnimationClass(panel, DetectorData.Text.class);
277         showAnimationClass(panel, TrafficLightData.class);
278         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
279         hideAnimationClass(panel, ConflictData.class);
280         hideAnimationClass(panel, GtuGeneratorPositionData.class);
281         hideAnimationClass(panel, GtuGeneratorPositionAnimation.Queue.class);
282         hideAnimationClass(panel, BusStopData.class);
283         hideAnimationClass(panel, BusStopAnimation.Text.class);
284     }
285 
286 }