source: tmcsimulator-scriptbuilder/branches/ScriptBuilder4/src/scriptbuilder/structures/SimulationScript.java @ 6

Revision 6, 4.7 KB checked in by jdalbey, 9 years ago (diff)

Add original prototype to branch

Line 
1package scriptbuilder.structures;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.Observable;
7import java.util.Observer;
8import java.util.Random;
9import scriptbuilder.structures.ScriptEvent.ScriptEventType;
10import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent;
11import scriptbuilder.structures.ScriptIncident.SliceChangedEvent;
12
13/**
14 *
15 * @author Greg Eddington <geddingt@calpoly.edu>
16 */
17public class SimulationScript extends Observable implements Observer
18{
19    public static final Color[] incidentColors = { Color.BLACK,
20                                                    Color.BLUE,
21                                                    Color.RED,
22                                                    new Color(0x38, 0x5E, 0x0F),
23                                                    new Color(128, 0, 128),
24                                                    Color.MAGENTA,
25                                                    new Color(0x23, 0x6B, 0x8E),
26                                                    Color.ORANGE,
27                                                    new Color(0x60, 0x33, 0x11),
28                                                    Color.GRAY                  };
29    public List<ScriptIncident> incidents;
30
31    public SimulationScript()
32    {
33        incidents = new ArrayList<ScriptIncident>();
34
35        // Create the media event
36        incidents.add(new ScriptIncident(incidentColors[0], 100, "Media",
37                "An incident for the media in CAD.", 10800, this));
38
39        // Add some demo events
40        incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck",
41                "Blueberry truck crashed on the freeway.", 8800, this));
42        incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash",
43                "Crash at construction site on Red Road.", 6800, this));
44        incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip",
45                "Car flipped across the lane divider on the freeway.", 7200, this));
46        incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash",
47                "Crash taking two lanes on Tree Road.", 4200, this));
48        incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck",
49                "Truck stalled on the freeway.", 2800, this));
50        //incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill",
51        //        "Tomato trucked spilt tomatos all over the freeway.", 3200, this));
52        //incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection",
53        //        "Crash at the intersection of Tree Road and Red Road.", 4300, this));
54        //incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat",
55        //        "Bomb threat and Road X.", 6000, this));*/
56        incidents.add(null);
57        incidents.add(null);
58        incidents.add(null);
59
60        // Create the "other" event
61        incidents.add(new ScriptIncident(incidentColors[9], 999, "Other",
62                "An incident for small-scale events, false events, "  +
63                "and noise.  All events added to this incident will " +
64                "receive a randomly generated incident number.",
65                10800, this));
66
67        Random rng = new Random();
68        ScriptEventType[] eventTypes = ScriptEventType.values();
69
70        for(int i = 0; i < 300; i++)
71        {
72            int n = rng.nextInt();
73            int s = rng.nextInt();
74            int e = rng.nextInt();
75            if (n < 0) n *= -1;
76            if (s < 0) s *= -1;
77            if (e < 0) e *= -1;
78
79            incidents.get(n % 6).slices.get(s % (incidents.get(n % 6)
80                    .slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length]));
81        }
82
83        incidents.get(1).setOffset(200);
84        incidents.get(2).setOffset(3400);
85        incidents.get(3).setOffset(1400);
86        incidents.get(4).setOffset(4400);
87        incidents.get(5).setOffset(1400);
88        //incidents.get(6).setOffset(7600);
89        //incidents.get(7).setOffset(2400);
90        //incidents.get(8).setOffset(4800);
91    }
92
93    public void update(Observable o, Object arg)
94    {
95        if (arg instanceof SliceChangedEvent )
96        {
97            // The slice focus has changed; pass the message
98            setChanged();
99            notifyObservers(arg);
100        }
101        else if (arg instanceof IncidentFocusedEvent)
102        {
103            // The slice focus has changed; pass the message
104            setChanged();
105            notifyObservers(arg);
106        }
107        else
108        {
109            // The script has changed, notify observers
110            setChanged();
111            notifyObservers(this);
112        }
113    }
114}
Note: See TracBrowser for help on using the repository browser.