Changeset 138 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/MyScriptHandler.java


Ignore:
Timestamp:
11/29/2017 10:06:59 AM (8 years ago)
Author:
bmcguffin
Message:

Added support for incident color. Color is now read from the xml file; if no color field exists, it picks a random one. Upon saving the file, color is written out in RGB format. The DTD now contains a new field, COLOR, with three attributes: r, g, b.

File:
1 edited

Legend:

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

    r76 r138  
    66package scriptbuilder.structures; 
    77 
     8import java.awt.Color; 
    89import java.util.ArrayList; 
    910import java.util.Random; 
     
    239240    private CadData cad = null; 
    240241 
     242    private Color incColor = null; 
     243 
    241244    /** 
    242245     * Constructor. Initializes incident map. 
     
    382385                } 
    383386            } 
     387            else if (qName.equals(ELEMENT.COLOR.tag)) 
     388            { 
     389                incColor = new Color(Integer.parseInt(attributes.getValue("r")), 
     390                        Integer.parseInt(attributes.getValue("g")), 
     391                        Integer.parseInt(attributes.getValue("b"))); 
     392            } 
    384393            else if (qName.equals(ELEMENT.FACILITATOR_EVALUATION.tag)) 
    385394            { 
     
    458467            { 
    459468                cad = new CadData(); 
     469                //Nullify color 
     470                //This gets overwritten if color tag exists 
     471                incColor = null; 
    460472            } 
    461473 
     
    732744                } 
    733745            } 
     746            else if (currentElement == ELEMENT.COLOR) 
     747            { 
     748                currInc.color = incColor; 
     749            } 
    734750            else if (currentElement == ELEMENT.EXPECTED_ACTION) 
    735751            { 
     
    887903                if (incidentMap.get(incidentLogNumber) == null) 
    888904                { 
     905                    Color newColor = SimulationScript.incidentColors[Math.abs(new Random().nextInt()) 
     906                            % SimulationScript.incidentColors.length]; 
     907 
    889908                    incidentMap.put(incidentLogNumber, 
    890                             new ScriptIncident(SimulationScript.incidentColors[Math.abs(new Random().nextInt()) % SimulationScript.incidentColors.length], 
     909                            new ScriptIncident(newColor, 
    891910                                    incidentLogNumber, currentIncName, currentIncidentDesc, 
    892911                                    script, (int) currentEventTime)); 
     
    919938                    unit.Curr_Loc = pcData.remove(ELEMENT.CURR_LOC); 
    920939                } 
    921                 if (pcData.containsKey(ELEMENT.DESTINATION)) 
     940                if (pcData.containsKey(ELEMENT.DESTINATION))     
    922941                { 
    923942                    unit.Destination = pcData.remove(ELEMENT.DESTINATION); 
Note: See TracChangeset for help on using the changeset viewer.