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 729a4e3f81f441a7cac9d29136dda2850a2ba5db Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Nov 30 15:42:44 2021 +0100 Add a contextual menu for clearing the table of category colors. --- .../apache/sis/gui/coverage/CoverageControls.java | 8 ++++-- .../apache/sis/gui/coverage/CoverageStyling.java | 29 ++++++++++++++++++++-- .../sis/gui/coverage/CoverageStylingApp.java | 6 +++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java index c63933e..9b829ff 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java @@ -24,6 +24,7 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; +import javafx.scene.layout.Priority; import javafx.collections.ObservableList; import javafx.scene.control.Label; import javafx.scene.control.TableView; @@ -120,7 +121,8 @@ final class CoverageControls extends ViewAndControls { * Creates a "Categories" section with the category table. */ final CoverageStyling styling = new CoverageStyling(view); - categoryTable = styling.createCategoryTable(vocabulary); + categoryTable = styling.createCategoryTable(resources, vocabulary); + VBox.setVgrow(categoryTable, Priority.ALWAYS); /* * All sections put together. */ @@ -138,7 +140,9 @@ final class CoverageControls extends ViewAndControls { final ValueColorMapper mapper = new ValueColorMapper(resources, vocabulary); isolines = new IsolineRenderer(view); isolines.setIsolineTables(java.util.Collections.singletonList(mapper.getSteps())); - isolinesPane = new VBox(mapper.getView()); // TODO: add band selector + final Region view = mapper.getView(); + VBox.setVgrow(view, Priority.ALWAYS); + isolinesPane = new VBox(view); // TODO: add band selector } /* * Put all sections together and have the first one expanded by default. diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java index 56632b5..06a115d 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageStyling.java @@ -26,9 +26,13 @@ import javafx.geometry.Pos; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.control.MenuItem; +import javafx.collections.ObservableList; import javafx.beans.value.ObservableValue; +import javafx.scene.control.ContextMenu; import org.apache.sis.coverage.Category; import org.apache.sis.internal.coverage.j2d.Colorizer; +import org.apache.sis.internal.gui.Resources; import org.apache.sis.internal.gui.ImmutableObjectProperty; import org.apache.sis.internal.gui.control.ColorRamp; import org.apache.sis.internal.gui.control.ColorColumnHandler; @@ -43,7 +47,7 @@ import org.opengis.util.InternationalString; * that may change in any future version.</p> * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @@ -82,6 +86,21 @@ final class CoverageStyling extends ColorColumnHandler<Category> implements Func } /** + * Resets all colors to their default values. + * + * @param items list of items of the table to clear. + */ + private void clear(final ObservableList<Category> items) { + final Category[] content = items.toArray(new Category[items.size()]); + items.clear(); // For forcing a repaint of the table. + customizedColors.clear(); + items.setAll(content); + if (canvas != null) { + canvas.setCategoryColors(null); + } + } + + /** * Returns the key to use in {@link #customizedColors} for the given category. */ private static String key(final Category category) { @@ -168,7 +187,7 @@ final class CoverageStyling extends ColorColumnHandler<Category> implements Func * @param vocabulary localized resources, given because already known by the caller * (this argument would be removed if this method was public API). */ - final TableView<Category> createCategoryTable(final Vocabulary vocabulary) { + final TableView<Category> createCategoryTable(final Resources resources, final Vocabulary vocabulary) { final TableColumn<Category,String> name = new TableColumn<>(vocabulary.getString(Vocabulary.Keys.Name)); name.setCellValueFactory(CoverageStyling::getCategoryName); name.setCellFactory(CoverageStyling::createNameCell); @@ -181,6 +200,12 @@ final class CoverageStyling extends ColorColumnHandler<Category> implements Func final TableView<Category> table = new TableView<>(); table.getColumns().add(name); addColumnTo(table, vocabulary.getString(Vocabulary.Keys.Colors)); + /* + * Add contextual menu items. + */ + final MenuItem reset = new MenuItem(resources.getString(Resources.Keys.ClearAll)); + reset.setOnAction((e) -> clear(table.getItems())); + table.setContextMenu(new ContextMenu(reset)); return table; } diff --git a/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/CoverageStylingApp.java b/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/CoverageStylingApp.java index 815d5d8..094e77b 100644 --- a/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/CoverageStylingApp.java +++ b/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/CoverageStylingApp.java @@ -26,6 +26,7 @@ import javafx.scene.layout.BorderPane; import org.apache.sis.coverage.Category; import org.apache.sis.coverage.SampleDimension; import org.apache.sis.util.resources.Vocabulary; +import org.apache.sis.internal.gui.Resources; import org.apache.sis.measure.Units; @@ -33,7 +34,7 @@ import org.apache.sis.measure.Units; * Shows category table built by {@link CoverageStyling} with arbitrary data. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @@ -78,7 +79,8 @@ public final strictfp class CoverageStylingApp extends Application { final CoverageStyling styling = new CoverageStyling(null); styling.setARGB(band.getCategories().get(1), new int[] {0xFF607080}); - final TableView<Category> table = styling.createCategoryTable(Vocabulary.getResources((Locale) null)); + final TableView<Category> table = styling.createCategoryTable( + Resources.forLocale(null), Vocabulary.getResources((Locale) null)); table.getItems().setAll(band.getCategories()); return table; }