This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 967040206d Fix the position of preferred CRS when the list is almost
empty.
967040206d is described below
commit 967040206d41089397493f11fcd530fc3645136c
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon May 4 11:44:50 2026 +0200
Fix the position of preferred CRS when the list is almost empty.
---
.../sis/gui/referencing/RecentReferenceSystems.java | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
index 10cc7bdaba..64131f997f 100644
---
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
+++
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/RecentReferenceSystems.java
@@ -89,6 +89,8 @@ public class RecentReferenceSystems {
/**
* Number of reference systems to always show before all other reference
systems.
* They are the native of preferred reference system for the visualized
data.
+ *
+ * @see #numCoreItems()
*/
private static final int NUM_CORE_ITEMS = 1;
@@ -420,6 +422,16 @@ public class RecentReferenceSystems {
refreshObservedReferenceSystemList();
}
+ /**
+ * Returns the number of reference systems to always show before all other
reference systems.
+ * This is {@link #NUM_CORE_ITEMS}, but taking in account the case when
the list is empty.
+ */
+ private int numCoreItems() {
+ int n = Math.min(systemsOrCodes.size(), NUM_CORE_ITEMS);
+ if (n != 0 && systemsOrCodes.get(n-1) == OTHER) n--;
+ return n;
+ }
+
/**
* Invoked when a new reference system is selected and has not been found
in the current list of systems.
* It may be, for example, a system selected among the content of a
registry shown by {@link CRSChooser}.
@@ -429,7 +441,7 @@ public class RecentReferenceSystems {
*/
final synchronized void addSelectedItem(final ReferenceSystem system) {
if (isAuthoritative(system)) {
- systemsOrCodes.add(Math.min(systemsOrCodes.size(),
NUM_CORE_ITEMS), system);
+ systemsOrCodes.add(numCoreItems(), system);
refreshObservedReferenceSystemList();
}
}
@@ -670,7 +682,7 @@ public class RecentReferenceSystems {
* is added. The first occurrence of duplicated values is kept, which
will result in above-cited
* order as the priority order where to insert the CRS.
*/
- final int insertAt = Math.min(systemsOrCodes.size(), NUM_CORE_ITEMS);
+ final int insertAt = numCoreItems();
final List<ReferenceSystem> selected = getSelectedItems();
systemsOrCodes.addAll(insertAt, selected);
systemsOrCodes.addAll(insertAt + selected.size(), referenceSystems);