1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Objects;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
|
---|
7 | import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
|
---|
8 | import org.openstreetmap.josm.data.Preferences.pref;
|
---|
9 | import org.openstreetmap.josm.data.Preferences.writeExplicitly;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Data class representing one entry in the filter dialog.
|
---|
13 | *
|
---|
14 | * @author Petr_Dlouhý
|
---|
15 | * @since 2125
|
---|
16 | */
|
---|
17 | public 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 | @pref public String version = "1";
|
---|
75 |
|
---|
76 | @pref 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 | @pref public String mode = "add";
|
---|
89 |
|
---|
90 | @pref public boolean case_sensitive;
|
---|
91 |
|
---|
92 | @pref public boolean regex_search;
|
---|
93 |
|
---|
94 | @pref public boolean mapCSS_search;
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Enabled status.
|
---|
98 | * @see Filter#enable
|
---|
99 | */
|
---|
100 | @writeExplicitly
|
---|
101 | @pref 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 | @pref 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 | @pref 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.toString();
|
---|
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 | }
|
---|