Ticket #17754: 17754.patch

File 17754.patch, 2.8 KB (added by GerdP, 7 years ago)

execute validate() when radio button is selected

  • src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java

     
    99import java.awt.FlowLayout;
    1010import java.awt.GridBagLayout;
    1111import java.awt.event.ActionEvent;
     12import java.awt.event.ItemEvent;
     13import java.awt.event.ItemListener;
    1214import java.awt.event.MouseAdapter;
    1315import java.awt.event.MouseEvent;
    1416import java.util.Arrays;
     
    118120        standardSearch = new JRadioButton(tr("standard"), !searchSettings.regexSearch && !searchSettings.mapCSSSearch);
    119121        regexSearch = new JRadioButton(tr("regular expression"), searchSettings.regexSearch);
    120122        mapCSSSearch = new JRadioButton(tr("MapCSS selector"), searchSettings.mapCSSSearch);
     123
    121124        ButtonGroup bg2 = new ButtonGroup();
    122125        bg2.add(standardSearch);
    123126        bg2.add(regexSearch);
     
    165168         * every time the content of the field has changed. If the query is incorrect, then
    166169         * the text field is colored red.
    167170         */
    168         document.addDocumentListener(new AbstractTextComponentValidator(editorComponent) {
     171        AbstractTextComponentValidator validator = new AbstractTextComponentValidator(editorComponent) {
    169172
    170173            @Override
    171174            public void validate() {
     
    190193                    return false;
    191194                }
    192195            }
    193         });
     196        };
     197        document.addDocumentListener(validator);
     198        ItemListener validateActionListener = e -> {
     199            if (e.getStateChange() == ItemEvent.SELECTED) {
     200                validator.validate();
     201            }
     202        };
     203        standardSearch.addItemListener(validateActionListener);
     204        regexSearch.addItemListener(validateActionListener);
     205        mapCSSSearch.addItemListener(validateActionListener);
    194206
    195207        /*
    196208         * Setup the logic to append preset queries to the search text field according to
     
    326338                        trc("search string example", "user:anonymous (objects without an assigned author)"))
    327339                .addKeyword("id:", "id:", tr("objects with given ID"),
    328340                        trc("search string example", "id:0 (new objects)"))
    329                 .addKeyword("version:", "version:", tr("objects with given version"), 
     341                .addKeyword("version:", "version:", tr("objects with given version"),
    330342                        trc("search string example", "version:0 (objects without an assigned version)"))
    331343                .addKeyword("changeset:", "changeset:", tr("objects with given changeset ID"),
    332344                        trc("search string example", "changeset:0 (objects without an assigned changeset)"))