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