This is an automated email from the ASF dual-hosted git repository.
desruisseaux 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 3a021d2345 Consolidation of the handling of CRS shown in the status
bar.
3a021d2345 is described below
commit 3a021d234527488a0edcd951a04b50102d08466c
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue Mar 31 15:55:58 2026 +0200
Consolidation of the handling of CRS shown in the status bar.
---
.../apache/sis/gui/coverage/CoverageControls.java | 25 +++++++---
.../main/org/apache/sis/gui/map/MapCanvas.java | 11 +++--
.../main/org/apache/sis/gui/map/MapMenu.java | 18 ++++---
.../main/org/apache/sis/gui/map/StatusBar.java | 31 ++++++------
.../org/apache/sis/gui/referencing/MenuSync.java | 57 ++++++++++++++--------
.../gui/referencing/RecentReferenceSystems.java | 28 +++++------
6 files changed, 97 insertions(+), 73 deletions(-)
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageControls.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageControls.java
index f53be4ff3a..65106c39bd 100644
---
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageControls.java
+++
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageControls.java
@@ -82,13 +82,13 @@ final class CoverageControls extends ViewAndControls {
final MapMenu menu = new MapMenu(view);
menu.addReferenceSystems(owner.referenceSystems);
menu.addCopyOptions(status);
- final ObservableObjectValue<String> selectedReferenceSystem =
menu.selectedReferenceSystem().orElse(null);
- if (selectedReferenceSystem == null) {
+ final ObservableObjectValue<String> mapCRS =
menu.selectedReferenceSystem().orElse(null);
+ if (mapCRS == null) {
referenceSystemTooltip = null;
} else {
referenceSystemTooltip = new
Tooltip(resources.getString(Resources.Keys.SelectCrsByContextMenu));
- selectedReferenceSystem.addListener((p,o,n) ->
notifyReferenceSystemChanged(n, status.positionReferenceSystemName().get()));
- status.positionReferenceSystemName().addListener((p,o,n) ->
notifyReferenceSystemChanged(selectedReferenceSystem.get(), n));
+ mapCRS.addListener((p,o,n) -> notifyReferenceSystemChanged(n,
status.getReferenceSystemName().get(), true));
+ status.getReferenceSystemName().addListener((p,o,n) ->
notifyReferenceSystemChanged(mapCRS.get(), n, false));
}
/*
* "Layers" section with the following controls:
@@ -135,12 +135,21 @@ final class CoverageControls extends ViewAndControls {
/**
* Invoked in JavaFX thread after the reference system of the coverage or
of the status bar changed.
+ * The {@code interim} argument is {@code true} if the change was in the
<abbr>CRS</abbr> of the map,
+ * and the <abbr>CRS</abbr> shown in the status bar is expected to be
updated to the same value soon.
+ * In the latter case, we avoid distracting the user with a message saying
that the reference systems
+ * are not consistent.
*
- * @param coverage the name of the reference system of the rendered
coverage.
- * @param coordinates the name of the reference system of coordinates
shown in the status bar.
+ * @param coverage the name of the reference system of the rendered
coverage.
+ * @param coordinates the name of the reference system of coordinates
shown in the status bar.
+ * @param interim {@code true} if this event is expected to be
followed soon by another event.
*/
- private void notifyReferenceSystemChanged(String coverage, String
coordinates) {
- if (coverage != null && !coverage.equalsIgnoreCase(coordinates)) {
+ private void notifyReferenceSystemChanged(String coverage, final String
coordinates, final boolean interim) {
+ if (coverage != null && coordinates != null &&
!coverage.equals(coordinates)) {
+ if (interim) {
+ status.setDefaultMessage(null, referenceSystemTooltip);
+ return;
+ }
coverage =
Resources.forLocale(owner.getLocale()).getString(Resources.Keys.MismatchedRS);
}
status.setDefaultMessage(coverage, coverage == null ? null :
referenceSystemTooltip);
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
index b9ee1bade1..a3e9114511 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
@@ -755,8 +755,8 @@ public abstract class MapCanvas extends PlanarCanvas {
public void changed(final ObservableValue<? extends ReferenceSystem>
property,
final ReferenceSystem oldValue, final
ReferenceSystem newValue)
{
- if (newValue instanceof CoordinateReferenceSystem) {
- setObjectiveCRS((CoordinateReferenceSystem) newValue, this,
property);
+ if (newValue instanceof CoordinateReferenceSystem crs) {
+ setObjectiveCRS(crs, this, property);
}
}
@@ -792,9 +792,8 @@ public abstract class MapCanvas extends PlanarCanvas {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (OBJECTIVE_CRS_PROPERTY.equals(event.getPropertyName())) {
- final Object value = event.getNewValue();
- if (value instanceof ReferenceSystem) {
- selectedCrsProperty.set((ReferenceSystem) value);
+ if (event.getNewValue() instanceof ReferenceSystem value) {
+ selectedCrsProperty.set(value);
}
if (!isPositionableProjection) {
positionables.selectToggle(null);
@@ -1332,6 +1331,7 @@ public abstract class MapCanvas extends PlanarCanvas {
/**
* Invoked after the background thread created by {@link #repaint()}
finished to update map content.
+ * This method should be invoked in all cases: after successful
completion, failure or cancellation.
* The {@link #changeInProgress} is the JavaFX transform at the time the
repaint event was trigged and
* which is now integrated in the map. That transform will be removed from
{@link #floatingPane} transforms.
* The {@link #transform} result is identity if no zoom, rotation or pan
gesture has been applied since last
@@ -1522,6 +1522,7 @@ public abstract class MapCanvas extends PlanarCanvas {
* Returns a property telling whether a rendering is in progress. This
property become {@code true}
* when this {@code MapCanvas} is about to start a background thread for
performing a rendering, and
* is reset to {@code false} after this {@code MapCanvas} has been updated
with new rendering result.
+ * The reset to {@code false} happens in all cases: after successful
completion, failure or cancellation.
*
* @return a property telling whether a rendering is in progress.
*
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapMenu.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapMenu.java
index 3c943cdbc7..23b28cb580 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapMenu.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapMenu.java
@@ -122,7 +122,7 @@ public class MapMenu extends ContextMenu {
}
/**
- * Adds menu items for CRS selection. The menu items are in two groups:
+ * Adds menu items for <abbr>CRS</abbr> selection. The menu items are in
two groups:
*
* <ul>
* <li><i>Reference system</i> with some items from EPSG database.</li>
@@ -142,12 +142,12 @@ public class MapMenu extends ContextMenu {
final MapCanvas.MenuHandler handler = startNewMenuItems(CRS);
final Menu systemChoices = preferences.createMenuItems(true, handler);
handler.selectedCrsProperty =
RecentReferenceSystems.getSelectedProperty(systemChoices);
- handler.positionables = new ToggleGroup();
+ handler.positionables = new ToggleGroup();
final Resources resources = Resources.forLocale(canvas.getLocale());
final Menu localSystems = new
Menu(resources.getString(Resources.Keys.CenteredProjection));
for (final PositionableProjection projection :
PositionableProjection.values()) {
- final RadioMenuItem item = new
RadioMenuItem(projection.toString());
+ final var item = new RadioMenuItem(projection.toString());
item.setToggleGroup(handler.positionables);
item.setOnAction((e) -> handler.createProjectedCRS(projection));
localSystems.getItems().add(item);
@@ -158,10 +158,12 @@ public class MapMenu extends ContextMenu {
/**
* Adds a menu item for copying coordinates at the mouse position where
right click occurred.
- * The coordinate reference system is determined by the status bar; it is
not necessarily the
- * coordinate reference system of the map.
+ * The coordinate reference system is determined by the status bar,
+ * it is not necessarily the coordinate reference system of the map.
+ * This method can be invoked at most once.
*
* @param format status bar determining the CRS and format to use for
coordinate values.
+ * @throws IllegalStateException if this method has already been invoked.
*/
public void addCopyOptions(final StatusBar format) {
Objects.requireNonNull(format);
@@ -170,7 +172,7 @@ public class MapMenu extends ContextMenu {
final MenuItem coordinates =
resources.menu(Resources.Keys.CopyCoordinates, (event) -> {
try {
final String text =
format.formatTabSeparatedCoordinates(handler.x, handler.y);
- final ClipboardContent content = new ClipboardContent();
+ final var content = new ClipboardContent();
content.putString(text);
Clipboard.getSystemClipboard().setContent(content);
} catch (TransformException | RuntimeException e) {
@@ -181,10 +183,10 @@ public class MapMenu extends ContextMenu {
}
/**
- * Returns an observable value for showing the name of the currently
selected <abbr>CRS</abbr>.
+ * Returns an observable value for showing the name of the currently
selected <abbr>CRS</abbr> for the map canvas.
* The value is absent if {@link
#addReferenceSystems(RecentReferenceSystems)} has never been invoked.
*
- * @return the currently selected <abbr>CRS</abbr> as a text.
+ * @return name of the currently selected <abbr>CRS</abbr> for the map
canvas.
*
* @see #addReferenceSystems(RecentReferenceSystems)
*/
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/StatusBar.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/StatusBar.java
index 9ef30b67b7..5032f31028 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/StatusBar.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/StatusBar.java
@@ -49,8 +49,8 @@ import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ObjectPropertyBase;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectPropertyBase;
-import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ObservableStringValue;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
@@ -286,7 +286,7 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
* directly instead. We omit the "Property" suffix for making this
operation more natural.
*
* @see #position
- * @see #positionReferenceSystemName()
+ * @see #getReferenceSystemName()
*/
public final ReadOnlyObjectProperty<ReferenceSystem>
positionReferenceSystem;
@@ -430,7 +430,7 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
* The text property of this tool tip may be used outside this class.
*
* @see #positionReferenceSystem
- * @see #positionReferenceSystemName()
+ * @see #getReferenceSystemName()
*/
private final Tooltip positionReferenceSystemName;
@@ -549,19 +549,18 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
/*
* Create a contextual menu offering to user a choice of CRS in which
to display the coordinates.
* The CRS choices are controlled by `RecentReferenceSystems`.
Selection of a new CRS causes the
- * `setPositionCRS(…)` method to be invoked.
+ * `setPositionCRS(…)` or `setPositionRID(…)` method to be invoked,
which may do their work in a
+ * background thread. Therefore, change of selected menu item may not
take effect immediately.
*/
this.systemChooser = systemChooser;
if (systemChooser == null) {
selectedSystem = null;
} else {
final Menu choices = systemChooser.createMenuItems(false,
(property, oldValue, newValue) -> {
- if (newValue instanceof CoordinateReferenceSystem) {
- setPositionCRS((CoordinateReferenceSystem) newValue);
- } else if (newValue instanceof ReferencingByIdentifiers) {
- setPositionRID((ReferencingByIdentifiers) newValue);
- } else {
- setPositionCRS(null); // Default to `objectiveCRS`.
+ switch (newValue) {
+ case CoordinateReferenceSystem rs -> setPositionCRS(rs);
+ case ReferencingByIdentifiers rs -> setPositionRID(rs);
+ default /* Canvas objective CRS */ -> setPositionCRS(null);
}
});
selectedSystem =
RecentReferenceSystems.getSelectedProperty(choices);
@@ -622,14 +621,16 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
Errors.Keys.TooManyCollectionElements_3, "canvas", 1,
2));
}
/*
- * If a canvas is specified, register listeners for mouse position,
rendering events, errors, etc.
+ * Register listeners on the specified canvas for mouse position,
rendering events, errors, etc.
* We do not allow the canvas to be changed after construction because
of the added complexity
* (e.g. we would have to remember all registered listeners so we can
unregister them).
*/
this.canvas = Objects.requireNonNull(canvas);
sampleValuesProvider.set(ValuesUnderCursor.create(canvas));
canvas.errorProperty().addListener((p,o,n) -> setRenderingError(n));
- canvas.renderingProperty().addListener((p,o,n) -> {if (!n)
applyCanvasGeometry();});
+ canvas.renderingProperty().addListener((p,o,n) -> {
+ if (!n) applyCanvasGeometry(); // Apply only after completion
of the background rendering task.
+ });
applyCanvasGeometry();
if (canvas.getObjectiveCRS() != null) {
registerMouseListeners();
@@ -909,8 +910,8 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
/**
* Sets the coordinate reference system of the position shown in this
status bar.
- * The change may not appear immediately after method return; this method
may use a
- * background thread for computing the coordinate operation. That task
may be long
+ * The change may not appear immediately after method return, as this
method may use
+ * a background thread for computing the coordinate operation. That task
may be long
* the first time that it is executed, but should be fast on subsequent
invocations.
*
* @param crs the new CRS, or {@code null} for {@link #objectiveCRS}.
@@ -1612,7 +1613,7 @@ public class StatusBar extends Widget implements
EventHandler<MouseEvent> {
* @see #positionReferenceSystem
* @since 1.7
*/
- public ReadOnlyStringProperty positionReferenceSystemName() {
+ public ObservableStringValue getReferenceSystemName() {
return positionReferenceSystemName.textProperty();
}
diff --git
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
index 409812c2c7..36236ed27d 100644
---
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
+++
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/MenuSync.java
@@ -102,21 +102,28 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
private final ToggleGroup group;
/**
- * The action to execute when a reference system is selected. This is not
directly the user-specified action,
- * but rather a {@link
org.apache.sis.gui.referencing.RecentReferenceSystems.SelectionListener}
instance wrapping
- * that action. This listener is invoked explicitly instead of using
{@link SimpleObjectProperty} listeners because
- * we do not invoke it in all cases.
+ * The action to execute when a reference system is selected. This is the
action given in argument to the
+ * public {@link RecentReferenceSystems#createMenuItems(boolean,
ChangeListener)} method but wrapped in a
+ * {@link
org.apache.sis.gui.referencing.RecentReferenceSystems.SelectionListener}
instance for managing
+ * side-effects such as changing the <abbr>CRS</abbr> order in the list of
menu items.
+ *
+ * <p>This listener is not registered as a {@link SimpleObjectProperty}
listeners.
+ * Instead, its {@code changed(…)} method is invoked directly because we
do not want
+ * to notify the listener in all cases.</p>
+ *
+ * @see RecentReferenceSystems#createMenuItems(boolean, ChangeListener)
*/
private final RecentReferenceSystems.SelectionListener action;
/**
* Creates a new synchronization for the given list of menu items.
+ * The public method for this constructor is {@link
RecentReferenceSystems#createMenuItems(boolean, ChangeListener)}.
*
* @param systems the reference systems for which to build menu items.
* @param byIds whether to add a sub-menu for "Referencing by
identifiers".
* @param derived content of "Referencing by cell indices" sub-menu, or
{@code null} for omitting that sub-menu.
* @param bean the menu to keep synchronized with the list of
reference systems.
- * @param action the user-specified action to execute when a reference
system is selected.
+ * @param action a wrapper over the user-specified action to execute
when a reference system is selected.
*/
MenuSync(final List<ReferenceSystem> systems, final boolean byIds, final
List<DerivedCRS> derived,
final Menu bean, final RecentReferenceSystems.SelectionListener
action)
@@ -130,7 +137,7 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
/*
* Root menu. The list of recent reference system is dynamic and will
change according user actions.
*/
- final List<MenuItem> items = new ArrayList<>(systems.size() + 1);
+ final var items = new ArrayList<MenuItem>(systems.size() + 1);
final Locale locale = action.owner().locale;
for (final ReferenceSystem system : systems) {
if (system == RecentReferenceSystems.OTHER) {
@@ -165,9 +172,9 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
*/
private void initialize() {
for (final ReferenceSystem system : recentSystems) {
- if (system instanceof CoordinateReferenceSystem) {
- if (CRS.getDimensionOrZero((CoordinateReferenceSystem) system)
== BIDIMENSIONAL) {
- set(system);
+ if (system instanceof CoordinateReferenceSystem crs) {
+ if (CRS.getDimensionOrZero(crs) == BIDIMENSIONAL) {
+ set(crs);
break;
}
}
@@ -179,12 +186,12 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
*/
private MenuItem createItem(final ReferenceSystem system, final Locale
locale) {
if (system == RecentReferenceSystems.OTHER) {
- final MenuItem item = new
MenuItem(ObjectStringConverter.other(locale));
+ final var item = new MenuItem(ObjectStringConverter.other(locale));
item.getProperties().put(REFERENCE_SYSTEM_KEY, CHOOSER);
item.setOnAction(this);
return item;
} else {
- final RadioMenuItem item = new
RadioMenuItem(IdentifiedObjects.getDisplayName(system, locale));
+ final var item = new
RadioMenuItem(IdentifiedObjects.getDisplayName(system, locale));
item.getProperties().put(REFERENCE_SYSTEM_KEY, system);
item.setToggleGroup(group);
item.setOnAction(this);
@@ -194,7 +201,8 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
/**
* Creates new menu items for references system by identifiers, offered in
a separated sub-menu.
- * This list of reference systems is fixed; items are not added or removed
following user's selection.
+ * This list of reference systems is fixed, items are not added or removed
by user's selection.
+ * This method is invoked indirectly by {@link
RecentReferenceSystems#createMenuItems(boolean, ChangeListener)}.
*/
private void addReferencingByIdentifiers(final Locale locale) {
final GazetteerFactory factory = new GazetteerFactory();
@@ -237,7 +245,7 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
}
}
for (int i = cellIndicesMenus.size(); --i >= n;) {
- final RadioMenuItem item = (RadioMenuItem)
cellIndicesMenus.remove(i);
+ final var item = (RadioMenuItem) cellIndicesMenus.remove(i);
item.setToggleGroup(null);
item.setOnAction(null);
}
@@ -271,13 +279,15 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
final var mapping = new IdentityHashMap<Object,MenuItem>(10);
for (final Iterator<MenuItem> it = rootMenus.iterator();
it.hasNext();) {
final MenuItem item = it.next();
- if (item instanceof Menu) {
- subMenus.add((Menu) item);
- } else if (item instanceof SeparatorMenuItem) {
- separator = (SeparatorMenuItem) item; // Should have
only one.
- } else if
(mapping.putIfAbsent(item.getProperties().get(REFERENCE_SYSTEM_KEY), item) !=
null) {
- it.remove(); // Remove duplicated item. Should never
happen, but we are paranoiac.
- dispose(item);
+ switch (item) {
+ case Menu c -> subMenus.add(c);
+ case SeparatorMenuItem c -> separator = c; // Should have
only one.
+ default -> {
+ if
(mapping.putIfAbsent(item.getProperties().get(REFERENCE_SYSTEM_KEY), item) !=
null) {
+ it.remove(); // Remove duplicated item. Should
never happen, but we are paranoiac.
+ dispose(item);
+ }
+ }
}
}
/*
@@ -367,7 +377,7 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
if (value == CHOOSER) {
action.changed(this, get(), RecentReferenceSystems.OTHER);
} else {
- final ReferenceSystem system = (ReferenceSystem) value;
+ final var system = (ReferenceSystem) value;
if (cellIndicesMenus != null && cellIndicesMenus.contains(source))
{
final ReferenceSystem old = get();
super.set(system); // Set without
adding to `recentSystems` list.
@@ -399,6 +409,11 @@ final class MenuSync extends
SimpleObjectProperty<ReferenceSystem> implements Ev
((RadioMenuItem) item).setSelected(true);
action.changed(this, old, system);
return;
+ /*
+ * Note: if the action was provided by `MapCanvas`,
the call to `action.changed(…)`
+ * may start a background task which will invoke
`StatusBar.applyCanvasGeometry(…)`
+ * after completion, when the `MapCanvas.isRendering`
flag is reset to `false`.
+ */
}
}
}
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 26ff43c839..76eac51ae7 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
@@ -184,11 +184,8 @@ public class RecentReferenceSystems {
/** Returns the verified (if possible) reference system. */
ReferenceSystem find(final IdentifiedObjectFinder finder) throws
FactoryException {
- if (finder != null) {
- final IdentifiedObject replacement =
finder.findSingleton(system);
- if (replacement instanceof ReferenceSystem) {
- return (ReferenceSystem) replacement;
- }
+ if (finder != null && finder.findSingleton(system) instanceof
ReferenceSystem replacement) {
+ return replacement;
}
return system;
}
@@ -553,7 +550,7 @@ public class RecentReferenceSystems {
*/
private List<ReferenceSystem> filterReferenceSystems(final
ImmutableEnvelope domain, final ComparisonMode mode) {
final List<ReferenceSystem> systems;
- final GazetteerFactory gf = new GazetteerFactory(); // Cheap to
construct.
+ final var gf = new GazetteerFactory(); // Cheap to
construct.
synchronized (systemsOrCodes) {
@SuppressWarnings("LocalVariableHidesMemberVariable")
CRSAuthorityFactory factory = this.factory; // Hide
volatile field by local field.
@@ -651,7 +648,7 @@ public class RecentReferenceSystems {
final int n = systemsOrCodes.size();
systems = new ArrayList<>(Math.min(NUM_SHOWN_ITEMS, n) +
NUM_OTHER_ITEMS);
for (int i=0; i<n; i++) {
- final ReferenceSystem system = (ReferenceSystem)
systemsOrCodes.get(i);
+ final var system = (ReferenceSystem) systemsOrCodes.get(i);
if (i >= NUM_CORE_ITEMS && !Utils.intersects(domain, system)) {
continue;
}
@@ -836,7 +833,7 @@ public class RecentReferenceSystems {
}
final ComparisonMode mode = duplicationCriterion.get();
if (newValue == OTHER) {
- final CRSChooser chooser = new CRSChooser(factory,
geographicAOI, locale);
+ final var chooser = new CRSChooser(factory, geographicAOI,
locale);
newValue =
chooser.showDialog(GUIUtilities.getWindow(property)).orElse(null);
if (newValue == null) {
newValue = oldValue;
@@ -970,7 +967,7 @@ public class RecentReferenceSystems {
* (usually no more than 3 elements) that it is not worth to use
HashSet.
*/
int count = 0;
- final ReferenceSystem[] selected = new
ReferenceSystem[controlValues.size()];
+ final var selected = new ReferenceSystem[controlValues.size()];
for (final WritableValue<ReferenceSystem> value : controlValues) {
final ReferenceSystem system = value.getValue();
if (system != null) selected[count++] = system;
@@ -1001,7 +998,7 @@ public class RecentReferenceSystems {
*/
next: for (int i=0; i<count; i++) {
final ReferenceSystem system = selected[i];
- for (int j=ordered.size(); --j >= 0;) {
+ for (int j = ordered.size(); --j >= 0;) {
if (ordered.get(j) == system) {
continue next; // Skip duplicated
value.
}
@@ -1035,7 +1032,7 @@ next: for (int i=0; i<count; i++) {
*/
public ChoiceBox<ReferenceSystem> createChoiceBox(final boolean filtered,
final ChangeListener<ReferenceSystem> action) {
ArgumentChecks.ensureNonNull("action", action);
- final ChoiceBox<ReferenceSystem> choices = new
ChoiceBox<>(getReferenceSystems(filtered));
+ final var choices = new
ChoiceBox<ReferenceSystem>(getReferenceSystems(filtered));
choices.setConverter(new ObjectStringConverter<>(choices.getItems(),
locale));
choices.valueProperty().addListener(new SelectionListener(action));
controlValues.add(choices.valueProperty());
@@ -1066,8 +1063,8 @@ next: for (int i=0; i<count; i++) {
ArgumentChecks.ensureNonNull("action", action);
final List<ReferenceSystem> main = getReferenceSystems(filtered);
final List<DerivedCRS> derived = (filtered) ? null : cellIndiceSystems;
- final Menu menu = new
Menu(Vocabulary.forLocale(locale).getString(Vocabulary.Keys.ReferenceSystem));
- final MenuSync property = new MenuSync(main, !filtered, derived, menu,
new SelectionListener(action));
+ final var menu = new
Menu(Vocabulary.forLocale(locale).getString(Vocabulary.Keys.ReferenceSystem));
+ final var property = new MenuSync(main, !filtered, derived, menu, new
SelectionListener(action));
menu.getProperties().put(SELECTED_ITEM_KEY, property);
controlValues.add(property);
return menu;
@@ -1081,9 +1078,8 @@ next: for (int i=0; i<count; i++) {
*/
public static ObjectProperty<ReferenceSystem> getSelectedProperty(final
Menu menu) {
if (menu != null) {
- final Object property =
menu.getProperties().get(SELECTED_ITEM_KEY);
- if (property instanceof MenuSync) {
- return (MenuSync) property;
+ if (menu.getProperties().get(SELECTED_ITEM_KEY) instanceof
MenuSync property) {
+ return property;
}
}
return null;