Changeset 182 in tmcsimulator-scriptbuilder


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
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.form

    r177 r182  
    479479          <Properties> 
    480480            <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 
    481               <Connection code="new DefaultComboBoxModel(colorModel)" type="code"/> 
     481              <Connection code="new DefaultComboBoxModel(SimulationScript.colorNames)" type="code"/> 
    482482            </Property> 
    483483          </Properties> 
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java

    r179 r182  
    8484     */ 
    8585    private Color selectedColor; 
    86      /** 
    87      * Strings to show in the incident color combo box 
    88      */ 
    89     private final String[] colorModel = {"BLUE", "RED", "CYAN", "GREEN",  
    90         "ORANGE", "MAGENTA", "YELLOW", "BLACK"}; 
    91     /**  
    92      * Allowed color choices. These colors must match the items in the combobox. 
    93      */ 
    94     private final Color[] colorChoices = {Color.BLUE, Color.RED, Color.CYAN,  
    95         Color.GREEN, Color.ORANGE, Color.MAGENTA, Color.YELLOW, Color.BLACK}; 
     86 
    9687    /** 
    9788     * Get the script currently in use. 
     
    712703        jLabel2.setText("Incident Type:"); 
    713704 
    714         colorComboBox.setModel(new DefaultComboBoxModel(colorModel)); 
     705        colorComboBox.setModel(new DefaultComboBoxModel(SimulationScript.colorNames)); 
    715706        colorComboBox.addActionListener(new java.awt.event.ActionListener() { 
    716707            public void actionPerformed(java.awt.event.ActionEvent evt) { 
     
    13481339 
    13491340        scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() { 
     1341            public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 
     1342            } 
    13501343            public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 
    13511344                scriptBuilderMenuBarAncestorAdded(evt); 
    13521345            } 
    13531346            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 
    1354             } 
    1355             public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 
    13561347            } 
    13571348        }); 
     
    16311622 
    16321623    /** 
    1633      * Executed when the "OK" button is pressed on the Incident editor. If 
     1624     * Executed when the "OK" button is pressed on the Incident properties window. If 
    16341625     * incident is new, and is valid, adds it to the model and updates. If 
    16351626     * editing existing incident, verifies changes are valid and applies them. 
     
    18131804        addIncidentStart.setValue(0); 
    18141805        txtIncidentLength.setText("0"); 
    1815         selectedColor = colorChoices[0]; 
    1816         incidentColorField.setBackground(colorChoices[0]); 
     1806        selectedColor = SimulationScript.incidentColors[0]; 
     1807        incidentColorField.setBackground(selectedColor); 
    18171808        colorComboBox.setSelectedIndex(0); 
    18181809        addIncidentDescription.setText(""); 
     
    19601951        //addIncidentLength.setValue(i.length / 60); 
    19611952        incidentColorField.setBackground(i.color); 
    1962         colorComboBox.setSelectedIndex(lookupColor(i.color)); 
     1953        colorComboBox.setSelectedIndex(SimulationScript.lookupColor(i.color)); 
    19631954        selectedColor = i.color; 
    19641955        addIncidentDescription.setText(i.description); 
     
    23622353 
    23632354    private void incidentDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incidentDetailsActionPerformed 
    2364         // TODO add your handling code here: 
    23652355        Object[] incidentList = script.incidents.toArray(); 
    23662356        ScriptIncident i = (ScriptIncident) JOptionPane.showInputDialog( 
     
    23872377            //addIncidentLength.setValue(i.length / 60); 
    23882378            incidentColorField.setBackground(i.color); 
    2389             colorComboBox.setSelectedIndex(lookupColor(i.color)); 
     2379            colorComboBox.setSelectedIndex(SimulationScript.lookupColor(i.color)); 
    23902380            selectedColor = i.color; 
    23912381            addIncidentDescription.setText(i.description); 
     
    24442434        // Save the chosen color 
    24452435        int index = colorComboBox.getSelectedIndex(); 
    2446         selectedColor = colorChoices[index]; 
     2436        selectedColor = SimulationScript.incidentColors[index]; 
    24472437        incidentColorField.setBackground(selectedColor); 
    24482438    }//GEN-LAST:event_colorSelectedHandler 
    2449     /** Given a color, find its index in the color Choices. 
    2450      * @param color a java color  
    2451      * @pre color exists in color choices 
    2452      */ 
    2453     private int lookupColor(Color color) 
    2454     { 
    2455         int idx = 0; 
    2456         while(idx < colorChoices.length && colorChoices[idx] != color) 
    2457         {  
    2458             idx++; 
    2459         } 
    2460         return idx; 
    2461     } 
     2439 
    24622440 
    24632441    /** 
     
    25052483        { 
    25062484            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); 
     2485            //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     2486            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); 
    25072487        } 
    25082488        catch (Exception ex) 
  • 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.