Changeset 207 in josm for src/org/openstreetmap/josm/actions/search
- Timestamp:
- 2007-04-03T17:46:00+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm/actions/search
- Files:
-
- 2 edited
-
SearchAction.java (modified) (5 diffs)
-
SearchCompiler.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/search/SearchAction.java
r191 r207 9 9 10 10 import javax.swing.ButtonGroup; 11 import javax.swing.JCheckBox; 11 12 import javax.swing.JLabel; 12 13 import javax.swing.JOptionPane; … … 51 52 bg.add(add); 52 53 bg.add(remove); 54 55 JCheckBox caseSensitive = new JCheckBox(tr("case sensitive"), false); 53 56 54 57 JPanel p = new JPanel(new GridBagLayout()); … … 57 60 p.add(replace, GBC.eol()); 58 61 p.add(add, GBC.eol()); 59 p.add(remove, GBC.eol()); 62 p.add(remove, GBC.eop()); 63 p.add(caseSensitive, GBC.eol()); 60 64 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null){ 61 65 @Override public void selectInitialValue() { … … 69 73 lastSearch = input.getText(); 70 74 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()); 72 76 } 73 77 74 public static void search(String search, SearchMode mode) { 78 public static void search(String search, SearchMode mode, boolean caseSensitive) { 75 79 if (search.startsWith("http://") || search.startsWith("ftp://") || search.startsWith("https://") || search.startsWith("file:/")) { 76 80 SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode); … … 81 85 } 82 86 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 83 SearchCompiler.Match matcher = SearchCompiler.compile(search); 87 SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive); 84 88 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 85 89 if (mode == SearchMode.replace) { -
src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r191 r207 17 17 public class SearchCompiler { 18 18 19 boolean caseSensitive = false; 20 19 21 abstract public static class Match { 20 22 abstract public boolean match(OsmPrimitive osm); … … 65 67 } 66 68 67 private staticclass KeyValue extends Match {69 private class KeyValue extends Match { 68 70 private String key; 69 71 private String value; … … 78 80 if (value == null) 79 81 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; 81 85 } 82 86 @Override public String toString() {return key+"="+(notValue?"!":"")+value;} 83 87 } 84 88 85 private staticclass Any extends Match {89 private class Any extends Match { 86 90 private String s; 87 91 public Any(String s) {this.s = s;} … … 89 93 if (osm.keys == null) 90 94 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) 94 100 return true; 101 } 95 102 return false; 96 103 } … … 134 141 } 135 142 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))); 138 147 } 139 148
Note:
See TracChangeset
for help on using the changeset viewer.
