Changeset 3175 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2010-04-11T12:08:22+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r3102 r3175 16 16 import java.util.LinkedList; 17 17 import java.util.List; 18 import java.util.Map; 18 19 19 20 import javax.swing.ButtonGroup; … … 25 26 26 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.actions.ActionParameter; 27 29 import org.openstreetmap.josm.actions.JosmAction; 30 import org.openstreetmap.josm.actions.ParameterizedAction; 31 import org.openstreetmap.josm.actions.ActionParameter.SearchSettingsActionParameter; 28 32 import org.openstreetmap.josm.data.osm.DataSet; 29 33 import org.openstreetmap.josm.data.osm.Filter; … … 34 38 import org.openstreetmap.josm.tools.Shortcut; 35 39 36 public class SearchAction extends JosmAction {40 public class SearchAction extends JosmAction implements ParameterizedAction { 37 41 38 42 public static final int DEFAULT_SEARCH_HISTORY_SIZE = 10; 39 43 44 private static final String SEARCH_EXPRESSION = "searchExpression"; 45 40 46 public static enum SearchMode { 41 replace, add, remove, in_selection 47 replace('R'), add('A'), remove('D'), in_selection('S'); 48 49 private final char code; 50 51 SearchMode(char code) { 52 this.code = code; 53 } 54 55 public char getCode() { 56 return code; 57 } 58 59 public static SearchMode fromCode(char code) { 60 for (SearchMode mode: values()) { 61 if (mode.getCode() == code) 62 return mode; 63 } 64 return null; 65 } 42 66 } 43 67 … … 56 80 return; 57 81 search(); 82 } 83 84 public void actionPerformed(ActionEvent e, Map<String, Object> parameters) { 85 if (parameters.get(SEARCH_EXPRESSION) == null) { 86 actionPerformed(e); 87 } else { 88 searchWithoutHistory((SearchSetting) parameters.get(SEARCH_EXPRESSION)); 89 } 58 90 } 59 91 … … 349 381 return text.hashCode(); 350 382 } 383 384 public static SearchSetting readFromString(String s) { 385 if (s.length() == 0) 386 return null; 387 388 SearchSetting result = new SearchSetting(); 389 390 int index = 1; 391 392 result.mode = SearchMode.fromCode(s.charAt(0)); 393 if (result.mode == null) { 394 result.mode = SearchMode.replace; 395 index = 0; 396 } 397 398 while (index < s.length()) { 399 if (s.charAt(index) == 'C') { 400 result.caseSensitive = true; 401 } else if (s.charAt(index) == 'R') { 402 result.regexSearch = true; 403 } else if (s.charAt(index) == ' ') { 404 break; 405 } else { 406 System.out.println("Uknown char in SearchSettings: " + s); 407 break; 408 } 409 index++; 410 } 411 412 if (index < s.length() && s.charAt(index) == ' ') { 413 index++; 414 } 415 416 result.text = s.substring(index); 417 418 return result; 419 } 420 421 public String writeToString() { 422 if (text == null || text.length() == 0) 423 return ""; 424 425 StringBuilder result = new StringBuilder(); 426 result.append(mode.getCode()); 427 if (caseSensitive) { 428 result.append('C'); 429 } 430 if (regexSearch) { 431 result.append('R'); 432 } 433 result.append(' '); 434 result.append(text); 435 return result.toString(); 436 } 351 437 } 352 438 … … 359 445 setEnabled(getEditLayer() != null); 360 446 } 447 448 public List<ActionParameter<?>> getActionParameters() { 449 return Collections.<ActionParameter<?>>singletonList(new SearchSettingsActionParameter(SEARCH_EXPRESSION)); 450 } 361 451 }
Note:
See TracChangeset
for help on using the changeset viewer.