Changeset 177 in tmcsimulator-scriptbuilder for trunk/src


Ignore:
Timestamp:
12/22/2019 02:45:25 PM (6 years ago)
Author:
jdalbey
Message:

ScriptBuilderFrame?.java Remove color chooser widget from New Incident panel and replace with a simple combo box.

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

Legend:

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

    r151 r177  
    258258                              <Component id="addIncidentName" pref="199" max="32767" attributes="0"/> 
    259259                              <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"/> 
    262262                                  <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"/> 
    264264                              </Group> 
    265265                          </Group> 
     
    320320                  <Group type="103" groupAlignment="3" attributes="0"> 
    321321                      <Component id="labelIncidentColor" alignment="3" min="-2" max="-2" attributes="0"/> 
    322                       <Component id="btnChooseColor" alignment="3" min="-2" max="-2" attributes="0"/> 
    323322                      <Component id="incidentColorField" alignment="3" min="-2" max="-2" attributes="0"/> 
     323                      <Component id="colorComboBox" alignment="3" min="-2" max="-2" attributes="0"/> 
    324324                  </Group> 
    325325                  <EmptySpace max="-2" attributes="0"/> 
     
    336336                  <Component id="labelIncidentDescription" min="-2" max="-2" attributes="0"/> 
    337337                  <EmptySpace max="-2" attributes="0"/> 
    338                   <Component id="incidentPropertiesScrollPane" pref="130" max="32767" attributes="0"/> 
     338                  <Component id="incidentPropertiesScrollPane" pref="132" max="32767" attributes="0"/> 
    339339                  <EmptySpace max="-2" attributes="0"/> 
    340340                  <Group type="103" groupAlignment="3" attributes="0"> 
     
    444444          </Properties> 
    445445        </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> 
    454446        <Component class="javax.swing.JTextField" name="incidentColorField"> 
    455447          <Properties> 
     
    483475        </Component> 
    484476        <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="&lt;String&gt;"/> 
     489          </AuxValues> 
    485490        </Component> 
    486491      </SubComponents> 
  • trunk/src/scriptbuilder/gui/ScriptBuilderFrame.java

    r163 r177  
    3232import java.util.logging.Level; 
    3333import java.util.logging.Logger; 
     34import javax.swing.DefaultComboBoxModel; 
    3435import javax.swing.DefaultListModel; 
    3536import javax.swing.JFileChooser; 
     
    7980     */ 
    8081    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}; 
    8296    /** 
    8397     * Get the script currently in use. 
     
    407421        labelIncidentStart = new javax.swing.JLabel(); 
    408422        addIncidentStart = new javax.swing.JSpinner(); 
    409         btnChooseColor = new javax.swing.JButton(); 
    410423        incidentColorField = new javax.swing.JTextField(); 
    411424        txtIncidentLength = new javax.swing.JLabel(); 
     
    414427        jLabel2 = new javax.swing.JLabel(); 
    415428        addIncidentType = new javax.swing.JTextField(); 
     429        colorComboBox = new javax.swing.JComboBox<>(); 
    416430        addNoiseFrame = new javax.swing.JFrame(); 
    417431        labelRadioChatter = new javax.swing.JLabel(); 
     
    681695        addIncidentStart.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1)); 
    682696 
    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  
    690697        incidentColorField.setEditable(false); 
    691698        incidentColorField.setBackground(new java.awt.Color(0, 0, 0)); 
     
    704711 
    705712        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        }); 
    706720 
    707721        javax.swing.GroupLayout incidentFrameLayout = new javax.swing.GroupLayout(incidentFrame.getContentPane()); 
     
    722736                            .addComponent(addIncidentName, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) 
    723737                            .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) 
    726740                                .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)))) 
    728742                    .addGroup(incidentFrameLayout.createSequentialGroup() 
    729743                        .addComponent(incidentCancelButton) 
     
    768782                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
    769783                    .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)) 
    772786                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    773787                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
     
    781795                .addComponent(labelIncidentDescription) 
    782796                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    783                 .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE) 
     797                .addComponent(incidentPropertiesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE) 
    784798                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 
    785799                .addGroup(incidentFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 
     
    13341348 
    13351349        scriptBuilderMenuBar.addAncestorListener(new javax.swing.event.AncestorListener() { 
    1336             public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 
    1337             } 
    13381350            public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 
    13391351                scriptBuilderMenuBarAncestorAdded(evt); 
    13401352            } 
    13411353            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 
     1354            } 
     1355            public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 
    13421356            } 
    13431357        }); 
     
    17981812        addIncidentStart.setValue(0); 
    17991813        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); 
    18061817        addIncidentDescription.setText(""); 
    18071818        addIncidentLocation.setText(""); 
     
    19481959        //addIncidentLength.setValue(i.length / 60); 
    19491960        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)); 
    19541962        selectedColor = i.color; 
    19551963        addIncidentDescription.setText(i.description); 
     
    22042212        } 
    22052213    }//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 
    22402215 
    22412216    /* Help > About simply displays the current SVN revision number so 
     
    24112386            //addIncidentLength.setValue(i.length / 60); 
    24122387            incidentColorField.setBackground(i.color); 
     2388            colorComboBox.setSelectedIndex(lookupColor(i.color)); 
    24132389            selectedColor = i.color; 
    24142390            addIncidentDescription.setText(i.description); 
     
    24612437//        script.loadUnitsFromFile(f); 
    24622438    }//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    } 
    24632461 
    24642462    /** 
     
    25422540    private javax.swing.JButton btnAddTime; 
    25432541    private javax.swing.JButton btnCancelNoise; 
    2544     private javax.swing.JButton btnChooseColor; 
    25452542    private javax.swing.JButton btnGenerateNoise; 
    25462543    private javax.swing.JMenuItem cadEvent; 
    25472544    private javax.swing.JFrame cadEventFrame; 
    25482545    private javax.swing.JButton cancelButton; 
     2546    private javax.swing.JComboBox<String> colorComboBox; 
    25492547    private javax.swing.JMenuItem deleteEventList; 
    25502548    private javax.swing.JMenuItem deleteIncident; 
Note: See TracChangeset for help on using the changeset viewer.