All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.gsi.chart.plugins.measurements.utils.DataSetSelector Maven / Gradle / Ivy

Go to download

This charting library ${project.artifactId}- is an extension in the spirit of Oracle's XYChart and performance/time-proven JDataViewer charting functionalities. Emphasis was put on plotting performance for both large number of data points and real-time displays, as well as scientific accuracies leading to error bar/surface plots, and other scientific plotting features (parameter measurements, fitting, multiple axes, zoom, ...).

There is a newer version: 11.2.7
Show newest version
package de.gsi.chart.plugins.measurements.utils;

import de.gsi.chart.XYChart;
import de.gsi.dataset.DataSet;
import javafx.collections.ObservableList;
import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;

/**
 * @author rstein
 */
public class DataSetSelector extends HBox {
    private static final int DEFAULT_SELECTOR_HEIGHT = 50;
    protected final ListView dataSets;
    protected final ObservableList allDataSets;

    public DataSetSelector(final XYChart chart) {
        super();
        final Label label = new Label("Selected Dataset:");

        allDataSets = chart.getAllDatasets();
        dataSets = new ListView<>(allDataSets);
        dataSets.setOrientation(Orientation.VERTICAL);
        dataSets.setPrefSize(-1, DataSetSelector.DEFAULT_SELECTOR_HEIGHT);
        if (!allDataSets.isEmpty()) {
            dataSets.getSelectionModel().select(0);
        }

        dataSets.setCellFactory(list -> new DataSetLabel());

        getChildren().addAll(label, dataSets);
    }

    static protected class DataSetLabel extends ListCell {
        @Override
        public void updateItem(final DataSet item, final boolean empty) {
            super.updateItem(item, empty);
            if (item != null) {
                setText(item.getName());
            }
        }
    }

    public int getNumberDataSets() {
        return allDataSets.size();
    }

    public DataSet getSelectedDataSet() {
        return dataSets.getSelectionModel().getSelectedItem();
    }

    // protected final ObservableList getAllDataSets(final XYChartPane chartPane) {
    // final ObservableList allDataSets = FXCollections.observableArrayList();
    // allDataSets.addAll(chartPane.getChart().getAllDatasets());
    // final ObservableList a = chartPane.getOverlayCharts();
    // for (final XYChart chart : a) {
    // allDataSets.addAll(chart.getAllDatasets());
    // }
    //
    // return allDataSets;
    // }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy