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 2020/02/24 11:54:20 UTC
[sis] 02/02: Remove (for now) the code managing related windows
since it is no longer used. We may bring it back later but in another form.
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 8d17146b9e5c4d20e7c4fedb2683c49be698f1c4
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Mon Feb 24 12:26:45 2020 +0100
Remove (for now) the code managing related windows since it is no longer used.
We may bring it back later but in another form.
---
.../apache/sis/gui/coverage/CoverageExplorer.java | 57 +++++-----
.../org/apache/sis/gui/dataset/DataWindow.java | 126 ++-------------------
.../org/apache/sis/internal/gui/ToolbarButton.java | 78 ++-----------
3 files changed, 51 insertions(+), 210 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 be291eb..153967d 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
@@ -16,9 +16,8 @@
*/
package org.apache.sis.gui.coverage;
-import java.util.Locale;
-import javafx.scene.Node;
import javafx.scene.control.SplitPane;
+import javafx.scene.control.Separator;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Toggle;
import javafx.event.ActionEvent;
@@ -91,7 +90,8 @@ public class CoverageExplorer {
* The coverage property may be shown in various ways (tabular data, image).
* Each visualization way is an entry in the `views` array.
*/
- final Vocabulary vocabulary = Vocabulary.getResources((Locale) null);
+ final Resources localized = Resources.forLocale(null);
+ final Vocabulary vocabulary = Vocabulary.getResources(localized.getLocale());
views = new Controls[2];
views[TABLE_VIEW] = new GridControls(vocabulary);
views[IMAGE_VIEW] = new CoverageControls(vocabulary, coverageProperty);
@@ -108,37 +108,34 @@ public class CoverageExplorer {
* text and action for each button.
*/
final ToggleGroup group = new ToggleGroup();
- ToolbarButton.insert(content, new ToolbarButton() {
- /** 🗺 — World map. */
- @Override public Node createButton(final Resources localized) {
- return createButton(group, "\uD83D\uDDFA\uFE0F", localized, Resources.Keys.Visualize);
- }
- @Override public void handle(final ActionEvent event) {
- selectView(event, IMAGE_VIEW);
- }
- }, new ToolbarButton() {
- /** 🔢 — Input symbol for numbers. */
- @Override public Node createButton(final Resources localized) {
- return createButton(group, "\uD83D\uDD22\uFE0F", localized, Resources.Keys.TabularData);
- }
- @Override public void handle(final ActionEvent event) {
- selectView(event, TABLE_VIEW);
- }
- });
+ ToolbarButton.insert(content,
+ new Separator(),
+ new Selector(IMAGE_VIEW).createButton(group, "\uD83D\uDDFA\uFE0F", localized, Resources.Keys.Visualize), // 🗺 — World map.
+ new Selector(TABLE_VIEW).createButton(group, "\uD83D\uDD22\uFE0F", localized, Resources.Keys.TabularData) // 🔢 — Input symbol for numbers.
+ );
}
/**
- * Invoked when the user selects another view to show (tabular data or the image).
- *
- * @param index {@link #TABLE_VIEW} or {@link #IMAGE_VIEW}.
+ * The action to execute when the user selects a view.
*/
- private void selectView(final ActionEvent event, final int index) {
- final Toggle button = (Toggle) event.getSource();
- if (button.isSelected()) {
- final Controls c = views[index];
- content.getItems().setAll(c.controls(), c.view());
- } else {
- button.setSelected(true); // Prevent situation where all buttons are unselected.
+ private final class Selector extends ToolbarButton {
+ /** {@link #TABLE_VIEW} or {@link #IMAGE_VIEW}. */
+ private final int index;
+
+ /** Creates a new action which will show the view at the given index. */
+ Selector(final int index) {
+ this.index = index;
+ }
+
+ /** Invoked when the user selects another view to show (tabular data or the image). */
+ @Override public void handle(final ActionEvent event) {
+ final Toggle button = (Toggle) event.getSource();
+ if (button.isSelected()) {
+ final Controls c = views[index];
+ content.getItems().setAll(c.controls(), c.view());
+ } else {
+ button.setSelected(true); // Prevent situation where all buttons are unselected.
+ }
}
}
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 b607bbb..a4f45fc 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
@@ -28,8 +28,6 @@ import javafx.scene.control.Labeled;
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;
@@ -47,11 +45,8 @@ import org.apache.sis.internal.gui.ToolbarButton;
final class DataWindow extends Stage {
/**
* The tools bar. Removed from the pane when going in full screen mode, and reinserted
- * when exiting full screen mode. The first button in this toolbar shall be the "home"
- * button (for showing the main window on front) — if a different position is desired,
- * revisit {@link #getHomeButton()}.
+ * when exiting full screen mode.
*
- * @see #getHomeButton()
* @see #onFullScreen(boolean)
*/
private final ToolBar tools;
@@ -64,42 +59,17 @@ final class DataWindow extends Stage {
* @param data the data selected by user, to show in a new window.
*/
DataWindow(final Stage home, final SelectedData data) {
- this(data.createView(), data.localized);
- getHomeButton().setOnAction((e) -> {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());
- }
-
- /**
- * Returns the "home" button. This implementation assumes that "home" is the first button on the toolbar.
- * This method is kept close to the following constructor for making easier to verify its assumption.
- */
- private Button getHomeButton() {
- return ((Button) tools.getItems().get(0));
- }
-
- /**
- * Creates a new window for the given content. After this constructor returned,
- * caller should set an action on {@link #getHomeButton()} and set the window size.
- *
- * @param content content of the window to create.
- * @param localized {@link Resources} instance, provided because often known by the caller.
- */
- private DataWindow(final Region content, final Resources localized) {
+ final Region content = data.createView();
/*
* Build the tools bar. This bar will be hidden in full screen mode. Note that above
* method assumes that the "home" button created below is the first one in the toolbar.
*/
final Button mainWindow = new Button("\u2302\uFE0F"); // ⌂ — house
- mainWindow.setTooltip(new Tooltip(localized.getString(Resources.Keys.MainWindow)));
+ mainWindow.setTooltip(new Tooltip(data.localized.getString(Resources.Keys.MainWindow)));
+ mainWindow.setOnAction((e) -> {home.show(); home.toFront();});
final Button fullScreen = new Button("\u21F1\uFE0F"); // ⇱ — North West Arrow to Corner
- fullScreen.setTooltip(new Tooltip(localized.getString(Resources.Keys.FullScreen)));
+ fullScreen.setTooltip(new Tooltip(data.localized.getString(Resources.Keys.FullScreen)));
fullScreen.setOnAction((event) -> setFullScreen(true));
fullScreenProperty().addListener((source, oldValue, newValue) -> onFullScreen(newValue));
@@ -108,13 +78,7 @@ final class DataWindow extends Stage {
* 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.
*/
- for (final ToolbarButton specialized : ToolbarButton.remove(content)) {
- final Node button = specialized.createButton(localized);
- if (specialized instanceof ToolbarButton.RelatedWindow) {
- ((Button) button).setOnAction(new Related(this, (ToolbarButton.RelatedWindow) specialized));
- }
- tools.getItems().add(button);
- }
+ tools.getItems().addAll(ToolbarButton.remove(content));
/*
* After we finished adding all buttons, set the font of all of them to a larger size.
*/
@@ -132,79 +96,13 @@ final class DataWindow extends Stage {
pane.setTop(tools);
pane.setCenter(content);
setScene(new Scene(pane));
- }
-
- /**
- * Manage the creation and display of another window related to the enclosing {@link DataWindow}.
- * For example is the enclosing window shows the tabular data, the window created by this class
- * may show 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 for creating the window on the first time that the user clicks on the button.
- * This is set to {@code null} when no longer needed, in which case {@link #window} should
- * be a reference to the window that we created.
- */
- private ToolbarButton.RelatedWindow 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 this class has created.
- */
- private DataWindow window;
-
- /**
- * Prepares an action for invoking {@code creator.createView()} when first needed.
- * The given {@code originator} window will be the target of the "back" button.
- *
- * @param originator the original window that created this {@code Related} instance.
- * @param creator a factory for the new window to create when the user request it.
- */
- Related(final DataWindow originator, final ToolbarButton.RelatedWindow creator) {
- this.window = originator;
- this.creator = creator;
- }
-
- /**
- * Invoked when the user clicked on the button for showing the window managed by this {@code Related} object.
- * On the first click, the related window is created. On subsequent clicks, that window is brought to front.
+ /*
+ * 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.
*/
- @Override
- public void handle(final ActionEvent event) {
- if (creator != null) {
- final DataWindow originator = window;
- final Resources localized = Resources.forLocale(null);
- final Region content = creator.createView();
- final Button backButton = creator.createBackButton(localized);
- ToolbarButton.insert(content, new ToolbarButton() {
- @Override public Node createButton(Resources localized) {
- backButton.setOnAction(this);
- return backButton;
- }
- @Override public void handle(ActionEvent event) {
- originator.show();
- originator.toFront();
- }
- });
- final DataWindow rw = new DataWindow(content, localized);
- rw.getHomeButton().setOnAction(originator.getHomeButton().getOnAction());
- rw.setTitle (originator.getTitle());
- rw.setWidth (originator.getWidth());
- rw.setHeight(originator.getHeight());
- rw.setX(originator.getX() + LOCATION);
- rw.setY(originator.getY() + LOCATION);
- window = rw; // Set only on success.
- creator = null;
- }
- window.show();
- window.toFront();
- }
+ final Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
+ setWidth (0.8 * bounds.getWidth());
+ setHeight(0.8 * bounds.getHeight());
}
/**
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 3b1f3c5..3e6bfe4 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,19 +17,19 @@
package org.apache.sis.internal.gui;
import javafx.scene.Node;
+import javafx.scene.control.Control;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBase;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
-import javafx.scene.layout.Region;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import org.apache.sis.util.ArraysExt;
/**
- * Description of a button to add in a the {@link org.apache.sis.gui.dataset.DataWindow} toolbar.
+ * Builder for a button to add in a the {@link org.apache.sis.gui.dataset.DataWindow} toolbar.
* This class is used only for content-specific buttons; it is not used for buttons managed directly by
* {@code DataWindow} itself. A {@code ToolbarButton} can create and configure a button with its icon,
* tooltip text and action to execute when the button is pushed.
@@ -45,32 +45,32 @@ import org.apache.sis.util.ArraysExt;
public abstract class ToolbarButton implements EventHandler<ActionEvent> {
/**
* The property to use in {@link Node#getProperties()} for storing instances of this class.
- * Values associated to this key shall be arrays of {@code ToolbarButton[]} type.
+ * Values associated to this key shall be arrays of {@code Control[]} type.
*/
- private static final String PROPERTY_KEY = "org.apache.sis.gui.ToolbarButton";
+ private static final String PROPERTY_KEY = "org.apache.sis.gui.ToolbarButtons";
/**
* Gets and removes the toolbar buttons associated to the given content pane. Those buttons
- * should have been specified by a previous call to {@link #insert(Node, ToolbarButton...)}.
+ * should have been specified by a previous call to {@link #insert(Node, Control...)}.
* They will be requested by {@link org.apache.sis.gui.dataset.DataWindow} only once,
* which is why we remove them afterward.
*
* @param content the pane for which to get the toolbar buttons.
* @return the toolbar buttons (never null, but may be empty).
*/
- public static ToolbarButton[] remove(final Node content) {
- final ToolbarButton[] buttons = (ToolbarButton[]) content.getProperties().remove(PROPERTY_KEY);
- return (buttons != null) ? buttons : new ToolbarButton[0];
+ public static Control[] remove(final Node content) {
+ final Control[] buttons = (Control[]) content.getProperties().remove(PROPERTY_KEY);
+ return (buttons != null) ? buttons : new Control[0];
}
/**
- * Sets the toolbar buttons that the given pane which to have in the data window.
- * If the pane already has buttons, the new one will be inserted before existing ones.
+ * Sets the toolbar buttons that the given pane wants to have in the data window.
+ * If the pane already has buttons, the new ones will be inserted before existing ones.
*
* @param content the pane for which to set the toolbar buttons.
* @param buttons the toolbar buttons to add.
*/
- public static void insert(final Node content, final ToolbarButton... buttons) {
+ public static void insert(final Node content, final Control... buttons) {
content.getProperties().merge(PROPERTY_KEY, buttons, ToolbarButton::prepend);
}
@@ -89,19 +89,6 @@ public abstract class ToolbarButton implements EventHandler<ActionEvent> {
}
/**
- * Creates a button configured with its icon, tooltip and action.
- * The button will be added to the toolbar by the caller.
- *
- * <p>If this {@code ToolbarButton} is an instance of {@link RelatedWindow},
- * then this method does not need to set an action on the button because it
- * will be done by the caller.</p>
- *
- * @param localized an instance of {@link Resources} for current locale.
- * @return the button configured with text or icon, tooltip and action.
- */
- public abstract Node createButton(Resources localized);
-
- /**
* Convenience method for creating a button.
* The action handler will be {@code this}.
*
@@ -111,7 +98,7 @@ public abstract class ToolbarButton implements EventHandler<ActionEvent> {
* @param tooltip the {@link Resources.Keys} value for the tooltip.
* @return the button configured with text or icon, tooltip and action.
*/
- protected final ButtonBase createButton(final ToggleGroup group, final String icon, final Resources localized, final short tooltip) {
+ public final ButtonBase createButton(final ToggleGroup group, final String icon, final Resources localized, final short tooltip) {
final ButtonBase b;
if (group != null) {
final ToggleButton tb = new ToggleButton(icon);
@@ -132,45 +119,4 @@ public abstract class ToolbarButton implements EventHandler<ActionEvent> {
*/
@Override
public abstract void handle(ActionEvent event);
-
- /**
- * A toolbar button for creating and showing a new window related to the window in which the button has been pushed.
- * The button action will create a new instance of {@link org.apache.sis.gui.dataset.DataWindow} which will itself
- * contain a button for going back to the original window.
- */
- public abstract static class RelatedWindow extends ToolbarButton {
- /**
- * For subclass constructors.
- */
- protected RelatedWindow() {
- }
-
- /**
- * Creates a button configured with its icon, tooltip and action.
- * This button does not need to contain an action; it will be set by the caller.
- *
- * @param localized an instance of {@link Resources} for current locale.
- * @return the button configured with text or icon and tooltip.
- */
- @Override
- public abstract Button createButton(Resources localized);
-
- /**
- * Creates the button for navigation back to the original window.
- * This button does not need to contain an action; it will be set by the caller.
- *
- * @param localized an instance of {@link Resources} for current locale.
- * @return the button configured with text or icon and tooltip.
- */
- public abstract Button createBackButton(Resources localized);
-
- /**
- * 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();
- }
}