sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 04/06: Simplify a bit the layout of coverage controls. This provides a visual easier to read.
Date Mon, 29 Jun 2020 17:31:20 GMT
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 05ffbcef0de8be084c961e742a96a22b0319dec3
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Jun 29 12:46:30 2020 +0200

    Simplify a bit the layout of coverage controls.
    This provides a visual easier to read.
---
 .../java/org/apache/sis/gui/coverage/Controls.java | 43 ++++++++-------------
 .../apache/sis/gui/coverage/CoverageControls.java  | 44 ++++++++++++++++------
 .../org/apache/sis/gui/coverage/GridControls.java  |  8 ++--
 3 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Controls.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Controls.java
index bbebf32..e8999d6 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Controls.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/Controls.java
@@ -20,13 +20,10 @@ import javafx.geometry.Insets;
 import javafx.scene.control.ButtonBase;
 import javafx.scene.control.Control;
 import javafx.scene.control.Label;
-import javafx.scene.layout.Border;
-import javafx.scene.layout.BorderStroke;
-import javafx.scene.layout.BorderStrokeStyle;
-import javafx.scene.layout.GridPane;
 import javafx.scene.layout.Region;
+import javafx.scene.text.Font;
+import javafx.scene.text.FontWeight;
 import org.apache.sis.coverage.grid.GridCoverage;
-import org.apache.sis.internal.gui.Styles;
 import org.apache.sis.util.resources.IndexedResourceBundle;
 
 
@@ -43,18 +40,17 @@ abstract class Controls {
     /**
      * Margin to keep around captions on top of tables or lists.
      */
-    static final Insets CAPTION_MARGIN = new Insets(12, 0, 9, 0);
+    private static final Insets CAPTION_MARGIN = new Insets(12, 0, 6, 0);
 
     /**
      * Margin to keep around captions after the first one.
      */
-    private static final Insets NEXT_CAPTION_MARGIN = new Insets(30, 0, 9, 0);
+    private static final Insets NEXT_CAPTION_MARGIN = new Insets(30, 0, 6, 0);
 
     /**
-     * The border to use for grouping some controls together.
+     * Margin for adding an indentation to a node.
      */
-    private static final Border GROUP_BORDER = new Border(new BorderStroke(
-            Styles.GROUP_BORDER, BorderStrokeStyle.SOLID, null, null));
+    static final Insets INDENT = new Insets(0, 0, 0, 15);
 
     /**
      * The toolbar button for selecting this view.
@@ -69,23 +65,6 @@ abstract class Controls {
     }
 
     /**
-     * Creates a grid pane with one (label, control) per row and all rows with the same height.
-     * The controls must be associated to the given labels by {@link Label#getLabelFor()}.
-     * If a label is {@code null}, then no row is created for that label.
-     *
-     * @param  row       index of the first row. If different than 0, then it is caller responsibility
-     *                   to provide controls for all rows before the specified index.
-     * @param  controls  (label, control) pairs to layout in rows.
-     * @return a pane with each (label, control) pair on a row.
-     */
-    static GridPane createControlGrid(final int row, final Label... controls) {
-        final GridPane gp = Styles.createControlGrid(row, controls);
-        Styles.setAllRowToSameHeight(gp);
-        gp.setBorder(GROUP_BORDER);
-        return gp;
-    }
-
-    /**
      * Creates a label with the specified text (fetched from localized resources) associated
to the given control.
      * If the given control is {@code null}, then this method returns {@code null} for skipping
the row completely.
      *
@@ -114,13 +93,21 @@ abstract class Controls {
      * @return label associated to the given group of controls.
      */
     static Label labelOfGroup(final IndexedResourceBundle vocabulary, final short key, final
Region group, final boolean isFirst) {
-        final Label label = new Label(vocabulary.getLabel(key));
+        final Label label = new Label(vocabulary.getString(key));
         label.setPadding(isFirst ? CAPTION_MARGIN : NEXT_CAPTION_MARGIN);
         label.setLabelFor(group);
+        label.setFont(fontOfGroup());
         return label;
     }
 
     /**
+     * Returns the font to assign to the label of a group of control.
+     */
+    static Font fontOfGroup() {
+        return Font.font(null, FontWeight.BOLD, -1);
+    }
+
+    /**
      * Returns the main component, which is showing coverage data or image.
      * This is the component to shown on the right (largest) part of the split pane.
      */
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 ad3780f..6d707e3 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
@@ -27,12 +27,15 @@ import javafx.scene.control.TitledPane;
 import javafx.scene.layout.BorderPane;
 import javafx.scene.layout.GridPane;
 import javafx.scene.layout.Region;
-import javafx.scene.layout.VBox;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
+import javafx.collections.ObservableList;
+import javafx.scene.Node;
 import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Label;
 import javafx.scene.paint.Color;
+import javafx.scene.text.Font;
 import javafx.util.StringConverter;
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -40,6 +43,7 @@ import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.gui.referencing.RecentReferenceSystems;
 import org.apache.sis.gui.map.StatusBar;
 import org.apache.sis.image.Interpolation;
+import org.apache.sis.internal.gui.Styles;
 import org.apache.sis.util.resources.Vocabulary;
 
 
@@ -97,18 +101,36 @@ final class CoverageControls extends Controls implements PropertyChangeListener
          *    - Color stretching
          *    - Background color
          */
-        final VBox displayPane;
+        final GridPane displayPane;
         {   // Block for making variables locale to this scope.
-            final GridPane referencing = createControlGrid(0,
-                label(vocabulary, Vocabulary.Keys.Interpolation, createInterpolationButton(vocabulary.getLocale()))
-            );
-            final GridPane colors = createControlGrid(0,
+            final int valuesHeader = 0;
+            final int colorsHeader = 2;
+            displayPane = Styles.createControlGrid(valuesHeader + 1,
+                label(vocabulary, Vocabulary.Keys.Interpolation, createInterpolationButton(vocabulary.getLocale())),
                 label(vocabulary, Vocabulary.Keys.Stretching, Stretching.createButton((p,o,n)
-> view.setStyling(n))),
-                label(vocabulary, Vocabulary.Keys.Background, createBackgroundButton(background))
-            );
-            displayPane = new VBox(
-                labelOfGroup(vocabulary, Vocabulary.Keys.Values, referencing, true), referencing,
-                labelOfGroup(vocabulary, Vocabulary.Keys.Colors, colors,     false), colors);
+                label(vocabulary, Vocabulary.Keys.Background, createBackgroundButton(background)));
+            /*
+             * Insert space (one row) betweeb "interpolation" and "stretching"
+             * so we can insert the "colors" section header.
+             */
+            final ObservableList<Node> items = displayPane.getChildren();
+            for (final Node item : items) {
+                if (GridPane.getColumnIndex(item) == 0) {
+                    ((Label) item).setPadding(INDENT);
+                }
+                final int row = GridPane.getRowIndex(item);
+                if (row >= colorsHeader) {
+                    GridPane.setRowIndex(item, row + 1);
+                }
+            }
+            final Font font = fontOfGroup();
+            final Label values = new Label(vocabulary.getString(Vocabulary.Keys.Values));
+            final Label colors = new Label(vocabulary.getString(Vocabulary.Keys.Colors));
+            values.setFont(font);
+            colors.setFont(font);
+            GridPane.setConstraints(values, 0, valuesHeader, 2, 1);    // Span 2 columns.
+            GridPane.setConstraints(colors, 0, colorsHeader, 2, 1);
+            items.addAll(values, colors);
         }
         /*
          * 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/GridControls.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridControls.java
index 260a21b..3e7a140 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridControls.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridControls.java
@@ -31,6 +31,7 @@ import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.coverage.grid.GridCoverage;
 import org.apache.sis.gui.referencing.RecentReferenceSystems;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.internal.gui.Styles;
 
 
 /**
@@ -85,11 +86,12 @@ final class GridControls extends Controls {
          */
         final VBox displayPane;
         {   // Block for making variables locale to this scope.
-            final GridPane gp = createControlGrid(0,
+            final GridPane gp = Styles.createControlGrid(0,
                 label(vocabulary, Vocabulary.Keys.Width,  createSlider(view.cellWidth,  30,
200)),
                 label(vocabulary, Vocabulary.Keys.Height, createSlider(view.cellHeight, 10,
 50)),
-                label(vocabulary, Vocabulary.Keys.Format, view.cellFormat.createEditor())
-            );
+                label(vocabulary, Vocabulary.Keys.Format, view.cellFormat.createEditor()));
+
+            Styles.setAllRowToSameHeight(gp);
             displayPane = new VBox(labelOfGroup(vocabulary, Vocabulary.Keys.Cells, gp, true),
gp);
         }
         /*


Mime
View raw message