View Javadoc
1   package org.opentrafficsim.swing.gui;
2   
3   import org.opentrafficsim.core.gtu.GTU;
4   import org.opentrafficsim.core.network.OTSLink;
5   import org.opentrafficsim.core.network.OTSNode;
6   import org.opentrafficsim.draw.gtu.DefaultCarAnimation;
7   import org.opentrafficsim.draw.gtu.GTUGeneratorAnimation;
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.LaneAnimation;
12  import org.opentrafficsim.draw.road.SensorAnimation;
13  import org.opentrafficsim.draw.road.TrafficLightAnimation;
14  import org.opentrafficsim.road.network.lane.Lane;
15  import org.opentrafficsim.road.network.lane.Shoulder;
16  import org.opentrafficsim.road.network.lane.Stripe;
17  import org.opentrafficsim.road.network.lane.conflict.Conflict;
18  import org.opentrafficsim.road.network.lane.object.BusStop;
19  import org.opentrafficsim.road.network.lane.object.sensor.Sensor;
20  import org.opentrafficsim.road.network.lane.object.sensor.SingleSensor;
21  import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight;
22  
23  import nl.tudelft.simulation.dsol.animation.Locatable;
24  
25  /**
26   * Set the default animation toggles for the animation panel.
27   * <p>
28   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
30   * </p>
31   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
32   * initial version Dec 11, 2016 <br>
33   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
34   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
35   * @author <a href="http://www.transport.citg.tudelft.nl">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 OTSAnimationPanel; the WrappableAnimation.
51       */
52      public static void setTextAnimationTogglesFull(final OTSAnimationPanel panel)
53      {
54          panel.addToggleAnimationButtonText("Node", OTSNode.class, "Show/hide nodes", true);
55          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false);
56          panel.addToggleAnimationButtonText("Link", OTSLink.class, "Show/hide links", true);
57          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
58          panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
59          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", 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("Sensor", SingleSensor.class, "Show/hide sensors", true);
65          panel.addToggleAnimationButtonText("SensorId", SensorAnimation.Text.class, "Show/hide sensors Ids", false);
66          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
67          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide sensors Ids", false);
68          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
69          panel.addToggleAnimationButtonText("Generator", GTUGeneratorAnimation.class, "Show/hide generators", false);
70          panel.addToggleAnimationButtonText("Bus", BusStop.class, "Show/hide bus stops", false);
71          panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop Ids", false);
72      }
73  
74      /**
75       * Set the most common animation on, and create the toggles on the left hand side.
76       * @param panel OTSAnimationPanel; the WrappableAnimation.
77       */
78      public static void setTextAnimationTogglesStandard(final OTSAnimationPanel panel)
79      {
80          panel.addToggleAnimationButtonText("Node", OTSNode.class, "Show/hide nodes", false);
81          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false);
82          panel.addToggleAnimationButtonText("Link", OTSLink.class, "Show/hide links", false);
83          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
84          panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
85          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false);
86          panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
87          panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
88          panel.addToggleAnimationButtonText("GTU", GTU.class, "Show/hide GTUs", true);
89          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
90          panel.addToggleAnimationButtonText("Sensor", Sensor.class, "Show/hide sensors", false);
91          panel.addToggleAnimationButtonText("SensorId", SensorAnimation.Text.class, "Show/hide sensors Ids", false);
92          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
93          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide sensors Ids", false);
94          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
95          panel.addToggleAnimationButtonText("Generator", GTUGeneratorAnimation.class, "Show/hide generators", false);
96      }
97  
98      /**
99       * Set all animation on, and create the toggles on the left hand side.
100      * @param panel OTSAnimationPanel; the WrappableAnimation.
101      */
102     public static void setIconAnimationTogglesFull(final OTSAnimationPanel panel)
103     {
104         panel.addToggleAnimationButtonIcon("Node", OTSNode.class, "/icons/Node24.png", "Show/hide nodes", true, false);
105         panel.addToggleAnimationButtonIcon("NodeId", NodeAnimation.Text.class, "/icons/Id24.png", "Show/hide node Ids", false,
106                 true);
107         panel.addToggleAnimationButtonIcon("Link", OTSLink.class, "/icons/Link24.png", "Show/hide links", true, false);
108         panel.addToggleAnimationButtonIcon("LinkId", LinkAnimation.Text.class, "/icons/Id24.png", "Show/hide link Ids", false,
109                 true);
110         panel.addToggleAnimationButtonIcon("Lane", Lane.class, "/icons/Lane24.png", "Show/hide lanes", true, false);
111         panel.addToggleAnimationButtonIcon("LaneId", LaneAnimation.Text.class, "/icons/Id24.png", "Show/hide lane Ids", false,
112                 true);
113         panel.addToggleAnimationButtonIcon("Stripe", Stripe.class, "/icons/Stripe24.png", "Show/hide stripes", true, false);
114         panel.addToggleAnimationButtonIcon("Shoulder", Shoulder.class, "/icons/Shoulder24.png", "Show/hide shoulders", true,
115                 false);
116         panel.addToggleAnimationButtonIcon("GTU", GTU.class, "/icons/Gtu24.png", "Show/hide GTUs", true, false);
117         panel.addToggleAnimationButtonIcon("GTUId", DefaultCarAnimation.Text.class, "/icons/Id24.png", "Show/hide GTU Ids",
118                 false, true);
119         panel.addToggleAnimationButtonIcon("Sensor", Sensor.class, "/icons/Sensor24.png", "Show/hide sensors", true, false);
120         panel.addToggleAnimationButtonIcon("SensorId", SensorAnimation.Text.class, "/icons/Id24.png", "Show/hide sensors Ids",
121                 false, true);
122         panel.addToggleAnimationButtonIcon("Light", TrafficLight.class, "/icons/TrafficLight24.png", "Show/hide traffic lights",
123                 true, false);
124         panel.addToggleAnimationButtonIcon("LightId", TrafficLightAnimation.Text.class, "/icons/Id24.png",
125                 "Show/hide sensors Ids", false, true);
126         panel.addToggleAnimationButtonIcon("Conflict", Conflict.class, "/icons/Conflict24.png", "Show/hide conflicts", false,
127                 false);
128         panel.addToggleAnimationButtonIcon("Generator", GTUGeneratorAnimation.class, "/icons/Generator24.png",
129                 "Show/hide generators", false, false);
130         panel.addToggleAnimationButtonIcon("Bus", BusStop.class, "/icons/BusStop24.png", "Show/hide bus stops", true, false);
131         panel.addToggleAnimationButtonIcon("BusId", BusStopAnimation.Text.class, "/icons/Id24.png", "Show/hide bus stops",
132                 false, true);
133     }
134 
135     /**
136      * Set the most common animation on, and create the toggles on the left hand side.
137      * @param panel OTSAnimationPanel; the WrappableAnimation.
138      */
139     public static void setIconAnimationTogglesStandard(final OTSAnimationPanel panel)
140     {
141         panel.addToggleAnimationButtonIcon("Node", OTSNode.class, "/icons/Node24.png", "Show/hide nodes", false, false);
142         panel.addToggleAnimationButtonIcon("NodeId", NodeAnimation.Text.class, "/icons/Id24.png", "Show/hide node Ids", false,
143                 true);
144         panel.addToggleAnimationButtonIcon("Link", OTSLink.class, "/icons/Link24.png", "Show/hide links", false, false);
145         panel.addToggleAnimationButtonIcon("LinkId", LinkAnimation.Text.class, "/icons/Id24.png", "Show/hide link Ids", false,
146                 true);
147         panel.addToggleAnimationButtonIcon("Lane", Lane.class, "/icons/Lane24.png", "Show/hide lanes", true, false);
148         panel.addToggleAnimationButtonIcon("LaneId", LaneAnimation.Text.class, "/icons/Id24.png", "Show/hide lane Ids", false,
149                 true);
150         panel.addToggleAnimationButtonIcon("Stripe", Stripe.class, "/icons/Stripe24.png", "Show/hide stripes", true, false);
151         panel.addToggleAnimationButtonIcon("Shoulder", Shoulder.class, "/icons/Shoulder24.png", "Show/hide shoulders", true,
152                 false);
153         panel.addToggleAnimationButtonIcon("GTU", GTU.class, "/icons/Gtu24.png", "Show/hide GTUs", true, false);
154         panel.addToggleAnimationButtonIcon("GTUId", DefaultCarAnimation.Text.class, "/icons/Id24.png", "Show/hide GTU Ids",
155                 false, true);
156         panel.addToggleAnimationButtonIcon("Sensor", Sensor.class, "/icons/Sensor24.png", "Show/hide sensors", false, false);
157         panel.addToggleAnimationButtonIcon("SensorId", SensorAnimation.Text.class, "/icons/Id24.png", "Show/hide sensors Ids",
158                 false, true);
159         panel.addToggleAnimationButtonIcon("Light", TrafficLight.class, "/icons/TrafficLight24.png", "Show/hide traffic lights",
160                 true, false);
161         panel.addToggleAnimationButtonIcon("LightId", TrafficLightAnimation.Text.class, "/icons/Id24.png",
162                 "Show/hide sensors Ids", false, true);
163         panel.addToggleAnimationButtonIcon("Conflict", Conflict.class, "/icons/Conflict24.png", "Show/hide conflicts", false,
164                 false);
165         panel.addToggleAnimationButtonIcon("Generator", GTUGeneratorAnimation.class, "/icons/Generator24.png",
166                 "Show/hide generators", false, false);
167         panel.addToggleAnimationButtonIcon("Bus", BusStop.class, "/icons/BusStop24.png", "Show/hide bus stops", false, false);
168         panel.addToggleAnimationButtonIcon("BusId", BusStopAnimation.Text.class, "/icons/Id24.png", "Show/hide bus stops",
169                 false, true);
170     }
171 
172     /**
173      * Set a class to be shown in the animation to true.
174      * @param panel OTSAnimationPanel; the OTSAnimationPanel where the animation of a class has to be switched off
175      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
176      */
177     public final static void showAnimationClass(final OTSAnimationPanel panel, final Class<? extends Locatable> locatableClass)
178     {
179         panel.getAnimationPanel().showClass(locatableClass);
180         panel.updateAnimationClassCheckBox(locatableClass);
181     }
182 
183     /**
184      * Set a class to be shown in the animation to false.
185      * @param panel OTSAnimationPanel; the OTSAnimationPanel where the animation of a class has to be switched off
186      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
187      */
188     public final static void hideAnimationClass(final OTSAnimationPanel panel, final Class<? extends Locatable> locatableClass)
189     {
190         panel.getAnimationPanel().hideClass(locatableClass);
191         panel.updateAnimationClassCheckBox(locatableClass);
192     }
193 
194     /**
195      * Set all animation on, and create the toggles on the left hand side.
196      * @param panel OTSAnimationPanel; the WrappableAnimation.
197      */
198     public static void showAnimationFull(final OTSAnimationPanel panel)
199     {
200         showAnimationClass(panel, OTSNode.class);
201         hideAnimationClass(panel, NodeAnimation.Text.class);
202         showAnimationClass(panel, OTSLink.class);
203         hideAnimationClass(panel, LinkAnimation.Text.class);
204         showAnimationClass(panel, Lane.class);
205         hideAnimationClass(panel, LaneAnimation.Text.class);
206         showAnimationClass(panel, Stripe.class);
207         showAnimationClass(panel, Shoulder.class);
208         showAnimationClass(panel, GTU.class);
209         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
210         showAnimationClass(panel, SingleSensor.class);
211         hideAnimationClass(panel, SensorAnimation.Text.class);
212         showAnimationClass(panel, TrafficLight.class);
213         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
214         showAnimationClass(panel, Conflict.class);
215         hideAnimationClass(panel, BusStop.class);
216         hideAnimationClass(panel, BusStopAnimation.Text.class);
217         showAnimationClass(panel, GTUGeneratorAnimation.class);
218     }
219 
220     /**
221      * Set the most common animation on, and create the toggles on the left hand side.
222      * @param panel OTSAnimationPanel; the WrappableAnimation.
223      */
224     public static void showAnimationStandard(final OTSAnimationPanel panel)
225     {
226         hideAnimationClass(panel, OTSNode.class);
227         hideAnimationClass(panel, NodeAnimation.Text.class);
228         hideAnimationClass(panel, OTSLink.class);
229         hideAnimationClass(panel, LinkAnimation.Text.class);
230         showAnimationClass(panel, Lane.class);
231         hideAnimationClass(panel, LaneAnimation.Text.class);
232         showAnimationClass(panel, Stripe.class);
233         showAnimationClass(panel, Shoulder.class);
234         showAnimationClass(panel, GTU.class);
235         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
236         hideAnimationClass(panel, SingleSensor.class);
237         hideAnimationClass(panel, SensorAnimation.Text.class);
238         showAnimationClass(panel, TrafficLight.class);
239         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
240         hideAnimationClass(panel, Conflict.class);
241         hideAnimationClass(panel, BusStop.class);
242         hideAnimationClass(panel, BusStopAnimation.Text.class);
243         hideAnimationClass(panel, GTUGeneratorAnimation.class);
244     }
245 
246 }