You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2021/01/11 17:50:10 UTC
[sis] 02/03: Move `IsolineTable` to `ValueColorMapper` for allowing
usage (in the future) for other purposes than isolines.
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 3e83f90ae3143925be7a6d8f6f2c88e2a2101fe5
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Mon Jan 11 16:06:01 2021 +0100
Move `IsolineTable` to `ValueColorMapper` for allowing usage (in the future) for other purposes than isolines.
---
.../apache/sis/gui/coverage/CoverageControls.java | 5 +-
.../org/apache/sis/gui/coverage/IsolineLevel.java | 75 -------------
.../gui/control/ValueColorMapper.java} | 117 +++++++++++++++------
.../gui/control/ValueColorMapperApp.java} | 24 ++---
4 files changed, 99 insertions(+), 122 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 3d15129..bdc1a43 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
@@ -47,6 +47,7 @@ import org.apache.sis.image.Interpolation;
import org.apache.sis.internal.gui.Styles;
import org.apache.sis.internal.gui.Resources;
import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.internal.gui.control.ValueColorMapper;
/**
@@ -143,8 +144,8 @@ final class CoverageControls extends Controls {
*/
final VBox isolinesPane;
{ // Block for making variables locale to this scope.
- final IsolineTable table = new IsolineTable();
- final TableView<IsolineLevel> isolinesTable = table.createIsolineTable(vocabulary);
+ final ValueColorMapper table = new ValueColorMapper();
+ final TableView<ValueColorMapper.Step> isolinesTable = table.createIsolineTable(vocabulary);
isolinesPane = new VBox(isolinesTable); // TODO: add band selector
}
/*
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineLevel.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineLevel.java
deleted file mode 100644
index 7c71f0b..0000000
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineLevel.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sis.gui.coverage;
-
-import javafx.scene.paint.Color;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.DoubleProperty;
-import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.SimpleObjectProperty;
-import javafx.beans.property.SimpleDoubleProperty;
-import javafx.beans.property.SimpleBooleanProperty;
-import org.apache.sis.internal.gui.control.ColorRamp;
-
-
-/**
- * Colors to apply on isoline for a given level.
- *
- * @author Martin Desruisseaux (Geomatys)
- * @version 1.1
- * @since 1.1
- * @module
- */
-final class IsolineLevel {
- /**
- * Isolines level.
- */
- public final DoubleProperty value;
-
- /**
- * Color associated to isoline at this level.
- *
- * The value type is {@link ColorRamp} for now, but if this property become public in a future version
- * then the type should be changed to {@link Color} and bidirectionally binded to another property
- * (package-private) of type {@link ColorRamp}.
- */
- final ObjectProperty<ColorRamp> color;
-
- /**
- * Whether the isoline should be drawn on the map.
- */
- public final BooleanProperty visible;
-
- /**
- * Creates an empty isoline level.
- */
- IsolineLevel() {
- value = new SimpleDoubleProperty (this, "value", Double.NaN);
- color = new SimpleObjectProperty<>(this, "color");
- visible = new SimpleBooleanProperty (this, "visible");
- }
-
- /**
- * Creates an isoline level for the given value.
- */
- IsolineLevel(final double value, final Color color) {
- this();
- this.value.set(value);
- this.color.set(new ColorRamp(color));
- visible.set(true);
- }
-}
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineTable.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
similarity index 65%
rename from application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineTable.java
rename to application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
index a7a87ec..4f0d02d 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/IsolineTable.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/control/ValueColorMapper.java
@@ -14,33 +14,81 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.gui.coverage;
+package org.apache.sis.internal.gui.control;
import java.text.NumberFormat;
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.DoubleProperty;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+import javafx.beans.property.SimpleDoubleProperty;
+import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.scene.paint.Color;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.cell.CheckBoxTableCell;
-import org.apache.sis.internal.gui.control.FormatTableCell;
-import org.apache.sis.internal.gui.control.ColorColumnHandler;
-import org.apache.sis.internal.gui.control.ColorRamp;
import org.apache.sis.internal.gui.Styles;
import org.apache.sis.util.resources.Vocabulary;
/**
- * Table of isolines (values and colors).
+ * Provides a widget for associating numeric values to solid colors.
+ * It can be used as a table of isolines or as a {@link ColorRamp} editor.
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
* @since 1.1
* @module
*/
-final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
+public final class ValueColorMapper extends ColorColumnHandler<ValueColorMapper.Step> {
/**
- * The format to use for formatting isoline levels.
+ * Colors to associate to a given value.
+ */
+ public static final class Step {
+ /**
+ * The value for which to associate a color. The initial value is {@link Double#NaN},
+ * but that value should be used only for the insertion row.
+ */
+ public final DoubleProperty value;
+
+ /**
+ * Color associated to the {@linkplain #value}.
+ *
+ * The value type is {@link ColorRamp} for now, but if this property become public in a future version
+ * then the type should be changed to {@link Color} and bidirectionally binded to another property
+ * (package-private) of type {@link ColorRamp}.
+ */
+ final ObjectProperty<ColorRamp> color;
+
+ /**
+ * Whether this step should be used. For example if {@code ValueColorMapper} is used as an isoline table,
+ * then this property determines whether the isoline should be drawn on the map.
+ */
+ public final BooleanProperty visible;
+
+ /**
+ * Creates an empty step to be used as a placeholder for the insertion row.
+ */
+ Step() {
+ value = new SimpleDoubleProperty (this, "value", Double.NaN);
+ color = new SimpleObjectProperty<>(this, "color");
+ visible = new SimpleBooleanProperty (this, "visible");
+ }
+
+ /**
+ * Creates a step associating the given color to the given value.
+ */
+ Step(final double value, final Color color) {
+ this();
+ this.value.set(value);
+ this.color.set(new ColorRamp(color));
+ visible.set(true);
+ }
+ }
+ /**
+ * The format to use for formatting numerical values.
* The same instance will be shared by all {@link FormatTableCell}s in this table.
*/
private final NumberFormat format;
@@ -48,16 +96,18 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
/**
* Creates a new handler.
*/
- IsolineTable() {
+ public ValueColorMapper() {
format = NumberFormat.getInstance();
}
/**
- * Returns the colors to apply for the given isoline level, or {@code null} for transparent.
+ * Returns the colors to apply for the given step, or {@code null} for transparent.
* This method is defined for safety but should not be invoked; use {@link #getObservableValue(S)} instead.
+ *
+ * @param level the value for which to get the color to show in color cell.
*/
@Override
- protected int[] getARGB(final IsolineLevel level) {
+ protected int[] getARGB(final Step level) {
final ColorRamp r = level.color.get();
return (r != null) ? r.colors : null;
}
@@ -65,33 +115,33 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
/**
* Returns the color associated to given row as an observable value.
*
- * @param level the isoline level for which to get color to show in color cell.
- * @return the color(s) to use for the given isoline, or {@code null} if none (transparent).
+ * @param level the value for which to get the color to show in color cell.
+ * @return the color(s) to use for the given value, or {@code null} if none (transparent).
*/
@Override
- protected ObservableValue<ColorRamp> getObservableValue(final IsolineLevel level) {
+ protected ObservableValue<ColorRamp> getObservableValue(final Step level) {
return level.color;
}
/**
* Invoked when users confirmed that (s)he wants to use the selected colors.
*
- * @param level the isoline level for which to assign new color(s).
- * @param colors the new color for the given isoline, or {@code null} for resetting default value.
+ * @param level the value for which to assign new color(s).
+ * @param colors the new color for the given value, or {@code null} for resetting default value.
* @return the type of color (always solid for this class).
*/
@Override
- protected ColorRamp.Type applyColors(final IsolineLevel level, ColorRamp colors) {
+ protected ColorRamp.Type applyColors(final Step level, ColorRamp colors) {
level.color.set(colors);
return ColorRamp.Type.SOLID;
}
/**
- * Invoked when an isoline value has been edited. This method saves the value, checks the isoline
- * as visible and set a default color if no color was already set.
+ * Invoked when a numerical value has been edited. This method saves the value,
+ * checks the step as visible and set a default color if no color was already set.
*/
- private static void commitEdit(final TableColumn.CellEditEvent<IsolineLevel,Number> event) {
- final IsolineLevel level = event.getRowValue();
+ private static void commitEdit(final TableColumn.CellEditEvent<Step,Number> event) {
+ final Step level = event.getRowValue();
final Number obj = event.getNewValue();
final double value = (obj != null) ? obj.doubleValue() : Double.NaN;
level.value.set(value);
@@ -103,8 +153,8 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
* worth the additional complexity. We do not use `items.sort(…)` because we want
* to move only one row and its new position will determine the default color.
*/
- final TableView<IsolineLevel> table = event.getTableView();
- final ObservableList<IsolineLevel> items = table.getItems();
+ final TableView<Step> table = event.getTableView();
+ final ObservableList<Step> items = table.getItems();
final int row = event.getTablePosition().getRow();
int dst = row;
while (--dst >= 0) {
@@ -123,11 +173,11 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
}
if (row >= size) {
// If the edited line was the insertion row, add a new insertion row.
- items.add(new IsolineLevel());
+ items.add(new Step());
}
/*
* If the row has no color (should be the case only for insertion row), interpolate a default color
- * using the isolines before and after the new row. If we are at the beginning or end of the list,
+ * using the steps before and after the new row. If we are at the beginning or end of the list,
* then interpolation will actually be an extrapolation.
*/
if (level.color.get() == null) {
@@ -143,8 +193,8 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
iup = last - 1;
ilo = last - 2;
}
- final IsolineLevel lo = items.get(ilo);
- final IsolineLevel up = items.get(iup);
+ final Step lo = items.get(ilo);
+ final Step up = items.get(iup);
final double base = lo.value.get();
final double f = (value - base) / (up.value.get() - base);
final Color clo = lo.color.get().color();
@@ -179,13 +229,14 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
*
* @param vocabulary localized resources, given because already known by the caller
* (this argument would be removed if this method was public API).
+ * @return table of isolines.
*/
- final TableView<IsolineLevel> createIsolineTable(final Vocabulary vocabulary) {
+ public final TableView<Step> createIsolineTable(final Vocabulary vocabulary) {
/*
* First column containing a checkbox for choosing whether the isoline should be drawn or not.
* Header text is 🖉 (lower left pencil).
*/
- final TableColumn<IsolineLevel,Boolean> visible = new TableColumn<>("\uD83D\uDD89");
+ final TableColumn<Step,Boolean> visible = new TableColumn<>("\uD83D\uDD89");
visible.setCellFactory(CheckBoxTableCell.forTableColumn(visible));
visible.setCellValueFactory((cell) -> cell.getValue().visible);
visible.setSortable(false);
@@ -196,18 +247,18 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
* Second column containing the level value.
* The number can be edited using a `NumberFormat` in current locale.
*/
- final TableColumn<IsolineLevel,Number> level = new TableColumn<>(vocabulary.getString(Vocabulary.Keys.Level));
- final FormatTableCell.Trigger<IsolineLevel> trigger = new FormatTableCell.Trigger<>(level, format);
+ final TableColumn<Step,Number> level = new TableColumn<>(vocabulary.getString(Vocabulary.Keys.Level));
+ final FormatTableCell.Trigger<Step> trigger = new FormatTableCell.Trigger<>(level, format);
level.setCellFactory((column) -> new FormatTableCell<>(Number.class, format, trigger));
level.setCellValueFactory((cell) -> cell.getValue().value);
- level.setOnEditCommit(IsolineTable::commitEdit);
+ level.setOnEditCommit(ValueColorMapper::commitEdit);
level.setSortable(false); // We will do our own sorting.
level.setId("level");
/*
* Create the table with above "category name" column (read-only),
* and add an editable column for color(s).
*/
- final TableView<IsolineLevel> table = new TableView<>();
+ final TableView<Step> table = new TableView<>();
table.getColumns().setAll(visible, level);
addColumnTo(table, vocabulary);
/*
@@ -215,7 +266,7 @@ final class IsolineTable extends ColorColumnHandler<IsolineLevel> {
* when a digit is typed (this is the purpose of `trigger`). For making easier to edit the cell in current row,
* a listener on F2 key (same as Excel and OpenOffice) is also registered.
*/
- table.getItems().add(new IsolineLevel());
+ table.getItems().add(new Step());
trigger.registerTo(table);
return table;
}
diff --git a/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/IsolineTableApp.java b/application/sis-javafx/src/test/java/org/apache/sis/internal/gui/control/ValueColorMapperApp.java
similarity index 69%
rename from application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/IsolineTableApp.java
rename to application/sis-javafx/src/test/java/org/apache/sis/internal/gui/control/ValueColorMapperApp.java
index 094ba00..c1ac37b 100644
--- a/application/sis-javafx/src/test/java/org/apache/sis/gui/coverage/IsolineTableApp.java
+++ b/application/sis-javafx/src/test/java/org/apache/sis/internal/gui/control/ValueColorMapperApp.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.gui.coverage;
+package org.apache.sis.internal.gui.control;
import java.util.Locale;
import javafx.stage.Stage;
@@ -28,14 +28,14 @@ import org.apache.sis.util.resources.Vocabulary;
/**
- * Shows isoline table built by {@link IsolineTable} with arbitrary data.
+ * Shows isoline table built by {@link ValueColorMapper} with arbitrary data.
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
* @since 1.1
* @module
*/
-public final strictfp class IsolineTableApp extends Application {
+public final strictfp class ValueColorMapperApp extends Application {
/**
* Starts the test application.
*
@@ -55,7 +55,7 @@ public final strictfp class IsolineTableApp extends Application {
final BorderPane pane = new BorderPane();
pane.setCenter(createIsolineTable());
pane.setBottom(new Button("Focus here"));
- window.setTitle("IsolineTable Test");
+ window.setTitle("ValueColorMapper Test");
window.setScene(new Scene(pane));
window.setWidth (400);
window.setHeight(300);
@@ -65,15 +65,15 @@ public final strictfp class IsolineTableApp extends Application {
/**
* Creates a table with arbitrary isolines to show.
*/
- private static TableView<IsolineLevel> createIsolineTable() {
- final IsolineTable handler = new IsolineTable();
- final TableView<IsolineLevel> table = handler.createIsolineTable(Vocabulary.getResources((Locale) null));
+ private static TableView<ValueColorMapper.Step> createIsolineTable() {
+ final ValueColorMapper handler = new ValueColorMapper();
+ final TableView<ValueColorMapper.Step> table = handler.createIsolineTable(Vocabulary.getResources((Locale) null));
table.getItems().setAll(
- new IsolineLevel( 10, Color.BLUE),
- new IsolineLevel( 25, Color.GREEN),
- new IsolineLevel( 50, Color.ORANGE),
- new IsolineLevel(100, Color.RED),
- new IsolineLevel()); // Empty row for inserting new values.
+ new ValueColorMapper.Step( 10, Color.BLUE),
+ new ValueColorMapper.Step( 25, Color.GREEN),
+ new ValueColorMapper.Step( 50, Color.ORANGE),
+ new ValueColorMapper.Step(100, Color.RED),
+ new ValueColorMapper.Step()); // Empty row for inserting new values.
return table;
}
}