Changeset 1808 in josm for trunk/src/org/openstreetmap/josm/actions/search
- Timestamp:
- 2009-07-19T10:31:27+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r1677 r1808 23 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 24 import org.openstreetmap.josm.gui.ExtendedDialog; 25 import org.openstreetmap.josm.gui.layer.Layer; 26 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 25 27 import org.openstreetmap.josm.tools.GBC; 26 28 import org.openstreetmap.josm.tools.Shortcut; 27 29 28 public class SearchAction extends JosmAction {30 public class SearchAction extends JosmAction implements LayerChangeListener{ 29 31 30 32 public static final int SEARCH_HISTORY_SIZE = 10; … … 40 42 public SearchAction() { 41 43 super(tr("Search..."), "dialogs/search", tr("Search for objects."), 42 Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true); 44 Shortcut.registerShortcut("system:find", tr("Search..."), KeyEvent.VK_F, Shortcut.GROUP_HOTKEY), true); 45 Layer.listeners.add(this); 46 refreshEnabled(); 43 47 } 44 48 45 49 public void actionPerformed(ActionEvent e) { 50 if (!isEnabled()) 51 return; 46 52 if (Main.map == null) { 47 53 JOptionPane.showMessageDialog(Main.parent, tr("No data loaded.")); … … 49 55 } 50 56 SearchSetting s = lastSearch; 51 if (s == null) 57 if (s == null) { 52 58 s = new SearchSetting("", false, false, SearchMode.replace); 59 } 53 60 showSearchDialog(s); 54 61 } … … 81 88 JPanel right = new JPanel(); 82 89 JLabel description = 83 new JLabel("<html><ul>"84 + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>"85 + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>"86 + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>"87 + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>"88 + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>"89 + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>"90 + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>"91 + "<li>"+tr("<u>Special targets:</u>")+"</li>"92 + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>"93 + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"94 + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>"95 + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"96 + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"97 + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"98 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"99 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>"100 + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"101 + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>"102 + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>"103 + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>"104 + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"105 + "</ul></html>");90 new JLabel("<html><ul>" 91 + "<li>"+tr("<b>Baker Street</b> - 'Baker' and 'Street' in any key or name.")+"</li>" 92 + "<li>"+tr("<b>\"Baker Street\"</b> - 'Baker Street' in any key or name.")+"</li>" 93 + "<li>"+tr("<b>name:Bak</b> - 'Bak' anywhere in the name.")+"</li>" 94 + "<li>"+tr("<b>type=route</b> - key 'type' with value exactly 'route'.") + "</li>" 95 + "<li>"+tr("<b>type=*</b> - key 'type' with any value. Try also <b>*=value</b>, <b>type=</b>, <b>*=*</b>, <b>*=</b>") + "</li>" 96 + "<li>"+tr("<b>-name:Bak</b> - not 'Bak' in the name.")+"</li>" 97 + "<li>"+tr("<b>foot:</b> - key=foot set to any value.")+"</li>" 98 + "<li>"+tr("<u>Special targets:</u>")+"</li>" 99 + "<li>"+tr("<b>type:</b> - type of the object (<b>node</b>, <b>way</b>, <b>relation</b>)")+"</li>" 100 + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>" 101 + "<li>"+tr("<b>id:</b>... - object with given ID")+"</li>" 102 + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>" 103 + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>" 104 + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>" 105 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>" 106 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>" 107 + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>" 108 + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>" 109 + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>" 110 + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>" 111 + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>" 112 + "</ul></html>"); 106 113 description.setFont(description.getFont().deriveFont(Font.PLAIN)); 107 114 right.add(description); … … 112 119 113 120 int result = new ExtendedDialog(Main.parent, 114 tr("Search"),115 p,116 new String[] {tr("Start Search"), tr("Cancel")},117 new String[] {"dialogs/search.png", "cancel.png"}).getValue();121 tr("Search"), 122 p, 123 new String[] {tr("Start Search"), tr("Cancel")}, 124 new String[] {"dialogs/search.png", "cancel.png"}).getValue(); 118 125 if(result != 1) return; 119 126 … … 132 139 */ 133 140 public static void searchWithHistory(SearchSetting s) { 134 if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) 141 if(searchHistory.isEmpty() || !s.equals(searchHistory.getFirst())) { 135 142 searchHistory.addFirst(s); 136 while (searchHistory.size() > SEARCH_HISTORY_SIZE) 143 } 144 while (searchHistory.size() > SEARCH_HISTORY_SIZE) { 137 145 searchHistory.removeLast(); 146 } 138 147 lastSearch = s; 139 148 search(s.text, s.mode, s.caseSensitive, s.regexSearch); … … 163 172 sel.add(osm); 164 173 ++foundMatches; 165 } else 174 } else { 166 175 sel.remove(osm); 176 } 167 177 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) { 168 178 sel.add(osm); … … 176 186 if (foundMatches == 0) { 177 187 String msg = null; 178 if (mode == SearchMode.replace) 188 if (mode == SearchMode.replace) { 179 189 msg = tr("No match found for ''{0}''", search); 180 else if (mode == SearchMode.add)190 } else if (mode == SearchMode.add) { 181 191 msg = tr("Nothing added to selection by searching for ''{0}''", search); 182 else if (mode == SearchMode.remove)192 } else if (mode == SearchMode.remove) { 183 193 msg = tr("Nothing removed from selection by searching for ''{0}''", search); 194 } 184 195 Main.map.statusLine.setHelpText(msg); 185 196 JOptionPane.showMessageDialog(Main.parent, msg); 186 } else 197 } else { 187 198 Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches)); 199 } 188 200 } catch (SearchCompiler.ParseError e) { 189 201 JOptionPane.showMessageDialog(Main.parent, e.getMessage()); … … 212 224 } 213 225 226 @Override 214 227 public boolean equals(Object other) { 215 228 if(!(other instanceof SearchSetting)) … … 217 230 SearchSetting o = (SearchSetting) other; 218 231 return (o.caseSensitive == this.caseSensitive 219 && o.regexSearch == this.regexSearch 220 && o.mode.equals(this.mode) 221 && o.text.equals(this.text)); 222 } 232 && o.regexSearch == this.regexSearch 233 && o.mode.equals(this.mode) 234 && o.text.equals(this.text)); 235 } 236 } 237 238 /** 239 * Refreshes the enabled state 240 * 241 */ 242 protected void refreshEnabled() { 243 setEnabled(Main.map != null 244 && Main.map.mapView !=null 245 && Main.map.mapView.getEditLayer() != null 246 ); 247 } 248 249 /* ---------------------------------------------------------------------------------- */ 250 /* Interface LayerChangeListener */ 251 /* ---------------------------------------------------------------------------------- */ 252 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 253 refreshEnabled(); 254 } 255 256 public void layerAdded(Layer newLayer) { 257 refreshEnabled(); 258 } 259 260 public void layerRemoved(Layer oldLayer) { 261 refreshEnabled(); 223 262 } 224 263 }
Note:
See TracChangeset
for help on using the changeset viewer.