- Timestamp:
- 01/11/2020 05:45:23 PM (6 years ago)
- Location:
- trunk/src/scriptbuilder
- Files:
-
- 4 edited
-
gui/ScriptBuilderFrame.form (modified) (1 diff)
-
gui/ScriptBuilderFrame.java (modified) (10 diffs)
-
structures/MyScriptHandler.java (modified) (2 diffs)
-
structures/SimulationScript.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/gui/ScriptBuilderFrame.form
r177 r182 479 479 <Properties> 480 480 <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"/> 482 482 </Property> 483 483 </Properties> -
trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java
r179 r182 84 84 */ 85 85 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 96 87 /** 97 88 * Get the script currently in use. … … 712 703 jLabel2.setText("Incident Type:"); 713 704 714 colorComboBox.setModel(new DefaultComboBoxModel( colorModel));705 colorComboBox.setModel(new DefaultComboBoxModel(SimulationScript.colorNames)); 715 706 colorComboBox.addActionListener(new java.awt.event.ActionListener() { 716 707 public void actionPerformed(java.awt.event.ActionEvent evt) { … … 1348 1339 1349 1340 scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() { 1341 public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 1342 } 1350 1343 public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 1351 1344 scriptBuilderMenuBarAncestorAdded(evt); 1352 1345 } 1353 1346 public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 1354 }1355 public void ancestorMoved(javax.swing.event.AncestorEvent evt) {1356 1347 } 1357 1348 }); … … 1631 1622 1632 1623 /** 1633 * Executed when the "OK" button is pressed on the Incident editor. If1624 * Executed when the "OK" button is pressed on the Incident properties window. If 1634 1625 * incident is new, and is valid, adds it to the model and updates. If 1635 1626 * editing existing incident, verifies changes are valid and applies them. … … 1813 1804 addIncidentStart.setValue(0); 1814 1805 txtIncidentLength.setText("0"); 1815 selectedColor = colorChoices[0];1816 incidentColorField.setBackground( colorChoices[0]);1806 selectedColor = SimulationScript.incidentColors[0]; 1807 incidentColorField.setBackground(selectedColor); 1817 1808 colorComboBox.setSelectedIndex(0); 1818 1809 addIncidentDescription.setText(""); … … 1960 1951 //addIncidentLength.setValue(i.length / 60); 1961 1952 incidentColorField.setBackground(i.color); 1962 colorComboBox.setSelectedIndex( lookupColor(i.color));1953 colorComboBox.setSelectedIndex(SimulationScript.lookupColor(i.color)); 1963 1954 selectedColor = i.color; 1964 1955 addIncidentDescription.setText(i.description); … … 2362 2353 2363 2354 private void incidentDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incidentDetailsActionPerformed 2364 // TODO add your handling code here:2365 2355 Object[] incidentList = script.incidents.toArray(); 2366 2356 ScriptIncident i = (ScriptIncident) JOptionPane.showInputDialog( … … 2387 2377 //addIncidentLength.setValue(i.length / 60); 2388 2378 incidentColorField.setBackground(i.color); 2389 colorComboBox.setSelectedIndex( lookupColor(i.color));2379 colorComboBox.setSelectedIndex(SimulationScript.lookupColor(i.color)); 2390 2380 selectedColor = i.color; 2391 2381 addIncidentDescription.setText(i.description); … … 2444 2434 // Save the chosen color 2445 2435 int index = colorComboBox.getSelectedIndex(); 2446 selectedColor = colorChoices[index];2436 selectedColor = SimulationScript.incidentColors[index]; 2447 2437 incidentColorField.setBackground(selectedColor); 2448 2438 }//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 2462 2440 2463 2441 /** … … 2505 2483 { 2506 2484 UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); 2485 //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 2486 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); 2507 2487 } 2508 2488 catch (Exception ex) -
trunk/src/scriptbuilder/structures/MyScriptHandler.java
r170 r182 749 749 else if (currentElement == ELEMENT.COLOR) 750 750 { 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)]; 752 754 } 753 755 else if (currentElement == ELEMENT.EXPECTED_ACTION) … … 906 908 if (incidentMap.get(incidentLogNumber) == null) 907 909 { 910 // Select a random color to display for this incident 911 // Will be overriden if a color tag is provided. 908 912 Color newColor = SimulationScript.incidentColors[Math.abs(new Random().nextInt()) 909 913 % SimulationScript.incidentColors.length]; 910 914 911 915 incidentMap.put(incidentLogNumber, 912 916 new ScriptIncident(newColor, -
trunk/src/scriptbuilder/structures/SimulationScript.java
r169 r182 33 33 34 34 /** 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}; 51 46 /** 52 47 * The file to which this script will be saved. … … 428 423 return count; 429 424 } 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 } 431 446 }
Note: See TracChangeset
for help on using the changeset viewer.
