Changeset 177 in tmcsimulator-scriptbuilder
- Timestamp:
- 12/22/2019 02:45:25 PM (6 years ago)
- Location:
- trunk/src/scriptbuilder/gui
- Files:
-
- 2 edited
-
ScriptBuilderFrame.form (modified) (5 diffs)
-
ScriptBuilderFrame.java (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/gui/ScriptBuilderFrame.form
r151 r177 258 258 <Component id="addIncidentName" pref="199" max="32767" attributes="0"/> 259 259 <Component id="addIncidentNumber" alignment="0" pref="199" max="32767" attributes="0"/> 260 <Group type="102" alignment=" 1" attributes="0">261 <Component id="incidentColorField" pref="97" max="32767" attributes="0"/>260 <Group type="102" alignment="0" attributes="0"> 261 <Component id="incidentColorField" min="-2" pref="55" max="-2" attributes="0"/> 262 262 <EmptySpace max="-2" attributes="0"/> 263 <Component id=" btnChooseColor" min="-2" pref="93" max="-2" attributes="0"/>263 <Component id="colorComboBox" max="32767" attributes="0"/> 264 264 </Group> 265 265 </Group> … … 320 320 <Group type="103" groupAlignment="3" attributes="0"> 321 321 <Component id="labelIncidentColor" alignment="3" min="-2" max="-2" attributes="0"/> 322 <Component id="btnChooseColor" alignment="3" min="-2" max="-2" attributes="0"/>323 322 <Component id="incidentColorField" alignment="3" min="-2" max="-2" attributes="0"/> 323 <Component id="colorComboBox" alignment="3" min="-2" max="-2" attributes="0"/> 324 324 </Group> 325 325 <EmptySpace max="-2" attributes="0"/> … … 336 336 <Component id="labelIncidentDescription" min="-2" max="-2" attributes="0"/> 337 337 <EmptySpace max="-2" attributes="0"/> 338 <Component id="incidentPropertiesScrollPane" pref="13 0" max="32767" attributes="0"/>338 <Component id="incidentPropertiesScrollPane" pref="132" max="32767" attributes="0"/> 339 339 <EmptySpace max="-2" attributes="0"/> 340 340 <Group type="103" groupAlignment="3" attributes="0"> … … 444 444 </Properties> 445 445 </Component> 446 <Component class="javax.swing.JButton" name="btnChooseColor">447 <Properties>448 <Property name="text" type="java.lang.String" value="Choose..."/>449 </Properties>450 <Events>451 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnChooseColorActionPerformed"/>452 </Events>453 </Component>454 446 <Component class="javax.swing.JTextField" name="incidentColorField"> 455 447 <Properties> … … 483 475 </Component> 484 476 <Component class="javax.swing.JTextField" name="addIncidentType"> 477 </Component> 478 <Component class="javax.swing.JComboBox" name="colorComboBox"> 479 <Properties> 480 <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> 481 <Connection code="new DefaultComboBoxModel(colorModel)" type="code"/> 482 </Property> 483 </Properties> 484 <Events> 485 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="colorSelectedHandler"/> 486 </Events> 487 <AuxValues> 488 <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/> 489 </AuxValues> 485 490 </Component> 486 491 </SubComponents> -
trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java
r163 r177 32 32 import java.util.logging.Level; 33 33 import java.util.logging.Logger; 34 import javax.swing.DefaultComboBoxModel; 34 35 import javax.swing.DefaultListModel; 35 36 import javax.swing.JFileChooser; … … 79 80 */ 80 81 private int oldIncidentIndex; 81 82 /** 83 * incident color 84 */ 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}; 82 96 /** 83 97 * Get the script currently in use. … … 407 421 labelIncidentStart = new javax.swing.JLabel(); 408 422 addIncidentStart = new javax.swing.JSpinner(); 409 btnChooseColor = new javax.swing.JButton();410 423 incidentColorField = new javax.swing.JTextField(); 411 424 txtIncidentLength = new javax.swing.JLabel(); … … 414 427 jLabel2 = new javax.swing.JLabel(); 415 428 addIncidentType = new javax.swing.JTextField(); 429 colorComboBox = new javax.swing.JComboBox<>(); 416 430 addNoiseFrame = new javax.swing.JFrame(); 417 431 labelRadioChatter = new javax.swing.JLabel(); … … 681 695 addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1)); 682 696 683 btnChooseColor.setText("Choose...");684 btnChooseColor.addActionListener(new java.awt.event.ActionListener() {685 public void actionPerformed(java.awt.event.ActionEvent evt) {686 btnChooseColorActionPerformed(evt);687 }688 });689 690 697 incidentColorField.setEditable(false); 691 698 incidentColorField.setBackground(new java.awt.Color(0, 0, 0)); … … 704 711 705 712 jLabel2.setText("Incident Type:"); 713 714 colorComboBox.setModel(new DefaultComboBoxModel(colorModel)); 715 colorComboBox.addActionListener(new java.awt.event.ActionListener() { 716 public void actionPerformed(java.awt.event.ActionEvent evt) { 717 colorSelectedHandler(evt); 718 } 719 }); 706 720 707 721 javax.swing.GroupLayout incidentFrameLayout = new javax.swing.GroupLayout(incidentFrame.getContentPane()); … … 722 736 .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 723 737 .addComponent(addIncidentNumber, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 724 .addGroup( javax.swing.GroupLayout.Alignment.TRAILING,incidentFrameLayout.createSequentialGroup()725 .addComponent(incidentColorField, javax.swing.GroupLayout. DEFAULT_SIZE, 97, Short.MAX_VALUE)738 .addGroup(incidentFrameLayout.createSequentialGroup() 739 .addComponent(incidentColorField, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) 726 740 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 727 .addComponent( btnChooseColor, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))))741 .addComponent(colorComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) 728 742 .addGroup(incidentFrameLayout.createSequentialGroup() 729 743 .addComponent(incidentCancelButton) … … 768 782 .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 769 783 .addComponent(labelIncidentColor) 770 .addComponent( btnChooseColor)771 .addComponent( incidentColorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))784 .addComponent(incidentColorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 785 .addComponent(colorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 772 786 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 773 787 .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) … … 781 795 .addComponent(labelIncidentDescription) 782 796 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 783 .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 13 0, Short.MAX_VALUE)797 .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE) 784 798 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 785 799 .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) … … 1334 1348 1335 1349 scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() { 1336 public void ancestorMoved(javax.swing.event.AncestorEvent evt) {1337 }1338 1350 public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 1339 1351 scriptBuilderMenuBarAncestorAdded(evt); 1340 1352 } 1341 1353 public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 1354 } 1355 public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 1342 1356 } 1343 1357 }); … … 1798 1812 addIncidentStart.setValue(0); 1799 1813 txtIncidentLength.setText("0"); 1800 incidentColorField.setBackground(Color.BLACK); 1801 String colStr = "" + Integer.toHexString(Color.BLACK.getRed()) 1802 + Integer.toHexString(Color.BLACK.getGreen()) 1803 + Integer.toHexString(Color.BLACK.getBlue()); 1804 incidentColorField.setText(colStr); 1805 selectedColor = Color.BLACK; 1814 selectedColor = colorChoices[0]; 1815 incidentColorField.setBackground(colorChoices[0]); 1816 colorComboBox.setSelectedIndex(0); 1806 1817 addIncidentDescription.setText(""); 1807 1818 addIncidentLocation.setText(""); … … 1948 1959 //addIncidentLength.setValue(i.length / 60); 1949 1960 incidentColorField.setBackground(i.color); 1950 String colStr = "" + Integer.toHexString(i.color.getRed()) 1951 + Integer.toHexString(i.color.getGreen()) 1952 + Integer.toHexString(i.color.getBlue()); 1953 incidentColorField.setText(colStr); 1961 colorComboBox.setSelectedIndex(lookupColor(i.color)); 1954 1962 selectedColor = i.color; 1955 1963 addIncidentDescription.setText(i.description); … … 2204 2212 } 2205 2213 }//GEN-LAST:event_zoomOutIconMouseClicked 2206 private Color selectedColor = Color.BLACK; 2207 2208 private void btnChooseColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseColorActionPerformed 2209 //For whatever reason, this causes the incident properties frame to be hidden 2210 //this needs to be changed to edit only a certain number of colors, perhaps only the colors that are specified by java.awt.Color 2211 2212 Color newColor = incidentColorChooser.showDialog(this, "Incident Color", incidentColorField.getBackground()); 2213 // Color newColor = Color.BLUE; 2214 // JColorChooser chooser = (new JColorChooser(incidentColorField.getBackground())); 2215 // AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); 2216 // for(AbstractColorChooserPanel panel:panels) 2217 // { 2218 // System.out.println(panel.getDisplayName()); 2219 // } 2220 // chooser.setPreviewPanel(new JPanel()); 2221 // JColorChooser.createDialog( 2222 // this.getParent(), 2223 // "Choose an Incident Color", 2224 // true, 2225 // chooser,null,null 2226 // ).setVisible(true); 2227 if (newColor != null) 2228 { 2229 //If the user selected a color, apply it to the properties frame 2230 selectedColor = newColor; 2231 incidentColorField.setBackground(newColor); 2232 String colStr = "" + Integer.toHexString(newColor.getRed()) 2233 + Integer.toHexString(newColor.getGreen()) 2234 + Integer.toHexString(newColor.getBlue()); 2235 incidentColorField.setText(colStr); 2236 } 2237 //Return focus to the properties frame 2238 incidentFrame.setVisible(true); 2239 }//GEN-LAST:event_btnChooseColorActionPerformed 2214 2240 2215 2241 2216 /* Help > About simply displays the current SVN revision number so … … 2411 2386 //addIncidentLength.setValue(i.length / 60); 2412 2387 incidentColorField.setBackground(i.color); 2388 colorComboBox.setSelectedIndex(lookupColor(i.color)); 2413 2389 selectedColor = i.color; 2414 2390 addIncidentDescription.setText(i.description); … … 2461 2437 // script.loadUnitsFromFile(f); 2462 2438 }//GEN-LAST:event_scriptBuilderMenuBarAncestorAdded 2439 /** Handle a user selection in the incident color combo box. 2440 * @author jdalbey 2441 */ 2442 private void colorSelectedHandler(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colorSelectedHandler 2443 // Save the chosen color 2444 int index = colorComboBox.getSelectedIndex(); 2445 selectedColor = colorChoices[index]; 2446 incidentColorField.setBackground(selectedColor); 2447 }//GEN-LAST:event_colorSelectedHandler 2448 /** Given a color, find its index in the color Choices. 2449 * @param color a java color 2450 * @pre color exists in color choices 2451 */ 2452 private int lookupColor(Color color) 2453 { 2454 int idx = 0; 2455 while(idx < colorChoices.length && colorChoices[idx] != color) 2456 { 2457 idx++; 2458 } 2459 return idx; 2460 } 2463 2461 2464 2462 /** … … 2542 2540 private javax.swing.JButton btnAddTime; 2543 2541 private javax.swing.JButton btnCancelNoise; 2544 private javax.swing.JButton btnChooseColor;2545 2542 private javax.swing.JButton btnGenerateNoise; 2546 2543 private javax.swing.JMenuItem cadEvent; 2547 2544 private javax.swing.JFrame cadEventFrame; 2548 2545 private javax.swing.JButton cancelButton; 2546 private javax.swing.JComboBox<String> colorComboBox; 2549 2547 private javax.swing.JMenuItem deleteEventList; 2550 2548 private javax.swing.JMenuItem deleteIncident;
Note: See TracChangeset
for help on using the changeset viewer.
