From 5b52f88329f9b1f8ed1f5b48039293fbafec0950 Mon Sep 17 00:00:00 2001 From: stoecker Date: Sun, 13 Mar 2022 12:40:25 +0000 Subject: [PATCH] fix #21922 - patch by Bjoeni - GPX file marked as modified when saving session git-svn-id: https://josm.openstreetmap.de/svn/trunk@18399 0c6e7542-c601-0410-84e7-c038aed88b3b --- .../openstreetmap/josm/data/gpx/GpxData.java | 30 +++++++++++++++---- .../openstreetmap/josm/data/gpx/GpxTrack.java | 11 ++++--- src/org/openstreetmap/josm/io/GpxWriter.java | 2 +- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/org/openstreetmap/josm/data/gpx/GpxData.java b/src/org/openstreetmap/josm/data/gpx/GpxData.java index 7338e15edae..4bce174328e 100644 --- a/src/org/openstreetmap/josm/data/gpx/GpxData.java +++ b/src/org/openstreetmap/josm/data/gpx/GpxData.java @@ -1092,10 +1092,29 @@ public synchronized boolean equals(Object obj) { return true; } + /** + * Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present). + * + * @param key the key + * @param value the value + */ @Override public void put(String key, Object value) { + put(key, value, true); + } + + /** + * Put a key / value pair as a new attribute. Overrides key / value pair with the same key (if present). + * Only sets the modified state when setModified is true. + * + * @param key the key + * @param value the value + * @param setModified whether to change the modified state + * @since 18399 + */ + public void put(String key, Object value, boolean setModified) { super.put(key, value); - invalidate(); + fireInvalidate(setModified); } /** @@ -1132,12 +1151,12 @@ public void invalidate() { } private void fireInvalidate(boolean setModified) { + if (setModified) { + setModified(true); + } if (updating || initializing) { suppressedInvalidate = true; } else { - if (setModified) { - setModified(true); - } if (listeners.hasListeners()) { GpxDataChangeEvent e = new GpxDataChangeEvent(this); listeners.fireEvent(l -> l.gpxDataChanged(e)); @@ -1158,10 +1177,9 @@ public void beginUpdate() { * @since 15496 */ public void endUpdate() { - boolean setModified = updating; updating = initializing = false; if (suppressedInvalidate) { - fireInvalidate(setModified); + fireInvalidate(false); suppressedInvalidate = false; } } diff --git a/src/org/openstreetmap/josm/data/gpx/GpxTrack.java b/src/org/openstreetmap/josm/data/gpx/GpxTrack.java index a3910fc1078..a496ded3fe0 100644 --- a/src/org/openstreetmap/josm/data/gpx/GpxTrack.java +++ b/src/org/openstreetmap/josm/data/gpx/GpxTrack.java @@ -82,18 +82,21 @@ private Bounds calculateBounds() { @Override public void setColor(Color color) { - setColorExtension(color); + setColorExtensionGPXD(color, true); colorCache = color; } - private void setColorExtension(Color color) { + private void setColorExtensionGPXD(Color color, boolean invalidate) { getExtensions().findAndRemove("gpxx", "DisplayColor"); if (color == null) { getExtensions().findAndRemove("gpxd", "color"); } else { getExtensions().addOrUpdate("gpxd", "color", String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue())); } - fireInvalidate(); + colorFormat = ColorFormat.GPXD; + if (invalidate) { + fireInvalidate(); + } } @Override @@ -167,7 +170,7 @@ public void convertColor(ColorFormat cFormat) { closestGarminColorCache.put(c, colorString); getExtensions().addIfNotPresent("gpxx", "TrackExtension").getExtensions().addOrUpdate("gpxx", "DisplayColor", colorString); } else if (cFormat == ColorFormat.GPXD) { - setColor(c); + setColorExtensionGPXD(c, false); } colorFormat = cFormat; } diff --git a/src/org/openstreetmap/josm/io/GpxWriter.java b/src/org/openstreetmap/josm/io/GpxWriter.java index 6c6c54e2708..6deef446df0 100644 --- a/src/org/openstreetmap/josm/io/GpxWriter.java +++ b/src/org/openstreetmap/josm/io/GpxWriter.java @@ -123,7 +123,7 @@ public void write(GpxData data, ColorFormat colorFormat, boolean savePrefs) { e.put("value", entry.getValue()); }); } - data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString()); + data.put(META_TIME, (metaTime != null ? metaTime : Instant.now()).toString(), false); data.endUpdate(); Collection all = new ArrayList<>();