source: josm/trunk/src/org/openstreetmap/josm/data/osm/Filter.java@ 13207

Last change on this file since 13207 was 13205, checked in by Don-vip, 6 years ago

enable PMD rule StringToString

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Objects;
5
6import org.openstreetmap.josm.data.StructUtils.StructEntry;
7import org.openstreetmap.josm.data.StructUtils.WriteExplicitly;
8import org.openstreetmap.josm.data.osm.search.SearchMode;
9import org.openstreetmap.josm.data.osm.search.SearchSetting;
10
11/**
12 * Data class representing one entry in the filter dialog.
13 *
14 * @author Petr_Dlouhý
15 * @since 2125
16 */
17public class Filter extends SearchSetting {
18 private static final String version = "1";
19
20 /**
21 * Enabled status.
22 * @see FilterPreferenceEntry#enable
23 */
24 public boolean enable = true;
25
26 /**
27 * If this option is activated, the chosen objects are completely hidden.
28 * Otherwise they are disabled and shown in a shade of gray.
29 * @see FilterPreferenceEntry#hiding
30 */
31 public boolean hiding;
32
33 /**
34 * Normally, the specified objects are hidden and the rest is shown.
35 * If this option is activated, only the specified objects are shown and the rest is hidden.
36 * @see FilterPreferenceEntry#inverted
37 */
38 public boolean inverted;
39
40 /**
41 * Constructs a new {@code Filter}.
42 */
43 public Filter() {
44 super();
45 mode = SearchMode.add;
46 }
47
48 /**
49 * Constructs a new {@code Filter} from a preference entry.
50 * @param e preference entry
51 */
52 public Filter(FilterPreferenceEntry e) {
53 this();
54 text = e.text;
55 if ("replace".equals(e.mode)) {
56 mode = SearchMode.replace;
57 } else if ("add".equals(e.mode)) {
58 mode = SearchMode.add;
59 } else if ("remove".equals(e.mode)) {
60 mode = SearchMode.remove;
61 } else if ("in_selection".equals(e.mode)) {
62 mode = SearchMode.in_selection;
63 }
64 caseSensitive = e.case_sensitive;
65 regexSearch = e.regex_search;
66 mapCSSSearch = e.mapCSS_search;
67 enable = e.enable;
68 hiding = e.hiding;
69 inverted = e.inverted;
70 }
71
72 public static class FilterPreferenceEntry {
73 @WriteExplicitly
74 @StructEntry public String version = "1";
75
76 @StructEntry public String text;
77
78 /**
79 * Mode selector which defines how a filter is combined with the previous one:<ul>
80 * <li>replace: replace selection</li>
81 * <li>add: add to selection</li>
82 * <li>remove: remove from selection</li>
83 * <li>in_selection: find in selection</li>
84 * </ul>
85 * @see SearchMode
86 */
87 @WriteExplicitly
88 @StructEntry public String mode = "add";
89
90 @StructEntry public boolean case_sensitive;
91
92 @StructEntry public boolean regex_search;
93
94 @StructEntry public boolean mapCSS_search;
95
96 /**
97 * Enabled status.
98 * @see Filter#enable
99 */
100 @WriteExplicitly
101 @StructEntry public boolean enable = true;
102
103 /**
104 * If this option is activated, the chosen objects are completely hidden.
105 * Otherwise they are disabled and shown in a shade of gray.
106 * @see Filter#hiding
107 */
108 @WriteExplicitly
109 @StructEntry public boolean hiding;
110
111 /**
112 * Normally, the specified objects are hidden and the rest is shown.
113 * If this option is activated, only the specified objects are shown and the rest is hidden.
114 * @see Filter#inverted
115 */
116 @WriteExplicitly
117 @StructEntry public boolean inverted;
118
119 @Override
120 public int hashCode() {
121 return Objects.hash(case_sensitive, enable, hiding, inverted, mapCSS_search, mode, regex_search, text, version);
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj)
127 return true;
128 if (obj == null || getClass() != obj.getClass())
129 return false;
130 FilterPreferenceEntry other = (FilterPreferenceEntry) obj;
131 return case_sensitive == other.case_sensitive
132 && enable == other.enable
133 && hiding == other.hiding
134 && inverted == other.inverted
135 && mapCSS_search == other.mapCSS_search
136 && regex_search == other.regex_search
137 && Objects.equals(mode, other.mode)
138 && Objects.equals(text, other.text)
139 && Objects.equals(version, other.version);
140 }
141 }
142
143 /**
144 * Returns a new preference entry for this filter.
145 * @return preference entry
146 */
147 public FilterPreferenceEntry getPreferenceEntry() {
148 FilterPreferenceEntry e = new FilterPreferenceEntry();
149 e.version = version;
150 e.text = text;
151 e.mode = mode.name();
152 e.case_sensitive = caseSensitive;
153 e.regex_search = regexSearch;
154 e.mapCSS_search = mapCSSSearch;
155 e.enable = enable;
156 e.hiding = hiding;
157 e.inverted = inverted;
158 return e;
159 }
160}
Note: See TracBrowser for help on using the repository browser.