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 136d403 Highlight the cell under mouse position. We will provide
geographic coordinates of that cell in a future commit.
136d403 is described below
commit 136d4030730a9460f198f3c7bb8cb37da8bb0657
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sun Feb 2 17:45:54 2020 +0100
Highlight the cell under mouse position. We will provide geographic
coordinates of that cell in a future commit.
---
.../apache/sis/gui/coverage/CoverageExplorer.java | 2 +-
.../java/org/apache/sis/gui/coverage/GridRow.java | 1 +
.../org/apache/sis/gui/coverage/GridRowSkin.java | 2 +-
.../java/org/apache/sis/gui/coverage/GridView.java | 2 +-
.../org/apache/sis/gui/coverage/GridViewSkin.java | 74 +++++++++++++++++++---
.../java/org/apache/sis/internal/gui/Styles.java | 9 ++-
6 files changed, 76 insertions(+), 14 deletions(-)
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
index bd48f4f..d2ecb09 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageExplorer.java
@@ -68,7 +68,7 @@ public class CoverageExplorer {
* The border to use for grouping some controls together.
*/
private static final Border GROUP_BORDER = new Border(new BorderStroke(
- Styles.BORDER, BorderStrokeStyle.SOLID, null, null));
+ Styles.GROUP_BORDER, BorderStrokeStyle.SOLID, null, null));
/**
* The data shown in this table. Note that setting this property to a
non-null value may not
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java
index 732ce9a..78ed0ee 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java
@@ -65,6 +65,7 @@ final class GridRow extends IndexedCell<Void> {
view = (GridView) owner.getParent();
setPrefWidth(view.getContentWidth());
setFont(Font.font(null, FontWeight.BOLD, -1)); // Apply only to
the header column.
+ setOnMouseMoved((GridViewSkin) view.getSkin());
setManaged(false);
}
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRowSkin.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRowSkin.java
index 4bb4390..372d7b1 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRowSkin.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRowSkin.java
@@ -98,7 +98,7 @@ final class GridRowSkin extends CellSkinBase<GridRow> {
final double cellWidth = layout.cellWidth; // Includes
the cell spacing.
final double available = layout.cellInnerWidth;
final double limit = layout.rightPosition; // Horizontal
position where to stop.
- int column = layout.firstVisibleColumn; // Column
index in the RenderedImage.
+ int column = layout.firstVisibleColumn; // Zero-based
column index in image.
int childIndex = 0;
List<GridCell> newChildren = null;
final int count = children.size();
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
index 09734fe..297a115 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
@@ -471,7 +471,7 @@ public class GridView extends Control {
/**
* Formats a row index or column index.
*
- * @param index the row or column index to format.
+ * @param index the zero-based row or column index to format.
* @param vertical {@code true} if formatting row index, or {@code
false} if formatting column index.
*/
final String formatHeaderValue(final int index, final boolean vertical) {
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridViewSkin.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridViewSkin.java
index eac75e6..23f7f30 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridViewSkin.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridViewSkin.java
@@ -30,6 +30,9 @@ import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Font;
+import javafx.scene.input.MouseEvent;
+import javafx.event.EventHandler;
+import org.apache.sis.internal.gui.Styles;
/**
@@ -50,7 +53,7 @@ import javafx.scene.text.Font;
* @since 1.1
* @module
*/
-final class GridViewSkin extends VirtualContainerBase<GridView, GridRow> {
+final class GridViewSkin extends VirtualContainerBase<GridView, GridRow>
implements EventHandler<MouseEvent> {
/**
* The cells that we put in the header row on the top of the view. The
children list is initially empty;
* new elements are added or removed when first needed and when the view
size changed.
@@ -63,9 +66,9 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
private final Rectangle topBackground, leftBackground;
/**
- * Image index of the first column visible in the view, ignoring the
header column.
- * This is a {@link RenderedImage} <var>x</var> index (with an arbitrary
origin),
- * not necessarily the same value than the zero-based index used in JavaFX
views.
+ * Zero-based index of the first column visible in the view, ignoring the
header column.
+ * This is equal to the {@link RenderedImage} <var>x</var> index if the
image coordinates
+ * also start at zero (i.e. {@link RenderedImage#getMinX()} = 0).
*
* <p>This field is written by {@link #layoutChildren(double, double,
double, double)}.
* All other accesses (especially from outside of this class) should be
read-only.</p>
@@ -123,6 +126,11 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
private boolean hasErrors;
/**
+ * A rectangle around selected cells.
+ */
+ private final Rectangle selection;
+
+ /**
* Creates a new skin for the specified view.
*/
GridViewSkin(final GridView view) {
@@ -147,10 +155,48 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
leftBackground.fillProperty().bind(view.headerBackground);
topBackground .fillProperty().bind(view.headerBackground);
/*
+ * Rectangle around the selected cell (for example the cell below
mouse position).
+ * Become visible only when the mouse enter in the widget area.
+ */
+ selection = new Rectangle(view.cellWidth.getValue(),
view.cellHeight.getValue());
+ selection.setFill(Styles.SELECTION_BACKGROUND);
+ selection.setVisible(false);
+ flow.setOnMouseExited(this::hideSelection);
+ /*
* The list of children is initially empty. We need to
* add the virtual flow, otherwise nothing will appear.
*/
- getChildren().addAll(topBackground, leftBackground, headerRow, flow);
+ getChildren().addAll(topBackground, leftBackground, headerRow,
selection, flow);
+ }
+
+ /**
+ * Invoked when the mouse is moving over the cells. This method computes
cell indices
+ * and draws the selection rectangle around that cell. Then, listeners are
notified.
+ *
+ * <p>This listener is registered for each {@link GridRow} instances.
+ * It is not designed for other kinds of event source.</p>
+ */
+ @Override
+ public final void handle(final MouseEvent event) {
+ final double tx = leftBackground.getWidth();
+ final double x = event.getX() - tx;
+ boolean visible = (x >= 0);
+ if (visible) {
+ final int column = (int) (x / cellWidth);
+ visible = (column >= firstVisibleColumn);
+ if (visible) {
+ selection.setX((column - firstVisibleColumn) * cellWidth + tx);
+ selection.setY(((GridRow) event.getSource()).getLayoutY() +
topBackground.getHeight());
+ }
+ }
+ selection.setVisible(visible);
+ }
+
+ /**
+ * Hides the selection when the mouse moved outside the grid view area.
+ */
+ private void hideSelection(final MouseEvent event) {
+ selection.setVisible(false);
}
/**
@@ -159,8 +205,13 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
*/
private void cellHeightChanged(ObservableValue<? extends Number> property,
Number oldValue, Number newValue) {
final Flow flow = (Flow) getVirtualFlow();
- final double value = newValue.doubleValue();
- flow.setFixedCellSize(value >= GridView.MIN_CELL_SIZE ? value :
GridView.MIN_CELL_SIZE);
+ double value = newValue.doubleValue();
+ if (!(value >= GridView.MIN_CELL_SIZE)) { // Use ! for
catching NaN values.
+ value = GridView.MIN_CELL_SIZE;
+ }
+ flow.setFixedCellSize(value);
+ selection.setVisible(false);
+ selection.setHeight(value);
contentChanged(false);
}
@@ -169,12 +220,17 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
* This method notifies all children about the new width.
*/
private void cellWidthChanged(ObservableValue<? extends Number> property,
Number oldValue, Number newValue) {
- final double width = getSkinnable().getContentWidth();
+ final GridView view = getSkinnable();
+ final double width = view.getContentWidth();
for (final Node child : getChildren()) {
if (child instanceof GridRow) { // The first instances
are not a GridRow.
((GridRow) child).setPrefWidth(width);
}
}
+ if (property == view.cellWidth) {
+ selection.setVisible(false);
+ selection.setWidth(newValue.doubleValue());
+ }
layoutAll = true;
contentChanged(false);
}
@@ -362,7 +418,7 @@ final class GridViewSkin extends
VirtualContainerBase<GridView, GridRow> {
cellInnerWidth = cellWidth - cellSpacing;
leftPosition = flow.getHorizontalPosition(); //
Horizontal position in the virtual view.
rightPosition = leftPosition + width; //
Horizontal position where to stop.
- firstVisibleColumn = (int) (leftPosition / cellWidth); // Column
index in the RenderedImage.
+ firstVisibleColumn = (int) (leftPosition / cellWidth); //
Zero-based column index in the image.
/*
* Set the rectangle position before to do final adjustment on cell
position,
* because the background to fill should include the `cellSpacing`
margin.
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
index 524b900..a6eb094 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
@@ -77,9 +77,14 @@ public final class Styles {
public static final Color EXPANDED_ROW = Color.GAINSBORO;
/**
- * The color for border grouping some controls together.
+ * Color for border grouping some controls together.
*/
- public static final Color BORDER = Color.SILVER;
+ public static final Color GROUP_BORDER = Color.SILVER;
+
+ /**
+ * Color for background of a selection.
+ */
+ public static final Color SELECTION_BACKGROUND = Color.LIGHTBLUE;
/**
* Do not allow instantiation of this class.