Changeset 182 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures


Ignore:
Timestamp:
01/11/2020 05:45:23 PM (6 years ago)
Author:
jdalbey
Message:

Modifications to ScriptBuilderFrame?, SimulationScript?, MyScriptHandler? to fix #217

Location:
trunk/src/scriptbuilder/structures
Files:
2 edited

Legend:

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

    r170 r182  
    749749            else if (currentElement == ELEMENT.COLOR) 
    750750            { 
    751                 currInc.color = incColor; 
     751                // Validate that the color read is actually a legal color 
     752                // then assign it to the incident 
     753                currInc.color = SimulationScript.incidentColors[SimulationScript.lookupColor(incColor)]; 
    752754            } 
    753755            else if (currentElement == ELEMENT.EXPECTED_ACTION) 
     
    906908                if (incidentMap.get(incidentLogNumber) == null) 
    907909                { 
     910                    // Select a random color to display for this incident 
     911                    // Will be overriden if a color tag is provided. 
    908912                    Color newColor = SimulationScript.incidentColors[Math.abs(new Random().nextInt()) 
    909913                            % SimulationScript.incidentColors.length]; 
    910  
     914                     
    911915                    incidentMap.put(incidentLogNumber, 
    912916                            new ScriptIncident(newColor, 
  • trunk/src/scriptbuilder/structures/SimulationScript.java

    r169 r182  
    3333 
    3434    /** 
    35      * All default options for GUI colorings of incidents. 
    36      */ 
    37     public static final Color[] incidentColors = 
    38     { 
    39         Color.BLACK, 
    40         Color.BLUE, 
    41         Color.RED, 
    42         new Color(0x38, 0x5E, 0x0F), 
    43         new Color(128, 0, 128), 
    44         Color.MAGENTA, 
    45         new Color(0x23, 0x6B, 0x8E), 
    46         Color.ORANGE, 
    47         new Color(0x60, 0x33, 0x11), 
    48         Color.GRAY 
    49     }; 
    50  
     35     * Strings to show in the incident color combo box.  Last item should be black, 
     36     * which will be used if invalid color is provided to lookupColor(). 
     37     */ 
     38    public static final String[] colorNames = {"BLUE", "RED", "CYAN", "GREEN",  
     39        "ORANGE", "MAGENTA", "YELLOW", "BLACK"}; 
     40    /**  
     41     * Allowed color choices for incident display.  
     42     * These colors must match the items in colorNames. 
     43     */ 
     44    public static final Color[] incidentColors = {Color.BLUE, Color.RED, Color.CYAN,  
     45        Color.GREEN, Color.ORANGE, Color.MAGENTA, Color.YELLOW, Color.BLACK}; 
    5146    /** 
    5247     * The file to which this script will be saved. 
     
    428423        return count; 
    429424    } 
    430  
     425     
     426    /** Given a color, find its index in the incidentColors. 
     427     * @param color a java color  
     428     * @return the index of color in incidentColors, or last index if color isn't  
     429     * in incidentColors.  The last item in incidentColors should be black. 
     430     */ 
     431    public static int lookupColor(Color color) 
     432    { 
     433        int idx = 0; 
     434        // search color array for target 
     435        while(idx < incidentColors.length && !incidentColors[idx].equals(color)) 
     436        {  
     437            idx++; 
     438        } 
     439        // if color not found, return index of last item. 
     440        if (idx == incidentColors.length)  
     441        { 
     442            return idx-1; 
     443        } 
     444        else return idx; 
     445    } 
    431446} 
Note: See TracChangeset for help on using the changeset viewer.