sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Basic navigation between the window showing tabular data and the window showing the image (empty for now).
Date Fri, 21 Feb 2020 00:20:50 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 7e9faf3  Basic navigation between the window showing tabular data and the window
showing the image (empty for now).
7e9faf3 is described below

commit 7e9faf33a5e8cfecac1341232b0d467190d06cd9
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Feb 21 01:13:42 2020 +0100

    Basic navigation between the window showing tabular data and the window showing the image
(empty for now).
---
 .../apache/sis/gui/coverage/CoverageExplorer.java  |   5 +-
 .../org/apache/sis/gui/coverage/CoverageView.java  |  13 ++-
 .../org/apache/sis/gui/dataset/DataWindow.java     | 127 ++++++++++++++++++---
 .../org/apache/sis/internal/gui/ToolbarButton.java |  13 +++
 4 files changed, 142 insertions(+), 16 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 409580a..a94993d 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
@@ -185,7 +185,10 @@ addRows:    for (int row = 0;; row++) {
          */
         content.getProperties().put(ToolbarButton.PROPERTY_KEY, new ToolbarButton[] {
             new ToolbarButton() {
-                @Override public String getText() {return "\uD83D\uDDFA";}      // World
map character.
+                @Override public String getText() {return "\uD83D\uDDFA\uFE0F";}      //
World map character.
+                @Override public Region createView() {
+                    return new CoverageView(null).getView();
+                }
             }
         });
     }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
index f044132..8ba4aec 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageView.java
@@ -30,6 +30,7 @@ import javafx.scene.image.PixelBuffer;
 import javafx.scene.image.PixelFormat;
 import javafx.scene.image.WritableImage;
 import javafx.scene.layout.Pane;
+import javafx.scene.layout.Region;
 import javafx.util.Callback;
 import org.opengis.referencing.datum.PixelInCell;
 import org.apache.sis.coverage.grid.GridCoverage;
@@ -101,7 +102,7 @@ final class CoverageView extends PlanarCanvas {
      *
      * @param  locale  the locale to use for labels and some messages, or {@code null} for
default.
      */
-    CoverageView(final Locale locale) {
+    public CoverageView(final Locale locale) {
         super(locale);
         dataToImage = new AffineTransform();
         view        = new Pane();
@@ -112,6 +113,16 @@ final class CoverageView extends PlanarCanvas {
     }
 
     /**
+     * Returns the region containing the image view.
+     * The subclass is implementation dependent and may change in any future version.
+     *
+     * @return the region to show.
+     */
+    public final Region getView() {
+        return view;
+    }
+
+    /**
      * Sets the image to display.
      */
     private void setImage(final RenderedImage source) {
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/DataWindow.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/DataWindow.java
index 124dbfe..40244cd 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/DataWindow.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/DataWindow.java
@@ -16,15 +16,20 @@
  */
 package org.apache.sis.gui.dataset;
 
+import java.util.Locale;
 import javafx.geometry.Rectangle2D;
 import javafx.stage.Screen;
 import javafx.stage.Stage;
 import javafx.scene.Scene;
+import javafx.scene.Node;
 import javafx.scene.control.Button;
 import javafx.scene.control.ToolBar;
 import javafx.scene.control.Tooltip;
 import javafx.scene.layout.BorderPane;
 import javafx.scene.layout.Region;
+import javafx.scene.text.Font;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
 import org.apache.sis.internal.gui.Resources;
 import org.apache.sis.internal.gui.ToolbarButton;
 
@@ -41,55 +46,149 @@ import org.apache.sis.internal.gui.ToolbarButton;
  */
 final class DataWindow extends Stage {
     /**
+     * The locale for this window.
+     */
+    private final Locale locale;
+
+    /**
      * The tools bar. Removed from the pane when going in full screen mode,
      * and reinserted when exiting full screen mode.
      */
     private final ToolBar tools;
 
     /**
-     * Creates a new window for the given data.
+     * Creates a new window for the given data selected in the explorer or determined by
the active tab.
      *
      * @param  home  the window containing the main explorer, to be the target of "home"
button.
-     * @param  data  the data to show in a new window.
+     * @param  data  the data selected by user, to show in a new window.
      */
     DataWindow(final Stage home, final SelectedData data) {
-        final Region content = data.createView();
+        this(null, data.createView(), data.localized,
+                (event) -> {home.show(); home.toFront();});
+        /*
+         * We use an initial size covering a large fraction of the screen because
+         * this window is typically used for showing image or large tabular data.
+         */
+        final Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
+        setWidth (0.8 * bounds.getWidth());
+        setHeight(0.8 * bounds.getHeight());
+    }
+
+    /**
+     * Creates a new window for the given content. The {@code home} and {@code localized}
arguments
+     * shall be non-null only if {@code originator} is null.
+     *
+     * @param  originator  the window from which this window is derived, or {@code null}
if none.
+     * @param  content     content of the window to create.
+     * @param  localized   {@link Resources} instance provided because often know by the
caller.
+     * @param  home        the action to execute when user clicks on the "home" button.
+     */
+    private DataWindow(final DataWindow originator, final Region content, Resources localized,
EventHandler<ActionEvent> home) {
+        if (originator != null) {
+            home = ((Button) originator.tools.getItems().get(0)).getOnAction();
+            localized = Resources.forLocale(originator.locale);
+        }
+        locale = localized.getLocale();
         /*
          * Build the tools bar. This bar will be hidden in full screen mode.
+         * Note that code above assumes that this button is the first button in the toolbar.
          */
-        final Button mainWindow = new Button("⌂");
-        mainWindow.setTooltip(new Tooltip(data.localized.getString(Resources.Keys.MainWindow)));
-        mainWindow.setOnAction((event) -> {home.show(); home.toFront();});
+        final Button mainWindow = new Button("\u2302\uFE0F");               // ⌂ — house
+        mainWindow.setTooltip(new Tooltip(localized.getString(Resources.Keys.MainWindow)));
+        mainWindow.setOnAction(home);
 
-        final Button fullScreen = new Button("⇱");
-        fullScreen.setTooltip(new Tooltip(data.localized.getString(Resources.Keys.FullScreen)));
+        final Button fullScreen = new Button("\u21F1\uFE0F");               // ⇱ — North
West Arrow to Corner
+        fullScreen.setTooltip(new Tooltip(localized.getString(Resources.Keys.FullScreen)));
         fullScreen.setOnAction((event) -> setFullScreen(true));
         /*
          * Hide/show the toolbar when entering/exiting full screen mode.
          */
         tools = new ToolBar(mainWindow, fullScreen);
         fullScreenProperty().addListener((source, oldValue, newValue) -> onFullScreen(newValue));
+
+        if (originator != null) {
+            final Button related = new Button("\uD83D\uDD22\uFE0F");    // Input symbol for
numbers.
+            related.setOnAction((event) -> {originator.show(); originator.toFront();});
+            tools.getItems().add(related);
+        }
         /*
-         * Add content-specific buttons.
+         * Add content-specific buttons. We use the "org.apache.sis.gui.ToolbarButton" property
+         * as a way to transfer ToolbarButton accross packages without making this class
public.
          */
         final ToolbarButton[] contentButtons = (ToolbarButton[]) content.getProperties().remove(ToolbarButton.PROPERTY_KEY);
         if (contentButtons != null) {
             for (final ToolbarButton tb : contentButtons) {
                 final Button b = new Button(tb.getText());
+                b.setOnAction(new Related(this, tb));
                 tools.getItems().add(b);
             }
         }
+        final Font bf = Font.font(20);
+        for (final Node node : tools.getItems()) {
+            ((Button) node).setFont(bf);
+        }
         /*
-         * Main content. We use an initial size covering a large fraction of the screen
-         * since this window is typically used for showing image or large tabular data.
+         * Main content. After this constructor returned, caller
+         * should set the width and height, then show the window.
          */
         final BorderPane pane = new BorderPane();
         pane.setTop(tools);
         pane.setCenter(content);
         setScene(new Scene(pane));
-        final Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
-        setWidth (0.8 * bounds.getWidth());
-        setHeight(0.8 * bounds.getHeight());
+    }
+
+    /**
+     * Manage the creation and display of another window related to the enclosing {@link
DataWindow}.
+     * For example is the enclosing window shown the tabular data, the window created by
this class
+     * may shown the map.
+     */
+    private static final class Related implements EventHandler<ActionEvent> {
+        /**
+         * The X and Y location of the new window relative to the original window.
+         */
+        private static final int LOCATION = 40;
+
+        /**
+         * The object that can create the window.
+         * This is set to {@code null} when no longer needed.
+         */
+        private ToolbarButton creator;
+
+        /**
+         * The related window. If {@link #creator} is non-null, then this is the original
window that
+         * created this {@code Related} instance. If {@link #creator} is null, this is the
new window
+         * that has been created.
+         */
+        private DataWindow window;
+
+        /**
+         * Prepares an action for invoking {@code creator.createView()} when first needed.
+         */
+        Related(final DataWindow originator, final ToolbarButton creator) {
+            this.window  = originator;
+            this.creator = creator;
+        }
+
+        /**
+         * Invoked when the user clicked on the button for showing the window managed by
this {@code Related}.
+         * On the first click, the related window is created. On subsequent click, that window
is brought to front.
+         */
+        @Override
+        public void handle(final ActionEvent event) {
+            if (creator != null) {
+                final String title = window.getTitle();     // TODO! make the title different.
+                final DataWindow rw = new DataWindow(window, creator.createView(), null,
null);
+                rw.setTitle(title);
+                rw.setWidth (window.getWidth());
+                rw.setHeight(window.getHeight());
+                rw.setX(window.getX() + LOCATION);
+                rw.setY(window.getY() + LOCATION);
+                window  = rw;                   // Set only on success.
+                creator = null;
+            }
+            window.show();
+            window.toFront();
+        }
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ToolbarButton.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ToolbarButton.java
index f472034..94a2384 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ToolbarButton.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ToolbarButton.java
@@ -17,6 +17,7 @@
 package org.apache.sis.internal.gui;
 
 import javafx.scene.Node;
+import javafx.scene.layout.Region;
 
 
 /**
@@ -24,6 +25,9 @@ import javafx.scene.Node;
  * other than the common buttons provided by {@code DataWindow} itself.
  * Those button depends on the window content.
  *
+ * <p>Current API is for creating a new window of related data. A future version
+ * may move that API in a subclass if we need to support other kinds of service.</p>
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.1
  * @since   1.1
@@ -48,4 +52,13 @@ public abstract class ToolbarButton {
      * @return the button text.
      */
     public abstract String getText();
+
+    /**
+     * Creates the content of the window to show when the user click on the button.
+     * This method is invoked only on the first click. For all subsequent clicks,
+     * the existing window will be shown again.
+     *
+     * @return content of the window to show.
+     */
+    public abstract Region createView();
 }


Mime
View raw message