| 1 | package scriptbuilder.structures; |
|---|
| 2 | |
|---|
| 3 | import java.util.Observable; |
|---|
| 4 | import 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 | */ |
|---|
| 14 | public abstract class ScriptEvent extends Observable implements I_ScriptEvent |
|---|
| 15 | { |
|---|
| 16 | |
|---|
| 17 | /** |
|---|
| 18 | * Compare the Script Events based on their type enum. |
|---|
| 19 | * |
|---|
| 20 | * @param o 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 | /** |
|---|
| 86 | * Constructor with type and length parameters. |
|---|
| 87 | * |
|---|
| 88 | * @param type The type of event. |
|---|
| 89 | * @param l the duration of the event in seconds. |
|---|
| 90 | */ |
|---|
| 91 | public ScriptEvent(ScriptEventType type, int l) |
|---|
| 92 | { |
|---|
| 93 | this.type = type; |
|---|
| 94 | this.length = l; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | /** |
|---|
| 98 | * Constructor with no length parameter. Event length will default to 1 |
|---|
| 99 | * second. |
|---|
| 100 | * |
|---|
| 101 | * @param type The type of event. |
|---|
| 102 | */ |
|---|
| 103 | public ScriptEvent(ScriptEventType type) |
|---|
| 104 | { |
|---|
| 105 | this.type = type; |
|---|
| 106 | this.length = 1; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * Get the event type of this ScriptEvent. |
|---|
| 111 | * |
|---|
| 112 | * @return The enum type of the event |
|---|
| 113 | */ |
|---|
| 114 | public ScriptEventType getScriptEventType() |
|---|
| 115 | { |
|---|
| 116 | return type; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Get the string representation of this event. This string will be used in |
|---|
| 121 | * the tooltip text when the user hover the mouse over this event. |
|---|
| 122 | * |
|---|
| 123 | * @return A string containing this event's type, and a STUB where its |
|---|
| 124 | * description will go later. |
|---|
| 125 | */ |
|---|
| 126 | @Override |
|---|
| 127 | public String toString() |
|---|
| 128 | { |
|---|
| 129 | return this.type.toString() + " - [Event Description]"; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | public static I_ScriptEvent factoryByType(ScriptEventType t) |
|---|
| 133 | { |
|---|
| 134 | switch (t) |
|---|
| 135 | { |
|---|
| 136 | case AUDIO_EVENT: |
|---|
| 137 | return new AudioEvent(); |
|---|
| 138 | case CAD_EVENT: |
|---|
| 139 | return new CADEvent(); |
|---|
| 140 | case CCTV_EVENT: |
|---|
| 141 | return new CCTVEvent(); |
|---|
| 142 | case CHP_RADIO_EVENT: |
|---|
| 143 | return new CHPRadioEvent(); |
|---|
| 144 | case PARAMICS_EVENT: |
|---|
| 145 | return new ParamicsEvent(); |
|---|
| 146 | case TOW_EVENT: |
|---|
| 147 | return new TowEvent(); |
|---|
| 148 | case UNIT_EVENT: |
|---|
| 149 | return new UnitEvent(); |
|---|
| 150 | case WITNESS_EVENT: |
|---|
| 151 | return new WitnessEvent(); |
|---|
| 152 | case MAINTENANCE_RADIO_EVENT: |
|---|
| 153 | return new MaintenanceRadioEvent(); |
|---|
| 154 | case TMT_RADIO_EVENT: |
|---|
| 155 | return new TMTRadioEvent(); |
|---|
| 156 | case TELEPHONE_EVENT: |
|---|
| 157 | return new TelephoneEvent(); |
|---|
| 158 | case ATMS_EVAL_EVENT: |
|---|
| 159 | return new ATMSEvaluationEvent(); |
|---|
| 160 | case ACTIVITY_LOG_EVAL_EVENT: |
|---|
| 161 | return new ActivityLogEvaluationEvent(); |
|---|
| 162 | case CAD_EVAL_EVENT: |
|---|
| 163 | return new CADEvaluationEvent(); |
|---|
| 164 | case CMS_EVAL_EVENT: |
|---|
| 165 | return new CMSEvaluationEvent(); |
|---|
| 166 | case FACILITATOR_EVAL_EVENT: |
|---|
| 167 | return new FacilitatorEvaluationEvent(); |
|---|
| 168 | case RADIO_EVAL_EVENT: |
|---|
| 169 | return new RadioEvaluationEvent(); |
|---|
| 170 | default: |
|---|
| 171 | return new TelephoneEvent(); |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | } |
|---|