- Timestamp:
- 2017-08-26T00:55:22+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 15 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r12656 r12659 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.tools.I18n.trc;7 6 import static org.openstreetmap.josm.tools.I18n.trn; 8 7 … … 25 24 import java.util.List; 26 25 import java.util.Map; 27 import java.util.Objects;28 26 import java.util.Set; 29 27 import java.util.function.Predicate; … … 50 48 import org.openstreetmap.josm.data.osm.OsmPrimitive; 51 49 import org.openstreetmap.josm.data.osm.search.SearchParseError; 50 import org.openstreetmap.josm.data.osm.search.SearchSetting; 52 51 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 52 import org.openstreetmap.josm.data.osm.search.SearchMode; 53 53 import org.openstreetmap.josm.gui.ExtendedDialog; 54 54 import org.openstreetmap.josm.gui.MainApplication; … … 86 86 87 87 private static final String SEARCH_EXPRESSION = "searchExpression"; 88 89 /**90 * Search mode.91 */92 public enum SearchMode {93 /** replace selection */94 replace('R'),95 /** add to selection */96 add('A'),97 /** remove from selection */98 remove('D'),99 /** find in selection */100 in_selection('S');101 102 private final char code;103 104 SearchMode(char code) {105 this.code = code;106 }107 108 /**109 * Returns the unique character code of this mode.110 * @return the unique character code of this mode111 */112 public char getCode() {113 return code;114 }115 116 /**117 * Returns the search mode matching the given character code.118 * @param code character code119 * @return search mode matching the given character code120 */121 public static SearchMode fromCode(char code) {122 for (SearchMode mode: values()) {123 if (mode.getCode() == code)124 return mode;125 }126 return null;127 }128 }129 88 130 89 private static final LinkedList<SearchSetting> searchHistory = new LinkedList<>(); … … 446 405 447 406 if (inSelection.isSelected()) { 448 initialValues.mode = Search Action.SearchMode.in_selection;407 initialValues.mode = SearchMode.in_selection; 449 408 } else if (replace.isSelected()) { 450 initialValues.mode = Search Action.SearchMode.replace;409 initialValues.mode = SearchMode.replace; 451 410 } else if (add.isSelected()) { 452 initialValues.mode = Search Action.SearchMode.add;411 initialValues.mode = SearchMode.add; 453 412 } else { 454 initialValues.mode = Search Action.SearchMode.remove;413 initialValues.mode = SearchMode.remove; 455 414 } 456 415 … … 850 809 851 810 /** 852 * This class defines a set of parameters that is used to853 * perform search within the search dialog.854 */855 public static class SearchSetting {856 public String text;857 public SearchMode mode;858 public boolean caseSensitive;859 public boolean regexSearch;860 public boolean mapCSSSearch;861 public boolean allElements;862 863 /**864 * Constructs a new {@code SearchSetting}.865 */866 public SearchSetting() {867 text = "";868 mode = SearchMode.replace;869 }870 871 /**872 * Constructs a new {@code SearchSetting} from an existing one.873 * @param original original search settings874 */875 public SearchSetting(SearchSetting original) {876 text = original.text;877 mode = original.mode;878 caseSensitive = original.caseSensitive;879 regexSearch = original.regexSearch;880 mapCSSSearch = original.mapCSSSearch;881 allElements = original.allElements;882 }883 884 @Override885 public String toString() {886 String cs = caseSensitive ?887 /*case sensitive*/ trc("search", "CS") :888 /*case insensitive*/ trc("search", "CI");889 String rx = regexSearch ? ", " +890 /*regex search*/ trc("search", "RX") : "";891 String css = mapCSSSearch ? ", " +892 /*MapCSS search*/ trc("search", "CSS") : "";893 String all = allElements ? ", " +894 /*all elements*/ trc("search", "A") : "";895 return '"' + text + "\" (" + cs + rx + css + all + ", " + mode + ')';896 }897 898 @Override899 public boolean equals(Object other) {900 if (this == other) return true;901 if (other == null || getClass() != other.getClass()) return false;902 SearchSetting that = (SearchSetting) other;903 return caseSensitive == that.caseSensitive &&904 regexSearch == that.regexSearch &&905 mapCSSSearch == that.mapCSSSearch &&906 allElements == that.allElements &&907 mode == that.mode &&908 Objects.equals(text, that.text);909 }910 911 @Override912 public int hashCode() {913 return Objects.hash(text, mode, caseSensitive, regexSearch, mapCSSSearch, allElements);914 }915 916 /**917 * <p>Transforms a string following a certain format, namely "[R | A | D | S][C?,R?,A?,M?] [a-zA-Z]"918 * where the first part defines the mode of the search, see {@link SearchMode}, the second defines919 * a set of attributes within the {@code SearchSetting} class and the second is the search query.920 * <p>921 * Attributes are as follows:922 * <ul>923 * <li>C - if search is case sensitive924 * <li>R - if the regex syntax is used925 * <li>A - if all objects are considered926 * <li>M - if the mapCSS syntax is used927 * </ul>928 * <p>For example, "RC type:node" is a valid string representation of an object that replaces the929 * current selection, is case sensitive and searches for all objects of type node.930 * @param s A string representation of a {@code SearchSetting} object931 * from which the object must be built.932 * @return A {@code SearchSetting} defined by the input string.933 */934 public static SearchSetting readFromString(String s) {935 if (s.isEmpty())936 return null;937 938 SearchSetting result = new SearchSetting();939 940 int index = 1;941 942 result.mode = SearchMode.fromCode(s.charAt(0));943 if (result.mode == null) {944 result.mode = SearchMode.replace;945 index = 0;946 }947 948 while (index < s.length()) {949 if (s.charAt(index) == 'C') {950 result.caseSensitive = true;951 } else if (s.charAt(index) == 'R') {952 result.regexSearch = true;953 } else if (s.charAt(index) == 'A') {954 result.allElements = true;955 } else if (s.charAt(index) == 'M') {956 result.mapCSSSearch = true;957 } else if (s.charAt(index) == ' ') {958 break;959 } else {960 Logging.warn("Unknown char in SearchSettings: " + s);961 break;962 }963 index++;964 }965 966 if (index < s.length() && s.charAt(index) == ' ') {967 index++;968 }969 970 result.text = s.substring(index);971 972 return result;973 }974 975 /**976 * Builds a string representation of the {@code SearchSetting} object,977 * see {@link #readFromString(String)} for more details.978 * @return A string representation of the {@code SearchSetting} object.979 */980 public String writeToString() {981 if (text == null || text.isEmpty())982 return "";983 984 StringBuilder result = new StringBuilder();985 result.append(mode.getCode());986 if (caseSensitive) {987 result.append('C');988 }989 if (regexSearch) {990 result.append('R');991 }992 if (mapCSSSearch) {993 result.append('M');994 }995 if (allElements) {996 result.append('A');997 }998 result.append(' ')999 .append(text);1000 return result.toString();1001 }1002 }1003 1004 /**1005 811 * {@link ActionParameter} implementation with {@link SearchSetting} as value type. 1006 812 * @since 12547 (moved from {@link ActionParameter}) -
trunk/src/org/openstreetmap/josm/data/osm/Filter.java
r11973 r12659 4 4 import java.util.Objects; 5 5 6 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;7 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;8 6 import org.openstreetmap.josm.data.Preferences.pref; 9 7 import org.openstreetmap.josm.data.Preferences.writeExplicitly; 8 import org.openstreetmap.josm.data.osm.search.SearchMode; 9 import org.openstreetmap.josm.data.osm.search.SearchSetting; 10 10 11 11 /** -
trunk/src/org/openstreetmap/josm/data/osm/FilterMatcher.java
r12656 r12659 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;9 8 import org.openstreetmap.josm.data.osm.search.SearchParseError; 10 9 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 10 import org.openstreetmap.josm.data.osm.search.SearchMode; 11 11 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 12 12 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Not; -
trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
r12656 r12659 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.actions.search.SearchAction;27 26 import org.openstreetmap.josm.data.Bounds; 28 27 import org.openstreetmap.josm.data.coor.LatLon; … … 62 61 * fact expression 63 62 * fact 64 * 63 * 65 64 * fact = 66 65 * ( expression ) … … 71 70 * term 72 71 * </pre> 73 * 72 * 74 73 * @author Imi 75 74 * @since 12656 (moved from actions.search package) … … 1647 1646 * @see #compile(String) 1648 1647 */ 1649 public static Match compile(Search Action.SearchSetting setting) throws SearchParseError {1648 public static Match compile(SearchSetting setting) throws SearchParseError { 1650 1649 if (setting.mapCSSSearch) { 1651 1650 return compileMapCSS(setting.text); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12647 r12659 73 73 import org.openstreetmap.josm.data.osm.DataSet; 74 74 import org.openstreetmap.josm.data.osm.OsmPrimitive; 75 import org.openstreetmap.josm.data.osm.search.SearchMode; 75 76 import org.openstreetmap.josm.data.validation.OsmValidator; 76 77 import org.openstreetmap.josm.gui.ProgramArguments.Option; … … 1024 1025 tasks.add(MainApplication.worker.submit(() -> { 1025 1026 for (String s : selectionArguments) { 1026 SearchAction.search(s, Search Action.SearchMode.add);1027 SearchAction.search(s, SearchMode.add); 1027 1028 } 1028 1029 })); -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r12636 r12659 44 44 import org.openstreetmap.josm.actions.relation.EditRelationAction; 45 45 import org.openstreetmap.josm.actions.relation.SelectInRelationListAction; 46 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;47 46 import org.openstreetmap.josm.data.SelectionChangedListener; 48 47 import org.openstreetmap.josm.data.coor.LatLon; … … 58 57 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 59 58 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 59 import org.openstreetmap.josm.data.osm.search.SearchSetting; 60 60 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent; 61 61 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent; -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r12656 r12659 60 60 import org.openstreetmap.josm.actions.relation.SelectMembersAction; 61 61 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 62 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;63 62 import org.openstreetmap.josm.command.ChangeCommand; 64 63 import org.openstreetmap.josm.command.ChangePropertyCommand; … … 78 77 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 79 78 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 79 import org.openstreetmap.josm.data.osm.search.SearchSetting; 80 80 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 81 81 import org.openstreetmap.josm.data.preferences.StringProperty; -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollection.java
r12656 r12659 8 8 import java.util.Map; 9 9 10 import org.openstreetmap.josm.actions.search.SearchAction;11 10 import org.openstreetmap.josm.data.osm.Tag; 12 11 import org.openstreetmap.josm.data.osm.search.SearchParseError; 12 import org.openstreetmap.josm.data.osm.search.SearchSetting; 13 13 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 14 14 import org.openstreetmap.josm.data.preferences.CollectionProperty; … … 82 82 } 83 83 84 public void setTagsToIgnore(Search Action.SearchSetting tagsToIgnore) throws SearchParseError {84 public void setTagsToIgnore(SearchSetting tagsToIgnore) throws SearchParseError { 85 85 setTagsToIgnore(tagsToIgnore.text.isEmpty() ? SearchCompiler.Never.INSTANCE : SearchCompiler.compile(tagsToIgnore)); 86 86 } 87 87 88 public Search Action.SearchSetting ignoreTag(Tag tagToIgnore, SearchAction.SearchSetting settingToUpdate) throws SearchParseError {88 public SearchSetting ignoreTag(Tag tagToIgnore, SearchSetting settingToUpdate) throws SearchParseError { 89 89 final String forTag = SearchCompiler.buildSearchStringForTag(tagToIgnore.getKey(), tagToIgnore.getValue()); 90 90 settingToUpdate.text = settingToUpdate.text.isEmpty() -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r12656 r12659 70 70 import org.openstreetmap.josm.data.osm.Tag; 71 71 import org.openstreetmap.josm.data.osm.search.SearchParseError; 72 import org.openstreetmap.josm.data.osm.search.SearchSetting; 72 73 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 73 74 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 130 131 Collections.<String>emptyList()); 131 132 public static final StringProperty PROPERTY_TAGS_TO_IGNORE = new StringProperty("properties.recent-tags.ignore", 132 new Search Action.SearchSetting().writeToString());133 new SearchSetting().writeToString()); 133 134 134 135 /** … … 163 164 164 165 final RecentTagCollection recentTags = new RecentTagCollection(MAX_LRU_TAGS_NUMBER); 165 Search Action.SearchSetting tagsToIgnore;166 SearchSetting tagsToIgnore; 166 167 167 168 /** … … 330 331 331 332 void loadTagsToIgnore() { 332 final Search Action.SearchSetting searchSetting = Utils.firstNonNull(333 Search Action.SearchSetting.readFromString(PROPERTY_TAGS_TO_IGNORE.get()), new SearchAction.SearchSetting());333 final SearchSetting searchSetting = Utils.firstNonNull( 334 SearchSetting.readFromString(PROPERTY_TAGS_TO_IGNORE.get()), new SearchSetting()); 334 335 if (!Objects.equals(tagsToIgnore, searchSetting)) { 335 336 try { … … 338 339 } catch (SearchParseError parseError) { 339 340 warnAboutParseError(parseError); 340 tagsToIgnore = new Search Action.SearchSetting();341 tagsToIgnore = new SearchSetting(); 341 342 recentTags.setTagsToIgnore(SearchCompiler.Never.INSTANCE); 342 343 } … … 1024 1025 @Override 1025 1026 public void actionPerformed(ActionEvent e) { 1026 final Search Action.SearchSetting newTagsToIngore = SearchAction.showSearchDialog(tagsToIgnore);1027 final SearchSetting newTagsToIngore = SearchAction.showSearchDialog(tagsToIgnore); 1027 1028 if (newTagsToIngore == null) { 1028 1029 return; -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Roles.java
r12656 r12659 13 13 import javax.swing.JPanel; 14 14 15 import org.openstreetmap.josm.actions.search.SearchAction;16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 16 import org.openstreetmap.josm.data.osm.Tag; 18 17 import org.openstreetmap.josm.data.osm.search.SearchParseError; 18 import org.openstreetmap.josm.data.osm.search.SearchSetting; 19 19 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 20 20 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; … … 78 78 public void setMember_expression(String memberExpression) throws SAXException { 79 79 try { 80 final Search Action.SearchSetting searchSetting = new SearchAction.SearchSetting();80 final SearchSetting searchSetting = new SearchSetting(); 81 81 searchSetting.text = memberExpression; 82 82 searchSetting.caseSensitive = true; -
trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
r12656 r12659 12 12 import org.junit.Test; 13 13 import org.openstreetmap.josm.TestUtils; 14 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;15 14 import org.openstreetmap.josm.command.SequenceCommand; 16 15 import org.openstreetmap.josm.data.osm.DataSet; … … 19 18 import org.openstreetmap.josm.data.osm.Way; 20 19 import org.openstreetmap.josm.data.osm.search.SearchParseError; 20 import org.openstreetmap.josm.data.osm.search.SearchSetting; 21 21 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 22 22 import org.openstreetmap.josm.io.OsmReader; -
trunk/test/unit/org/openstreetmap/josm/actions/JoinAreasActionTest.java
r12643 r12659 25 25 import org.openstreetmap.josm.data.osm.RelationMember; 26 26 import org.openstreetmap.josm.data.osm.Way; 27 import org.openstreetmap.josm.data.osm.search.SearchMode; 27 28 import org.openstreetmap.josm.gui.MainApplication; 28 29 import org.openstreetmap.josm.gui.layer.Layer; … … 84 85 for (String ref : new String[]{"A", "B", "C", "D", "E"}) { 85 86 System.out.print("Joining ways " + ref); 86 Collection<OsmPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, Search Action.SearchMode.replace);87 Collection<OsmPrimitive> found = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace); 87 88 assertEquals(2, found.size()); 88 89 89 90 MainApplication.getMenu().joinAreas.join(Utils.filteredCollection(found, Way.class)); 90 91 91 Collection<OsmPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, Search Action.SearchMode.replace);92 Collection<OsmPrimitive> found2 = SearchAction.searchAndReturn("type:way ref="+ref, SearchMode.replace); 92 93 assertEquals(1, found2.size()); 93 94 System.out.println(" ==> OK"); -
trunk/test/unit/org/openstreetmap/josm/data/osm/FilterTest.java
r12656 r12659 16 16 import org.junit.Rule; 17 17 import org.junit.Test; 18 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;19 18 import org.openstreetmap.josm.data.coor.LatLon; 20 19 import org.openstreetmap.josm.data.osm.Filter.FilterPreferenceEntry; 20 import org.openstreetmap.josm.data.osm.search.SearchMode; 21 21 import org.openstreetmap.josm.data.osm.search.SearchParseError; 22 22 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; -
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
r12656 r12659 19 19 import org.junit.Test; 20 20 import org.openstreetmap.josm.TestUtils; 21 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;22 21 import org.openstreetmap.josm.data.coor.LatLon; 23 22 import org.openstreetmap.josm.data.osm.DataSet; -
trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchModeTest.java
r12656 r12659 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm. actions.search;2 package org.openstreetmap.josm.data.osm.search; 3 3 4 4 import org.junit.Rule; 5 5 import org.junit.Test; 6 6 import org.openstreetmap.josm.TestUtils; 7 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;8 import org.openstreetmap.josm.data.osm.search.SearchCompiler;9 7 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 8 … … 12 10 13 11 /** 14 * Unit tests for class {@link Search Compiler}.12 * Unit tests for class {@link SearchMode}. 15 13 */ 16 public class Search ActionTest {14 public class SearchModeTest { 17 15 18 16 /** -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/RecentTagCollectionTest.java
r12656 r12659 11 11 import org.junit.Rule; 12 12 import org.junit.Test; 13 import org.openstreetmap.josm.actions.search.SearchAction;14 13 import org.openstreetmap.josm.data.osm.Tag; 15 14 import org.openstreetmap.josm.data.osm.search.SearchParseError; 15 import org.openstreetmap.josm.data.osm.search.SearchSetting; 16 16 import org.openstreetmap.josm.data.preferences.CollectionProperty; 17 17 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 63 63 recentTags.add(bar); 64 64 recentTags.add(baz); 65 final Search Action.SearchSetting searchSetting = new SearchAction.SearchSetting();65 final SearchSetting searchSetting = new SearchSetting(); 66 66 recentTags.ignoreTag(baz, searchSetting); 67 67 recentTags.ignoreTag(new Tag("something", "else"), searchSetting);
Note:
See TracChangeset
for help on using the changeset viewer.