| 1 | package tmcsim.client.cadclientgui.data; |
|---|
| 2 | |
|---|
| 3 | import java.text.SimpleDateFormat; |
|---|
| 4 | import java.util.Vector; |
|---|
| 5 | |
|---|
| 6 | import tmcsim.client.cadclientgui.enums.UnitStatusEnums; |
|---|
| 7 | import tmcsim.client.cadclientgui.enums.CADScriptTags.UNIT_TAGS; |
|---|
| 8 | import tmcsim.client.cadclientgui.screens.ScreenManager; |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * This class holds all the data for a unit Object. |
|---|
| 12 | * |
|---|
| 13 | * @author Vincent |
|---|
| 14 | * |
|---|
| 15 | */ |
|---|
| 16 | public class Unit { |
|---|
| 17 | |
|---|
| 18 | /* The init variables are set only from the XML script (readXMLNode method) |
|---|
| 19 | * and are only used for resetCADDataSimulation purposes |
|---|
| 20 | */ |
|---|
| 21 | private String init_id = ""; |
|---|
| 22 | private String init_masterInc = ""; |
|---|
| 23 | private String init_status = ""; |
|---|
| 24 | private String init_oos = ""; |
|---|
| 25 | private String init_type = ""; |
|---|
| 26 | private String init_currentLocation = ""; |
|---|
| 27 | private String init_destination = ""; |
|---|
| 28 | private String init_misc = ""; |
|---|
| 29 | private String init_stack = ""; |
|---|
| 30 | private String init_area = ""; |
|---|
| 31 | private String init_badge = ""; |
|---|
| 32 | private String init_officer = ""; |
|---|
| 33 | private int init_timer = 0; |
|---|
| 34 | private String init_office = ""; |
|---|
| 35 | private String init_p = ""; |
|---|
| 36 | private String init_agy = ""; |
|---|
| 37 | private String init_alias = ""; |
|---|
| 38 | private UnitStatusEnums init_unitStatus = null; |
|---|
| 39 | |
|---|
| 40 | private String id; |
|---|
| 41 | private String masterInc; |
|---|
| 42 | private String unitNum; |
|---|
| 43 | private String status; |
|---|
| 44 | private String oos; |
|---|
| 45 | private String type; |
|---|
| 46 | private String currentLocation; |
|---|
| 47 | private String destination; |
|---|
| 48 | private String misc; |
|---|
| 49 | private String stack; |
|---|
| 50 | private String area; |
|---|
| 51 | private String badge; |
|---|
| 52 | private String officer; |
|---|
| 53 | private int timer; |
|---|
| 54 | private String office; |
|---|
| 55 | private String p; |
|---|
| 56 | private String agy; |
|---|
| 57 | private String alias; |
|---|
| 58 | private UnitStatusEnums unitStatus; |
|---|
| 59 | private int assignedIncidentId; // -1 means not assigned |
|---|
| 60 | |
|---|
| 61 | private Vector<Object> toTableVector; |
|---|
| 62 | |
|---|
| 63 | /* |
|---|
| 64 | * Constructor. Initializes all objects to avoid null pointers. |
|---|
| 65 | */ |
|---|
| 66 | public Unit(String unitNum) { |
|---|
| 67 | this.unitNum = unitNum; |
|---|
| 68 | id = ""; |
|---|
| 69 | masterInc = ""; |
|---|
| 70 | status = ""; |
|---|
| 71 | oos = ""; |
|---|
| 72 | type = ""; |
|---|
| 73 | currentLocation = ""; |
|---|
| 74 | destination = ""; |
|---|
| 75 | misc = ""; |
|---|
| 76 | stack = ""; |
|---|
| 77 | area = ""; |
|---|
| 78 | badge = ""; |
|---|
| 79 | officer = ""; |
|---|
| 80 | timer = 0; |
|---|
| 81 | office = ""; |
|---|
| 82 | p = ""; |
|---|
| 83 | agy = ""; |
|---|
| 84 | alias = ""; |
|---|
| 85 | unitStatus = UnitStatusEnums.Assignable; |
|---|
| 86 | assignedIncidentId = -1; // Negative means not assigned |
|---|
| 87 | |
|---|
| 88 | toTableVector = new Vector<Object>(); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public void resetCADDataSimulation(){ |
|---|
| 92 | id = init_id; |
|---|
| 93 | masterInc = init_masterInc; |
|---|
| 94 | status = init_status; |
|---|
| 95 | oos = init_oos; |
|---|
| 96 | type = init_type; |
|---|
| 97 | currentLocation = init_currentLocation; |
|---|
| 98 | destination = init_destination; |
|---|
| 99 | misc = init_misc; |
|---|
| 100 | stack = init_stack; |
|---|
| 101 | area = init_area; |
|---|
| 102 | badge = init_badge; |
|---|
| 103 | officer = init_officer; |
|---|
| 104 | timer = init_timer; |
|---|
| 105 | office = init_office; |
|---|
| 106 | p = init_p; |
|---|
| 107 | agy = init_agy; |
|---|
| 108 | alias = init_alias; |
|---|
| 109 | if(init_unitStatus == null){ |
|---|
| 110 | unitStatus = UnitStatusEnums.Assignable; |
|---|
| 111 | }else{ |
|---|
| 112 | unitStatus = init_unitStatus; |
|---|
| 113 | } |
|---|
| 114 | assignedIncidentId = -1; // Negative means not assigned |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | public String getId() { |
|---|
| 118 | return id; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | public void setId(String id) { |
|---|
| 122 | this.id = id; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public String getMasterInc() { |
|---|
| 126 | return masterInc; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | public void setMasterInc(String masterInc) { |
|---|
| 130 | this.masterInc = masterInc; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | public String getUnitNum() { |
|---|
| 134 | return unitNum; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | public void setUnitNum(String unitNum) { |
|---|
| 138 | this.unitNum = unitNum; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | public String getStatus() { |
|---|
| 142 | return status; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public void setStatus(String status) { |
|---|
| 146 | this.status = status; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | public String getOos() { |
|---|
| 150 | return oos; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | public void setOos(String oos) { |
|---|
| 154 | this.oos = oos; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | public String getType() { |
|---|
| 158 | return type; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | public void setType(String type) { |
|---|
| 162 | this.type = type; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | public String getCurrentLocation() { |
|---|
| 166 | return currentLocation; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | public void setCurrentLocation(String currentLocation) { |
|---|
| 170 | this.currentLocation = currentLocation; |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | public String getDestination() { |
|---|
| 174 | return destination; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | public void setDestination(String destination) { |
|---|
| 178 | this.destination = destination; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | public String getMisc() { |
|---|
| 182 | return misc; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | public void setMisc(String misc) { |
|---|
| 186 | this.misc = misc; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | public String getStack() { |
|---|
| 190 | return stack; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | public void setStack(String stack) { |
|---|
| 194 | this.stack = stack; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | public String getArea() { |
|---|
| 198 | return area; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | public void setArea(String area) { |
|---|
| 202 | this.area = area; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | public String getBadge() { |
|---|
| 206 | return badge; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | public void setBadge(String badge) { |
|---|
| 210 | this.badge = badge; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | public String getOfficer() { |
|---|
| 214 | return officer; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | public void setOfficer(String officer) { |
|---|
| 218 | this.officer = officer; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | public int getTimer() { |
|---|
| 222 | return timer; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | public void setTimer(int timer) { |
|---|
| 226 | this.timer = timer; |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | public String getOffice() { |
|---|
| 230 | return office; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | public void setOffice(String office) { |
|---|
| 234 | this.office = office; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | public String getP() { |
|---|
| 238 | return p; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | public void setP(String p) { |
|---|
| 242 | this.p = p; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | public String getAgy() { |
|---|
| 246 | return agy; |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | public void setAgy(String agy) { |
|---|
| 250 | this.agy = agy; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | public String getAlias() { |
|---|
| 254 | return alias; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | public void setAlias(String alias) { |
|---|
| 258 | this.alias = alias; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | public UnitStatusEnums getUnitStatus() { |
|---|
| 262 | return unitStatus; |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | public void setUnitStatus(UnitStatusEnums unitStatus) { |
|---|
| 266 | this.unitStatus = unitStatus; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | public int getAssignedIncidentId() { |
|---|
| 270 | return assignedIncidentId; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | public void setAssignedIncidentId(int id) { |
|---|
| 274 | this.assignedIncidentId = id; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | public void resetAssignedIncidentId() { |
|---|
| 278 | id = ""; |
|---|
| 279 | unitStatus = UnitStatusEnums.Assignable; |
|---|
| 280 | this.assignedIncidentId = -1; // represents not assigned |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | public Vector<Object> toVector() { |
|---|
| 284 | toTableVector.clear(); |
|---|
| 285 | |
|---|
| 286 | if (assignedIncidentId >= 0) { |
|---|
| 287 | id = ((Integer) assignedIncidentId).toString(); |
|---|
| 288 | } |
|---|
| 289 | toTableVector.add(id); |
|---|
| 290 | toTableVector.add(masterInc); |
|---|
| 291 | toTableVector.add(unitNum); |
|---|
| 292 | toTableVector.add(status); |
|---|
| 293 | toTableVector.add(oos); |
|---|
| 294 | toTableVector.add(type); |
|---|
| 295 | toTableVector.add(currentLocation); |
|---|
| 296 | toTableVector.add(destination); |
|---|
| 297 | toTableVector.add(misc); |
|---|
| 298 | toTableVector.add(stack); |
|---|
| 299 | toTableVector.add(area); |
|---|
| 300 | toTableVector.add(badge); |
|---|
| 301 | toTableVector.add(officer); |
|---|
| 302 | toTableVector.add(intToHHMMSS(timer)); |
|---|
| 303 | toTableVector.add(office); |
|---|
| 304 | toTableVector.add(p); |
|---|
| 305 | toTableVector.add(agy); |
|---|
| 306 | toTableVector.add(alias); |
|---|
| 307 | toTableVector.add(unitStatus); |
|---|
| 308 | return toTableVector; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | /* |
|---|
| 312 | * Called from the tmc.simulator.cadclient.ScriptHandler.java. Handles |
|---|
| 313 | * storing data based on script tag. |
|---|
| 314 | */ |
|---|
| 315 | public void readXMLNode(String tag_name, String value) { |
|---|
| 316 | if (tag_name.equals(UNIT_TAGS.ID.tag)) { |
|---|
| 317 | init_id = value; |
|---|
| 318 | setId(value); |
|---|
| 319 | } |
|---|
| 320 | if (tag_name.equals(UNIT_TAGS.STATUS.tag)) { |
|---|
| 321 | init_status = value; |
|---|
| 322 | setStatus(value); |
|---|
| 323 | } else if (tag_name.equals(UNIT_TAGS.MASTER_INC_NUM.tag)) { |
|---|
| 324 | init_masterInc = value; |
|---|
| 325 | setMasterInc(value); |
|---|
| 326 | } else if (tag_name.equals(UNIT_TAGS.OOS.tag)) { |
|---|
| 327 | init_oos = value; |
|---|
| 328 | setOos(value); |
|---|
| 329 | } else if (tag_name.equals(UNIT_TAGS.TYPE.tag)) { |
|---|
| 330 | init_type = value; |
|---|
| 331 | setType(value); |
|---|
| 332 | } else if (tag_name.equals(UNIT_TAGS.CURR_LOC.tag)) { |
|---|
| 333 | init_currentLocation = value; |
|---|
| 334 | setCurrentLocation(value); |
|---|
| 335 | } else if (tag_name.equals(UNIT_TAGS.DESTINATION.tag)) { |
|---|
| 336 | init_destination = value; |
|---|
| 337 | setDestination(value); |
|---|
| 338 | } else if (tag_name.equals(UNIT_TAGS.MISC_INFO.tag)) { |
|---|
| 339 | init_misc = value; |
|---|
| 340 | setMisc(value); |
|---|
| 341 | } else if (tag_name.equals(UNIT_TAGS.STACK.tag)) { |
|---|
| 342 | init_stack = value; |
|---|
| 343 | setStack(value); |
|---|
| 344 | } else if (tag_name.equals(UNIT_TAGS.AREA.tag)) { |
|---|
| 345 | init_area = value; |
|---|
| 346 | setArea(value); |
|---|
| 347 | } else if (tag_name.equals(UNIT_TAGS.OFFICER.tag)) { |
|---|
| 348 | init_officer = value; |
|---|
| 349 | setOfficer(value); |
|---|
| 350 | } else if (tag_name.equals(UNIT_TAGS.BADGE_NUM.tag)) { |
|---|
| 351 | init_badge = value; |
|---|
| 352 | setBadge(value); |
|---|
| 353 | } else if (tag_name.equals(UNIT_TAGS.TIMER.tag)) { |
|---|
| 354 | init_timer = Integer.parseInt(value); |
|---|
| 355 | setTimer(Integer.parseInt(value)); |
|---|
| 356 | } else if (tag_name.equals(UNIT_TAGS.OFFICE.tag)) { |
|---|
| 357 | init_office = value; |
|---|
| 358 | setOffice(value); |
|---|
| 359 | } else if (tag_name.equals(UNIT_TAGS.P.tag)) { |
|---|
| 360 | init_p = value; |
|---|
| 361 | setP(value); |
|---|
| 362 | } else if (tag_name.equals(UNIT_TAGS.AGY.tag)) { |
|---|
| 363 | init_agy = value; |
|---|
| 364 | setAgy(value); |
|---|
| 365 | } else if (tag_name.equals(UNIT_TAGS.ALIAS.tag)) { |
|---|
| 366 | init_alias = value; |
|---|
| 367 | setAlias(value); |
|---|
| 368 | } else if (tag_name.equals(UNIT_TAGS.UNIT_STATUS.tag)) { |
|---|
| 369 | init_unitStatus = UnitStatusEnums.valueOf(value); |
|---|
| 370 | setUnitStatus(UnitStatusEnums.valueOf(value)); |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | public String intToHHMMSS(int time) { |
|---|
| 376 | String hhmmss = ""; |
|---|
| 377 | int hms; |
|---|
| 378 | |
|---|
| 379 | hms = time / 3600; |
|---|
| 380 | time = time % 3600; |
|---|
| 381 | hhmmss = hhmmss.concat(((Integer) hms).toString() + ":"); |
|---|
| 382 | |
|---|
| 383 | hms = time / 60; |
|---|
| 384 | time = time % 60; |
|---|
| 385 | hhmmss = hhmmss.concat(((Integer) hms).toString() + ":" |
|---|
| 386 | + ((Integer) time).toString()); |
|---|
| 387 | |
|---|
| 388 | return hhmmss; |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | public void TimerMinusSecond() { |
|---|
| 392 | if (timer > 0) { |
|---|
| 393 | this.timer--; |
|---|
| 394 | } |
|---|
| 395 | } |
|---|
| 396 | |
|---|
| 397 | public String getTimerInString() { |
|---|
| 398 | return intToHHMMSS(timer); |
|---|
| 399 | } |
|---|
| 400 | } |
|---|