Ignore:
Timestamp:
2007-04-03T17:46:00+02:00 (19 years ago)
Author:
imi
Message:
  • added "case sensitive" option to search dialog
  • added a plugin manifest option "Plugin-Stage" to specify boot stage order (default is 50, smaller first)
Location:
src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

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

    r191 r207  
    99
    1010import javax.swing.ButtonGroup;
     11import javax.swing.JCheckBox;
    1112import javax.swing.JLabel;
    1213import javax.swing.JOptionPane;
     
    5152        bg.add(add);
    5253        bg.add(remove);
     54       
     55        JCheckBox caseSensitive = new JCheckBox(tr("case sensitive"), false);
    5356   
    5457        JPanel p = new JPanel(new GridBagLayout());
     
    5760        p.add(replace, GBC.eol());
    5861        p.add(add, GBC.eol());
    59         p.add(remove, GBC.eol());
     62        p.add(remove, GBC.eop());
     63        p.add(caseSensitive, GBC.eol());
    6064        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null){
    6165                @Override public void selectInitialValue() {
     
    6973        lastSearch = input.getText();
    7074        SearchAction.SearchMode mode = replace.isSelected() ? SearchAction.SearchMode.replace : (add.isSelected() ? SearchAction.SearchMode.add : SearchAction.SearchMode.remove);
    71         search(lastSearch, mode);
     75        search(lastSearch, mode, caseSensitive.isSelected());
    7276    }
    7377
    74         public static void search(String search, SearchMode mode) {
     78        public static void search(String search, SearchMode mode, boolean caseSensitive) {
    7579        if (search.startsWith("http://") || search.startsWith("ftp://") || search.startsWith("https://") || search.startsWith("file:/")) {
    7680                SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode);
     
    8185        }
    8286        Collection<OsmPrimitive> sel = Main.ds.getSelected();
    83         SearchCompiler.Match matcher = SearchCompiler.compile(search);
     87        SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive);
    8488        for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {
    8589                if (mode == SearchMode.replace) {
  • src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r191 r207  
    1717public class SearchCompiler {
    1818
     19        boolean caseSensitive = false;
     20       
    1921        abstract public static class Match {
    2022                abstract public boolean match(OsmPrimitive osm);
     
    6567        }
    6668
    67         private static class KeyValue extends Match {
     69        private class KeyValue extends Match {
    6870                private String key;
    6971                private String value;
     
    7880                        if (value == null)
    7981                                return notValue;
    80                         return (value.toLowerCase().indexOf(this.value.toLowerCase()) != -1) != notValue;
     82                        String v1 = caseSensitive ? value : value.toLowerCase();
     83                        String v2 = caseSensitive ? this.value : this.value.toLowerCase();
     84                        return (v1.indexOf(v2) != -1) != notValue;
    8185                }
    8286                @Override public String toString() {return key+"="+(notValue?"!":"")+value;}
    8387        }
    8488
    85         private static class Any extends Match {
     89        private class Any extends Match {
    8690                private String s;
    8791                public Any(String s) {this.s = s;}
     
    8993                        if (osm.keys == null)
    9094                                return s.equals("");
    91                         for (Entry<String, String> e : osm.keys.entrySet())
    92                                 if (e.getKey().toLowerCase().indexOf(s.toLowerCase()) != -1
    93                                                 || e.getValue().toLowerCase().indexOf(s.toLowerCase()) != -1)
     95                        for (Entry<String, String> e : osm.keys.entrySet()) {
     96                                String key = caseSensitive ? e.getKey() : e.getKey().toLowerCase();
     97                                String value = caseSensitive ? e.getValue() : e.getValue().toLowerCase();
     98                                String search = caseSensitive ? s : s.toLowerCase();
     99                                if (key.indexOf(search) != -1 || value.indexOf(search) != -1)
    94100                                        return true;
     101                        }
    95102                        return false;
    96103                }
     
    134141        }
    135142       
    136         public static Match compile(String searchStr) {
    137                 return new SearchCompiler().parse(new PushbackReader(new StringReader(searchStr)));
     143        public static Match compile(String searchStr, boolean caseSensitive) {
     144                SearchCompiler searchCompiler = new SearchCompiler();
     145                searchCompiler.caseSensitive = caseSensitive;
     146                return searchCompiler.parse(new PushbackReader(new StringReader(searchStr)));
    138147        }
    139148
Note: See TracChangeset for help on using the changeset viewer.