Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/SimulationScript.java


Ignore:
Timestamp:
11/04/2019 08:14:32 AM (6 years ago)
Author:
sdanthin
Message:

Move from Git to Svn (LARGE COMMIT)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/structures/SimulationScript.java

    r131 r145  
    2121 * 
    2222 * @author Bryan McGuffin <bmcguffi@calpoly.edu> 
     23 * @author Sebastien Danthinne <sdanthin@calpoly.edu> 
    2324 * @version 2017/06/22 
    2425 */ 
     
    6162     * The units which participate in Unit events. 
    6263     */ 
    63     public List<Unit> units; 
     64    public List<Unit> units;  
    6465 
    6566    //Somewhere in the code, something assumes that the list of incidents 
    6667    //contains exactly 10 items. Until I can find and un-break that, this will do. 
     68    //todo: this incident fill count error 
    6769    private final int INCIDENT_FILL_COUNT = 10; 
    6870 
     
    7678     */ 
    7779    private MyScriptHandler sh; 
     80     
     81    public boolean saved; 
    7882 
    7983    //TODO: Pretty much everything in this constructor is dummy data. 
     
    8993        units = new ArrayList<Unit>(); 
    9094        numberOfIncidents = 0; 
     95        saved = true; 
    9196 
    9297        //Backfill with null incidents 
     
    96101        } 
    97102    } 
    98  
     103     
     104    /** 
     105     * checks and sees if this object has the unit passed. 
     106     * @param unitID 
     107     * @return does this SimulationScript have unitnum? 
     108     */ 
     109    public boolean hasUnit(String unitID){ 
     110        boolean indicator = false; 
     111        if(units.size()!=0){ 
     112            for(Unit u : units){ 
     113               if(unitID.equals(u.UnitNum)){ 
     114                   indicator = true; 
     115               } 
     116            } 
     117        } 
     118             
     119        return indicator; 
     120    } 
     121    /** 
     122     * creates a dummy unit that only has unit number 
     123     * @param unitNum  
     124     */ 
     125    public void addDummyUnit(String unitNum){ 
     126        Unit dummy = new Unit(); 
     127        dummy.UnitNum = unitNum; 
     128        units.add(dummy); 
     129    } 
    99130    /** 
    100131     * Update the script's observers. 
    101      * 
     132     *  
    102133     */ 
    103134    public void update() 
    104135    { 
    105136        // The script has changed, notify observers 
     137        //use to rewrite the save indicator 
     138        //System.out.println("Script changed"); 
    106139        setChanged(); 
    107140        notifyObservers(this); 
    108     } 
     141        saved = false; 
     142         
     143         
     144    } 
     145     
    109146 
    110147    /** 
     
    154191        { 
    155192            System.out.println("ERROR LOADING SCRIPT"); 
     193            ex.printStackTrace(); 
     194        } 
     195        System.out.println("H"); 
     196        for(Unit testUnit : units){ 
     197            System.out.println(testUnit.toXML()); 
     198        } 
     199        this.update(); 
     200    } 
     201     
     202    /** 
     203     * Load in an existing list of units from an XML file. 
     204     * @param f the file containing the units 
     205     */ 
     206    public void loadUnitsFromFile(File f){ 
     207        try 
     208        { 
     209            SAXParserFactory.newInstance().newSAXParser().parse(f, sh); 
     210            units.addAll(sh.getUnits()); 
     211        } 
     212        catch (Exception ex) 
     213        { 
     214            System.out.println("ERROR LOADING UNITS"); 
    156215            ex.printStackTrace(); 
    157216        } 
     
    197256            ex.printStackTrace(); 
    198257        } 
     258        saved = true; 
    199259    } 
    200260 
Note: See TracChangeset for help on using the changeset viewer.