View Javadoc
1   package org.opentrafficsim.web.animation;
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.GtuGeneratorQueueAnimation;
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  import nl.tudelft.simulation.dsol.web.animation.D2.HTMLAnimationPanel;
25  
26  /**
27   * Set the default animation toggles for the HTML animation panel.
28   * <p>
29   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
31   * </p>
32   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
33   * initial version Dec 11, 2016 <br>
34   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
35   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
36   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
37   */
38  public final class WebAnimationToggles
39  {
40      /**
41       * Do not instantiate this class.
42       */
43      private WebAnimationToggles()
44      {
45          // static class.
46      }
47  
48      /**
49       * Set all commonly used animation on, and create the toggles on the left hand side.
50       * @param panel HTMLAnimationPanel; the Animation panel to add the toggle to.
51       */
52      public static void setTextAnimationTogglesFull(final HTMLAnimationPanel panel)
53      {
54          panel.addToggleAnimationButtonText("Node", NodeAnimation.ElevatedNode.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("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
61          panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
62          panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
63          panel.addToggleAnimationButtonText("GTU", GTU.class, "Show/hide GTUs", true);
64          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
65          panel.addToggleAnimationButtonText("Sensor", SingleSensor.class, "Show/hide sensors", true);
66          panel.addToggleAnimationButtonText("SensorId", SensorAnimation.Text.class, "Show/hide sensors Ids", false);
67          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
68          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide sensors Ids", false);
69          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
70          panel.addToggleAnimationButtonText("Generator", GtuGeneratorQueueAnimation.class, "Show/hide generators", false);
71          panel.addToggleAnimationButtonText("Bus", BusStop.class, "Show/hide bus stops", false);
72          panel.addToggleAnimationButtonText("BusId", BusStopAnimation.Text.class, "Show/hide bus stop Ids", false);
73      }
74  
75      /**
76       * Set the most common animation on, and create the toggles on the left hand side.
77       * @param panel HTMLAnimationPanel; the Animation panel to add the toggle to.
78       */
79      public static void setTextAnimationTogglesStandard(final HTMLAnimationPanel panel)
80      {
81          panel.addToggleAnimationButtonText("Node", NodeAnimation.ElevatedNode.class, "Show/hide nodes", false);
82          panel.addToggleAnimationButtonText("NodeId", NodeAnimation.Text.class, "Show/hide node Ids", false);
83          panel.addToggleAnimationButtonText("Link", OTSLink.class, "Show/hide links", false);
84          panel.addToggleAnimationButtonText("LinkId", LinkAnimation.Text.class, "Show/hide link Ids", false);
85          panel.addToggleAnimationButtonText("Lane", Lane.class, "Show/hide lanes", true);
86          panel.addToggleAnimationButtonText("LaneId", LaneAnimation.Text.class, "Show/hide lane Ids", false);
87          panel.addToggleAnimationButtonText("LaneCenter", LaneAnimation.CenterLine.class, "Show/hide lane center lines", false);
88          panel.addToggleAnimationButtonText("Stripe", Stripe.class, "Show/hide stripes", true);
89          panel.addToggleAnimationButtonText("Shoulder", Shoulder.class, "Show/hide shoulders", true);
90          panel.addToggleAnimationButtonText("GTU", GTU.class, "Show/hide GTUs", true);
91          panel.addToggleAnimationButtonText("GTUId", DefaultCarAnimation.Text.class, "Show/hide GTU Ids", false);
92          panel.addToggleAnimationButtonText("Sensor", Sensor.class, "Show/hide sensors", false);
93          panel.addToggleAnimationButtonText("SensorId", SensorAnimation.Text.class, "Show/hide sensors Ids", false);
94          panel.addToggleAnimationButtonText("Light", TrafficLight.class, "Show/hide traffic lights", true);
95          panel.addToggleAnimationButtonText("LightId", TrafficLightAnimation.Text.class, "Show/hide sensors Ids", false);
96          panel.addToggleAnimationButtonText("Conflict", Conflict.class, "Show/hide conflicts", false);
97          panel.addToggleAnimationButtonText("Generator", GtuGeneratorQueueAnimation.class, "Show/hide generators", false);
98      }
99  
100     /**
101      * Set a class to be shown in the animation to true.
102      * @param panel OTSAnimationPanel; the HTMLAnimationPanel where the animation of a class has to be switched off
103      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
104      */
105     public final static void showAnimationClass(final HTMLAnimationPanel panel, final Class<? extends Locatable> locatableClass)
106     {
107         panel.showClass(locatableClass);
108     }
109 
110     /**
111      * Set a class to be shown in the animation to false.
112      * @param panel HTMLAnimationPanel; the HTMLAnimationPanel where the animation of a class has to be switched off
113      * @param locatableClass Class&lt;? extends Locatable&gt;; the class for which the animation has to be shown.
114      */
115     public final static void hideAnimationClass(final HTMLAnimationPanel panel, final Class<? extends Locatable> locatableClass)
116     {
117         panel.hideClass(locatableClass);
118     }
119 
120     /**
121      * Set all commonly used animation on, and create the toggles on the left hand side.
122      * @param panel HTMLAnimationPanel; the HTMLAnimationPanel where classes are shown or not.
123      */
124     public static void showAnimationFull(final HTMLAnimationPanel panel)
125     {
126         showAnimationClass(panel, OTSNode.class);
127         hideAnimationClass(panel, NodeAnimation.Text.class);
128         showAnimationClass(panel, OTSLink.class);
129         hideAnimationClass(panel, LinkAnimation.Text.class);
130         showAnimationClass(panel, Lane.class);
131         hideAnimationClass(panel, LaneAnimation.Text.class);
132         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
133         showAnimationClass(panel, Stripe.class);
134         showAnimationClass(panel, Shoulder.class);
135         showAnimationClass(panel, GTU.class);
136         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
137         showAnimationClass(panel, SingleSensor.class);
138         hideAnimationClass(panel, SensorAnimation.Text.class);
139         showAnimationClass(panel, TrafficLight.class);
140         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
141         showAnimationClass(panel, Conflict.class);
142         hideAnimationClass(panel, BusStop.class);
143         hideAnimationClass(panel, BusStopAnimation.Text.class);
144         showAnimationClass(panel, GtuGeneratorQueueAnimation.class);
145     }
146 
147     /**
148      * Set the most common animation on, and create the toggles on the left hand side.
149      * @param panel OTSAnimationPanel; the WrappableAnimation.
150      */
151     public static void showAnimationStandard(final HTMLAnimationPanel panel)
152     {
153         hideAnimationClass(panel, OTSNode.class);
154         hideAnimationClass(panel, NodeAnimation.Text.class);
155         hideAnimationClass(panel, OTSLink.class);
156         hideAnimationClass(panel, LinkAnimation.Text.class);
157         showAnimationClass(panel, Lane.class);
158         hideAnimationClass(panel, LaneAnimation.Text.class);
159         hideAnimationClass(panel, LaneAnimation.CenterLine.class);
160         showAnimationClass(panel, Stripe.class);
161         showAnimationClass(panel, Shoulder.class);
162         showAnimationClass(panel, GTU.class);
163         hideAnimationClass(panel, DefaultCarAnimation.Text.class);
164         hideAnimationClass(panel, SingleSensor.class);
165         hideAnimationClass(panel, SensorAnimation.Text.class);
166         showAnimationClass(panel, TrafficLight.class);
167         hideAnimationClass(panel, TrafficLightAnimation.Text.class);
168         hideAnimationClass(panel, Conflict.class);
169         hideAnimationClass(panel, BusStop.class);
170         hideAnimationClass(panel, BusStopAnimation.Text.class);
171         hideAnimationClass(panel, GtuGeneratorQueueAnimation.class);
172     }
173 
174 }