Search in sources :

Example 1 with ImageRequest

use of org.apache.sis.gui.coverage.ImageRequest in project sis by apache.

the class ResourceExplorer method updateDataTab.

/**
 * Assigns the given resource into the {@link #viewTab} or {@link #tableTab}, depending which one is visible.
 * Shall be invoked with a non-null resource only if a data tab is visible because data loading may be costly.
 *
 * @param  resource  the resource to set, or {@code null} if none.
 * @return {@code true} if the resource has been recognized.
 *
 * @see #dataShown
 * @see #updateDataTabWithDefault(Resource)
 */
private boolean updateDataTab(final Resource resource) {
    Region image = null;
    Region table = null;
    FeatureSet data = null;
    ImageRequest grid = null;
    TitledPane[] cpanes = null;
    final CoverageExplorer.View type = getCoverageView();
    if (resource instanceof GridCoverageResource) {
        // A null `type` value here would be a violation of method contract.
        if (coverage == null) {
            coverage = new CoverageExplorer(type);
        } else {
            coverage.setViewType(type);
        }
        final Region view = coverage.getDataView(type);
        switch(type) {
            case IMAGE:
                image = view;
                break;
            case TABLE:
                table = view;
                break;
        }
        grid = new ImageRequest((GridCoverageResource) resource, null, null);
        cpanes = coverage.getControls(type);
    } else if (resource instanceof FeatureSet) {
        data = (FeatureSet) resource;
        if (features == null) {
            features = new FeatureTable();
        }
        table = features;
    }
    /*
         * At least one of `grid` or `data` will be null. Invoking the following
         * setter methods with a null argument will release memory.
         */
    if (coverage != null)
        coverage.setCoverage(grid);
    if (features != null)
        features.setFeatures(data);
    if (image != null)
        viewTab.setContent(image);
    if (table != null)
        tableTab.setContent(table);
    final boolean isEmpty = (image == null & table == null);
    setNewWindowDisabled(isEmpty);
    /*
         * Add or remove controls for the selected view.
         * Information about the expanded pane needs to be saved before to remove controls,
         * and restored (for a potentially different view) after new controls have been added.
         */
    TitledPane expanded = controls.getExpandedPane();
    if (expanded != null && coverageView != null) {
        expandedPane.put(coverageView, expanded);
    }
    final ObservableList<TitledPane> items = controls.getPanes();
    final int size = items.size();
    items.remove(1, size);
    if (cpanes != null) {
        items.addAll(cpanes);
        if (!items.contains(expanded)) {
            expanded = expandedPane.get(type);
            if (expanded != null) {
                controls.setExpandedPane(expanded);
            }
        }
    }
    coverageView = type;
    return !isEmpty | (resource == null);
}
Also used : TitledPane(javafx.scene.control.TitledPane) ImageRequest(org.apache.sis.gui.coverage.ImageRequest) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) Region(javafx.scene.layout.Region) CoverageExplorer(org.apache.sis.gui.coverage.CoverageExplorer) FeatureSet(org.apache.sis.storage.FeatureSet)

Aggregations

TitledPane (javafx.scene.control.TitledPane)1 Region (javafx.scene.layout.Region)1 CoverageExplorer (org.apache.sis.gui.coverage.CoverageExplorer)1 ImageRequest (org.apache.sis.gui.coverage.ImageRequest)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1