- Timestamp:
- 2016-02-08T08:52:08+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r9332 r9759 23 23 24 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.data.Preferences.Setting;26 25 import org.openstreetmap.josm.data.Version; 27 26 import org.openstreetmap.josm.data.osm.DataSet; 28 27 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 28 import org.openstreetmap.josm.data.preferences.Setting; 29 29 import org.openstreetmap.josm.gui.ExtendedDialog; 30 30 import org.openstreetmap.josm.gui.widgets.JosmTextArea; -
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r9524 r9759 42 42 43 43 import org.openstreetmap.josm.Main; 44 import org.openstreetmap.josm.data. Preferences.ListListSetting;45 import org.openstreetmap.josm.data. Preferences.ListSetting;46 import org.openstreetmap.josm.data. Preferences.MapListSetting;47 import org.openstreetmap.josm.data. Preferences.Setting;48 import org.openstreetmap.josm.data. Preferences.StringSetting;44 import org.openstreetmap.josm.data.preferences.ListListSetting; 45 import org.openstreetmap.josm.data.preferences.ListSetting; 46 import org.openstreetmap.josm.data.preferences.MapListSetting; 47 import org.openstreetmap.josm.data.preferences.Setting; 48 import org.openstreetmap.josm.data.preferences.StringSetting; 49 49 import org.openstreetmap.josm.gui.io.DownloadFileTask; 50 50 import org.openstreetmap.josm.plugins.PluginDownloadTask; -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r9755 r9759 65 65 import org.openstreetmap.josm.Main; 66 66 import org.openstreetmap.josm.data.preferences.ColorProperty; 67 import org.openstreetmap.josm.data.preferences.ListListSetting; 68 import org.openstreetmap.josm.data.preferences.ListSetting; 69 import org.openstreetmap.josm.data.preferences.MapListSetting; 70 import org.openstreetmap.josm.data.preferences.Setting; 71 import org.openstreetmap.josm.data.preferences.SettingVisitor; 72 import org.openstreetmap.josm.data.preferences.StringSetting; 67 73 import org.openstreetmap.josm.io.CachedFile; 68 74 import org.openstreetmap.josm.io.OfflineAccessException; … … 158 164 */ 159 165 protected boolean initSuccessful = false; 160 161 /**162 * Interface for a preference value.163 *164 * Implementations must provide a proper <code>equals</code> method.165 *166 * @param <T> the data type for the value167 */168 public interface Setting<T> {169 /**170 * Returns the value of this setting.171 *172 * @return the value of this setting173 */174 T getValue();175 176 /**177 * Check if the value of this Setting object is equal to the given value.178 * @param otherVal the other value179 * @return true if the values are equal180 */181 boolean equalVal(T otherVal);182 183 /**184 * Clone the current object.185 * @return an identical copy of the current object186 */187 Setting<T> copy();188 189 /**190 * Enable usage of the visitor pattern.191 *192 * @param visitor the visitor193 */194 void visit(SettingVisitor visitor);195 196 /**197 * Returns a setting whose value is null.198 *199 * Cannot be static, because there is no static inheritance.200 * @return a Setting object that isn't null itself, but returns null201 * for {@link #getValue()}202 */203 Setting<T> getNullInstance();204 }205 206 /**207 * Base abstract class of all settings, holding the setting value.208 *209 * @param <T> The setting type210 */211 public abstract static class AbstractSetting<T> implements Setting<T> {212 protected final T value;213 /**214 * Constructs a new {@code AbstractSetting} with the given value215 * @param value The setting value216 */217 public AbstractSetting(T value) {218 this.value = value;219 }220 221 @Override222 public T getValue() {223 return value;224 }225 226 @Override227 public String toString() {228 return value != null ? value.toString() : "null";229 }230 231 @Override232 public int hashCode() {233 return Objects.hash(value);234 }235 236 @Override237 public boolean equals(Object obj) {238 if (this == obj) return true;239 if (obj == null || getClass() != obj.getClass()) return false;240 AbstractSetting<?> that = (AbstractSetting<?>) obj;241 return Objects.equals(value, that.value);242 }243 }244 245 /**246 * Setting containing a {@link String} value.247 */248 public static class StringSetting extends AbstractSetting<String> {249 /**250 * Constructs a new {@code StringSetting} with the given value251 * @param value The setting value252 */253 public StringSetting(String value) {254 super(value);255 }256 257 @Override258 public boolean equalVal(String otherVal) {259 if (value == null) return otherVal == null;260 return value.equals(otherVal);261 }262 263 @Override264 public StringSetting copy() {265 return new StringSetting(value);266 }267 268 @Override269 public void visit(SettingVisitor visitor) {270 visitor.visit(this);271 }272 273 @Override274 public StringSetting getNullInstance() {275 return new StringSetting(null);276 }277 278 @Override279 public boolean equals(Object other) {280 if (!(other instanceof StringSetting)) return false;281 return equalVal(((StringSetting) other).getValue());282 }283 }284 285 /**286 * Setting containing a {@link List} of {@link String} values.287 */288 public static class ListSetting extends AbstractSetting<List<String>> {289 /**290 * Constructs a new {@code ListSetting} with the given value291 * @param value The setting value292 */293 public ListSetting(List<String> value) {294 super(value);295 consistencyTest();296 }297 298 /**299 * Convenience factory method.300 * @param value the value301 * @return a corresponding ListSetting object302 */303 public static ListSetting create(Collection<String> value) {304 return new ListSetting(value == null ? null : Collections.unmodifiableList(new ArrayList<>(value)));305 }306 307 @Override308 public boolean equalVal(List<String> otherVal) {309 return Utils.equalCollection(value, otherVal);310 }311 312 @Override313 public ListSetting copy() {314 return ListSetting.create(value);315 }316 317 private void consistencyTest() {318 if (value != null && value.contains(null))319 throw new RuntimeException("Error: Null as list element in preference setting");320 }321 322 @Override323 public void visit(SettingVisitor visitor) {324 visitor.visit(this);325 }326 327 @Override328 public ListSetting getNullInstance() {329 return new ListSetting(null);330 }331 332 @Override333 public boolean equals(Object other) {334 if (!(other instanceof ListSetting)) return false;335 return equalVal(((ListSetting) other).getValue());336 }337 }338 339 /**340 * Setting containing a {@link List} of {@code List}s of {@link String} values.341 */342 public static class ListListSetting extends AbstractSetting<List<List<String>>> {343 344 /**345 * Constructs a new {@code ListListSetting} with the given value346 * @param value The setting value347 */348 public ListListSetting(List<List<String>> value) {349 super(value);350 consistencyTest();351 }352 353 /**354 * Convenience factory method.355 * @param value the value356 * @return a corresponding ListListSetting object357 */358 public static ListListSetting create(Collection<Collection<String>> value) {359 if (value != null) {360 List<List<String>> valueList = new ArrayList<>(value.size());361 for (Collection<String> lst : value) {362 valueList.add(new ArrayList<>(lst));363 }364 return new ListListSetting(valueList);365 }366 return new ListListSetting(null);367 }368 369 @Override370 public boolean equalVal(List<List<String>> otherVal) {371 if (value == null) return otherVal == null;372 if (otherVal == null) return false;373 if (value.size() != otherVal.size()) return false;374 Iterator<List<String>> itA = value.iterator();375 Iterator<List<String>> itB = otherVal.iterator();376 while (itA.hasNext()) {377 if (!Utils.equalCollection(itA.next(), itB.next())) return false;378 }379 return true;380 }381 382 @Override383 public ListListSetting copy() {384 if (value == null) return new ListListSetting(null);385 386 List<List<String>> copy = new ArrayList<>(value.size());387 for (Collection<String> lst : value) {388 List<String> lstCopy = new ArrayList<>(lst);389 copy.add(Collections.unmodifiableList(lstCopy));390 }391 return new ListListSetting(Collections.unmodifiableList(copy));392 }393 394 private void consistencyTest() {395 if (value == null) return;396 if (value.contains(null)) throw new RuntimeException("Error: Null as list element in preference setting");397 for (Collection<String> lst : value) {398 if (lst.contains(null)) throw new RuntimeException("Error: Null as inner list element in preference setting");399 }400 }401 402 @Override403 public void visit(SettingVisitor visitor) {404 visitor.visit(this);405 }406 407 @Override408 public ListListSetting getNullInstance() {409 return new ListListSetting(null);410 }411 412 @Override413 public boolean equals(Object other) {414 if (!(other instanceof ListListSetting)) return false;415 return equalVal(((ListListSetting) other).getValue());416 }417 }418 419 /**420 * Setting containing a {@link List} of {@link Map}s of {@link String} values.421 */422 public static class MapListSetting extends AbstractSetting<List<Map<String, String>>> {423 424 /**425 * Constructs a new {@code MapListSetting} with the given value426 * @param value The setting value427 */428 public MapListSetting(List<Map<String, String>> value) {429 super(value);430 consistencyTest();431 }432 433 @Override434 public boolean equalVal(List<Map<String, String>> otherVal) {435 if (value == null) return otherVal == null;436 if (otherVal == null) return false;437 if (value.size() != otherVal.size()) return false;438 Iterator<Map<String, String>> itA = value.iterator();439 Iterator<Map<String, String>> itB = otherVal.iterator();440 while (itA.hasNext()) {441 if (!equalMap(itA.next(), itB.next())) return false;442 }443 return true;444 }445 446 private static boolean equalMap(Map<String, String> a, Map<String, String> b) {447 if (a == null) return b == null;448 if (b == null) return false;449 if (a.size() != b.size()) return false;450 for (Entry<String, String> e : a.entrySet()) {451 if (!Objects.equals(e.getValue(), b.get(e.getKey()))) return false;452 }453 return true;454 }455 456 @Override457 public MapListSetting copy() {458 if (value == null) return new MapListSetting(null);459 List<Map<String, String>> copy = new ArrayList<>(value.size());460 for (Map<String, String> map : value) {461 Map<String, String> mapCopy = new LinkedHashMap<>(map);462 copy.add(Collections.unmodifiableMap(mapCopy));463 }464 return new MapListSetting(Collections.unmodifiableList(copy));465 }466 467 private void consistencyTest() {468 if (value == null) return;469 if (value.contains(null)) throw new RuntimeException("Error: Null as list element in preference setting");470 for (Map<String, String> map : value) {471 if (map.keySet().contains(null)) throw new RuntimeException("Error: Null as map key in preference setting");472 if (map.values().contains(null)) throw new RuntimeException("Error: Null as map value in preference setting");473 }474 }475 476 @Override477 public void visit(SettingVisitor visitor) {478 visitor.visit(this);479 }480 481 @Override482 public MapListSetting getNullInstance() {483 return new MapListSetting(null);484 }485 486 @Override487 public boolean equals(Object other) {488 if (!(other instanceof MapListSetting)) return false;489 return equalVal(((MapListSetting) other).getValue());490 }491 }492 493 public interface SettingVisitor {494 void visit(StringSetting setting);495 496 void visit(ListSetting value);497 498 void visit(ListListSetting value);499 500 void visit(MapListSetting value);501 }502 166 503 167 /** -
trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java
r9527 r9759 9 9 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 10 10 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 11 import org.openstreetmap.josm.data.Preferences.StringSetting;12 11 import org.openstreetmap.josm.data.osm.User; 13 12 import org.openstreetmap.josm.data.osm.UserInfo; 13 import org.openstreetmap.josm.data.preferences.StringSetting; 14 14 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 15 15 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r9685 r9759 41 41 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 42 42 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 43 import org.openstreetmap.josm.data.Preferences.Setting;44 43 import org.openstreetmap.josm.data.Version; 45 44 import org.openstreetmap.josm.data.osm.Changeset; 46 45 import org.openstreetmap.josm.data.osm.DataSet; 47 46 import org.openstreetmap.josm.data.osm.OsmPrimitive; 47 import org.openstreetmap.josm.data.preferences.Setting; 48 48 import org.openstreetmap.josm.gui.ExtendedDialog; 49 49 import org.openstreetmap.josm.gui.HelpAwareOptionPane; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r9622 r9759 40 40 import org.openstreetmap.josm.data.CustomConfigurator; 41 41 import org.openstreetmap.josm.data.Preferences; 42 import org.openstreetmap.josm.data.Preferences.Setting; 42 import org.openstreetmap.josm.data.preferences.Setting; 43 import org.openstreetmap.josm.data.preferences.StringSetting; 43 44 import org.openstreetmap.josm.gui.dialogs.LogShowDialog; 44 45 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting; … … 241 242 for (PrefEntry p: table.getSelectedItems()) { 242 243 // preferences with default values are not saved 243 if (!(p.getValue() instanceof Preferences.StringSetting)) {244 if (!(p.getValue() instanceof StringSetting)) { 244 245 hasLists = true; // => append and replace differs 245 246 } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileAction.java
r9239 r9759 20 20 import org.openstreetmap.josm.data.CustomConfigurator; 21 21 import org.openstreetmap.josm.data.Preferences; 22 import org.openstreetmap.josm.data. Preferences.Setting;22 import org.openstreetmap.josm.data.preferences.Setting; 23 23 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 24 24 import org.openstreetmap.josm.tools.Utils; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ListEditor.java
r9507 r9759 16 16 import javax.swing.table.AbstractTableModel; 17 17 18 import org.openstreetmap.josm.data. Preferences.ListSetting;18 import org.openstreetmap.josm.data.preferences.ListSetting; 19 19 import org.openstreetmap.josm.gui.widgets.JosmTextField; 20 20 import org.openstreetmap.josm.tools.GBC; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ListListEditor.java
r9507 r9759 12 12 import javax.swing.table.AbstractTableModel; 13 13 14 import org.openstreetmap.josm.data. Preferences.ListListSetting;14 import org.openstreetmap.josm.data.preferences.ListListSetting; 15 15 16 16 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/MapListEditor.java
r9507 r9759 16 16 import javax.swing.table.AbstractTableModel; 17 17 18 import org.openstreetmap.josm.data. Preferences.MapListSetting;18 import org.openstreetmap.josm.data.preferences.MapListSetting; 19 19 20 20 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PrefEntry.java
r9078 r9759 2 2 package org.openstreetmap.josm.gui.preferences.advanced; 3 3 4 import org.openstreetmap.josm.data. Preferences.Setting;4 import org.openstreetmap.josm.data.preferences.Setting; 5 5 import org.openstreetmap.josm.tools.CheckParameterUtil; 6 6 -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTable.java
r9224 r9759 29 29 30 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.data. Preferences.ListListSetting;32 import org.openstreetmap.josm.data. Preferences.ListSetting;33 import org.openstreetmap.josm.data. Preferences.MapListSetting;34 import org.openstreetmap.josm.data. Preferences.Setting;35 import org.openstreetmap.josm.data. Preferences.StringSetting;31 import org.openstreetmap.josm.data.preferences.ListListSetting; 32 import org.openstreetmap.josm.data.preferences.ListSetting; 33 import org.openstreetmap.josm.data.preferences.MapListSetting; 34 import org.openstreetmap.josm.data.preferences.Setting; 35 import org.openstreetmap.josm.data.preferences.StringSetting; 36 36 import org.openstreetmap.josm.gui.ExtendedDialog; 37 37 import org.openstreetmap.josm.gui.util.GuiHelper; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/StringEditor.java
r9239 r9759 10 10 import javax.swing.JPanel; 11 11 12 import org.openstreetmap.josm.data. Preferences.StringSetting;12 import org.openstreetmap.josm.data.preferences.StringSetting; 13 13 import org.openstreetmap.josm.gui.ExtendedDialog; 14 14 import org.openstreetmap.josm.gui.widgets.JosmTextField;
Note:
See TracChangeset
for help on using the changeset viewer.