Changeset 65 in tmcsimulator


Ignore:
Timestamp:
03/16/2017 09:53:13 AM (9 years ago)
Author:
jdalbey
Message:

CADData.java: Change error return value from null to new Incident()

Location:
trunk/src/tmcsim
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/application.properties

    r64 r65  
    1 #Thu, 16 Mar 2017 08:26:10 -0700 
     1#Thu, 16 Mar 2017 08:31:30 -0700 
    22 
    3 Application.revision=63 
     3Application.revision=64 
    44 
    5 Application.buildnumber=44 
     5Application.buildnumber=45 
  • trunk/src/tmcsim/client/cadclientgui/data/CADData.java

    r3 r65  
    44import java.awt.event.ActionListener; 
    55import java.io.Serializable; 
    6 import java.rmi.RemoteException; 
    7 import java.rmi.server.UnicastRemoteObject; 
    86import java.util.Collections; 
    97import java.util.Vector; 
    10  
     8import java.util.logging.Level; 
     9import java.util.logging.Logger; 
    1110import javax.swing.Timer; 
    1211import javax.swing.table.DefaultTableModel; 
    13 import javax.swing.table.TableColumn; 
    14 import javax.swing.table.TableColumnModel; 
    15  
    1612import tmcsim.client.cadclientgui.enums.IncidentEnums; 
    1713import tmcsim.client.cadclientgui.enums.TableHeaders; 
    1814import tmcsim.client.cadclientgui.enums.UnitStatusEnums; 
    19 import tmcsim.interfaces.CADClientInterface; 
    2015 
    2116/** 
    2217 * This class holds the data for all the units and incidents. It is responsible 
    2318 * for sending out data to all the screens. 
    24  *  
     19 * 
    2520 * @author Vincent 
    26  *  
     21 * 
    2722 */ 
    28 public class CADData implements Serializable { 
    29  
     23public class CADData implements Serializable 
     24{ 
    3025    private final int ONE_SECOND = 1000; 
    31  
    3226    private static Vector<Unit> units; 
    3327    private static Vector<Incident> incidents; 
     
    4539    private static DefaultTableModel assignedIncidentsTableModel; 
    4640    private static DefaultTableModel incidentEditorModel; 
    47  
    48     public CADData() { 
     41    private static Logger logger = Logger.getLogger("tmcsim.client"); 
     42 
     43    public CADData() 
     44    { 
    4945        units = new Vector<Unit>(); 
    5046        incidents = new Vector<Incident>(); 
     
    6662        handleUpdateTimes(); 
    6763    } 
    68      
    69     public void clearData(){ 
     64 
     65    public void clearData() 
     66    { 
    7067        units = new Vector<Unit>(); 
    7168        incidents = new Vector<Incident>(); 
    7269    } 
    73      
    74     public void resetSimulation(){ 
    75         for(Incident inc : incidents){ 
     70 
     71    public void resetSimulation() 
     72    { 
     73        for (Incident inc : incidents) 
     74        { 
    7675            inc.resetCADDataSimulation(); 
    7776        } 
    78         for(Unit unit : units){ 
     77        for (Unit unit : units) 
     78        { 
    7979            unit.resetCADDataSimulation(); 
    8080        } 
    8181    } 
    8282 
    83     private void initializeAssignedIncidentsSettings() { 
     83    private void initializeAssignedIncidentsSettings() 
     84    { 
    8485        Collections 
    8586                .addAll(assignedIncidentsHeaders, TableHeaders.ASSIGNED_INCIDENTS_HEADERS); 
    86         assignedIncidentsTableModel = new DefaultTableModel() { 
    87             public boolean isCellEditable(int row, int column) { 
     87        assignedIncidentsTableModel = new DefaultTableModel() 
     88        { 
     89            public boolean isCellEditable(int row, int column) 
     90            { 
    8891                return false;// This causes all cells to be not editable 
    8992            } 
     
    9396    } 
    9497 
    95     private void initializeUnitStatusSettings() { 
     98    private void initializeUnitStatusSettings() 
     99    { 
    96100        Collections.addAll(unitStatusHeaders, TableHeaders.UNIT_STATUS_HEADERS); 
    97         unitStatusTableModel = new DefaultTableModel() { 
    98             public boolean isCellEditable(int row, int column) { 
     101        unitStatusTableModel = new DefaultTableModel() 
     102        { 
     103            public boolean isCellEditable(int row, int column) 
     104            { 
    99105                return false;// This causes all cells to be not editable 
    100106            } 
     
    103109    } 
    104110 
    105     private void initializeIncidentEditorSettings() { 
     111    private void initializeIncidentEditorSettings() 
     112    { 
    106113        Collections.addAll(incidentEditorHeaders, TableHeaders.INCIDENT_EDITOR_HEADERS); 
    107         incidentEditorModel = new DefaultTableModel() { 
    108             public boolean isCellEditable(int row, int column) { 
     114        incidentEditorModel = new DefaultTableModel() 
     115        { 
     116            public boolean isCellEditable(int row, int column) 
     117            { 
    109118                return false;// This causes all cells to be not editable 
    110119            } 
     
    113122    } 
    114123 
    115     private void initializePendingIncidentsSettings() { 
     124    private void initializePendingIncidentsSettings() 
     125    { 
    116126        Collections.addAll(pendingIncidentsHeaders, TableHeaders.PENDING_INCIDENTS_HEADERS); 
    117         pendingIncidentsTableModel = new DefaultTableModel() { 
    118             public boolean isCellEditable(int row, int column) { 
     127        pendingIncidentsTableModel = new DefaultTableModel() 
     128        { 
     129            public boolean isCellEditable(int row, int column) 
     130            { 
    119131                return false;// This causes all cells to be not editable 
    120132            } 
     
    126138    /** 
    127139     * Obtains the list of units from the XML. 
    128      *  
    129      * @param unit 
    130      *            the new list of units. 
    131      */ 
    132     public void setUnitsFromXML(Vector<Unit> unit) { 
     140     * 
     141     * @param unit the new list of units. 
     142     */ 
     143    public void setUnitsFromXML(Vector<Unit> unit) 
     144    { 
    133145        units = unit; 
    134146    } 
     
    136148    /** 
    137149     * Obtains the list of incidents from the XML. 
    138      *  
    139      * @param incident 
    140      *            the new list of incidents. 
    141      */ 
    142     public void setIncidentsFromXML(Vector<Incident> incident) { 
     150     * 
     151     * @param incident the new list of incidents. 
     152     */ 
     153    public void setIncidentsFromXML(Vector<Incident> incident) 
     154    { 
    143155        incidents = incident; 
    144156    } 
     
    147159     * Returns the specified unitNum 
    148160     */ 
    149     public Unit getUnit(String unitNum) { 
    150         for (int i = 0; i < units.size(); i++) { 
    151             if (units.get(i).getUnitNum().equals(unitNum)) { 
     161    public Unit getUnit(String unitNum) 
     162    { 
     163        for (int i = 0; i < units.size(); i++) 
     164        { 
     165            if (units.get(i).getUnitNum().equals(unitNum)) 
     166            { 
    152167                return units.get(i); 
    153168            } 
     
    159174     * Check if it contains an incident with the specified Id. 
    160175     */ 
    161     public boolean checkForValidId(int incidentId) { 
    162         for (int i = 0; i < incidents.size(); i++) { 
    163             if (incidents.get(i).getLogNum() == incidentId) { 
     176    public boolean checkForValidId(int incidentId) 
     177    { 
     178        for (int i = 0; i < incidents.size(); i++) 
     179        { 
     180            if (incidents.get(i).getLogNum() == incidentId) 
     181            { 
    164182                return true; 
    165183            } 
     
    170188    /** 
    171189     * Uses an Incident's masterInc to look up its corresponding ID. 
    172      *  
    173      * @param masterInc 
    174      *            the Incident's masterInc 
     190     * 
     191     * @param masterInc the Incident's masterInc 
    175192     * @return the Incident's ID, -1 if invalid masterInc 
    176193     */ 
    177     public int getIncidentId(String masterInc) { 
    178         for (int i = 0; i < incidents.size(); i++) { 
    179             if (incidents.get(i).getMasterInc().equals(masterInc)) { 
     194    public int getIncidentId(String masterInc) 
     195    { 
     196        for (int i = 0; i < incidents.size(); i++) 
     197        { 
     198            if (incidents.get(i).getMasterInc().equals(masterInc)) 
     199            { 
    180200                return incidents.get(i).getLogNum(); 
    181201            } 
     
    187207     * Returns the specified incident 
    188208     */ 
    189     public Incident getIncident(int incidentId) { 
    190         for (int i = 0; i < incidents.size(); i++) { 
    191             if (incidents.get(i).getLogNum() == incidentId) { 
     209    public Incident getIncident(int incidentId) 
     210    { 
     211        for (int i = 0; i < incidents.size(); i++) 
     212        { 
     213            if (incidents.get(i).getLogNum() == incidentId) 
     214            { 
    192215                return incidents.get(i); 
    193216            } 
    194217        } 
    195         return null; 
     218        logger.logp(Level.INFO, "CADData", 
     219                "getIncident", "id=" + incidentId, "incident not found."); 
     220        return new Incident(0, "", 0); 
    196221    } 
    197222 
    198223    /** 
    199224     * Sends all the objects for UnitStatus 
    200      *  
     225     * 
    201226     * @return DefaultTableModel for UnitStatus 
    202227     */ 
    203     public DefaultTableModel tableForUnitStatus() { 
     228    public DefaultTableModel tableForUnitStatus() 
     229    { 
    204230        toUnitTableVector.clear(); 
    205         for (int i = 0; i < units.size(); i++) { 
     231        for (int i = 0; i < units.size(); i++) 
     232        { 
    206233            toUnitTableVector.add(units.get(i).toVector()); 
    207234        } 
     
    213240    /** 
    214241     * Sends all the objects for AssignedIncidents 
    215      *  
     242     * 
    216243     * @return DefaultTableModel for AssignedIncidents 
    217244     */ 
    218     public DefaultTableModel tableForAssignedIncidents() { 
     245    public DefaultTableModel tableForAssignedIncidents() 
     246    { 
    219247        toAssignedTableVector.clear(); 
    220         for (int i = 0; i < incidents.size(); i++) { 
     248        for (int i = 0; i < incidents.size(); i++) 
     249        { 
    221250            if (incidents.get(i).hasOccured() 
    222                     && incidents.get(i).getIncidentStatus() == IncidentEnums.Assigned) { 
     251                    && incidents.get(i).getIncidentStatus() == IncidentEnums.Assigned) 
     252            { 
    223253                toAssignedTableVector.add(incidents.get(i) 
    224254                        .toVectorForAssignedIncidents()); 
     
    232262    /** 
    233263     * Sends all the objects for PendingIncidents 
    234      *  
     264     * 
    235265     * @return DefaultTableModel for PendingIncidents 
    236266     */ 
    237     public DefaultTableModel tableForPendingIncidents() { 
     267    public DefaultTableModel tableForPendingIncidents() 
     268    { 
    238269        toPendingTableVector.clear(); 
    239         for (int i = 0; i < incidents.size(); i++) { 
     270        for (int i = 0; i < incidents.size(); i++) 
     271        { 
    240272            if (incidents.get(i).hasOccured() 
    241                     && incidents.get(i).getIncidentStatus() == IncidentEnums.Pending) { 
     273                    && incidents.get(i).getIncidentStatus() == IncidentEnums.Pending) 
     274            { 
    242275                toPendingTableVector.add(incidents.get(i) 
    243276                        .toVectorForPendingIncidents()); 
     
    251284    /** 
    252285     * Sends all the objects for IncidentEditor 
    253      *  
     286     * 
    254287     * @return DefaultTableModel for IncidentEditor 
    255288     */ 
    256     public DefaultTableModel tableForIncidentEditor() { 
     289    public DefaultTableModel tableForIncidentEditor() 
     290    { 
    257291        toIncidentEditorVector.clear(); 
    258         for (int i = 0; i < incidents.size(); i++) { 
    259             if (incidents.get(i).hasOccured()) { 
     292        for (int i = 0; i < incidents.size(); i++) 
     293        { 
     294            if (incidents.get(i).hasOccured()) 
     295            { 
    260296                toIncidentEditorVector.add(incidents.get(i) 
    261297                        .toVectorForIncidentEditor()); 
     
    270306     * Sets up a timer to subtract one from the unit's timer every second. 
    271307     */ 
    272     public void handleUpdateTimes() { 
    273         Timer timer = new Timer(ONE_SECOND, new ActionListener() { 
    274             public void actionPerformed(ActionEvent e) { 
    275                 for (int i = 0; i < units.size(); i++) { 
     308    public void handleUpdateTimes() 
     309    { 
     310        Timer timer = new Timer(ONE_SECOND, new ActionListener() 
     311        { 
     312            public void actionPerformed(ActionEvent e) 
     313            { 
     314                for (int i = 0; i < units.size(); i++) 
     315                { 
    276316                    units.get(i).TimerMinusSecond(); 
    277317                } 
     
    280320        timer.start(); 
    281321    } 
    282      
    283     /** 
    284      * Assigns the specified unit to the specified incident and updates information in both screens 
     322 
     323    /** 
     324     * Assigns the specified unit to the specified incident and updates 
     325     * information in both screens 
     326     * 
    285327     * @param unitNum the unit being assigned 
    286328     * @param incidentNum the incident being assigned to 
    287329     * @param primary whether or not the assigned unit is the primary unit 
    288330     */ 
    289      
    290     public void unitAssignedToIncident(String unitNum, int incidentNum, boolean primary){ 
    291         if(primary){ 
     331    public void unitAssignedToIncident(String unitNum, int incidentNum, boolean primary) 
     332    { 
     333        if (primary) 
     334        { 
    292335            getIncident(incidentNum).setPrimaryAssignedUnitNum(unitNum); 
    293336            getIncident(incidentNum).setIncidentStatus(IncidentEnums.Assigned); 
    294         }else{ 
     337        } 
     338        else 
     339        { 
    295340            getIncident(incidentNum).addAssignedUnitNum(unitNum); 
    296341        } 
    297              
     342 
    298343        getUnit(unitNum).setAssignedIncidentId(incidentNum); 
    299344        getUnit(unitNum).setMasterInc(getIncident(incidentNum).getMasterInc()); 
     
    302347        getUnit(unitNum).setType(getIncident(incidentNum).getAdditionalInfo().getType()); 
    303348        getUnit(unitNum).setDestination(getIncident(incidentNum).getIncidentLocation().getAddress()); 
    304         getUnit(unitNum).setArea(getIncident(incidentNum).getIncidentLocation().getArea());  
     349        getUnit(unitNum).setArea(getIncident(incidentNum).getIncidentLocation().getArea()); 
    305350        getUnit(unitNum).setP(getIncident(incidentNum).getP()); 
    306351    } 
    307      
    308     /** 
    309      * Updates information in both incident and unit screens for when a unit has arrived at scene 
    310      * aka that the unit status is "10-97" 
     352 
     353    /** 
     354     * Updates information in both incident and unit screens for when a unit has 
     355     * arrived at scene aka that the unit status is "10-97" 
     356     * 
    311357     * @param unitNum the unit which arrived at the scene 
    312358     */ 
    313     public void unitArrivedAtIncidentScene(String unitNum, int incidentNum, boolean primary){ 
    314         if(getUnit(unitNum).getAssignedIncidentId() != incidentNum){ 
    315             if(primary){ 
     359    public void unitArrivedAtIncidentScene(String unitNum, int incidentNum, boolean primary) 
     360    { 
     361        if (getUnit(unitNum).getAssignedIncidentId() != incidentNum) 
     362        { 
     363            if (primary) 
     364            { 
    316365                getIncident(incidentNum).setPrimaryAssignedUnitNum(unitNum); 
    317366                getIncident(incidentNum).setIncidentStatus(IncidentEnums.Assigned); 
    318             }else{ 
     367            } 
     368            else 
     369            { 
    319370                getIncident(incidentNum).addAssignedUnitNum(unitNum); 
    320371            } 
     
    323374            getUnit(unitNum).setType(getIncident(incidentNum).getAdditionalInfo().getType()); 
    324375            getUnit(unitNum).setDestination(getIncident(incidentNum).getIncidentLocation().getAddress()); 
    325             getUnit(unitNum).setArea(getIncident(incidentNum).getIncidentLocation().getArea());  
     376            getUnit(unitNum).setArea(getIncident(incidentNum).getIncidentLocation().getArea()); 
    326377            getUnit(unitNum).setP(getIncident(incidentNum).getP()); 
    327378        } 
     
    330381        getUnit(unitNum).setCurrentLocation(getUnit(unitNum).getDestination()); 
    331382    } 
    332      
    333     /** 
    334      * Updates information in both incident and unit screens for when a unit has become available again 
    335      * aka that the unit status is "10-98" 
     383 
     384    /** 
     385     * Updates information in both incident and unit screens for when a unit has 
     386     * become available again aka that the unit status is "10-98" 
     387     * 
    336388     * @param unitNum the unit which arrived at the scene 
    337389     */ 
    338     public void unitAvailable(String unitNum){ 
     390    public void unitAvailable(String unitNum) 
     391    { 
    339392        getIncident(getUnit(unitNum).getAssignedIncidentId()).removeAssignedUnitNum(unitNum); 
    340          
     393 
    341394        getUnit(unitNum).setStatus("10-98"); 
    342395        getUnit(unitNum).setUnitStatus(UnitStatusEnums.Assignable); 
     
    346399        getUnit(unitNum).setDestination(""); 
    347400        getUnit(unitNum).setP(""); 
    348          
     401 
    349402    } 
    350403} 
Note: See TracChangeset for help on using the changeset viewer.