Search in sources :

Example 1 with ColorTableCell

use of eu.fthevenet.util.javafx.controls.ColorTableCell in project selenium_java by sergueik.

the class WorksheetController method initTableViewPane.

private void initTableViewPane() {
    for (ChartViewPort<Double> currentViewPort : viewPorts) {
        currentViewPort.getSeriesTable().getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        CheckBox showAllCheckBox = new CheckBox();
        TableColumn<TimeSeriesInfo<Double>, Boolean> visibleColumn = new TableColumn<>();
        visibleColumn.setGraphic(showAllCheckBox);
        visibleColumn.setSortable(false);
        visibleColumn.setResizable(false);
        visibleColumn.setPrefWidth(32);
        InvalidationListener isVisibleListener = (observable) -> {
            boolean andAll = true;
            boolean orAll = false;
            for (TimeSeriesInfo<?> t : currentViewPort.getDataStore().getSeries()) {
                andAll &= t.isSelected();
                orAll |= t.isSelected();
            }
            showAllCheckBox.setIndeterminate(Boolean.logicalXor(andAll, orAll));
            showAllCheckBox.setSelected(andAll);
        };
        ChangeListener<Boolean> refreshListener = (observable, oldValue, newValue) -> {
            if (worksheet.getChartLayout() == ChartLayout.OVERLAID) {
                invalidateAll(false, false, false);
            } else {
                invalidate(currentViewPort, false, false);
            }
        };
        currentViewPort.getDataStore().getSeries().forEach(doubleTimeSeriesInfo -> {
            bindingManager.attachListener(doubleTimeSeriesInfo.selectedProperty(), refreshListener);
            bindingManager.attachListener(doubleTimeSeriesInfo.selectedProperty(), isVisibleListener);
            // Explicitly call the listener to initialize the proper status of the checkbox
            isVisibleListener.invalidated(null);
        });
        visibleColumn.setCellValueFactory(p -> p.getValue().selectedProperty());
        visibleColumn.setCellFactory(CheckBoxTableCell.forTableColumn(visibleColumn));
        showAllCheckBox.setOnAction(event -> {
            ChangeListener<Boolean> r = (observable, oldValue, newValue) -> {
                if (worksheet.getChartLayout() == ChartLayout.OVERLAID) {
                    invalidateAll(false, false, false);
                } else {
                    invalidate(currentViewPort, false, false);
                }
            };
            boolean b = ((CheckBox) event.getSource()).isSelected();
            currentViewPort.getDataStore().getSeries().forEach(s -> bindingManager.detachAllChangeListeners(s.selectedProperty()));
            currentViewPort.getDataStore().getSeries().forEach(t -> t.setSelected(b));
            r.changed(null, null, null);
            currentViewPort.getDataStore().getSeries().forEach(s -> bindingManager.attachListener(s.selectedProperty(), r));
        });
        DecimalFormatTableCellFactory<TimeSeriesInfo<Double>, String> alignRightCellFactory = new DecimalFormatTableCellFactory<>();
        alignRightCellFactory.setAlignment(TextAlignment.RIGHT);
        TableColumn<TimeSeriesInfo<Double>, Color> colorColumn = new TableColumn<>();
        colorColumn.setSortable(false);
        colorColumn.setResizable(false);
        colorColumn.setPrefWidth(32);
        TableColumn<TimeSeriesInfo<Double>, Boolean> nameColumn = new TableColumn<>("Name");
        nameColumn.setSortable(false);
        nameColumn.setPrefWidth(160);
        nameColumn.setCellValueFactory(new PropertyValueFactory<>("displayName"));
        TableColumn<TimeSeriesInfo<Double>, String> minColumn = new TableColumn<>("Min.");
        minColumn.setSortable(false);
        minColumn.setPrefWidth(75);
        minColumn.setCellFactory(alignRightCellFactory);
        TableColumn<TimeSeriesInfo<Double>, String> maxColumn = new TableColumn<>("Max.");
        maxColumn.setSortable(false);
        maxColumn.setPrefWidth(75);
        maxColumn.setCellFactory(alignRightCellFactory);
        TableColumn<TimeSeriesInfo<Double>, String> avgColumn = new TableColumn<>("Avg.");
        avgColumn.setSortable(false);
        avgColumn.setPrefWidth(75);
        avgColumn.setCellFactory(alignRightCellFactory);
        TableColumn<TimeSeriesInfo<Double>, String> currentColumn = new TableColumn<>("Current");
        currentColumn.setSortable(false);
        currentColumn.setPrefWidth(75);
        currentColumn.setCellFactory(alignRightCellFactory);
        currentColumn.getStyleClass().add("column-bold-text");
        TableColumn<TimeSeriesInfo<Double>, String> pathColumn = new TableColumn<>("Path");
        pathColumn.setSortable(false);
        pathColumn.setPrefWidth(400);
        currentColumn.setVisible(crossHair.isVerticalMarkerVisible());
        bindingManager.attachListener(crossHair.verticalMarkerVisibleProperty(), (ChangeListener<Boolean>) (observable, oldValue, newValue) -> currentColumn.setVisible(newValue));
        pathColumn.setCellValueFactory(p -> new SimpleStringProperty(p.getValue().getBinding().getTreeHierarchy()));
        colorColumn.setCellFactory(param -> new ColorTableCell<>(colorColumn));
        colorColumn.setCellValueFactory(p -> p.getValue().displayColorProperty());
        avgColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getAverageValue()), p.getValue().processorProperty()));
        minColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getMinValue()), p.getValue().processorProperty()));
        maxColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> p.getValue().getProcessor() == null ? "NaN" : currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().getMaxValue()), p.getValue().processorProperty()));
        currentColumn.setCellValueFactory(p -> Bindings.createStringBinding(() -> {
            if (p.getValue().getProcessor() == null) {
                return "NaN";
            }
            return currentViewPort.getPrefixFormatter().format(p.getValue().getProcessor().tryGetNearestValue(crossHair.getCurrentXValue()).orElse(Double.NaN));
        }, crossHair.currentXValueProperty()));
        currentViewPort.getSeriesTable().setRowFactory(this::seriesTableRowFactory);
        currentViewPort.getSeriesTable().setOnKeyReleased(event -> {
            if (event.getCode().equals(KeyCode.DELETE)) {
                removeSelectedBinding((TableView<TimeSeriesInfo<Double>>) event.getSource());
            }
        });
        currentViewPort.getSeriesTable().setItems(currentViewPort.getDataStore().getSeries());
        currentViewPort.getSeriesTable().getColumns().addAll(visibleColumn, colorColumn, nameColumn, minColumn, maxColumn, avgColumn, currentColumn, pathColumn);
        TitledPane newPane = new TitledPane(currentViewPort.getDataStore().getName(), currentViewPort.getSeriesTable());
        newPane.setOnDragOver(this::handleDragOverWorksheetView);
        newPane.setOnDragDropped(this::handleDragDroppedOnWorksheetView);
        newPane.setUserData(currentViewPort);
        GridPane titleRegion = new GridPane();
        titleRegion.setHgap(5);
        titleRegion.getColumnConstraints().add(new ColumnConstraints(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, Priority.ALWAYS, HPos.LEFT, true));
        titleRegion.getColumnConstraints().add(new ColumnConstraints(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, USE_COMPUTED_SIZE, Priority.NEVER, HPos.RIGHT, false));
        bindingManager.bind(titleRegion.minWidthProperty(), newPane.widthProperty().subtract(30));
        bindingManager.bind(titleRegion.maxWidthProperty(), newPane.widthProperty().subtract(30));
        Label label = new Label();
        bindingManager.bind(label.textProperty(), currentViewPort.getDataStore().nameProperty());
        bindingManager.bind(label.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty().not());
        HBox editFieldsGroup = new HBox();
        DoubleBinding db = Bindings.createDoubleBinding(() -> editFieldsGroup.isVisible() ? USE_COMPUTED_SIZE : 0.0, editFieldsGroup.visibleProperty());
        bindingManager.bind(editFieldsGroup.prefHeightProperty(), db);
        bindingManager.bind(editFieldsGroup.maxHeightProperty(), db);
        bindingManager.bind(editFieldsGroup.minHeightProperty(), db);
        bindingManager.bind(editFieldsGroup.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
        editFieldsGroup.setSpacing(5);
        TextField chartNameField = new TextField();
        chartNameField.textProperty().bindBidirectional(currentViewPort.getDataStore().nameProperty());
        TextField unitNameField = new TextField();
        unitNameField.textProperty().bindBidirectional(currentViewPort.getDataStore().unitProperty());
        ChoiceBox<UnitPrefixes> unitPrefixChoiceBox = new ChoiceBox<>();
        unitPrefixChoiceBox.getItems().setAll(UnitPrefixes.values());
        unitPrefixChoiceBox.getSelectionModel().select(currentViewPort.getDataStore().getUnitPrefixes());
        bindingManager.bind(currentViewPort.getDataStore().unitPrefixesProperty(), unitPrefixChoiceBox.getSelectionModel().selectedItemProperty());
        HBox.setHgrow(chartNameField, Priority.ALWAYS);
        titleRegion.setOnMouseClicked(event -> {
            if (event.getClickCount() == 2) {
                chartNameField.selectAll();
                chartNameField.requestFocus();
                currentViewPort.getDataStore().setShowProperties(true);
            }
        });
        editFieldsGroup.getChildren().addAll(chartNameField, unitNameField, unitPrefixChoiceBox);
        // *** Toolbar ***
        HBox toolbar = new HBox();
        toolbar.getStyleClass().add("title-pane-tool-bar");
        toolbar.setAlignment(Pos.CENTER);
        Button closeButton = (Button) newToolBarButton(Button::new, "Close", "Remove this chart from the worksheet.", new String[] { "exit" }, new String[] { "cross-icon", "small-icon" });
        closeButton.setOnAction(event -> {
            if (Dialogs.confirmDialog(root, "Are you sure you want to remove chart \"" + currentViewPort.getDataStore().getName() + "\"?", "", ButtonType.YES, ButtonType.NO) == ButtonType.YES) {
                worksheet.getCharts().remove(currentViewPort.getDataStore());
            }
        });
        bindingManager.bind(closeButton.disableProperty(), Bindings.createBooleanBinding(() -> worksheet.getCharts().size() > 1, worksheet.getCharts()).not());
        ToggleButton editButton = (ToggleButton) newToolBarButton(ToggleButton::new, "Settings", "Edit the chart's settings", new String[] { "dialog-button" }, new String[] { "settings-icon", "small-icon" });
        editButton.selectedProperty().bindBidirectional(currentViewPort.getDataStore().showPropertiesProperty());
        editButton.setOnAction(event -> newPane.setExpanded(true));
        editButtonsGroup.getToggles().add(editButton);
        Button moveUpButton = (Button) newToolBarButton(Button::new, "Up", "Move the chart up the list.", new String[] { "dialog-button" }, new String[] { "upArrow-icon", "small-icon" });
        bindingManager.bind(moveUpButton.disableProperty(), Bindings.createBooleanBinding(() -> seriesTableContainer.getPanes().indexOf(newPane) == 0, seriesTableContainer.getPanes()));
        bindingManager.bind(moveUpButton.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
        moveUpButton.setOnAction(event -> {
            int idx = worksheet.getCharts().indexOf(currentViewPort.getDataStore());
            this.preventReload = true;
            try {
                worksheet.getCharts().remove(currentViewPort.getDataStore());
            } finally {
                this.preventReload = false;
            }
            worksheet.getCharts().add(idx - 1, currentViewPort.getDataStore());
        });
        Button moveDownButton = (Button) newToolBarButton(Button::new, "Down", "Move the chart down the list.", new String[] { "dialog-button" }, new String[] { "downArrow-icon", "small-icon" });
        bindingManager.bind(moveDownButton.disableProperty(), Bindings.createBooleanBinding(() -> seriesTableContainer.getPanes().indexOf(newPane) >= seriesTableContainer.getPanes().size() - 1, seriesTableContainer.getPanes()));
        bindingManager.bind(moveDownButton.visibleProperty(), currentViewPort.getDataStore().showPropertiesProperty());
        moveDownButton.setOnAction(event -> {
            int idx = worksheet.getCharts().indexOf(currentViewPort.getDataStore());
            this.preventReload = true;
            try {
                worksheet.getCharts().remove(currentViewPort.getDataStore());
            } finally {
                this.preventReload = false;
            }
            worksheet.getCharts().add(idx + 1, currentViewPort.getDataStore());
        });
        toolbar.getChildren().addAll(moveUpButton, moveDownButton, editButton, closeButton);
        titleRegion.getChildren().addAll(label, editFieldsGroup, toolbar);
        HBox hBox = new HBox();
        hBox.setAlignment(Pos.CENTER);
        GridPane.setConstraints(label, 0, 0, 1, 1, HPos.LEFT, VPos.CENTER);
        GridPane.setConstraints(toolbar, 1, 0, 1, 1, HPos.RIGHT, VPos.CENTER);
        newPane.setGraphic(titleRegion);
        newPane.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
        newPane.setAnimated(false);
        seriesTableContainer.getPanes().add(newPane);
    }
    Platform.runLater(() -> seriesTableContainer.getPanes().get(getWorksheet().getSelectedChart()).setExpanded(true));
    bindingManager.attachListener(seriesTableContainer.expandedPaneProperty(), (ObservableValue<? extends TitledPane> observable, TitledPane oldPane, TitledPane newPane) -> {
        Boolean expandRequiered = true;
        for (TitledPane pane : seriesTableContainer.getPanes()) {
            if (pane.isExpanded()) {
                expandRequiered = false;
            }
        }
        getAttachedViewport(newPane).ifPresent(nv -> {
            getWorksheet().setSelectedChart(viewPorts.indexOf(nv));
            if (editButtonsGroup.getSelectedToggle() != null) {
                nv.getDataStore().setShowProperties(true);
            }
        });
        if ((expandRequiered) && (oldPane != null)) {
            getWorksheet().setSelectedChart(seriesTableContainer.getPanes().indexOf(oldPane));
            Platform.runLater(() -> {
                seriesTableContainer.setExpandedPane(oldPane);
            });
        }
    });
}
Also used : TimeRangePicker(eu.fthevenet.util.javafx.controls.TimeRangePicker) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) BindingManager(eu.fthevenet.util.javafx.bindings.BindingManager) Initializable(javafx.fxml.Initializable) DoubleBinding(javafx.beans.binding.DoubleBinding) javafx.scene.layout(javafx.scene.layout) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) CacheHint(javafx.scene.CacheHint) javafx.scene.control(javafx.scene.control) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) Side(javafx.geometry.Side) InvalidationListener(javafx.beans.InvalidationListener) ColorTableCell(eu.fthevenet.util.javafx.controls.ColorTableCell) MaskerPane(org.controlsfx.control.MaskerPane) ListChangeListener(javafx.collections.ListChangeListener) ImageIO(javax.imageio.ImageIO) eu.fthevenet.binjr.data.workspace(eu.fthevenet.binjr.data.workspace) DelayedAction(eu.fthevenet.util.javafx.controls.DelayedAction) USE_COMPUTED_SIZE(javafx.scene.layout.Region.USE_COMPUTED_SIZE) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) ReadOnlyDoubleProperty(javafx.beans.property.ReadOnlyDoubleProperty) AsyncTaskManager(eu.fthevenet.binjr.data.async.AsyncTaskManager) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Duration(javafx.util.Duration) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) javafx.scene.chart(javafx.scene.chart) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) ObservableList(javafx.collections.ObservableList) Path(javafx.scene.shape.Path) Profiler(eu.fthevenet.util.logging.Profiler) java.util(java.util) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Bindings(javafx.beans.binding.Bindings) Function(java.util.function.Function) Supplier(java.util.function.Supplier) VPos(javafx.geometry.VPos) FXMLLoader(javafx.fxml.FXMLLoader) GlobalPreferences(eu.fthevenet.binjr.preferences.GlobalPreferences) TextAlignment(javafx.scene.text.TextAlignment) Chart(eu.fthevenet.binjr.data.workspace.Chart) DecimalFormatTableCellFactory(eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory) Color(javafx.scene.paint.Color) javafx.scene.input(javafx.scene.input) Node(javafx.scene.Node) Property(javafx.beans.property.Property) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) eu.fthevenet.util.javafx.charts(eu.fthevenet.util.javafx.charts) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) DateTimeFormatter(java.time.format.DateTimeFormatter) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) LogManager(org.apache.logging.log4j.LogManager) ObservableValue(javafx.beans.value.ObservableValue) DecimalFormatTableCellFactory(eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DoubleBinding(javafx.beans.binding.DoubleBinding) Color(javafx.scene.paint.Color) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) CacheHint(javafx.scene.CacheHint) InvalidationListener(javafx.beans.InvalidationListener)

Aggregations

DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)1 TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)1 AsyncTaskManager (eu.fthevenet.binjr.data.async.AsyncTaskManager)1 NoAdapterFoundException (eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException)1 eu.fthevenet.binjr.data.workspace (eu.fthevenet.binjr.data.workspace)1 Chart (eu.fthevenet.binjr.data.workspace.Chart)1 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)1 GlobalPreferences (eu.fthevenet.binjr.preferences.GlobalPreferences)1 BindingManager (eu.fthevenet.util.javafx.bindings.BindingManager)1 eu.fthevenet.util.javafx.charts (eu.fthevenet.util.javafx.charts)1 ColorTableCell (eu.fthevenet.util.javafx.controls.ColorTableCell)1 DecimalFormatTableCellFactory (eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory)1 DelayedAction (eu.fthevenet.util.javafx.controls.DelayedAction)1 TimeRangePicker (eu.fthevenet.util.javafx.controls.TimeRangePicker)1 Profiler (eu.fthevenet.util.logging.Profiler)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1