sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1832316 - in /sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui: Main.java metadata/ metadata/MetadataNode.java metadata/MetadataOverview.java metadata/ResourceView.java
Date Sat, 26 May 2018 16:23:25 GMT
Author: desruisseaux
Date: Sat May 26 16:23:25 2018
New Revision: 1832316

URL: http://svn.apache.org/viewvc?rev=1832316&view=rev
Log:
Initial commit of Smaniotto Enzo work from SIS-417, with some renaming.

Added:
    sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java  
(with props)
    sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/
    sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
  (with props)
    sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
  (with props)
    sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
  (with props)

Added: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java?rev=1832316&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java (added)
+++ sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java [UTF-8]
Sat May 26 16:23:25 2018
@@ -0,0 +1,123 @@
+/*
+ * 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;
+
+import java.io.File;
+import javafx.application.Application;
+import javafx.application.Platform;
+import javafx.scene.Scene;
+import javafx.scene.control.Menu;
+import javafx.scene.control.MenuBar;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.SeparatorMenuItem;
+import javafx.scene.input.KeyCombination;
+import javafx.scene.layout.BorderPane;
+import javafx.stage.FileChooser;
+import javafx.stage.Stage;
+import org.apache.sis.gui.metadata.ResourceView;
+
+
+/**
+ * Entry point for Apache SIS application.
+ *
+ * @author  Smaniotto Enzo
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class Main extends Application {
+    /**
+     * The primary stage onto which the application scene is set.
+     */
+    private Stage window;
+
+    /**
+     * The main content of this application. For now this is the metadata viewer.
+     * In a future version it will be another component.
+     */
+    private ResourceView content;
+
+    /**
+     * Creates a new Apache SIS application.
+     */
+    public Main() {
+    }
+
+    /**
+     * Invoked by JavaFX for starting the application.
+     * This method is called on the JavaFX Application Thread.
+     *
+     * @param window  the primary stage onto which the application scene will be be set.
+     */
+    @Override
+    public void start(final Stage window) {
+        this.window = window;
+        /*
+         * Configure the menu bar.
+         */
+        final MenuBar menus = new MenuBar();
+        final Menu file = new Menu("File");                                 // TODO: localize
+        menus.getMenus().add(file);
+
+        final MenuItem open = new MenuItem("Open…");                        // TODO: localize
+        open.setAccelerator(KeyCombination.keyCombination("Shortcut+O"));
+        open.setOnAction(e -> open());
+
+        final MenuItem exit = new MenuItem("Exit");                         // TODO: localize
+        exit.setOnAction(e -> Platform.exit());
+        file.getItems().addAll(open, new SeparatorMenuItem(), exit);
+        /*
+         *
+         */
+        content = new ResourceView();
+        final BorderPane pane = new BorderPane();
+        pane.setTop(menus);
+        pane.setCenter(content.pane);
+        Scene scene = new Scene(pane);
+        window.setTitle("Apache Spatial Information System");
+        window.setScene(scene);
+        window.setWidth(800);
+        window.setHeight(650);
+        window.show();
+    }
+
+    /**
+     * Invoked when the user selected "File / open" menu.
+     */
+    private void open() {
+        final FileChooser fileChooser = new FileChooser();
+        fileChooser.setTitle("Open data file");                         // TODO: localize
+        File fileByChooser = fileChooser.showOpenDialog(window);
+        if (fileByChooser != null) {
+            if (fileByChooser.isDirectory()) {
+                content.openDirectory(fileByChooser);
+            } else {
+                content.openFile(fileByChooser);
+            }
+        }
+    }
+
+    /**
+     * Starts the Apache SIS application.
+     *
+     * @param args  ignored.
+     */
+    public static void main(final String[] args) {
+        launch(args);
+    }
+}

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/Main.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java?rev=1832316&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
(added)
+++ sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
[UTF-8] Sat May 26 16:23:25 2018
@@ -0,0 +1,228 @@
+/*
+ * 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.metadata;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Predicate;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.property.SimpleStringProperty;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeTableColumn;
+import javafx.scene.control.TreeTableView;
+import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.collection.TreeTable;
+import org.opengis.referencing.ReferenceSystem;
+
+
+/**
+ *
+ * @author Siddhesh Rane
+ */
+final class MetadataNode extends TreeTableView<TreeTable.Node> {
+
+    private static final Predicate<TreeTable.Node> HIDE_EMPTY_LEAF = t -> !t.isLeaf()
|| t.getValue(TableColumn.VALUE) != null;
+    private static final Predicate<TreeTable.Node> EXPAND_SINGLE_CHILD = node ->
node.getChildren().size() == 1 || node.getParent() == null;
+
+    private TreeTable treeTable;
+    private TreeTableColumn<TreeTable.Node, String> nameColumn;
+    private TreeTableColumn<TreeTable.Node, TreeTable.Node> valueColumn;
+    private TreeTableColumn<TreeTable.Node, String> textColumn;
+
+    private final ObjectProperty<Predicate<TreeTable.Node>> createTreeItemForNodeProperty
= new SimpleObjectProperty<>(HIDE_EMPTY_LEAF);
+
+    /**
+     * A property containing predicate that returns true if the given
+     * {@link TreeTable.Node} must be shown as a {@link TreeItem} in the
+     * {@link TreeTableView}. By default return true for all nodes unless
+     * preferences are loaded
+     *
+     * @return The property containing the expansion predicate
+     */
+    private ObjectProperty<Predicate<TreeTable.Node>> createTreeItemForNodeProperty()
{
+        return createTreeItemForNodeProperty;
+    }
+
+    private Predicate<TreeTable.Node> getCreateTreeItemForNode() {
+        return createTreeItemForNodeProperty.get();
+    }
+
+    private void setCreateTreeItemForNode(Predicate<TreeTable.Node> createTreeItemForNode)
{
+        createTreeItemForNodeProperty.set(createTreeItemForNode);
+    }
+
+    private final SimpleObjectProperty<Predicate<TreeTable.Node>> expandNodeProperty
= new SimpleObjectProperty<>(EXPAND_SINGLE_CHILD);
+
+    /**
+     * A property containing predicate that returns true if the given
+     * {@link TreeTable.Node} must be expanded in the {@link TreeTableView} to
+     * show its children by default.
+     *
+     * @return The property containing the expansion predicate
+     */
+    private ObjectProperty<Predicate<TreeTable.Node>> expandNodeProperty() {
+        return expandNodeProperty;
+    }
+
+    private Predicate<TreeTable.Node> getExpandNode() {
+        return expandNodeProperty.get();
+    }
+
+    private void setExpandNode(Predicate<TreeTable.Node> expandNode) {
+        expandNodeProperty.set(expandNode);
+    }
+
+    private void expandNodes(TreeItem<TreeTable.Node> root) {
+        if (root == null || root.isLeaf()) {
+            return;
+        }
+        root.setExpanded(getExpandNode().test(root.getValue()));
+        for (TreeItem<TreeTable.Node> child : root.getChildren()) {
+            expandNodes(child);
+        }
+    }
+
+    ObjectProperty<Comparator<TreeTable.Node>> order = new SimpleObjectProperty<>(Comparator.comparingInt(n
-> 0));
+
+    /**
+     * the default order of sorting for rows of the tree table.
+     *
+     * @return
+     */
+    private ObjectProperty<Comparator<TreeTable.Node>> orderProperty() {
+        return order;
+    }
+
+    private void setOrder(Comparator c) {
+        order.set(c);
+    }
+
+    private Comparator<TreeTable.Node> getOrder() {
+        return order.get();
+    }
+
+    MetadataNode(TreeTable treeTable) {
+        this();
+        setTreeTable(treeTable);
+    }
+
+    private MetadataNode() {
+        createTableColumns();
+        setShowRoot(false);
+        setColumnResizePolicy(CONSTRAINED_RESIZE_POLICY);
+        expandNodeProperty.addListener(ob -> expandNodes(getRoot()));
+    }
+
+    /**
+     * Creates {@link TableColumn}s for name, identifier, value valueastext, but
+     * doesnt add them to the table. These columns can later be added according
+     * what all is contained by the TreeTable.
+     */
+    private void createTableColumns() {
+        //NAME column
+        nameColumn = new TreeTableColumn<>(TableColumn.NAME.getHeader().toString());
+        nameColumn.setCellValueFactory((param) -> {
+            CharSequence value = param.getValue().getValue().getValue(TableColumn.NAME);
+            return new SimpleStringProperty(Objects.toString(value, ""));
+        });
+
+        //TEXT column
+        textColumn = new TreeTableColumn<>(TableColumn.VALUE_AS_TEXT.getHeader().toString());
+        textColumn.setCellValueFactory((param) -> {
+            CharSequence value = param.getValue().getValue().getValue(TableColumn.VALUE_AS_TEXT);
+            return new SimpleStringProperty(Objects.toString(value, ""));
+        });
+
+        //VALUE column
+        valueColumn = new TreeTableColumn<>(TableColumn.VALUE.getHeader().toString());
+        valueColumn.setCellValueFactory((param) -> {
+            TreeTable.Node value = param.getValue().getValue();
+            SimpleObjectProperty ret = new SimpleObjectProperty(value.getValue(TableColumn.VALUE));
+            if (value.getValue(TableColumn.NAME).toString().equals("Reference system info"))
{
+                ReferenceSystem newVal = (ReferenceSystem) ret.getValue();
+                ret.setValue(newVal.getName());
+            }
+            return ret;
+        });
+    }
+
+    private TreeTable getTreeTable() {
+        return treeTable;
+    }
+
+    private void setTreeTable(TreeTable treeTable) {
+        this.treeTable = treeTable;
+        if (treeTable == null) {
+            setRoot(null);
+            return;
+        }
+
+        List<TableColumn<?>> columns = treeTable.getColumns();
+        if (columns.contains(TableColumn.NAME)) {
+            if (nameColumn.getTreeTableView() == null) {
+                getColumns().add(nameColumn);
+            }
+        } else {
+            getColumns().remove(nameColumn);
+        }
+        if (columns.contains(TableColumn.VALUE)) {
+            if (valueColumn.getTreeTableView() == null) {
+                getColumns().add(valueColumn);
+            }
+        } else {
+            getColumns().remove(valueColumn);
+        }
+        if (columns.contains(TableColumn.VALUE_AS_TEXT)) {
+            if (textColumn.getTreeTableView() == null) {
+                getColumns().add(textColumn);
+            }
+        } else {
+            getColumns().remove(textColumn);
+        }
+        TreeItem<TreeTable.Node> rootItem = new TreeItem<>(treeTable.getRoot());
+        setRoot(rootItem);
+        rootItem.setExpanded(true);
+        updateRoot();
+    }
+
+    private void updateRoot() {
+        getRoot().getChildren().clear();
+        createTreeItems(getRoot(), treeTable.getRoot().getChildren());
+    }
+
+    private void createTreeItems(TreeItem<TreeTable.Node> rootItem, Collection<TreeTable.Node>
children) {
+        for (TreeTable.Node node : children) {
+            TreeItem parent = rootItem;
+            //include this node in the tree table view?
+            if (getCreateTreeItemForNode().test(node)) {
+                parent = new TreeItem(node);
+                parent.setExpanded(getExpandNode().test(node));
+                rootItem.getChildren().add(parent);
+            }
+            if (!node.isLeaf()) {
+                createTreeItems(parent, node.getChildren());
+            }
+            if (parent.getChildren().size() > 1) {
+                Comparator<TreeItem<TreeTable.Node>> cp = Comparator.comparing(TreeItem<TreeTable.Node>::getValue,
getOrder());
+                parent.getChildren().sort(cp);
+            }
+        }
+    }
+}

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataNode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java?rev=1832316&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
(added)
+++ sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
[UTF-8] Sat May 26 16:23:25 2018
@@ -0,0 +1,432 @@
+/*
+ * 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.metadata;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import static java.text.NumberFormat.getIntegerInstance;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javafx.beans.value.ObservableValue;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import static javafx.event.ActionEvent.ACTION;
+import javafx.event.Event;
+import javafx.geometry.Insets;
+import javafx.scene.Node;
+import javafx.scene.canvas.Canvas;
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.TitledPane;
+import javafx.scene.control.Toggle;
+import javafx.scene.control.ToggleButton;
+import javafx.scene.control.ToggleGroup;
+import javafx.scene.image.Image;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
+import org.apache.sis.metadata.iso.DefaultMetadata;
+import org.apache.sis.metadata.iso.citation.DefaultIndividual;
+import org.apache.sis.metadata.iso.citation.DefaultOrganisation;
+import org.apache.sis.metadata.iso.spatial.DefaultGridSpatialRepresentation;
+import static org.apache.sis.util.iso.Types.getCodeTitle;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.citation.CitationDate;
+import org.opengis.metadata.citation.Party;
+import org.opengis.metadata.citation.Responsibility;
+import org.opengis.metadata.extent.Extent;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.metadata.extent.GeographicDescription;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.metadata.identification.DataIdentification;
+import org.opengis.metadata.identification.Identification;
+import org.opengis.metadata.identification.TopicCategory;
+import org.opengis.metadata.spatial.Dimension;
+import org.opengis.metadata.spatial.SpatialRepresentation;
+import org.opengis.metadata.spatial.SpatialRepresentationType;
+import org.opengis.referencing.ReferenceSystem;
+import org.opengis.util.InternationalString;
+
+/**
+ * Metadata Viewer.
+ *
+ * @author Smaniotto Enzo
+ */
+class MetadataOverview extends StackPane {
+
+    private final Metadata METADATA;
+    private final String FROMFILE;
+    private final Locale LOCALE = Locale.getDefault();
+
+    public MetadataOverview(DefaultMetadata _md, String _fromFile) {
+        METADATA = _md;
+        FROMFILE = _fromFile;
+        VBox root = new VBox();
+        root.setStyle("-fx-background-color: linear-gradient(to bottom right, #aeb7c4, #fafafa);");
+
+        // Creation of the differents views.
+        VBox summaryView = createSummaryView();
+        DefaultMetadata md = (DefaultMetadata) METADATA;
+        MetadataNode advancedView = new MetadataNode(md.asTreeTable());
+        advancedView.setMaxHeight(Double.MAX_VALUE);
+        VBox.setVgrow(advancedView, Priority.ALWAYS);
+
+        // Create and configure view selection buttons.
+        ToggleGroup buttonGroup = new ToggleGroup();
+        ToggleButton tb1 = new ToggleButton("Summary");
+        ToggleButton tb2 = new ToggleButton("Advanced");
+        tb1.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight:
bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box
, rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;");
+        tb2.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight:
bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box
, rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;");
+
+        tb1.setToggleGroup(buttonGroup);
+        tb1.setSelected(true);
+        tb1.setDisable(true);
+        tb2.setToggleGroup(buttonGroup);
+        buttonGroup.selectToggle(tb1);
+        buttonGroup.selectedToggleProperty().addListener((ObservableValue<? extends Toggle>
observable, Toggle oldValue, Toggle newValue) -> {
+            if (tb2.isSelected()) {
+                tb2.setDisable(true);
+                root.getChildren().remove(summaryView);
+                root.getChildren().add(advancedView);
+                tb1.setDisable(false);
+            } else {
+                tb1.setDisable(true);
+                root.getChildren().add(summaryView);
+                root.getChildren().remove(advancedView);
+                tb2.setDisable(false);
+            }
+        });
+
+        HBox toggleGroupLayout = new HBox();
+        toggleGroupLayout.getChildren().addAll(tb1, tb2);
+        toggleGroupLayout.setPadding(new Insets(0, 0, 10, 0));
+
+        root.getChildren().add(toggleGroupLayout);
+        root.getChildren().add(summaryView);
+
+        this.getChildren().add(root);
+    }
+
+    private VBox createSummaryView() {
+        VBox vb = new VBox();
+        TitledPane idPane = new TitledPane("Identification info", createIdGridPane());
+        TitledPane spatialPane = new TitledPane("Spatial representation", createSpatialGridPane());
+        vb.getChildren().add(idPane);
+        vb.getChildren().add(spatialPane);
+        return vb;
+    }
+
+    private GridPane createIdGridPane() {
+        GridPane gp = new GridPane();
+        gp.setHgap(10.00);
+        int j = 0, k = 1;
+
+        HashMap<String, Identification> m = new HashMap<>();
+        ComboBox comboBox = createComboBox(m);
+        comboBox.setStyle("-fx-font-weight: bold; -fx-font-size: 2em;");
+        if (!comboBox.isVisible()) {
+            Label la = new Label(comboBox.getValue().toString());
+            la.setStyle("-fx-font-weight: bold; -fx-font-size: 2em;");
+            gp.add(la, j, k++, 2, 1);
+        } else {
+            gp.add(comboBox, j, k++, 2, 1);
+        }
+
+        // Show author information.
+        Collection<? extends Responsibility> contacts = this.METADATA.getContacts();
+        if (!contacts.isEmpty()) {
+            Responsibility contact = contacts.iterator().next();
+            Collection<? extends Party> parties = contact.getParties();
+            if (!parties.isEmpty()) {
+                Party party = parties.iterator().next();
+                if (party.getName() != null) {
+                    Label partyType = new Label("Party");
+                    Label partyValue = new Label(party.getName().toString());
+                    if (party instanceof DefaultOrganisation) {
+                        partyType.setText("Organisation");
+                    } else if (party instanceof DefaultIndividual) {
+                        partyType.setText("Author");
+                    }
+                    gp.add(partyType, j, k);
+                    gp.add(partyValue, ++j, k++);
+                    j = 0;
+                }
+            }
+        }
+
+        GridPane gpi = new GridPane();
+        gpi.setHgap(10.00);
+
+        comboBox.setOnAction(e -> {
+            gpi.getChildren().clear();
+            Identification id = m.get(comboBox.getValue().toString());
+
+            if (comboBox.getValue().toString().equals("No data to show")) {
+                return;
+            }
+
+            // Show the abstract or the credit, the topic category, the creation date, the
type of data, the representation system info and also the geographical area.
+            Object ab = id.getAbstract();
+            if (ab != null) {
+                InternationalString abs = (InternationalString) ab;
+                Label crd = new Label("Abstract");
+                Label crdValue = new Label(abs.toString(LOCALE));
+                gpi.add(crd, 0, 1);
+                gpi.add(crdValue, 1, 1);
+            } else {
+                Collection<? extends InternationalString> credits = id.getCredits();
+                if (!credits.isEmpty()) {
+                    InternationalString credit = credits.iterator().next();
+                    Label crd = new Label("Credit");
+                    Label crdValue = new Label(credit.toString());
+                    gpi.add(crd, 0, 1);
+                    gpi.add(crdValue, 1, 1);
+                }
+            }
+
+            Collection<TopicCategory> tcs = id.getTopicCategories();
+            if (!tcs.isEmpty()) {
+                TopicCategory tc = tcs.iterator().next();
+                Label topicC = new Label("Topic Category");
+                Label topicValue = new Label(tc.toString());
+                gpi.add(topicC, 0, 2);
+                gpi.add(topicValue, 1, 2);
+            }
+
+            if (!id.getCitation().getDates().isEmpty()) {
+                CitationDate dateAndType = id.getCitation().getDates().iterator().next();
+                DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM,
LOCALE);
+                String dateStr = dateFormat.format(dateAndType.getDate());
+                String s = dateAndType.getDateType().toString();
+                s = s.replace("DateType[", "");
+                s = s.replace("]", "");
+                Label dt = new Label("Date type: " + s.toLowerCase());
+                Label dtValue = new Label(dateStr);
+                gpi.add(dt, 0, 3);
+                gpi.add(dtValue, 1, 3);
+            }
+
+            if (id instanceof DataIdentification) {
+                Label topicC = new Label("Object type");
+                Label topicValue = new Label("Data");
+                gpi.add(topicC, 0, 4);
+                gpi.add(topicValue, 1, 4);
+            } else {
+                Label topicC = new Label("Object type");
+                Label topicValue = new Label("Service");
+                gpi.add(topicC, 0, 4);
+                gpi.add(topicValue, 1, 4);
+            }
+
+            Collection<SpatialRepresentationType> spatialRepresentationTypes = id.getSpatialRepresentationTypes();
+            Iterator<SpatialRepresentationType> its = spatialRepresentationTypes.iterator();
+            String typeList = "Spatial representation type: ";
+            while (its.hasNext()) {
+                SpatialRepresentationType spatialRepresentationType = its.next();
+                typeList += spatialRepresentationType.toString().toLowerCase(LOCALE).replace("spatialrepresentationtype[",
"").replace(']', '\0') + ", ";
+            }
+            if (!typeList.equals("Spatial representation type: ")) {
+                Label list = new Label(typeList.substring(0, typeList.length() - 2));
+                gpi.add(list, 0, 5, 2, 1);
+            }
+
+            Collection<? extends Extent> exs = id.getExtents();
+            if (!exs.isEmpty()) {
+                Extent ex = exs.iterator().next();
+                Collection<? extends GeographicExtent> ges = ex.getGeographicElements();
+                Iterator<? extends GeographicExtent> it = ges.iterator();
+                while (it.hasNext()) {
+                    GeographicExtent ge = it.next();
+                    Label geoEx = new Label("Zone");
+                    Label geoExValue = new Label(ge.toString());
+                    if (ge instanceof GeographicBoundingBox) {
+                        geoEx.setText("");
+                        GeographicBoundingBox gbd = (GeographicBoundingBox) ge;
+                        geoExValue.setText("");
+                        Canvas c = createMap(gbd.getNorthBoundLatitude(), gbd.getEastBoundLongitude(),
gbd.getSouthBoundLatitude(), gbd.getWestBoundLongitude());
+                        if (c != null) {
+                            gpi.add(c, 0, 6, 2, 1);
+                        } else {
+                            geoEx.setText("Impossible to load the map.");
+                            gpi.add(geoEx, 0, 6);
+                            gpi.add(geoExValue, 1, 6);
+                        }
+                    } else if (ge instanceof GeographicDescription) {
+                        geoEx.setText("Geographic description");
+                        GeographicDescription gd = (GeographicDescription) ge;
+                        geoExValue.setText(gd.getGeographicIdentifier().getCode());
+                    }
+                }
+            }
+
+        });
+
+        Event.fireEvent(comboBox, new Event(ACTION));
+        gp.add(gpi, j, k++, 2, 1);
+
+        int ind = 0;
+        for (Node n : gp.getChildren()) {
+            if (ind++ != 0) {
+                n.setStyle("-fx-padding: 0 83 10 0;");
+            } else {
+                n.setStyle("-fx-padding: 0 0 10 0; -fx-font-weight: bold; -fx-font-size:
2em;");
+            }
+        }
+
+        for (Node n : gpi.getChildren()) {
+            n.setStyle("-fx-padding: 0 0 10 0;");
+        }
+
+        return gp;
+    }
+
+    private Canvas createMap(double north, double east, double south, double west) {
+        Canvas can = new Canvas();
+        final File file = new File("/home/admin/Documents/WorldMap360*180.png");
+        Image image;
+        String localUrl;
+        try {
+            localUrl = file.toURI().toURL().toString();
+            image = new Image(localUrl);
+        } catch (MalformedURLException ex) {
+            Logger.getLogger(MetadataOverview.class.getName()).log(Level.SEVERE, null, ex);
+            return null;
+        }
+        if (image.errorProperty().getValue()) {
+            return null;
+        }
+
+        double height = image.getHeight();
+        double width = image.getWidth();
+
+        can.setHeight(height);
+        can.setWidth(width);
+        can.getGraphicsContext2D().drawImage(image, 0, 0, width, height);
+        can.getGraphicsContext2D().setStroke(Color.DARKBLUE);
+        can.getGraphicsContext2D().setGlobalAlpha(0.1);
+        double x = west + width / 2, y = height / 2 - north, w = east - west, h = north -
south;
+        can.getGraphicsContext2D().strokeRect(x, y, w, h);
+        final double minRectSize = 6.0;
+        if (w < minRectSize) {
+            double difX = minRectSize - w;
+            x -= difX / 2;
+            w = minRectSize;
+        }
+        if (h < minRectSize) {
+            double difY = minRectSize - h;
+            y -= difY / 2;
+            h = minRectSize;
+        }
+        can.getGraphicsContext2D().fillRect(x, y, w, h);
+        can.getGraphicsContext2D().setGlobalAlpha(1.0);
+        can.getGraphicsContext2D().setStroke(Color.DARKBLUE);
+        can.getGraphicsContext2D().strokeRect(x, y, w, h);
+
+        return can;
+    }
+
+    private GridPane createSpatialGridPane() {
+        GridPane gp = new GridPane();
+        gp.setHgap(10.00);
+        gp.setVgap(10.00);
+        int j = 0, k = 1;
+
+        Collection<? extends ReferenceSystem> referenceSystemInfos = METADATA.getReferenceSystemInfo();
+        if (!referenceSystemInfos.isEmpty()) {
+            ReferenceSystem referenceSystemInfo = referenceSystemInfos.iterator().next();
+            Label rsiValue = new Label("Reference system infos: " + referenceSystemInfo.getName().toString());
+            gp.add(rsiValue, j, k++);
+        }
+
+        Collection<? extends SpatialRepresentation> sris = this.METADATA.getSpatialRepresentationInfo();
+        if (sris.isEmpty()) {
+            Label noData = new Label("No data found.");
+            noData.setStyle("-fx-text-fill: red;");
+            gp.add(noData, ++j, k++, 2, 1);
+            return gp;
+        }
+        NumberFormat numberFormat = getIntegerInstance(LOCALE);
+        for (SpatialRepresentation sri : sris) {
+            String currentValue = "• ";
+            if (sri instanceof DefaultGridSpatialRepresentation) {
+                DefaultGridSpatialRepresentation sr = (DefaultGridSpatialRepresentation)
sri;
+
+                Iterator<? extends Dimension> it = sr.getAxisDimensionProperties().iterator();
+                while (it.hasNext()) {
+                    Dimension dim = it.next();
+                    currentValue += numberFormat.format(dim.getDimensionSize()) + " " + getCodeTitle(dim.getDimensionName())
+ " * ";
+                }
+                currentValue = currentValue.substring(0, currentValue.length() - 3);
+                Label spRep = new Label(currentValue);
+                gp.add(spRep, j, k++, 2, 1);
+                if (sr.getCellGeometry() != null) {
+                    Label cellGeo = new Label("Cell geometry:");
+                    Label cellGeoValue = new Label(getCodeTitle(sr.getCellGeometry()).toString());
+                    gp.add(cellGeo, j, k);
+                    gp.add(cellGeoValue, ++j, k++);
+                    j = 0;
+                }
+            }
+        }
+        return gp;
+    }
+
+    private ComboBox createComboBox(HashMap<String, Identification> m) {
+        ComboBox cb = new ComboBox();
+        Collection<? extends Identification> ids = this.METADATA.getIdentificationInfo();
+        ObservableList<String> options = FXCollections.observableArrayList();
+        int i = 1;
+        if (ids.size() > 1) {
+            for (Identification id : ids) {
+                String currentName;
+                if (id.getCitation() != null) {
+                    currentName = id.getCitation().getTitle().toString();
+                } else {
+                    currentName = Integer.toString(i);
+                }
+                options.add(currentName);
+                m.put(currentName, id);
+            }
+            cb.setItems(options);
+            cb.setValue(ids.iterator().next().getCitation().getTitle().toString());
+        } else if (ids.size() == 1) {
+            if (ids.iterator().next().getCitation() != null) {
+                m.put(ids.iterator().next().getCitation().getTitle().toString(), ids.iterator().next());
+                cb.setValue(ids.iterator().next().getCitation().getTitle().toString());
+                cb.setVisible(false);
+            }
+        } else {
+            cb.setValue("No data to show");
+            cb.setVisible(false);
+        }
+        return cb;
+    }
+
+    public final String getFromFile() {
+        return FROMFILE;
+    }
+
+}

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataOverview.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java?rev=1832316&view=auto
==============================================================================
--- sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
(added)
+++ sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
[UTF-8] Sat May 26 16:23:25 2018
@@ -0,0 +1,282 @@
+/*
+ * 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.metadata;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javafx.event.Event;
+import javafx.scene.control.Alert;
+import javafx.scene.control.ContextMenu;
+import javafx.scene.control.Label;
+import javafx.scene.control.MenuItem;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeView;
+import javafx.scene.input.DataFormat;
+import javafx.scene.input.Dragboard;
+import javafx.scene.input.MouseButton;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.input.TransferMode;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
+import org.apache.sis.internal.storage.folder.FolderStoreProvider;
+import org.apache.sis.metadata.iso.DefaultMetadata;
+import org.apache.sis.storage.Aggregate;
+import org.apache.sis.storage.DataStore;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.storage.DataStores;
+import org.apache.sis.storage.Resource;
+import org.apache.sis.storage.StorageConnector;
+
+
+/**
+ * Show resources available in data files.
+ *
+ * @author Smaniotto Enzo
+ */
+public class ResourceView {
+
+    private final TreeItem<Label> root = new TreeItem<>(new Label("Files"));
+    private final TreeView<Label> resources = new TreeView<>(root);
+    public final BorderPane pane = new BorderPane();
+    private final Map<Label, TreeItem<?>> labelToItem = new HashMap<>();
+
+    // TODO: What is that?
+    private final List<String> LABINTRV = new ArrayList<>();
+
+    private Label sauvLabel, parent;
+
+    public ResourceView() {
+        pane.setStyle("-fx-background-color: linear-gradient(to bottom right, #aeb7c4, #fafafa);");
+        final VBox dragTarget = new VBox();
+
+        root.setExpanded(true);
+        resources.setStyle("-fx-background-color: rgba(77, 201, 68, 0.4);");
+        resources.setShowRoot(false);
+
+        resources.setOnDragOver(event -> {
+            if (event.getGestureSource() != dragTarget && event.getDragboard().hasFiles())
{
+                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
+            }
+            event.consume();
+        });
+        resources.setOnDragDropped(event -> {
+            Dragboard db = event.getDragboard();
+            boolean success = false;
+
+            File firstFile = db.getFiles().get(0);
+            if (firstFile.isDirectory()) {
+                openDirectory(firstFile);
+                success = true;
+            } else {
+                if (db.hasFiles()) {
+                    success = true;
+                }
+                List<?> fileList = (List<?>) db.getContent(DataFormat.FILES);
+                for (Object item : fileList) {
+                    File f = (File) item;
+                    openFile(f);
+                }
+            }
+            event.setDropCompleted(success);
+            event.consume();
+        });
+
+        pane.setLeft(resources);
+        pane.setCenter(null);
+    }
+
+    private void addContextMenu(Label lab) {
+        MenuItem close = new MenuItem("Close");
+        close.setOnAction(ac -> {
+            root.getChildren().remove(labelToItem.get(lab));
+            labelToItem.remove(lab);
+            LABINTRV.remove(lab.getId());
+            if (pane.getCenter() != null) {
+                if (lab.getId().equals(((MetadataOverview) pane.getCenter()).getFromFile()))
{
+                    pane.setCenter(null);
+                }
+            }
+        });
+        ContextMenu cm = new ContextMenu(close);
+        lab.setContextMenu(cm);
+    }
+
+    private void setOnClick(Label lab) {
+        addContextMenu(lab);
+        lab.setOnMouseClicked(click -> {
+            if (click.getButton() == MouseButton.PRIMARY) {
+                if (sauvLabel != null) {
+                    sauvLabel.setTextFill(Color.BLACK);
+                }
+                addMetadatPanel(lab.getId());
+                sauvLabel = lab;
+                lab.setTextFill(Color.RED);
+            }
+        });
+    }
+
+    private boolean checkMetaPanel(String filePath) {
+        MetadataOverview meta;
+        try {
+            DataStore ds = DataStores.open(filePath);
+            meta = new MetadataOverview(new DefaultMetadata(ds.getMetadata()), filePath);
+            return true;
+        } catch (DataStoreException e) {
+            final Alert alert = new Alert(Alert.AlertType.ERROR);
+            alert.setTitle("An error was occur");
+            Label lab = new Label(e.getMessage());
+            lab.setWrapText(true);
+            lab.setMaxWidth(650);
+            VBox vb = new VBox();
+            vb.getChildren().add(lab);
+            alert.getDialogPane().setContent(vb);
+            alert.show();
+            return false;
+        }
+    }
+
+    private void addMetadatPanel(String filePath) {
+        MetadataOverview meta;
+        try {
+            DataStore ds = DataStores.open(filePath);
+            meta = new MetadataOverview(new DefaultMetadata(ds.getMetadata()), filePath);
+            pane.setCenter(meta);
+        } catch (DataStoreException e) {
+            final Alert alert = new Alert(Alert.AlertType.ERROR);
+            alert.setTitle("An error was occur");
+            Label lab = new Label(e.getMessage());
+            lab.setWrapText(true);
+            lab.setMaxWidth(650);
+            VBox vb = new VBox();
+            vb.getChildren().add(lab);
+            alert.getDialogPane().setContent(vb);
+            alert.show();
+        }
+    }
+
+    private void addMetadatPanel(Resource res, String filePath) {
+        MetadataOverview meta;
+        try {
+            meta = new MetadataOverview(((DefaultMetadata) res.getMetadata()), filePath);
+            pane.setCenter(meta);
+        } catch (DataStoreException e) {
+            final Alert alert = new Alert(Alert.AlertType.ERROR);
+            alert.setTitle("An error was occur");
+            Label lab = new Label(e.getMessage());
+            lab.setWrapText(true);
+            lab.setMaxWidth(650);
+            VBox vb = new VBox();
+            vb.getChildren().add(lab);
+            alert.getDialogPane().setContent(vb);
+            alert.show();
+        }
+    }
+
+    public void openFile(File f) {
+        if (checkMetaPanel(f.getAbsolutePath())) {
+            Label label = new Label(f.getName());
+            label.setId(f.getAbsolutePath());
+            if (LABINTRV.contains(f.getAbsolutePath())) {
+                for (Label elem : labelToItem.keySet()) {
+                    if (elem.getId().equals(f.getAbsolutePath())) {
+                        Event.fireEvent(elem, new MouseEvent(MouseEvent.MOUSE_CLICKED, 0,
0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true, true, true, true, true, true, true,
null));
+                    }
+                }
+            } else {
+                setOnClick(label);
+                TreeItem<Label> tItem = new TreeItem<>(label);
+                labelToItem.put(label, tItem);
+                LABINTRV.add(f.getAbsolutePath());
+                root.getChildren().add(tItem);
+            }
+        }
+    }
+
+    public void openDirectory(File firstFile) {
+        if (!LABINTRV.contains("[Aggregate] " + firstFile.getName())) {
+            DataStore resource = null;
+            try {
+                resource = FolderStoreProvider.INSTANCE.open(new StorageConnector(firstFile));
+            } catch (DataStoreException ex) {
+                ex.getMessage();
+            }
+            if (resource instanceof Aggregate) {
+                parent = new Label("[Aggregate] " + firstFile.getName());
+                parent.setId(firstFile.getAbsolutePath());
+                Label cl = parent;
+                parent.setOnMouseClicked(click -> {
+                    if (click.getButton() == MouseButton.SECONDARY) {
+                        parent = cl;
+                    }
+                });
+                TreeItem<Label> ti = new TreeItem<>(parent);
+
+                MenuItem close = new MenuItem("Close");
+                close.setOnAction(ac -> {
+                    root.getChildren().remove(labelToItem.get(cl));
+                    labelToItem.remove(cl);
+                    LABINTRV.remove(parent.getText());
+                    if (pane.getCenter() != null) {
+                        if (parent.getId().equals(((MetadataOverview) pane.getCenter()).getFromFile()))
{
+                            pane.setCenter(null);
+                        }
+                    }
+                });
+                ContextMenu cm = new ContextMenu(close);
+                parent.setContextMenu(cm);
+
+                try {
+                    for (Resource res : ((Aggregate) resource).components()) {
+                        Label lab = new Label(res.toString());
+                        lab.setOnMouseClicked(click -> {
+                            if (click.getButton() == MouseButton.PRIMARY) {
+                                if (sauvLabel != null) {
+                                    sauvLabel.setTextFill(Color.BLACK);
+                                }
+                                addMetadatPanel(res, cl.getId());
+                                sauvLabel = lab;
+                                lab.setTextFill(Color.RED);
+                            }
+                        });
+                        TreeItem<Label> tiChild = new TreeItem<>(lab);
+                        ti.getChildren().add(tiChild);
+                    }
+                } catch (DataStoreException ex) {
+                    System.out.println(ex.getMessage());        // TODO: NO!!!!!
+                }
+                root.getChildren().add(ti);
+                LABINTRV.add(parent.getText());
+                labelToItem.put(parent, ti);
+            }
+        } else { // If the file is already open.
+            if (sauvLabel != null) {
+                sauvLabel.setTextFill(Color.BLACK);
+            }
+            root.getChildren().forEach(elem -> {
+                if (elem.getValue().getText().equals("[Aggregate] " + firstFile.getName()))
{
+                    sauvLabel = elem.getValue();
+                    elem.getValue().setTextFill(Color.RED);
+                }
+            });
+            pane.setCenter(null);
+        }
+    }
+}

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/ResourceView.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message