Changeset 8971 in josm for trunk/src/org


Ignore:
Timestamp:
2015-10-31T01:32:04+01:00 (8 years ago)
Author:
Don-vip
Message:

Search dialog: provide real-time visual feedback on valid/invalid search expressions typed by user

Location:
trunk/src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r8902 r8971  
    4949import org.openstreetmap.josm.gui.preferences.ToolbarPreferences.ActionParser;
    5050import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     51import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
    5152import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    5253import org.openstreetmap.josm.tools.GBC;
     
    228229        JLabel label = new JLabel(initialValues instanceof Filter ? tr("Filter string:") : tr("Search string:"));
    229230        final HistoryComboBox hcbSearchString = new HistoryComboBox();
     231        final String tooltip = tr("Enter the search expression");
    230232        hcbSearchString.setText(initialValues.text);
    231         hcbSearchString.setToolTipText(tr("Enter the search expression"));
     233        hcbSearchString.setToolTipText(tooltip);
    232234        // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement()
    233235        //
     
    280282        right = new JPanel(new GridBagLayout());
    281283        buildHints(right, hcbSearchString);
     284
     285        final JTextComponent editorComponent = (JTextComponent) hcbSearchString.getEditor().getEditorComponent();
     286        editorComponent.getDocument().addDocumentListener(new AbstractTextComponentValidator(editorComponent) {
     287
     288            @Override
     289            public void validate() {
     290                if (!isValid()) {
     291                    feedbackInvalid(tr("Invalid search expression"));
     292                } else {
     293                    feedbackValid(tooltip);
     294                }
     295            }
     296
     297            @Override
     298            public boolean isValid() {
     299                try {
     300                    SearchSetting ss = new SearchSetting();
     301                    ss.text = hcbSearchString.getText();
     302                    ss.caseSensitive = caseSensitive.isSelected();
     303                    ss.regexSearch = regexSearch.isSelected();
     304                    ss.mapCSSSearch = mapCSSSearch.isSelected();
     305                    SearchCompiler.compile(ss);
     306                    return true;
     307                } catch (ParseError e) {
     308                    return false;
     309                }
     310            }
     311        });
    282312
    283313        final JPanel p = new JPanel(new GridBagLayout());
     
    619649        }
    620650
     651        /**
     652         * Constructs a new {@code SearchSetting} from an existing one.
     653         * @param original original search settings
     654         */
    621655        public SearchSetting(SearchSetting original) {
    622656            text = original.text;
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r8931 r8971  
    635635            Double v = null;
    636636            try {
    637                 v = Double.valueOf(referenceValue);
     637                if (referenceValue != null) {
     638                    v = Double.valueOf(referenceValue);
     639                }
    638640            } catch (NumberFormatException ignore) {
    639641                if (Main.isTraceEnabled()) {
Note: See TracChangeset for help on using the changeset viewer.