Warning: Can't use blame annotator:
svn blame failed on trunk/src/scriptbuilder/structures/ScriptEvent.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/structures/ScriptEvent.java @ 185

Revision 185, 5.7 KB checked in by jdalbey, 6 years ago (diff)

CADEvent.java added a toString() method with text that will appear in tooltip and Script Event panel.

RevLine 
1package scriptbuilder.structures;
2
3import java.util.Observable;
4import scriptbuilder.structures.events.*;
5
6/**
7 * A single script event. It has an event type, and a duration (in seconds) of
8 * at least 1. It is comparable based on event type.
9 *
10 * @author Greg Eddington <geddingt@calpoly.edu>
11 * @author Bryan McGuffin
12 * @version 2017/06/30
13 */
14public abstract class ScriptEvent extends Observable implements I_ScriptEvent
15{
16
17    /**
18     * Compare the Script Events based on their type enum.
19     *
20     * @param a the other script event to be compared
21     * @return -1, 0, or 1 depending on if this event's type comes before,
22     * simultaneously, or after the other event's type in the enum list
23     */
24    @Override
25    public int compareTo(Object a)
26    {
27        ScriptEvent o = (ScriptEvent) a;
28        return this.type.compareTo(o.type);
29    }
30
31    @Override
32    public int getLength()
33    {
34        return length;
35    }
36
37    /**
38     * The different possible event types, ordered by event domain and then
39     * alphabetically. The string parameter of each type is the name of a .png
40     * image which will be used as an icon to represent that event type.
41     */
42    public static enum ScriptEventType
43    {
44
45        CAD_EVENT("CAD"),
46        UNIT_EVENT("Unit"),
47        TOW_EVENT("Tow"),
48        WITNESS_EVENT("Witness"),
49        AUDIO_EVENT("Audio"),
50        CCTV_EVENT("CCTV"),
51        CHP_RADIO_EVENT("CHPRadio"),
52        PARAMICS_EVENT("Paramics"),
53        TELEPHONE_EVENT("Telephone"),
54        CAD_EVAL_EVENT("CADEval"),
55        ATMS_EVAL_EVENT("ATMSEval"),
56        CMS_EVAL_EVENT("CMSEval"),
57        ACTIVITY_LOG_EVAL_EVENT("ActivityLogEval"),
58        FACILITATOR_EVAL_EVENT("FacilitatorEval"),
59        RADIO_EVAL_EVENT("RadioEval"),
60        MAINTENANCE_RADIO_EVENT("MaintenanceRadio"),
61        TMT_RADIO_EVENT("TMTRadio");
62
63        /**
64         * The file name of a PNG image to be used as the icon for this event
65         * type.
66         */
67        public String IMAGE_NAME;
68
69        private ScriptEventType(String image)
70        {
71            this.IMAGE_NAME = image;
72        }
73    }
74
75    /**
76     * The Event type, from the enum of ScriptEventType.
77     */
78    private ScriptEventType type;
79
80    /**
81     * Number of seconds this event lasts
82     */
83    public int length;
84   
85    public TimeSlice slice;
86
87    /**
88     * Constructor with type and length parameters.
89     *
90     * @param type The type of event.
91     * @param l the duration of the event in seconds.
92     */
93    public ScriptEvent(ScriptEventType type, int l)
94    {
95        this.type = type;
96        this.length = l;
97    }
98
99    /**
100     * Constructor with no length parameter. Event length will default to 1
101     * second.
102     *
103     * @param type The type of event.
104     */
105    public ScriptEvent(ScriptEventType type)
106    {
107        this.type = type;
108        this.length = 1;
109    }
110
111    /**
112     * Get the event type of this ScriptEvent.
113     *
114     * @return The enum type of the event
115     */
116    public ScriptEventType getScriptEventType()
117    {
118        return type;
119    }
120
121    /**
122     * Get the string representation of this event. This string will be used in
123     * the tooltip text when the user hover the mouse over this event.
124     *
125     * @return A string containing this event's type, and a STUB where its
126     * description will go later.
127     */
128    @Override
129    public String toString()
130    {
131        return this.type.toString() + " - [Event Details will appear here.]";
132    }
133
134    /**
135     * Generate a new script event object of the specified type.
136     *
137     * @param t the type of the script event
138     * @return a new I_ScriptEvent object matching the given type
139     */
140    public static I_ScriptEvent factoryByType(ScriptEventType t)
141    {
142        switch (t)
143        {
144            case AUDIO_EVENT:
145                return new AudioEvent();
146            case CAD_EVENT:
147                return new CADEvent();
148            case CCTV_EVENT:
149                return new CCTVEvent();
150            case CHP_RADIO_EVENT:
151                return new CHPRadioEvent();
152            case PARAMICS_EVENT:
153                return new ParamicsEvent();
154            case TOW_EVENT:
155                return new TowEvent();
156            case UNIT_EVENT:
157                return new UnitEvent();
158            case WITNESS_EVENT:
159                return new WitnessEvent();
160            case MAINTENANCE_RADIO_EVENT:
161                return new MaintenanceRadioEvent();
162            case TMT_RADIO_EVENT:
163                return new TMTRadioEvent();
164            case TELEPHONE_EVENT:
165                return new TelephoneEvent();
166            case ATMS_EVAL_EVENT:
167                return new ATMSEvaluationEvent();
168            case ACTIVITY_LOG_EVAL_EVENT:
169                return new ActivityLogEvaluationEvent();
170            case CAD_EVAL_EVENT:
171                return new CADEvaluationEvent();
172            case CMS_EVAL_EVENT:
173                return new CMSEvaluationEvent();
174            case FACILITATOR_EVAL_EVENT:
175                return new FacilitatorEvaluationEvent();
176            case RADIO_EVAL_EVENT:
177                return new RadioEvaluationEvent();
178            default:
179                return new TelephoneEvent();
180        }
181    }
182
183    /**
184     * Determines if the event in question is an evaluation event.
185     *
186     * @param event the event to be checked
187     * @return true if the event implements I_EvaluationEvent
188     */
189    public static boolean isEvaluationEvent(I_ScriptEvent event)
190    {
191        return event instanceof I_EvaluationEvent;
192    }
193   
194    @Override
195    public void removeThis()
196    {
197        this.slice.events.remove(this);
198        this.slice.checkEmpty();
199    }
200   
201    @Override
202    public void assignTimeSlice(TimeSlice ts)
203    {
204        this.slice = ts;
205    }
206}
Note: See TracBrowser for help on using the repository browser.