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
commit 7a507877d478988077db7717f5dbe93ca8d004e8 Author: Martin Desruisseaux <[email protected]> AuthorDate: Tue Mar 31 18:28:21 2026 +0200 Use a little bit more of modern Java features in the GUI module. --- .../org/apache/sis/gui/controls/ColorRamp.java | 3 +- .../apache/sis/gui/controls/FormatApplicator.java | 4 +-- .../apache/sis/gui/controls/ValueColorMapper.java | 3 +- .../org/apache/sis/gui/coverage/CellFormat.java | 15 ++++----- .../apache/sis/gui/coverage/CoverageCanvas.java | 4 +-- .../main/org/apache/sis/gui/coverage/GridTile.java | 3 +- .../main/org/apache/sis/gui/coverage/GridView.java | 10 +++--- .../org/apache/sis/gui/dataset/ExpandableList.java | 5 ++- .../apache/sis/gui/dataset/ExpandedFeature.java | 3 +- .../org/apache/sis/gui/dataset/FeatureTable.java | 3 +- .../main/org/apache/sis/gui/dataset/LogViewer.java | 5 ++- .../org/apache/sis/gui/dataset/PathAction.java | 37 +++++++++++++--------- .../apache/sis/gui/dataset/ResourceExplorer.java | 9 ++---- .../org/apache/sis/gui/dataset/ResourceItem.java | 5 ++- .../org/apache/sis/gui/dataset/WindowHandler.java | 5 ++- .../apache/sis/gui/internal/DataStoreOpener.java | 4 +-- .../org/apache/sis/gui/internal/GUIUtilities.java | 7 ++-- .../apache/sis/gui/internal/ImageConverter.java | 5 ++- .../org/apache/sis/gui/internal/PropertyView.java | 21 +++++------- .../apache/sis/gui/internal/io/FileAccessItem.java | 4 +-- .../org/apache/sis/gui/map/ValuesFromCoverage.java | 7 ++-- .../org/apache/sis/gui/map/ValuesUnderCursor.java | 3 +- .../apache/sis/gui/map/style/MapContextView.java | 6 ++-- .../apache/sis/gui/metadata/MetadataSummary.java | 4 +-- .../org/apache/sis/gui/referencing/CRSChooser.java | 17 +++++----- .../main/org/apache/sis/gui/referencing/Utils.java | 3 +- .../main/org/apache/sis/gui/setup/Wizard.java | 3 +- 27 files changed, 89 insertions(+), 109 deletions(-) diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ColorRamp.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ColorRamp.java index 49f1fcb797..4ac4e6651a 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ColorRamp.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ColorRamp.java @@ -250,8 +250,7 @@ public final class ColorRamp { */ @Override public boolean equals(final Object obj) { - if (obj instanceof ColorRamp) { - final var other = (ColorRamp) obj; + if (obj instanceof ColorRamp other) { if (Arrays.equals(colors, other.colors)) { return (colors != null) || Objects.equals(name, other.name); } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/FormatApplicator.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/FormatApplicator.java index ea24ba17b4..768b19a303 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/FormatApplicator.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/FormatApplicator.java @@ -89,8 +89,8 @@ final class FormatApplicator<T> extends StringConverter<T> */ public static FormatApplicator<Number> createNumberFormat(final Locale locale) { final var f = new FormatApplicator<Number>(Number.class, NumberFormat.getInstance(locale)); - if (f.format instanceof DecimalFormat) { - ((DecimalFormat) f.format).setParseBigDecimal(true); + if (f.format instanceof DecimalFormat df) { + df.setParseBigDecimal(true); } return f; } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ValueColorMapper.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ValueColorMapper.java index e9da2185a0..9c69e58637 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ValueColorMapper.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/controls/ValueColorMapper.java @@ -127,8 +127,7 @@ public final class ValueColorMapper extends TabularWidget { */ @Override public boolean equals(final Object other) { - if (other instanceof Step) { - final Step that = (Step) other; + if (other instanceof Step that) { return Numerics.equals(value.get(), that.value.get()) && Objects.equals(color.get(), that.color.get()) && visible.get() == that.visible.get(); diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CellFormat.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CellFormat.java index bc7a3aaa38..9d20a3e348 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CellFormat.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CellFormat.java @@ -132,8 +132,8 @@ final class CellFormat extends SimpleStringProperty { * after the {@link #cellFormat} has been configured. */ private void updatePropertyValue() { - if (cellFormat instanceof DecimalFormat) { - super.setValue(((DecimalFormat) cellFormat).toLocalizedPattern()); + if (cellFormat instanceof DecimalFormat df) { + super.setValue(df.toLocalizedPattern()); } } @@ -148,8 +148,8 @@ final class CellFormat extends SimpleStringProperty { @Override public void setValue(final String pattern) { shortenedPattern = false; - if (cellFormat instanceof DecimalFormat) { - ((DecimalFormat) cellFormat).applyLocalizedPattern(pattern); + if (cellFormat instanceof DecimalFormat df) { + df.applyLocalizedPattern(pattern); updatePropertyValue(); ((GridView) getBean()).updateCellValues(); } @@ -189,8 +189,8 @@ final class CellFormat extends SimpleStringProperty { final void restorePattern() { if (shortenedPattern) { shortenedPattern = false; - if (cellFormat instanceof DecimalFormat) { - ((DecimalFormat) cellFormat).applyLocalizedPattern(getValue()); + if (cellFormat instanceof DecimalFormat df) { + df.applyLocalizedPattern(getValue()); } } } @@ -279,9 +279,8 @@ final class CellFormat extends SimpleStringProperty { } else { int n = getFractionDigits(image, band).orElse(1); if (n > 6 || n < -9) { // Arbitrary threshold for switching to scientific notation. - if (cellFormat instanceof DecimalFormat) { + if (cellFormat instanceof DecimalFormat df) { if (classicFormatPattern == null) { - final DecimalFormat df = (DecimalFormat) cellFormat; classicFormatPattern = df.toPattern(); df.applyPattern("0.000E00"); } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java index ca1a9b00ae..ba2b11181a 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java @@ -1146,8 +1146,8 @@ public class CoverageCanvas extends MapCanvasAWT { @Override protected void paint(final Graphics2D gr) { gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); - if (prefetchedImage instanceof TileErrorHandler.Executor) { - ((TileErrorHandler.Executor) prefetchedImage).execute( + if (prefetchedImage instanceof TileErrorHandler.Executor ex) { + ex.execute( () -> gr.drawRenderedImage(RenderingWorkaround.wrap(prefetchedImage), resampledToDisplay), new TileErrorHandler(data.processor.getErrorHandler(), CoverageCanvas.class, "paint")); } else if (!isCoverageHidden) { diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridTile.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridTile.java index be5cea1736..5a6c2188a2 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridTile.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridTile.java @@ -77,8 +77,7 @@ final class GridTile { */ @Override public boolean equals(final Object other) { - if (other instanceof GridTile) { - final var that = (GridTile) other; + if (other instanceof GridTile that) { return tileX == that.tileX && tileY == that.tileY; // Intentionally no other comparisons. } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridView.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridView.java index 4e05eb3cda..9aeed77f05 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridView.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/GridView.java @@ -486,9 +486,8 @@ public class GridView extends Control { minY = image.getMinY(); maxY = Math.addExact(minY, image.getHeight()); } - final Skin<?> skin = getSkin(); // May be null if the view is not yet shown. - if (skin instanceof GridViewSkin) { // Could be a user instance (not recommended). - ((GridViewSkin) skin).clear(); + if (getSkin() instanceof GridViewSkin skin) { // May be null if the view is not yet shown. + skin.clear(); } requestLayout(); } @@ -499,9 +498,8 @@ public class GridView extends Control { * has not changed. */ final void updateCellValues() { - final Skin<?> skin = getSkin(); // May be null if the view is not yet shown. - if (skin instanceof GridViewSkin) { // Could be a user instance (not recommended). - ((GridViewSkin) skin).updateCellValues(); + if (getSkin() instanceof GridViewSkin skin) { // May be null if the view is not yet shown. + skin.updateCellValues(); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandableList.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandableList.java index cd98d5a288..2266287f3a 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandableList.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandableList.java @@ -216,9 +216,8 @@ final class ExpandableList extends TransformationList<Feature,Feature> private boolean isExpandable(final Feature feature) { if (feature != null) { for (final String name : nameToIndex.keySet()) { - final Object value = feature.getPropertyValue(name); - if (value instanceof Collection<?>) { - final int size = ((Collection<?>) value).size(); + if (feature.getPropertyValue(name) instanceof Collection<?> value) { + final int size = value.size(); if (size >= 2) { return true; } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandedFeature.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandedFeature.java index 67ab103a13..1e6cf6a9b8 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandedFeature.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ExpandedFeature.java @@ -196,8 +196,7 @@ final class ExpandedFeature implements Feature { if (this == obj) { return true; } - if (obj instanceof ExpandedFeature) { - final ExpandedFeature other = (ExpandedFeature) obj; + if (obj instanceof ExpandedFeature other) { return index == other.index && source.equals(other.source); } return false; diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/FeatureTable.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/FeatureTable.java index 928ebdfacd..eae6a3e79e 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/FeatureTable.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/FeatureTable.java @@ -443,8 +443,7 @@ public class FeatureTable extends TableView<Feature> { */ @Override protected void updateItem(Object value, final boolean empty) { - if (value instanceof List<?>) { - final List<?> c = (List<?>) value; + if (value instanceof List<?> c) { value = c.isEmpty() ? null : c.get(0); } else if (value instanceof Iterable<?>) { final Iterator<?> c = ((Iterable<?>) value).iterator(); diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/LogViewer.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/LogViewer.java index 0d15552d8d..49680e1ca2 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/LogViewer.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/LogViewer.java @@ -570,9 +570,8 @@ public class LogViewer extends Widget { return false; }; } - final ObservableList<LogRecord> items = table.getItems(); - if (items instanceof FilteredList<?>) { - ((FilteredList<LogRecord>) items).setPredicate(filter); + if (table.getItems() instanceof FilteredList<LogRecord> items) { + items.setPredicate(filter); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/PathAction.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/PathAction.java index fa26f7162d..e9d5e10d9f 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/PathAction.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/PathAction.java @@ -104,21 +104,28 @@ final class PathAction implements EventHandler<ActionEvent> { Object file = path; Object uri = null; try { - if (path instanceof URI) { - uri = path; // Must be first because next line may fail. - file = new File((URI) path); - } else if (path instanceof URL) { - uri = path; // Must be first because next line may fail. - file = new File(((URL) path).toURI()); - } else if (path instanceof File) { - uri = ((File) path).toURI(); - } else if (path instanceof Path) { - uri = ((Path) path).toUri(); // Must be first because next line may fail. - file = ((Path) path).toFile(); - } else if (path instanceof CharSequence) { - uri = new URI(path.toString()); // Stay null if this operation fail. - } else { - file = ""; + switch (path) { + case URI c -> { + uri = path; // Must be first because next line may fail. + file = new File(c); + } + case URL c -> { + uri = path; // Must be first because next line may fail. + file = new File(c.toURI()); + } + case File c -> { + uri = c.toURI(); + } + case Path c -> { + uri = c.toUri(); // Must be first because next line may fail. + file = c.toFile(); + } + case CharSequence c -> { + uri = new URI(path.toString()); // Stay null if this operation fail. + } + default -> { + file = ""; + } } } catch (URISyntaxException | IllegalArgumentException | UnsupportedOperationException e) { // Ignore. The `uri` or `text` field that we failed to assign keep its original value. diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceExplorer.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceExplorer.java index 711b1c3dd9..0e3d3170fa 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceExplorer.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceExplorer.java @@ -408,8 +408,7 @@ public class ResourceExplorer extends Widget { */ String label = null; boolean disabled = true; - if (resource instanceof DataStore) { - final DataStore store = (DataStore) resource; + if (resource instanceof DataStore store) { final DataStoreProvider provider = store.getProvider(); if (provider != null) { label = provider.getShortName(); @@ -443,9 +442,7 @@ public class ResourceExplorer extends Widget { * This method is invoked when the tab become visible, or when a new resource is loaded. */ private void loadNativeMetadata() { - final Resource resource = getSelectedResource(); - if (resource instanceof DataStore) { - final DataStore store = (DataStore) resource; + if (getSelectedResource() instanceof DataStore store) { BackgroundThreads.execute(new Task<TreeTable>() { /** Invoked in a background thread for fetching metadata. */ @Override protected TreeTable call() throws DataStoreException { @@ -454,7 +451,7 @@ public class ResourceExplorer extends Widget { /** Shows the result in JavaFX thread. */ @Override protected void succeeded() { - if (resource == getSelectedResource()) { + if (store == getSelectedResource()) { nativeMetadata.setContent(getValue()); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceItem.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceItem.java index 89e574870d..e37fc2d773 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceItem.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/ResourceItem.java @@ -235,9 +235,8 @@ final class ResourceItem extends TreeItem<Resource> { final ObservableList<TreeItem<Resource>> children = super.getChildren(); if (!isChildrenKnown) { isChildrenKnown = true; // Set first for avoiding to repeat in case of failure. - final Resource resource = getValue(); - if (resource instanceof Aggregate) { - BackgroundThreads.execute(new GetChildren((Aggregate) resource)); + if (getValue() instanceof Aggregate resource) { + BackgroundThreads.execute(new GetChildren(resource)); children.add(new ResourceItem()); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/WindowHandler.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/WindowHandler.java index c6226552bb..6331ab20a9 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/WindowHandler.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/dataset/WindowHandler.java @@ -208,9 +208,8 @@ public abstract class WindowHandler { public void show() { if (window == null) { if (manager.main == this) { - Window w = getWindow(); - if (w instanceof Stage) { - window = (Stage) w; + if (getWindow() instanceof Stage w) { + window = w; } else { return; } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/DataStoreOpener.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/DataStoreOpener.java index 8ac65413e9..4871d0ecac 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/DataStoreOpener.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/DataStoreOpener.java @@ -198,8 +198,8 @@ public final class DataStoreOpener extends Task<DataStore> { * @return the input file name for message purpose. */ final String getFileName() { - if (source instanceof StorageConnector) { - return ((StorageConnector) source).getStorageName(); + if (source instanceof StorageConnector c) { + return c.getStorageName(); } String name = Strings.trimOrNull(IOUtilities.filename(source)); if (name == null) { diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/GUIUtilities.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/GUIUtilities.java index f92f956723..5398c28e2f 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/GUIUtilities.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/GUIUtilities.java @@ -61,10 +61,9 @@ public final class GUIUtilities { * @return the locale for the container of the given property, or {@code null}. */ public static Locale getLocale(final ObservableValue<?> property) { - if (property instanceof ReadOnlyProperty<?>) { - final Object bean = ((ReadOnlyProperty<?>) property).getBean(); - if (bean instanceof Localized) { - return ((Localized) bean).getLocale(); + if (property instanceof ReadOnlyProperty<?> c) { + if (c.getBean() instanceof Localized bean) { + return bean.getLocale(); } } return null; diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/ImageConverter.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/ImageConverter.java index add6fda8cf..b705ed308b 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/ImageConverter.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/ImageConverter.java @@ -203,10 +203,9 @@ final class ImageConverter extends Task<Statistics[]> { * Current implementation returns the mask as a transparent yellow image. */ private RenderedImage getMask(final ImageProcessor processor) { - final Object mask = source.getProperty(PlanarImage.MASK_KEY); - if (mask instanceof RenderedImage) try { + if (source.getProperty(PlanarImage.MASK_KEY) instanceof RenderedImage mask) try { processor.setColorizer(MASK_TRANSPARENCY); - return processor.visualize((RenderedImage) mask); + return processor.visualize(mask); } catch (IllegalArgumentException e) { /* * Ignore, we will not apply any mask over the thumbnail image. diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/PropertyView.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/PropertyView.java index 6774faccb5..e0d9dee5a5 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/PropertyView.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/PropertyView.java @@ -184,19 +184,14 @@ public final class PropertyView implements Localized, ChangeListener<Number> { pendingTask = null; task.cancel(BackgroundThreads.NO_INTERRUPT_DURING_IO); } - if (newValue == null) { - content = null; - } else if (newValue instanceof Throwable) { - content = setText((Throwable) newValue); - } else if (newValue instanceof IdentifiedObject) { - content = setCRS((IdentifiedObject) newValue); - } else if (newValue instanceof Collection<?>) { - content = setList(((Collection<?>) newValue).toArray()); - } else if (newValue.getClass().isArray()) { - content = setList(newValue); - } else { - content = setText(formats.formatValue(newValue, true)); - } + content = switch (newValue) { + case null -> null; + case Throwable c -> setText(c); + case IdentifiedObject c -> setCRS(c); + case Collection<?> c -> setList(c.toArray()); + default -> newValue.getClass().isArray() ? setList(newValue) + : setText(formats.formatValue(newValue, true)); + }; } view.set(content); value = newValue; // Assign only on success. diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/io/FileAccessItem.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/io/FileAccessItem.java index 957da8f2a7..85eec0595e 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/io/FileAccessItem.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/internal/io/FileAccessItem.java @@ -442,8 +442,8 @@ final class FileAccessItem implements Runnable, EventHandler<ActionEvent> { */ @Override public void rangeOfInterest(final long lower, final long upper) { - if (channel instanceof ByteRangeChannel) { - ((ByteRangeChannel) channel).rangeOfInterest(lower, upper); + if (channel instanceof ByteRangeChannel c) { + c.rangeOfInterest(lower, upper); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesFromCoverage.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesFromCoverage.java index 98acefe32f..7a8768ef68 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesFromCoverage.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesFromCoverage.java @@ -109,10 +109,9 @@ final class ValuesFromCoverage extends ValuesUnderCursor implements ChangeListen * provided directly by the {@link GridCoùverage} values. */ private static GridExtent getSelectedSlice(final ObservableValue<?> property) { - if (property instanceof ReadOnlyProperty<?>) { - final Object bean = ((ReadOnlyProperty<?>) property).getBean(); - if (bean instanceof CoverageCanvas) { - return ((CoverageCanvas) bean).getSliceExtent(); + if (property instanceof ReadOnlyProperty<?> c) { + if (c.getBean() instanceof CoverageCanvas bean) { + return bean.getSliceExtent(); } } return null; diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesUnderCursor.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesUnderCursor.java index 2c893792f9..3909876435 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesUnderCursor.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/ValuesUnderCursor.java @@ -326,8 +326,7 @@ public abstract class ValuesUnderCursor { * @return the sample values provider, or {@code null} if none. */ static ValuesUnderCursor create(final MapCanvas canvas) { - if (canvas instanceof CoverageCanvas) { - final CoverageCanvas cc = (CoverageCanvas) canvas; + if (canvas instanceof CoverageCanvas cc) { final ValuesFromCoverage listener = new ValuesFromCoverage(); cc.coverageProperty.addListener(new WeakChangeListener<>(listener)); cc.sliceExtentProperty.addListener((p,o,n) -> listener.setSlice(n)); diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/style/MapContextView.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/style/MapContextView.java index 666c8c5c0a..eafd13dfaa 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/style/MapContextView.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/style/MapContextView.java @@ -53,7 +53,7 @@ public class MapContextView extends Widget { /** Creates the unique instance. */ private CellFactory() { - selectedProperty = (item) -> item instanceof CheckBoxTreeItem<?> ? ((CheckBoxTreeItem<?>)item).selectedProperty() : null; + selectedProperty = (item) -> item instanceof CheckBoxTreeItem<?> c ? c.selectedProperty() : null; } /** Creates an initially empty tree cell for the given tree view. */ @@ -135,8 +135,8 @@ public class MapContextView extends Widget { */ private void onSelected(final TreeItem<MapItem> item) { Region config = noSelection; - if (item instanceof ItemController) { - config = ((ItemController) item).getConfigurationPanel(); + if (item instanceof ItemController c) { + config = c.getConfigurationPanel(); } itemsAndConfiguration.getItems().set(1, config); } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/metadata/MetadataSummary.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/metadata/MetadataSummary.java index 6202a35172..42e6e85b79 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/metadata/MetadataSummary.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/metadata/MetadataSummary.java @@ -231,8 +231,8 @@ public class MetadataSummary extends Widget { @Override protected void succeeded() { if (getter == this) try { setMetadata(getValue()); - if (resource instanceof Aggregate) { - getIdentificationInfo().completeMissingGeographicBounds((Aggregate) resource); + if (resource instanceof Aggregate c) { + getIdentificationInfo().completeMissingGeographicBounds(c); } } finally { getter = null; diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java index 9b49ea947b..1ca67d877c 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/CRSChooser.java @@ -376,15 +376,14 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem> { } final short key; final int expected; - if (crs instanceof GeographicCRS) {key = Vocabulary.Keys.Geographic; expected = 2;} - else if (crs instanceof GeodeticCRS) {key = Vocabulary.Keys.Geocentric; expected = 2;} - else if (crs instanceof VerticalCRS) {key = Vocabulary.Keys.Vertical; expected = 1;} - else if (crs instanceof TemporalCRS) {key = Vocabulary.Keys.Temporal; expected = 1;} - else if (crs instanceof ProjectedCRS) {key = Vocabulary.Keys.Projected; expected = 2;} - else if (crs instanceof EngineeringCRS) {key = Vocabulary.Keys.Engineering; expected = 0;} - else { - key = Vocabulary.Keys.NotKnown; - expected = 0; + switch (crs) { + case GeographicCRS _ -> {key = Vocabulary.Keys.Geographic; expected = 2;} + case GeodeticCRS _ -> {key = Vocabulary.Keys.Geocentric; expected = 2;} + case VerticalCRS _ -> {key = Vocabulary.Keys.Vertical; expected = 1;} + case TemporalCRS _ -> {key = Vocabulary.Keys.Temporal; expected = 1;} + case ProjectedCRS _ -> {key = Vocabulary.Keys.Projected; expected = 2;} + case EngineeringCRS _ -> {key = Vocabulary.Keys.Engineering; expected = 0;} + default -> {key = Vocabulary.Keys.NotKnown; expected = 0;} } String text = Vocabulary.forLocale(locale).getString(key); final int dimension = CRS.getDimensionOrZero(crs); diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/Utils.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/Utils.java index 6276b2390c..fe8f9bc3c4 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/Utils.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/referencing/Utils.java @@ -103,7 +103,6 @@ final class Utils { * Returns {@code true} if the given reference system should be ignored. */ static boolean isIgnoreable(final ReferenceSystem system) { - return (system instanceof CoordinateReferenceSystem) && - CommonCRS.Engineering.DISPLAY.datumUsedBy((CoordinateReferenceSystem) system); + return (system instanceof CoordinateReferenceSystem c) && CommonCRS.Engineering.DISPLAY.datumUsedBy(c); } } diff --git a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/setup/Wizard.java b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/setup/Wizard.java index 604a766565..336b2af85d 100644 --- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/setup/Wizard.java +++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/setup/Wizard.java @@ -600,8 +600,7 @@ final class Wizard extends FileFilter implements ActionListener, PropertyChangeL final int n = c.getComponentCount(); for (int i=0; i<n; i++) { final Component child = c.getComponent(i); - if (child instanceof JButton) { - final var button = (JButton) child; + if (child instanceof JButton button) { if (SELECT.equals(button.getText())) { return button; }
